Page 1 of 1

Windows batch script for tools menu

Posted: Wed Dec 01, 2004 1:31 am
by tinman
This Windows batch script will help you find the PureBasic compiler on any system. Useful for the "Tools" menu (I use it for recompiling windows.res and compiling to assembly).

NOTE: The character after "delims=" is a tab character and must be so. If in doubt, check with a hex editor, or set your text editor to use tabs rather than convert to spaces.

Feel free to post corrections if this doesn't work on your config. I haven't tested it on Win 9x/ME (which you'll need to change the start of the "find_compiler" routine - in fact, it probably doesn;t work on those systems :).

Oh, there's some extra crappy "echo"s in there, guess you won't need them except for debugging, when a pause at the end of your main script (in this case, the line before "goto end") would be needed.

Code: Select all

@echo off
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
IF DEFINED echo Parameter 1 is %1
IF DEFINED echo Parameter 2 is %2
IF DEFINED echo Parameter 3 is %3

call :find_compiler "pbcompiler.exe"
echo found at -=%PUREBASIC%\Compilers\pbcompiler.exe=-
goto end



REM Label "find_compiler" is used to get the path to the
REM PureBasic compiler. First it checks the command path
REM and if that fails, it checks whether there is a
REM "PUREBASIC" environment variable set. Failing that, it
REM checks some hardcoded likely locations (e.g. C:\Program
REM Files\PureBasic, etc).
REM
REM If that fails then you're boned and should probably set one of them ;)
:find_compiler
    REM Windows NT/2000/XP
    for /F "usebackq skip=3 delims=	 tokens=3" %%i in (`reg query HKCR\Applications\PureBasic.exe\shell\open\command /ve`) do @set PUREBASIC=%%~dpi

    REM Windows 9x/ME I guess
    REM for /F "usebackq skip=3 delims=	 tokens=3" %%i in (`reg query HKLM\Software\Classes\PureBasic.exe\shell\open\command /ve`) do @set PUREBASIC=%%~dpi

    IF NOT EXIST "!PUREBASIC!\Compilers\pbcompiler.exe" set PUREBASIC=

    IF NOT DEFINED PUREBASIC (
    	echo "Not found using for"
        set PUREBASIC=%~dp$PATH:1
        if defined PUREBASIC (
            PUSHD !PUREBASIC!
            cd ..
            set PUREBASIC=!CD!
            POPD
            echo "found it at " !PUREBASIC!
        ) ELSE (
            REM try to find the compiler based on the editor associated with the .pb file extension
            IF NOT EXIST "!PUREBASIC!\Compilers\pbcompiler.exe" set PUREBASIC=
        )
    )

    IF NOT DEFINED PUREBASIC (
        REM try some random locations as a last resort
        IF EXIST "C:\Program Files\PureBasic\Compilers\pbcompiler.exe" set PUREBASIC="C:\Program Files\PureBasic\"
        IF EXIST "D:\Program Files\PureBasic\Compilers\pbcompiler.exe" set PUREBASIC="D:\Program Files\PureBasic\"
        IF EXIST "E:\Program Files\PureBasic\Compilers\pbcompiler.exe" set PUREBASIC="E:\Program Files\PureBasic\"
        REM IF NOT DEFINED PUREBASIC echo "not found"
    )
goto :eof

:end

Posted: Wed Dec 01, 2004 8:15 am
by Bonne_den_kule
You are really good in batch scripts !
Good work! :)