It is currently Fri Sep 10, 2010 2:30 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Windows batch script for tools menu
PostPosted: Wed Dec 01, 2004 1:31 am 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 4:56 pm
Posts: 1042
Location: 57.1604N, 2.1345W
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:
@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

_________________
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB4.40)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 8:15 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jun 07, 2004 7:10 pm
Posts: 846
Location: Bergen, Norway
You are really good in batch scripts !
Good work! :)

_________________
PB4Java


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Ask Jeeves [Bot], Google Adsense [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye