NO

Author Topic: Batch script tricks??  (Read 9076 times)

lvckyluke

  • Guest
Batch script tricks??
« on: August 30, 2006, 11:07:25 am »
Anyone who like to compile from command-line console, oftenly uses a batch script for any general purpose..

So, do you have any batch script tips/tricks?? please share to us..

--
[/code]

lvckyluke

  • Guest
Batch script tricks??
« Reply #1 on: August 30, 2006, 11:31:51 am »
i found many batch script example from Hutch MASM32 Projects and POASM Projects..

There are a script for setting path environent, without knowing/have to put the the path directory inside batch.. but the problem, the script don't work well..

coz the result like:
Quote

set PATH=
c:\Compiler\BIN";%PATH%
set INCLUDE=
c:\Compiler\INCLUDE;%INCLUDE%
set LIB=
c:\Compiler\LIB;%LIB%

and windows cannot recognize the directory if put after new-line.

so i make my own script for similar function.

it can be use for any assembler/compiler which use BIN,INCLUDE,and LIB path environment. the script "setenv.bat" can be place on parent compiler directory or BIN subdirectory..


setenv.bat / setenv.cmd
Code: [Select]

@echo off
echo Setting Environment script v1.0
echo Copyright(R), LvCKyLuKe 2006.
echo.

if "%1"=="/?" goto info

cd bin
cd ..\bin
if errorlevel 1 goto end

cd >path.txt
echo @echo off>setpath.bat
for /f %%i in (path.txt) do @echo set PATH=%%i;%PATH%;>>setpath.bat
cd ..\include
if errorlevel 1 goto end
cd >>..\bin\path.txt
for /f "skip=1" %%j in (..\bin\path.txt) do @echo set INCLUDE="%%j";%INCLUDE%;>>..\bin\setpath.bat
cd ..\lib
if errorlevel 1 goto end
cd >>..\bin\path.txt
for /f "skip=2" %%k in (..\bin\path.txt) do @echo set LIB="%%k";%LIB%;>>..\bin\setpath.bat
cd ..\bin
if "%1"=="/r" goto norun
call setpath.bat
echo Path Environment are set to:
type path.txt
echo.
:norun
del path.txt
if "%1"=="/d" del setpath.bat
cd ..
goto end

:info
echo usage: setenv [option]
echo. /d  Do not create batch output
echo. /r  Do not run batch
echo. /?  This information
echo.
:end




I also make a script with the "for" function, to convert PODUMP/DUMPBIN text output result to definition file.. but i will post it later, coz i have to go..
my girl already waiting for me :p

Offline DMac

  • Member
  • *
  • Posts: 255
Pelles Install builder batch file
« Reply #2 on: August 30, 2006, 05:29:20 pm »
Here is a Drag-n-drop batcher for Pelles install scripts that I put together.

If it can't execute POINST, then it searches for it so that you can modify the script with the correct path.

Code: [Select]


@ECHO OFF
:: MakeInstaller.bat

:: You should Set the paths here. Don't include final
:: backslash characters in paths. Also make sure you don't add
:: trailing [Space]s to end of SET lines by accident, or they are
:: included in the program paths, too)
 
SET POINSTPATH=C:\Program Files\PellesC\Bin

:: Based on dragged-n-drop file change to the current directory
%~d1
CD %~f1\..

:: Check for Executable paths set correctly
IF NOT EXIST "%POINSTPATH%\POINST.EXE" GOTO _INSTALL

:: Check for (Souce file).PIS parameter(s) passed
IF (%~nx1)==() GOTO USAGE
 
IF NOT EXIST %~nx1 GOTO USAGE

:: Run the installer build operation
ECHO.
ECHO Running Pelles install builder for %~nx1 script...
ECHO.
"%POINSTPATH%\poinst.exe" /CD /VERBOSE %~nx1"
ECHO.
ECHO  Finished!
ECHO.

GOTO EOF

:USAGE
ECHO.
ECHO  Usage:  MakeInstaller.bat, Drag and drop a Pelles Install Script (*.PIS)  
ECHO  on this batch file icon to create a Win32 application installer.
ECHO.
GOTO EOF

