/* Includes2DataFile -- convert includefiles into RExpand data files ** Written by Peter Liljenberg 1996 ** Usage: rx Includes2DataFile */ /* Get arguments */ parse arg IncDir DataDir . if IncDir = "" | DataDir = "" then do say "Usage: rx Includes2DataFile " exit end address command ch = substr(IncDir, length(IncDir)) if ch ~= '/' & ch ~= ':' then IncDir = IncDir || '/' ch = substr(DataDir, length(DataDir)) if ch ~= '/' & ch ~= ':' then DataDir = DataDir || '/' /* List all headers except exec/types.h and prototype headers. ** Also avoid eventual FD and pragma files */ /*'list' IncDir'~(clib|fd|pragmas|protos)/~(types).h lformat "%f%n" to listfile.tmp' */ if ~open(1file, 'listfile.tmp', 'R') then do say "File error!" exit end do i = 1 while ~eof(1file) files.i = readln(1file) if files.i = "" then break end files.0 = i - 1 call close(1file) 'delete listfile.tmp quiet' do f = 1 to files.0 say '['f'/'files.0']' files.f line = xrange('A', 'Z') || '_' do i = 1 to 27 ch = substr(line, i, 1) data.ch.0 = 0 end morelines = 0 comment = 0 if open(1file, files.f, 'R') then do do while ~eof(1file) line = readln(1file) if morelines then do if lastpos('\', strip(line)) ~= length(strip(line)) then morelines = 0 end else if comment then do if pos('*/', line) ~= 0 then comment = 0 end else do comstart = pos('/*', line) comend = pos('*/', line) if comstart ~= 0 then do if comend = 0 then comment = 1 else line = delstr(line, comstart) end if ~comment then do /* Remove tabs */ line = translate(line, ' ', '09'x) parse var line type ident ident2 . select when substr(type, 1, 1) = '#' then if type = '#define' & length(ident) > 1 then if substr(ident, length(ident) - 1) ~= '_H' then addline = ident else addline = '' else addline = '' when type = 'struct' then if ident2 = '{' | ident2 = '' then addline = ident 'struct' ident else addline = ident2 when type = '}' then addline = ident when type = '{' | type = '};' then addline = '' when type ~= '' & ident ~= '' then addline = ident otherwise addline = '' end if length(addline) >= 4 then if pos('Reserved', addline) = 0 then do cpos = verify(addline, ';[,(', 'M') if cpos ~= 0 then addline = delstr(addline, cpos) do while substr(addline, 1, 1) = '*' addline = substr(addline, 2) end ch = upper(substr(addline, 1, 1)) if pos(ch, xrange('A', 'Z')) = 0 then ch = '_' Data.ch.0 = Data.ch.0 + 1 i = Data.ch.0 Data.ch.i = addline end end end end call close(1file) end line = xrange('A', 'Z') || '_' do i = 1 to 27 ch = substr(line, i, 1) if Data.ch.0 ~= 0 then do if ch = '_' then filename = DataDir || '.data' else filename = DataDir || ch || '.data' if open(1file, filename, 'A') then fileopen = 1 else if open(1file, filename, 'W') then fileopen = 1 else fileopen = 0 if fileopen then do do j = 1 to Data.ch.0 call writeln(1file, Data.ch.j) Data.ch.j = '' end call close(1file) end end end end