/*
 * ParseInc
 *
 * $VER: v1.0 Rick Younie Tue Mar 30 1993
 *
 *	 please send comments, questions or improvements:
 *			rick@emma.panam.wimsey.bc.ca	1:153/765.9
 *			rick@emma.tfbbs.wimsey.bc.ca
 *
 * USAGE: '?' for usage
 *
 * SYNOPSIS: 
 *	 builds indexes for 'getstruct.ced', a structure/object lookup
 *	 for CED.
 *		 - 'h' - make a list of structure names and their *.h location
 *					from the header files
 *		 - 'e' - make a list of E object names and their location from
 *					*.e files (ShowModule'd E *.m files)
 *		 - 'i' - make a list of structure names and their *.i location
 *					from the include files
 */

	signal on BREAK_C
	signal on SYNTAX

/* constants and assigns */

	lf				= '0a'x
	tab				= '09'x	

Main:

	if arg(1)~='h' & arg(1)~='i' & arg(1)~='e' then call Usage
	includeDir  = 'include_'arg(1)':'
	ext  = '*.'arg(1)
	call pragma 'D',includeDir

	if ~show('L','rexxarplib.library') then
		call addlib 'rexxarplib.library',0,-30,0

	file.0=filelist('*/'ext,'FILE')
	if file.0=0 then call ErX '..can''t find "'includeDir'*/'ext'"'

	say	/* need a blank first line for the lookup */
	do i=1 to file.0
		call close 'F'
		if ~open('F',file.i,'Read') then call ErX '..can''t open' file.i

		if arg(1)='h' then do 
			do until eof('F')
				line = readln('F')
				if left(line,6)~='struct' then iterate
				line = translate(line,,tab)
				if word(line,3)='{' then say upper(word(line,2)) file.i
				if words(line)=2 then say upper(word(line,2)) file.i
			end
		end
		if arg(1)='e' then do 
			do until eof('F')
				line = readln('F')
				if abbrev(line,'(---) OBJECT') then say upper(word(line,3)) file.i
			end
		end
		if arg(1)='i' then do 
			do until eof('F')
				line = translate(readln('F'),,tab)
				if word(line,1)~='STRUCTURE' then iterate
				parse var line 'STRUCTURE' structure ','
				say upper(strip(structure)) file.i
			end
		end
	end
	exit

Usage:
	say 'Usage:  [rx] parseinc h >include_h:INDEX'
	say '  -or-  parseinc e >include_e:INDEX'
	say '  -or-  parseinc i >include_i:INDEX'lf
	say ' assignments:'
	say '	  include_h: <dir that has the *.h files>'
	say '	  include_i: <dir that has the *.i files>'
	say '	  include_e: <dir that has the *.e files>'
	exit

SYNTAX:
	say '..aborting - you''re likely missing either rexxarplib.library'
	say '	or arp.library'
	exit
ErX:
	say arg(1)
BREAK_C:
	exit
