One of the hassles of Writing resource files is creating the PB "%Equate_Name" entities to use in your program. This may help.
-------------
Michael Mattias
Racine WI USA
[email protected]
Code:
$IF 0 FILE: REGEXPR-CREATE-INC.BAS FOR PB/CC 2.0 Parse "C" OR resource file, looking FOR #DEFINE SQL_xxxxxxxx nnnnnnn REPLACE WITH %SQL_xxxxxxxx = nnnnnnn That is, convert "#Define"s into PB equates Author: Michael Mattias, Racine WI March 5, 2000 This code is placed IN the public domain by the author, who expressly waives ANY claim OF copyright OR patent otherwise available under United States OF America OR other applicable international laws, treaties OR conventions. WHILE NOT required, credit would be way cool IF you find this useful. $ENDIF ' don't allow PB to assign REGISTER variables. #REGISTER NONE #DIM ALL '#DEBUG ERROR ON '#COMPILE EXE "REGEXPR-CREATE-INC.EXE" ' cuz the compiler is a 16-bit app $INCLUDE "WIN32API.INC" FUNCTION WinMain (BYVAL hCurInstance AS LONG, _ BYVAL hPrevInstance AS LONG, _ lpszCmdLine AS ASCIIZ PTR, _ BYVAL nCmdShow AS LONG) EXPORT AS LONG DIM ThisFile AS ASCIIZ * %Max_Path DIM Stat AS LONG DIM J$ Stat = GetModuleFileName (hCurInstance, ThisFile, SIZEOF(ThisFile) ) PRINT "Hello World from Program " & ThisFile J$ = WAITKEY$ CALL DoIt J$ = WAITKEY$ END FUNCTION SUB Doit DIM ThePath AS STRING ThePath = "C:\Software_Development\Testdata\" DIM Infile AS STRING, Outfile AS STRING Infile = "SQL.H" Outfile = EXTRACT$(Infile, ".") + ".BI" InFile = ThePath & Infile Outfile = ThePath & Outfile PRINT "Processing file " & Infile DIM Stat AS LONG DIM FileData AS STRING, IH AS LONG, OH AS LONG $IF 0 We want REGEXPR to look FOR: #define Literal [\x20]+ One OR more spaces SQL_ Literal [a-z0-9_] ANY combination OF letters, numbers AND underscores above two items TO be remembered AS tag1 [\x20]+ One OR more spaces [0-9xL]+ One OR more numeric digits, X AND L (TO be remembered AS tag2) This does NOT HANDLE "#define IDM_DO_THIS = WM_USER + 1" but that is an exercise left for the ambitious. $ENDIF DIM SearchForReplaceMask AS STRING SearchForReplaceMask = "#define[\x20]+(SQL_[a-z0-9_]+)[\x20]+([0-9xl]+)" DIM ReplaceMask AS STRING ReplaceMask = "%\01 = \02" ' %(SQL_xxxxx) = nnnnnn DIM NewData AS STRING DIM PosVar AS LONG, StartVar AS LONG, LenVar AS LONG DIM SelectCount AS LONG IH = FREEFILE OPEN InFile FOR INPUT AS IH OH = FREEFILE OPEN OutFile FOR OUTPUT AS OH PRINT #OH, "$IF 0" PRINT #OH, " Generated PowerBASIC Equate File" PRINT #OH, " Source file:" & Infile PRINT #OH, " Search mask Used:" & SearchForReplaceMask PRINT #OH, " Date Created:" & DATE$ PRINT #OH, " Courtesy: Michael Mattias Racine WI" PRINT #OH, "$ENDIF PRINT #OH, WHILE NOT EOF(IH) LINE INPUT #IH, FileData ' see if this is a valid line per our searchmask.. PosVar = 0 REGEXPR SearchForReplaceMask IN FileData TO PosVar, LenVar IF PosVar THEN INCR SelectCount StartVar=1: NewData = "" FileData = LEFT$(FileData, LenVar) REGREPL SearchForReplaceMask IN FileData WITH ReplaceMask AT StartVar TO Posvar, NewData ' make replacement of c-style "0x0" with PB-style "&h0" REPLACE "0x0" WITH "&h0" IN NewData ' remove trailing "L" sometimes used by C programmers to "cast" numeric values.. NewData = RTRIM$(NewData, ANY "lL") PRINT "."; PRINT #OH, NewData END IF WEND PRINT CLOSE IH, OH PRINT "Selected "; FORMAT$(SelectCount);" lines" PRINT "Wrote Output to file "; OutFile END SUB
-------------
Michael Mattias
Racine WI USA
[email protected]
Comment