Small introspective program

Richard A. O'Keefe ok at goanna.cs.rmit.oz.au
Thu Mar 14 14:33:25 AEST 1991


[About the hack for including a command to compile itself in a C program.]

Many years ago Tom Duff wrote a nifty little program called "com";
David Tilbrook added some options, and I later added another.

	com [-c$Escape] [-n] [-o | -x] file...

The program searches each file in turn for a comment
	/*% <command> \n
where % is the Escape chacter (which defaults to "%").  Any Escape
character occurring in the file is replaced by the file name from the
command line.  Then
    - if the -o flag appeared, the command is written to stdout, or
    - if the -x flag appeared, the command is written to stderr
    - if the -n flag did NOT appear, the command is given to system().
So the "com" program itself starts with a comment
	/*% cc -o com -O %
	*/
In an AWK script, one could have
	#/*% awk -f %

When 'make' come around I gradually stopped using 'com'.

> ! #ifdef notdef /*
> >   cc $0 -g -o `basename $0 .c` -Ineeded-includes -lneeded-libraries 
> !   exit
> +   */
> > #endif notdef

If you want to use the "shell-in-C" trick, though, it can be simplified:
#if 0 /*
exec cc -g -o `basename $0 .c` -Ineeded-includes $0 -lneeded-libraries 
*/
#endif
-- 
The purpose of advertising is to destroy the freedom of the market.



More information about the Alt.sources.d mailing list