:_INSTALL
ECHO You must SET the variable POINSTPATH in this Batch file,
ECHO as detailed in the source code, so that it contains the
ECHO path to the POINST.EXE executable
ECHO.
ECHO The path to POINST.EXE is the part BEFORE \POINST.EXE in POINST.EXE filespec
ECHO (Note: Don't include a final backslash \ character in path)
ECHO Attempting to locate POINST.EXE on your C: drive...
DIR C:\POINST.EXE /s /b | find /i "POINST.EXE"
IF ERRORLEVEL 1 ECHO. Couldn't find POINST.EXE on C: drive
ECHO.

:EOF
PAUSE
@ECHO ON

No one cares how much you know,
until they know how much you care.

lvckyluke

  • Guest
Batch script tricks??
« Reply #3 on: August 30, 2006, 07:09:22 pm »
thanx..

example txt2def

Code: [Select]

@echo off
if "%1"=="" goto info
if "%2"=="" goto noutname
if not exist %1 goto ninput
setlocal
set e=.def
set f=for /f "tokens=
set g=delims=.,(;:) " %%i in (%1) do @
set o=%2%e%

echo LIBRARY %2>%o%
echo EXPORTS>>%o%
if "%3"=="/l" goto libdmp
if "%3"=="/d" goto dlldmp
goto info

:libdmp
%f%4 skip=4 %g% echo "%%i">>%o%
goto endl

:dlldmp
%f%4 skip=15 %g% echo "%%i">>%o%
:endl
endlocal
goto end

:ninput
echo Error! input file not exist.
goto errend
:noutname
echo Error! specify output name.
:errend
echo.

:info
echo Text2Def Script v1.0 for PODUMP
echo Copyright(C), LvCKyLuKe 2006.
echo.
echo. usage: txt2def inputfile outname [switch]
echo. /d  text input is PODUMP DLL exports output
echo. /l  text input is PODUMP LIB exports/imports output
echo. ** outname is library name without extension
echo.

:end


batch, examples and notes are attached..

Synfire

  • Guest
Batch script tricks??
« Reply #4 on: August 30, 2006, 08:35:04 pm »
Here is how my source code looks in PoASM. I actually create my source files as Batch scripts, this allows me to use Right Click -> Edit to modify my source, and Double Click to build my source.

Code: [Select]

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; @echo off
; set Project=FileName
; set BinPath=E:\DEVELOPMENT\PELLESC\BIN
; set LibPath=E:\DEVELOPMENT\PELLESC\LIB\WIN
; set IncPath=E:\DEVELOPMENT\PELLESC\INCLUDE\WIN\ASM
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; set Libraries=kernel32.lib user32.lib
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; set AS=poasm.exe
; set LD=polink.exe
; set ASFLAGS=/AIA32 /Gz
; set LDFLAGS=/machine:ix86 /subsystem:windows
; goto BuildProject
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
.486
.MODEL FLAT, STDCALL
OPTION CASEMAP: NONE
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; [Project Title] - Copyright (c) [Author], [Year]
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
INCLUDE WINDOWS.INC
INCLUDE KERNEL32.INC
INCLUDE USER32.INC
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
WinMain PROTO :DWORD, :DWORD, :DWORD, :DWORD
WndProc PROTO :DWORD, :DWORD, :DWORD, :DWORD
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
.DATA
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ProjectClass DB "Project$Class", 0
ProjectTitle DB "Project Title", 0
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
.DATA?
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
g_hWindow DD ?
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
.CODE
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Project:
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
push SW_SHOWNORMAL
call GetCommandLine
push EAX
push NULL
push NULL
call GetModuleHandle
push EAX
call WinMain
push EAX
call ExitProcess
ret
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
WinMain PROC hInstance:DWORD, hPrevInstance:DWORD, lpszCmdLn:DWORD, dwShow:DWORD
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
LOCAL WndCls:WNDCLASSEX
LOCAL Message:MSG
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
mov WndCls.cbSize, SIZEOF WNDCLASSEX
mov WndCls.style, CS_HREDRAW + CS_VREDRAW
mov WndCls.lpfnWndProc, OFFSET WndProc
mov WndCls.cbClsExtra, NULL
mov WndCls.cbWndExtra, NULL
push hInstance
pop WndCls.hInstance
INVOKE LoadIcon, NULL, IDI_APPLICATION
mov WndCls.hIcon, EAX
mov WndCls.hIconSm, EAX
INVOKE LoadCursor, NULL, IDC_ARROW
mov WndCls.hCursor, EAX
mov WndCls.hbrBackground, COLOR_BTNFACE + 1
mov WndCls.lpszMenuName, NULL
mov WndCls.lpszClassName, OFFSET ProjectClass
INVOKE RegisterClassEx, ADDR WndCls

INVOKE CreateWindowEx, WS_EX_OVERLAPPEDWINDOW, ADDR ProjectClass, ADDR ProjectTitle, \
WS_OVERLAPPEDWINDOW + WS_VISIBLE, \
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,\
NULL, NULL, hInstance, NULL

cmp EAX, 0
jne @$CWEX_SUCCESS
mov EAX, -1
ret
@$CWEX_SUCCESS:
mov g_hWindow, EAX

INVOKE ShowWindow, g_hWindow, dwShow
INVOKE UpdateWindow, g_hWindow

INVOKE GetMessage, ADDR Message, NULL, FALSE, FALSE
@$MessageLoop:
INVOKE TranslateMessage, ADDR Message
INVOKE DispatchMessage, ADDR Message
INVOKE GetMessage, ADDR Message, NULL, FALSE, FALSE
cmp EAX, 0
jne @$MessageLoop

mov EAX, Message.wParam
ret
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
WinMain ENDP
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
WndProc PROC hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
mov EAX, uMsg
cmp EAX, WM_DESTROY
jne @$DEFAULT
INVOKE PostQuitMessage, NULL
jmp @$EXIT
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@$DEFAULT:
INVOKE DefWindowProc, hWnd, uMsg, wParam, lParam
@$EXIT:
ret
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
WndProc ENDP
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
END Project
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; :BuildProject
; %BinPath%\%AS% %ASFLAGS% /I%IncPath% "%Project%.bat"
; if exist "%Project%.obj" %BinPath%\%LD% %LDFLAGS% /LIBPATH:%LibPath% "%Project%.obj" %Libraries%
; if exist "%Project%.obj" del "%Project%.obj"
; dir /on /ta /q /a-d
; echo.
; pause
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::