Checking # of parms

Larry Wall lwall at jpl-devvax.JPL.NASA.GOV
Thu Dec 21 09:58:23 AEST 1989


In article <339 at cerc.wvu.wvnet.edu.edu> tad at cathedral.cerc.wvu.wvnet.edu (Tad Alan Davis) writes:
: Is there a quick & dirty way, using grep, awk, or some such filter to check
: the number of parmeters of a function.  Basically, I have a large set of 
: functions which I call frequently with the wrong number of parms.  I want to
: put the names of the functions and the number of parms in a file and use a
: filter to check them in a C program.
: 
: For example	File	
: 			funcX 2
: 
: 		Command	
: 			grep funcX prog.c | grep -v funcX([^,]*,[^,]*)
: 
: This works fine for
: 
: 		funcX("a", "b");		not printed, valid
: 		funcX("a", "b", "c");		printed, invalid
: 
:       but not for
: 
: 		funcX("a", funcX("a", "b"), "c");	not printed, invalid
: 		funcX("ok,ok", "a");			printed, valid
: 
: 
: Any ideas which would only take an hour or two?

How about a minute or two.  Put your definitions into File as

	#define funcX(a,b)

Then do something like

	cat File prog.c | /lib/cpp >/dev/null

or whatever you need to do to feed your files to the C preprocessor.

Larry Wall
lwall at jpl-devvax.jpl.nasa.gov



More information about the Comp.unix.questions mailing list