Xref: utzoo comp.lang.c:37064 alt.sources.d:1615 Path: utzoo!news-server.csri.toronto.edu!utgpu!cs.utexas.edu!sdd.hp.com!spool.mu.edu!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c,alt.sources.d Subject: Re: Small introspective program Message-ID: <4967@goanna.cs.rmit.oz.au> Date: 14 Mar 91 04:33:25 GMT References: <1991Mar10.231230.1301@casbah.acns.nwu.edu> Followup-To: comp.lang.c Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 36 [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 /*% \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.