home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume16 / identlist < prev    next >
Text File  |  1989-01-17  |  21KB  |  783 lines

  1. Subject:  v16i088:  List identifiers and declarations for C sources
  2. Newsgroups: comp.sources.unix,comp.lang.c
  3. Approved: rsalz@uunet.UU.NET
  4.  
  5. Submitted-by: arizona!rupley!local (John Rupley)
  6. Posting-number: Volume 16, Issue 88
  7. Archive-name: identlist
  8.  
  9. TITLE: cdeclist, identlist - list external declarations 
  10. for C source files; list identifiers
  11.  
  12. SUMMARY: The attached Lex source files are for filters that
  13. generate, for a C source file:  
  14.     (1) a list of external declarations (functions, arrays,
  15.         variables, structures); 
  16.     (2) a file of identifiers suitable for inverted indexing, 
  17.         making a word list, etc.  
  18. Run under SysV or BSD.  See README for test instructions:
  19.  
  20.  
  21. Hope you find them useful,
  22.  
  23. John Rupley
  24.  uucp: ..{cmcl2 | hao!ncar!noao}!arizona!rupley!local
  25.  internet: rupley!local@megaron.arizona.edu
  26.  
  27. -------------------------------------------------------------------------
  28. #!/bin/sh
  29. # to extract, remove the header and type "sh filename"
  30. if `test ! -s ./README`
  31. then
  32. echo "writing ./README"
  33. cat > ./README << '\Rogue\Monster\'
  34. README - Sat Aug 20 23:22:04 MST 1988
  35.  
  36. The attached Lex source files are for filters that generate, 
  37. for a C source file:
  38.     (1) a list of external declarations (functions, arrays, 
  39.         variables, structures);
  40.         each declaration on one line, for manipulation 
  41.         by awk, etc.;
  42.         initializers replaced by a /*comment*/;
  43.         function definitions with parameter declarations and
  44.         a dummy statement with appropriate return:
  45.             { [return [(n)];] }
  46.         preprocessing with cpp replaces defined names and executes
  47.         compilation conditionals;
  48.     (2) a file of identifiers suitable for inverted indexing, making
  49.         a word list, etc.
  50.  
  51. Use of the filters is explained by example:
  52.     (1) mk_cdeclist and the test targets in the Makefile show the 
  53.         generation of a declaration list;
  54.     (2) mk_indentlist shows the generation of a list of identifiers.
  55.  
  56. The make file works under csh/BSD and ksh/SYSV.
  57. To test:
  58.     copy a C source file and any non-system #include dependencies into
  59.         the directory with the unshared files from cdeclist.shar
  60.     run:
  61.         make TESTC="C_src_file" testall
  62.     you should get a file LLLLfilename, which is the declaration list,
  63.         some intermediate files LLfilename and temp?, which shou
  64.         what is going on at each stage, and a file ZZZZfilename,
  65.         which is the list of C keywords and identifiers, 
  66.         
  67.  
  68. The cdeclist filters, although simple, should parse most styles of coding.  
  69. Adjustment may be needed for the new ANSI standard.  The output
  70. is suitable for making a lint library.
  71.  
  72. The identlist filters are offered without much being claimed for them.
  73. I use the list as a guide and aid, without assuming it absolutely correct.
  74.  
  75. The shell scripts mk_* were written under ksh on a SYSV machine, and they
  76. need modification to run under csh or BSD.
  77.  
  78. John Rupley
  79.  uucp: ..{cmcl2 | hao!ncar!noao}!arizona!rupley!local
  80.  internet: rupley!local@megaron.arizona.edu
  81.  (H) 30 Calle Belleza, Tucson AZ 85716 - (602) 325-4533
  82.  (O) Dept. Biochemistry, Univ. Arizona, Tucson AZ 85721 - (602) 621-3929
  83.  
  84. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  85. MANIFEST: (for cdeclist.shr1)
  86.  
  87. README
  88. Makefile
  89. cdeclist.1        man page
  90.  
  91. uncomment.l    |
  92. cdeclist1.l    |
  93. cdeclist2.l    |    shell wrapper and filters generating declaration list
  94. cdeclist3.l    |
  95. cdeclist4.l    |
  96. mk_cdeclist    |
  97.  
  98. identlist.l    |    shell wrapper and filters generating file of identifiers
  99. identlist1.l    |
  100. mk_identlist    |
  101.  
  102. \Rogue\Monster\
  103. else
  104.   echo "will not over write ./README"
  105. fi
  106. if [ `wc -c ./README | awk '{printf $1}'` -ne 2358 ]
  107. then
  108. echo `wc -c ./README | awk '{print "Got " $1 ", Expected " 2358}'`
  109. fi
  110. if `test ! -s ./Makefile`
  111. then
  112. echo "writing ./Makefile"
  113. cat > ./Makefile << '\Rogue\Monster\'
  114. #MAKEFILE -
  115. #5 filters for extracting a list of declarations from a C source file;
  116. #    delete: comments; 
  117. #        (uncomment.l)
  118. #    filter with cpp: replace #defines; execute #ifdef control statements;
  119. #        (cdeclist1.l pre-processes, cdeclist2.l post-processes)
  120. #    delete: function {bodies}; initializations (= ....;);
  121. #        (cdeclist3.l)
  122. #    reformat: to one-line declarations; and a bit more;
  123. #        (cdeclist4.l)
  124. #output should be suitable for:
  125. #    making /*LINTLIBRARY*/, massaging with grep, awk..., etc;
  126. #all filters read stdin, write stdout;
  127. #probably need some adaptation for new ANSI standard;
  128. #
  129. #also 2 filters (identlist and identlist1) that prepare a C source
  130. #file for making a word list or index of identifiers; please don't 
  131. #flame me if the word list misses a few identifiers or includes a few 
  132. #non-existent ones -- I make no great claim for it -- and it assumes,
  133. #I am sure, an idiosyncratic style (mine).
  134. #
  135. #John Rupley
  136. # uucp: ..{cmcl2 | hao!ncar!noao}!arizona!rupley!local
  137. # internet: rupley!local@megaron.arizona.edu
  138. # (H) 30 Calle Belleza, Tucson AZ 85716 - (602) 325-4533
  139. # (O) Dept. Biochemistry, Univ. Arizona, Tucson AZ 85721 - (602) 621-3929
  140.  
  141. OPT=
  142.  
  143. dummy:
  144.     @echo please supply a target
  145.  
  146. all:    uncomment cdeclist1 cdeclist2 cdeclist3 cdeclist4 identlist identlist1
  147.  
  148. #remove comments
  149. uncomment:    uncomment.l
  150.     lex -v uncomment.l
  151.     $(CC) lex.yy.c $(CFLAGS) -ll $(LDFLAGS) -o uncomment
  152.  
  153.  
  154. #remove comments and quoted strings etc
  155. identlist:    identlist.l
  156.     lex -v identlist.l
  157.     $(CC) lex.yy.c $(CFLAGS) -ll $(LDFLAGS) -o identlist
  158.  
  159. #remove upper-case words and numbers
  160. identlist1:    identlist1.l
  161.     lex -v identlist1.l
  162.     $(CC) lex.yy.c $(CFLAGS) -ll $(LDFLAGS) -o identlist1
  163.  
  164. #prepare C source file for cpp processing
  165. cdeclist1:    cdeclist1.l
  166.     lex -v cdeclist1.l
  167.     $(CC) lex.yy.c $(CFLAGS) -ll $(LDFLAGS) -o cdeclist1
  168.  
  169. #remove additions associated with cpp processing
  170. cdeclist2:    cdeclist2.l
  171.     lex -v cdeclist2.l
  172.     $(CC) lex.yy.c $(CFLAGS) -ll $(LDFLAGS) -o cdeclist2
  173.  
  174. #remove function {bodies}, put in appropriate { return (n); }
  175. cdeclist3:    cdeclist3.l
  176.     lex -v cdeclist3.l
  177.     $(CC) lex.yy.c $(CFLAGS) -ll $(LDFLAGS) -o cdeclist3
  178.  
  179. #one-line declarations;remove initializatons;beautify a little
  180. cdeclist4:    cdeclist4.l
  181.     lex -v cdeclist4.l
  182.     $(CC) lex.yy.c $(OPT) $(CFLAGS) -ll $(LDFLAGS) -o cdeclist4 
  183.  
  184. SHARLIST=    \
  185.     README\
  186.     Makefile\
  187.     cdeclist.1\
  188.     uncomment.l\
  189.     cdeclist1.l\
  190.     cdeclist2.l\
  191.     cdeclist3.l\
  192.     cdeclist4.l\
  193.     mk_cdeclist\
  194.     identlist.l\
  195.     identlist1.l\
  196.     mk_identlist
  197.  
  198. mkshar:
  199.     shar -f cdeclist -c $(SHARLIST)
  200.  
  201. TESTC="please define TESTC=C_src_file on make line"
  202. #HDIR=hard_wired_path_for_headers
  203. #CDIR=hard_wired_path_for_sources
  204. HDIR="."
  205. CDIR="."
  206.  
  207. #test making a declaration list
  208. testc:        all
  209.     cat $(CDIR)/$(TESTC)|uncomment|cdeclist1 >temp1
  210.     /lib/cpp -P -C -I$(HDIR) temp1 >temp2
  211.     cat temp2|cdeclist2 >temp3
  212.     echo /*$(TESTC)*/ >LL$(TESTC)
  213.     echo >>LL$(TESTC)
  214.     cat temp3|cdeclist3 >>LL$(TESTC)
  215.  
  216. test2c:        cdeclist2
  217.     cat temp2|cdeclist2 >temp3
  218.  
  219. test3c:        cdeclist3
  220.     echo /*$(TESTC)*/ >LL$(TESTC)
  221.     echo >>LL$(TESTC)
  222.     cat temp3|cdeclist3 >>LL$(TESTC)
  223.  
  224. TESTLL=LL$(TESTC)
  225.  
  226. testll:        cdeclist4
  227.     cat $(TESTLL)|cdeclist4 >LL$(TESTLL)
  228.  
  229.  
  230. #test making a word list
  231. testw:        identlist identlist1
  232.     cat $(TESTC)|identlist|identlist1    |\
  233.         tr -s "     " "\012\012"|sort|uniq    >ZZZZ$(TESTC)
  234.  
  235.  
  236. #careful!
  237. testlint:
  238.     lint -uvx -Ml -otemp LL$(TESTLL)
  239.     cp llib-ltemp.ln /usr/lib/large
  240.     lint -uvx -Ml -ltemp $(TESTC)
  241.  
  242. testall: testc testll testw        #testlint 
  243. \Rogue\Monster\
  244. else
  245.   echo "will not over write ./Makefile"
  246. fi
  247. if [ `wc -c ./Makefile | awk '{printf $1}'` -ne 3409 ]
  248. then
  249. echo `wc -c ./Makefile | awk '{print "Got " $1 ", Expected " 3409}'`
  250. fi
  251. if `test ! -s ./cdeclist.1`
  252. then
  253. echo "writing ./cdeclist.1"
  254. cat > ./cdeclist.1 << '\Rogue\Monster\'
  255. .TH CDECLIST 1
  256. .SH NAME
  257. mk_cdeclist, mk_identlist \- list external declarations 
  258. for C source files; list identifiers
  259. .SH SYNOPSIS
  260. .B mk_cdeclist
  261. filelist
  262. .br
  263. .B mk_identlist
  264. filelist
  265. .SH DESCRIPTION
  266. .B Mk_cdeclist
  267. is a shell script that links a set of filters and the C preprocessor,
  268. .B cpp,
  269. to convert C source files
  270. into a list of external declarations (functions, arrays, 
  271. variables, structures).
  272. Each declaration is on one line, to simplify subsequent manipulation 
  273. by awk, etc.
  274. Initializers are replaced by a comment, /*INITIALIZED*/.
  275. Function definitions include parameter declarations and
  276. a dummy statement with appropriate return:
  277. .in +10
  278. { [return [(n)];] }
  279. .in
  280. The C preprocessor is used to replace defined names and to execute 
  281. compilation conditionals;
  282. declarations introduced by the preprocessing are removed, and
  283. include directives are restored.
  284. .PP
  285. The output of 
  286. .B mk_cdeclist
  287. can be compiled into a lint library.
  288. .PP
  289. .B Mk_identlist
  290. is a shell script with filters for converting C source files
  291. into a file of identifiers suitable for inverted indexing, making
  292. a word list, etc.
  293. .PP
  294. .SH FILES
  295. The filters for both
  296. .B mk_cdeclist 
  297. and
  298. .B mk_identlist
  299. are from Lex source files:
  300. .in +5
  301. uncomment.l, cdeclist[1-4].l and identlist[ 1].l.
  302. .in
  303. The executables are correspondingly named.
  304. .br
  305. .B Cpp
  306. is used in 
  307. .B mk_cdeclist.
  308. .SH AUTHOR
  309. John Rupley
  310. .br
  311.  uucp: ..{cmcl2 | hao!ncar!noao}!arizona!rupley!local
  312. .br
  313.  internet: rupley!local@megaron.arizona.edu
  314. .br
  315.  Dept. Biochemistry, Univ. Arizona, Tucson AZ 85721
  316. .SH BUGS
  317. The cdeclist filters, although simple, should parse most styles of coding.  
  318. Adjustment may be needed for the new ANSI standard.
  319. If there is a problem, try filtering first with
  320. .B cb
  321. or
  322. .B indent.
  323. .sp
  324. The identlist filters are offered without much being claimed for them.
  325. Use the list as a guide and aid, without assuming it absolutely correct.
  326. .sp
  327. The shell scripts mk_* were written under ksh on a SYSV machine, and they
  328. need modification to run under csh or BSD.
  329. \Rogue\Monster\
  330. else
  331.   echo "will not over write ./cdeclist.1"
  332. fi
  333. if [ `wc -c ./cdeclist.1 | awk '{printf $1}'` -ne 1998 ]
  334. then
  335. echo `wc -c ./cdeclist.1 | awk '{print "Got " $1 ", Expected " 1998}'`
  336. fi
  337. if `test ! -s ./uncomment.l`
  338. then
  339. echo "writing ./uncomment.l"
  340. cat > ./uncomment.l << '\Rogue\Monster\'
  341. %{
  342. /*UNCOMMENT- based on usenet posting by: */
  343. /*    Chris Thewalt; thewalt@ritz.cive.cmu.edu */
  344. %}
  345. STRING        \"([^"\n]|\\\")*\"
  346. COMMENTBODY    ([^*\n]|"*"+[^*/\n])*
  347. COMMENTEND    ([^*\n]|"*"+[^*/\n])*"*"*"*/"
  348. %START    COMMENT
  349. %%
  350. <COMMENT>{COMMENTBODY}        ;
  351. <COMMENT>{COMMENTEND}        BEGIN 0;
  352. <COMMENT>.|\n            ;
  353. "/*"                BEGIN COMMENT;
  354. {STRING}            ECHO;
  355. .|\n                ECHO;
  356.  
  357.  
  358. \Rogue\Monster\
  359. else
  360.   echo "will not over write ./uncomment.l"
  361. fi
  362. if [ `wc -c ./uncomment.l | awk '{printf $1}'` -ne 349 ]
  363. then
  364. echo `wc -c ./uncomment.l | awk '{print "Got " $1 ", Expected " 349}'`
  365. fi
  366. if `test ! -s ./cdeclist1.l`
  367. then
  368. echo "writing ./cdeclist1.l"
  369. cat > ./cdeclist1.l << '\Rogue\Monster\'
  370. %{
  371. /*-CDECLIST1: prepare for cpp execution of #ifdefs, etc.; */
  372. /*i.e., setup to restore #includes & remove code added by cpp */
  373. %}
  374. %%
  375. ^\#[ \t]*include.*$        {printf("/*%s*/\n", yytext);
  376.     printf("/*DINGDONGDELL*/\n");
  377.     printf("%s\n", yytext);
  378.     printf("/*DELLDONGDING*/\n");}
  379. .|\n                ECHO;
  380.  
  381.  
  382. \Rogue\Monster\
  383. else
  384.   echo "will not over write ./cdeclist1.l"
  385. fi
  386. if [ `wc -c ./cdeclist1.l | awk '{printf $1}'` -ne 289 ]
  387. then
  388. echo `wc -c ./cdeclist1.l | awk '{print "Got " $1 ", Expected " 289}'`
  389. fi
  390. if `test ! -s ./cdeclist2.l`
  391. then
  392. echo "writing ./cdeclist2.l"
  393. cat > ./cdeclist2.l << '\Rogue\Monster\'
  394. %{
  395. /*-CDECLIST2: remove cpp-included code, restore #include's */
  396. %}
  397. %START DING
  398. %%
  399. ^"/*DINGDONGDELL*/"$        BEGIN DING;
  400. ^"/*DELLDONGDING*/"$        BEGIN 0;
  401. <DING>^"/*#"[^*]*"*/"$         ;
  402. <DING>.|\n            ;
  403. ^"/*#"[^*]*"*/"$         {yytext[yyleng-2] = 0;
  404.     printf("%s", &yytext[2]);}
  405. ^[ \t]*\n            ;
  406. .|\n                 ECHO;
  407.  
  408.  
  409. \Rogue\Monster\
  410. else
  411.   echo "will not over write ./cdeclist2.l"
  412. fi
  413. if [ `wc -c ./cdeclist2.l | awk '{printf $1}'` -ne 291 ]
  414. then
  415. echo `wc -c ./cdeclist2.l | awk '{print "Got " $1 ", Expected " 291}'`
  416. fi
  417. if `test ! -s ./cdeclist3.l`
  418. then
  419. echo "writing ./cdeclist3.l"
  420. cat > ./cdeclist3.l << '\Rogue\Monster\'
  421. %{
  422. /*-CDECLIST3: for each function, remove the {function body}; */
  423. /*    (look out for {}'s escaped or  within " or ' pairs) */
  424. %}
  425.  int curly, retval;
  426. WLF        ([ \t\n\r\f]*)
  427. FUNCSTRT    (\){WLF}\{|\;{WLF}\{)
  428. SKIPALLQUOTED    (\"([^"\n]|\\\")*\"|\'.\'|\\.)
  429. %START CURLY
  430. %%
  431. <CURLY>\{            curly++;
  432. <CURLY>\}            {if (--curly == 0) {
  433.                     if (retval > 1)
  434.                         printf(" return (%d); }", retval);
  435.                     else if (retval)
  436.                         printf(" return; }");
  437.                     else
  438.                         printf("}");
  439.                     BEGIN 0;
  440.                 }}
  441. <CURLY>{FUNCSTRT}        curly++;
  442. <CURLY>{SKIPALLQUOTED}|.|\n    ;
  443. <CURLY>"return"{WLF}\;        retval |= 1;
  444. <CURLY>"return"{WLF}([^;]|{SKIPALLQUOTED})*\;    retval |= 2;
  445. {FUNCSTRT}            {curly=1;retval=0;ECHO;BEGIN CURLY;}
  446. ^[ \t]*\n            ;
  447. .|\n                 ECHO;
  448.  
  449.  
  450. \Rogue\Monster\
  451. else
  452.   echo "will not over write ./cdeclist3.l"
  453. fi
  454. if [ `wc -c ./cdeclist3.l | awk '{printf $1}'` -ne 720 ]
  455. then
  456. echo `wc -c ./cdeclist3.l | awk '{print "Got " $1 ", Expected " 720}'`
  457. fi
  458. if `test ! -s ./cdeclist4.l`
  459. then
  460. echo "writing ./cdeclist4.l"
  461. cat > ./cdeclist4.l << '\Rogue\Monster\'
  462. %{
  463. /*-CDECLIST4: process output of cdeclist3:
  464.     delete initialization expressions;
  465.     reformat for one-line declarations;
  466.     some beautfying -- wise to process original source with cb|indent;
  467. parsing in DECLST is hacked; would be better to base it cleanly on std ANSI;
  468. to delete externs or whatever, try: {WLF}extern[^;]*\;{WLF}
  469. */
  470. %}
  471.  int curly;
  472. W        ([ \t]*)
  473. WLF        ([ \t\n\f\r]*)
  474. LET        [_a-zA-Z]
  475. DIGIT        [0-9+-/*]
  476. DIGLET        [_a-zA-Z0-9]
  477. NAME        ([*]*{LET}{DIGLET}*)
  478. ARRAY        (\[{DIGIT}*\])
  479. DECL        ([;,*]|{WLF}|{NAME}|{ARRAY})
  480. FUNCPTR        (\({DECL}*\)\({DECL}*\))
  481. DECLST        ({DECL}|{FUNCPTR})*
  482. FINDSTRUCT    (struct|union|enum){WLF}{NAME}?{WLF}\{
  483. ENDSTRUCT    {WLF}\}{WLF}
  484. FINDFUNC    \){DECLST}\{[ ]?(return[^}\n]*)?\}
  485. ENDFUNC        {WLF}\{[ ]?(return[^}\n]*)?\}
  486. FINDINIT    {WLF}\={WLF}
  487. ENDINIT1    {WLF}\;{WLF}
  488. ENDINIT2    {WLF}\,{WLF}
  489. SKIPALLQUOTED    (\"([^"\n]|\\\")*\"|\'.\'|\\.)
  490. %START NORM DELETE DECL
  491. %{
  492. #include <ctype.h>
  493. main()
  494. {
  495.     BEGIN NORM;
  496.     yylex();
  497.     return 0;
  498. }
  499. %}
  500. %%
  501. <NORM>"/*"[^\n]*"*/"        print_skip(yytext);
  502. <NORM>"#"[^\n]*$         print_skip(yytext);
  503. <NORM>{WLF}{FINDINIT}        {BEGIN 0;BEGIN DELETE;}
  504. <NORM>{FINDFUNC}|{FINDSTRUCT}    {curly=0;BEGIN 0;BEGIN DECL;REJECT;}
  505. <DELETE>{SKIPALLQUOTED}|[^{},;]    ;
  506. <DELETE>\{            curly++;
  507. <DELETE>\}            curly--;
  508. <DELETE>{ENDINIT1}        {if (curly == 0) {
  509.                 printf("\;\t/*INITIALIZED*/\n");
  510.                 ;BEGIN 0; BEGIN NORM;}}
  511. <DELETE>{ENDINIT2}        {if (curly == 0) {
  512.                 printf(" /*INITIALIZED*/, ");
  513.                 ;BEGIN 0; BEGIN NORM;}}
  514. <DECL>{ENDSTRUCT}        {printf("} ");
  515.                 if (--curly == 0) {
  516.                     BEGIN 0;BEGIN NORM;
  517.                 }}
  518. <DECL>{ENDFUNC}            {printf(" ");print_skip(yytext);
  519.                 BEGIN 0;BEGIN NORM;}
  520. <DECL>\{            {ECHO;curly++;}
  521. <DECL>{WLF}\){WLF}/{ENDFUNC}    printf(")");
  522. <DECL>{WLF}\;{WLF}/{ENDFUNC}    printf(";");
  523. <DECL>{WLF}\;{WLF}        printf("; ");
  524. <NORM>{WLF}\;{WLF}        printf(";\n");
  525. <NORM,DECL>{WLF}\,{WLF}        printf(", ");
  526. <NORM,DECL>{WLF}/[/#]        ;
  527. <NORM,DECL>{WLF}        printf(" ");
  528. <NORM,DECL>.             ECHO;
  529. %%
  530. print_skip(s) char * s;
  531. {
  532.     int c;
  533.     while (isspace(*s))
  534.         s++;
  535.     printf("%s\n", s);
  536.     while (isspace(c=input()))
  537.         ;
  538.     unput(c);
  539. }
  540.  
  541.  
  542.  
  543.  
  544. \Rogue\Monster\
  545. else
  546.   echo "will not over write ./cdeclist4.l"
  547. fi
  548. if [ `wc -c ./cdeclist4.l | awk '{printf $1}'` -ne 2012 ]
  549. then
  550. echo `wc -c ./cdeclist4.l | awk '{print "Got " $1 ", Expected " 2012}'`
  551. fi
  552. if `test ! -s ./mk_cdeclist`
  553. then
  554. echo "writing ./mk_cdeclist"
  555. cat > ./mk_cdeclist << '\Rogue\Monster\'
  556. # MK_CDECLIST
  557.  
  558. DEFAULTDIR="."
  559. CDIR=`dirname $1`
  560. if [ ${CDIR} = "." ]
  561. then
  562.     CDIR=${DEFAULTDIR}
  563. fi
  564. HDIR=${CDIR}
  565. CDECLIST=""
  566. #option: if define LLOUT="Sall.1", then output concatenated onto Sall.1;
  567. #else get individual output files with prefix "LL";
  568. LLOUT="Sall.1"
  569. #LLOUT="dumdumdum"
  570.  
  571. for i in $*
  572. do
  573.     FILE=`basename ${i}`
  574.     echo processing file: $i >&2
  575.     if [ ${LLOUT} != "Sall.1" ]
  576.     then
  577.         LLOUT=LL${FILE}
  578.         CDECLIST="${CDECLIST} ${LLOUT}"
  579.     fi
  580.     echo "\n\n/*********************************************/\n" >>${LLOUT}
  581.     echo /*${FILE}*/ >>${LLOUT}
  582.     echo >>${LLOUT}
  583.     cat ${CDIR}/${FILE}|uncomment|cdeclist1|/lib/cpp -P -C -I${HDIR}|
  584.         cdeclist2|cdeclist3|cdeclist4 >>${LLOUT}
  585. done
  586.  
  587. #temporary++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  588. exit
  589.  
  590. #NOTE: what follows is an example of manipulation of the cdeclist output.
  591.  
  592. #the following cats a list of separate "LL" files onto Sall.1
  593. echo
  594. echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  595. echo combining files: ${CDECLIST}
  596. >Sall.1
  597. for i in ${CDECLIST}
  598. do
  599.  
  600.     cat ${i} >>Sall.1
  601. done
  602.  
  603. #the following extracts a list of function definitions _only_;
  604. #(no static or external declarations; no definitions of arrays/vars/structs);
  605. #collect comment header lines, functions, and struct declarations;
  606. #get rid of register specs;
  607. #strip any variable declarations trailing struct declarations;
  608. #change return (n) -> return (0), so ok for return of pointers;
  609. #insert VARARGS where needed;
  610. #to include structure definitions, add to 1st egrep: |struct[ ]+[^;({]+\{
  611. #remove several functions with "static" scope -- and that give errors in
  612. #compilation without struct definitions (same scope);
  613. #this gives a partial lint library - full library needs array/variables;
  614.  
  615. cat Sall.1|egrep '\/\*[^L]|\{\}|\ return[ ;]' |
  616.     egrep -v '^static\ |INITIALIZED' |
  617.     egrep -v '\ engr_at[(]|^del_engr[(]|\ outentry[(]|^ini_inv[(]' |
  618.     sed -e "s/register[ ]\([^;, ][^;, ]*[;,]\)/int\ \1/g"    \
  619.         -e "s/register[ ]//g"    \
  620.         -e "s/\}[^;}]*\;$/\}\ \;/"    \
  621.         -e "s/return\ .[1-3]./return\ \(0\)/g"    \
  622.         -e "s/^panic/\/\*VARARGS1\*\/\\
  623. panic/"    \
  624.         -e "s/^error/\/\*VARARGS1\*\/\\
  625. error/"    \
  626.         -e "s/^pline/\/\*VARARGS1\*\/\\
  627. pline/"    \
  628.         -e "s/^impossible/\/\*VARARGS1\*\/\\
  629. impossible/p" >Sall.2
  630.  
  631. \Rogue\Monster\
  632. else
  633.   echo "will not over write ./mk_cdeclist"
  634. fi
  635. if [ `wc -c ./mk_cdeclist | awk '{printf $1}'` -ne 2230 ]
  636. then
  637. echo `wc -c ./mk_cdeclist | awk '{print "Got " $1 ", Expected " 2230}'`
  638. fi
  639. if `test ! -s ./identlist.l`
  640. then
  641. echo "writing ./identlist.l"
  642. cat > ./identlist.l << '\Rogue\Monster\'
  643. %{
  644. /*IDENTLIST- comments & strings deleted; punc to space; etc*/
  645. /*(a filter to prep C source for bib INDEXing, making a word list, ...)*/
  646. /*convert to white space all tokens except C keywords and identifiers;*/
  647. /*comment recognition based on usenet posting by: */
  648. /*    Chris Thewalt; thewalt@ritz.cive.cmu.edu */
  649. %}
  650. W        [ \t]
  651. STRING        \"([^"\n]|\\\")*\"
  652. %START    COMMENT
  653. %%
  654. <COMMENT>([^*\n]|"*"+[^*/\n])*            ;
  655. <COMMENT>([^*\n]|"*"+[^*/\n])*"*"*"*/"        BEGIN 0;
  656. <COMMENT>.|\n            ;
  657. "/*"                BEGIN COMMENT;
  658. {STRING}            ;
  659. ^#.*$                ;
  660. [a-zA-Z_0-9]\.[a-zA-Z_0-9]    ECHO;
  661. [a-zA-Z_0-9]\-\>[a-zA-Z_0-9]    ECHO;
  662. \\|\||\+|\)|\(|\*|\&|\^|\%|\$        printf(" ");
  663. \#|\@|\!|\~|\`|\-|\=|\}|\{        printf(" ");
  664. \]|\[|\"|\:|\'|\;|\?|\/|\>|\.|\<|\,    printf(" ");
  665. .|\n                ECHO;
  666.  
  667. \Rogue\Monster\
  668. else
  669.   echo "will not over write ./identlist.l"
  670. fi
  671. if [ `wc -c ./identlist.l | awk '{printf $1}'` -ne 735 ]
  672. then
  673. echo `wc -c ./identlist.l | awk '{print "Got " $1 ", Expected " 735}'`
  674. fi
  675. if `test ! -s ./identlist1.l`
  676. then
  677. echo "writing ./identlist1.l"
  678. cat > ./identlist1.l << '\Rogue\Monster\'
  679. %{
  680. /*IDENTLIST1- remove strings that are all uppercase or all numbers*/
  681. /*(another filter to prep C source for bib INDEXing, making a word list, ...)*/
  682. /*
  683. ^[A-Z_0-9]+/{W}+        printf(" ");
  684. {W}+[A-Z_0-9]+$            printf(" ");
  685. ^[A-Z_0-9]+$            printf(" ");
  686. */
  687. %}
  688. W        [ \t]
  689. %START    COMMENT
  690. %%
  691. (^|{W}+)[A-Z_0-9]+/(\n|{W}+)    printf(" ");
  692. .|\n                ECHO;
  693.  
  694. \Rogue\Monster\
  695. else
  696.   echo "will not over write ./identlist1.l"
  697. fi
  698. if [ `wc -c ./identlist1.l | awk '{printf $1}'` -ne 335 ]
  699. then
  700. echo `wc -c ./identlist1.l | awk '{print "Got " $1 ", Expected " 335}'`
  701. fi
  702. if `test ! -s ./mk_identlist`
  703. then
  704. echo "writing ./mk_identlist"
  705. cat > ./mk_identlist << '\Rogue\Monster\'
  706. # MK_IDENTLIST
  707. #prepare C source files for making an inverted index, or whatever, using
  708. #identlist and identlist1 to: delete quoted strings, comments; 
  709. #convert punctuation to white space; delete numbers and all upper case words;
  710. #the result, with some stuff flagged for later reversal,
  711. #should be suitable for making an inverted index of identifiers in each 
  712. #source file.
  713. #
  714. #if use "invert" from the "bib" suite of programs, can exclude, as common
  715. #words, the C keywords and the system library
  716. #
  717. #(NOTE: as a test, the output of the loop containing the filters is 
  718. #sent through tr, sort and uniq, to produce a word list)
  719.  
  720. DEFAULTDIR="."
  721. CDIR=`dirname $1`
  722. if [ ${CDIR} = "." ]
  723. then
  724.     CDIR=${DEFAULTDIR}
  725. fi
  726.  
  727. for i in $*
  728. do
  729.     FILE=`basename ${i}`
  730.     echo processing file: $i >&2
  731.     cat ${CDIR}/${FILE}|identlist|identlist1|
  732.     sed -e '/^[     ]*$/d'
  733. done |tr -s "     " "\012\012"|sort|uniq            #produce a word list
  734.  
  735.  
  736. #temporary++++++++++++++++++++++++++++++++++++++++++++++++++
  737. exit
  738.  
  739. #to make an inverted index, replace the above loop by the following:
  740.  
  741. for i in $*
  742. do
  743.     FILE=`basename ${i}`
  744.     echo processing file: $i
  745.     cat ${CDIR}/${FILE}|identlist|identlist1|
  746.     sed -e 's/\([a-zA-Z_0-9]\)\.[^ \t]*[ \t]/\1\qsq\ /g' \
  747.         -e 's/\([a-zA-Z_0-9]\)\-\>[^ \t]*[ \t]/\1qsq\ /g' \
  748.         -e 's/\([a-zA-Z0-9]\)[_]\([a-zA-Z0-9]\)/\1quq\2/g' |
  749.     sed -e '/^[     ]*$/d'         >${FILE}
  750.     FILELIST=${FILELIST}" "${FILE}
  751. done
  752.  
  753.  
  754. #NOTE: if the above changes are made, mk_identlist should be run in 
  755. #an empty (scratch) directory;
  756. #intermediate files of the same name as the C source files are created;
  757. #the directory with the C source files can be given as DEFAULTDIR or as
  758. #the absolute pathname of the first file in the list;
  759.  
  760. #NOTE: the following is an example of processing to get an inverted index.
  761.  
  762. invert -ccommon -k5000 -l30 ${FILELIST}
  763. mv INDEX INDEX.long
  764. cat INDEX.long|
  765. sed -e 's/quq/\_/g' -e 's/qsq/STRUCT/g' \
  766.     -e 's/\([^0-9]\)[0-9][0-9]*\/[0-9][0-9]*\([^0-9]\)/\1\2/g'    \
  767.     -e 's/\([^0-9]\)[0-9][0-9]*\/[0-9][0-9]*$/\1/' |
  768. sort -o INDEX
  769.  
  770. \Rogue\Monster\
  771. else
  772.   echo "will not over write ./mk_identlist"
  773. fi
  774. if [ `wc -c ./mk_identlist | awk '{printf $1}'` -ne 2001 ]
  775. then
  776. echo `wc -c ./mk_identlist | awk '{print "Got " $1 ", Expected " 2001}'`
  777. fi
  778. echo "Finished archive 1 of 1"
  779. exit
  780.  
  781.  
  782.  
  783.