/* Wrapper for freeglut libray include files
uses freeglut_std.h
uses freeglut_ext.h
*/
% filename "WrapFreeglut.exe"
'include "$\inc\rtl32.inc"
include "$\inc\console.inc"
include "$\inc\stringutil.inc"
print "start wrapping:" cr
indexbase 1
string outfile = "freeglut.inc"
dim as string infile() => {
"freeglut_std.h",
"freeglut_ext.h"
}
% num_of_infile = spanof(infile)
string intro =
"'Wrapped for use with OxygenBasic" & cr &
"'Version " & version & cr
string prolog
string appendix =
cr & "end extern" & cr "'print " & chr(34) & "ok" & chr(34) & cr
' code to replace
type subst1
string org
string repl
end type
subst1 code[] => {
{"#define", "%"},
{"FGAPIENTRY ", ""},
{"FGAPI ", ""},
{"GLUTproc ","sys "},
{"#elif __APPLE__", "'#elif __APPLE__"},
{"( void )", "()"},
{"(void)", "()"},
{"#include", "' #include"},
{";", ""}
}
' code with 2 replaces
type subst2
string org
string repl
string end_org
string end_repl
end type
subst2 code2[] => {
{"extern void*", "sys", "", "()"}, '4th arg append
{"((void *) &", "", ")", " "}, '4th arg replace
{"((void *)", "", ")", " "} '4th arg replace
}
dim as string buffer[num_of_infile]
dim as string Lines[10000]
int lastline = 0
sub split_lines(string buffer)
' LineSplitter1.o2bas
indexbase 1
sys idx, jdx 'indexes
'initial
'=======
lines={32}
begin=1 'start of line
idx=0 'lines array index
jdx=1 'char index
byte address at (strptr buffer)
'splitter loop
'=============
do
select address
case 0
if jdx-begin>0 then
idx++
lines[idx]=mid(buffer,begin,jdx-begin)
end if
exit do
case 10 'LF TERMINATED LINES
idx++
lines[idx]=mid(buffer,begin,jdx-begin)
begin=jdx+1
case 13 'CR AND CRLF TERMINATED LINES
idx++
lines[idx]=mid(buffer,begin,jdx-begin)
if address[2]=10 then @address++ : jdx++ 'SKIP LF
begin=jdx+1
end select
@address++ 'inc pointer for address
jdx++
end do
LastLine=idx
end sub
'--------------------------------------
' start editing the files
for fn = 1 to num_of_infile
' load header file
getfile(infile[fn] , buffer[fn])
if buffer[fn] = "" then
print infile[fn] & " not found or empty!" cr: goto finish
end if
split_lines(buffer[fn])
if LastLine<1 then
print "Error in File: " infile[fn] & cr: goto finish
end if
buffer[fn] =""
' replace under some conditions
for x = 1 to LastLine
lines[x] = ltrim rtrim lines[x]
if left(lines[x],1) = "#" then lines[x] = "#" & ltrim mid(lines[x],2)
for y = 1 to spanof(code)
lines[x] = replace (lines[x], code[y].org, code[y].repl )
next y
for y = 1 to spanof(code2)
if instr(lines[x], code2[y].org) then
lines[x] = replace (lines[x], code2[y].org, code2[y].repl )
if code2[y].end_org = "" then
'append
lines[x] &= code2[y].end_repl
else
'replace
mid lines[x], len(lines[x]), code2[y].end_repl
end if
end if
next y
next x
' update buffer
for x = 1 to Lastline
buffer[fn] &= lines[x] & cr
next x
next fn
'--------------------------------------
' put the files together
getfile ("prolog.txt", prolog)
string buff = intro & cr & prolog & cr
for x = 1 to num_of_infile
buff &= buffer[x]
next x
buff &= appendix
putfile outfile, buff
finish:
print "ready"
waitkey()