home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume18 / cproto / patch02 / patch2
Encoding:
Text File  |  1991-04-10  |  6.7 KB  |  301 lines

  1. diff -c old/CHANGES ./CHANGES
  2. *** old/CHANGES    Wed Apr 03 21:42:20 1991
  3. --- ./CHANGES    Wed Apr 03 21:52:24 1991
  4. ***************
  5. *** 1,5 ****
  6. --- 1,15 ----
  7.   Version 2
  8.   
  9. + Patchlevel 2
  10. + - Cproto is now able to generate prototypes for functions defined in lex
  11. +   and yacc source files named on the command line.  Lex and yacc source
  12. +   files are recognized by the .l or .y extension.
  13. + - Fix: The memory allocated to the typedef symbol table was not being
  14. +   freed after scanning each source file.
  15. + - Fix: Failing to reset a variable during error recovery caused
  16. +   segmentation faults.
  17.   Patchlevel 1
  18.   
  19.   - Fix: Cproto incorrectly generated the parameter "int ..." in
  20. diff -c old/grammar.y ./grammar.y
  21. *** old/grammar.y    Wed Apr 03 21:42:26 1991
  22. --- ./grammar.y    Wed Apr 03 21:52:28 1991
  23. ***************
  24. *** 1,4 ****
  25. ! /* $Id: grammar.y 2.2 91/03/30 13:19:00 cthuang Exp $
  26.    *
  27.    * yacc grammar for C prototype generator
  28.    * This was derived from the grammar given in Appendix A of
  29. --- 1,4 ----
  30. ! /* $Id: grammar.y 2.3 91/04/03 21:27:01 cthuang Exp $
  31.    *
  32.    * yacc grammar for C prototype generator
  33.    * This was derived from the grammar given in Appendix A of
  34. ***************
  35. *** 558,563 ****
  36. --- 558,564 ----
  37.   yyerror (msg)
  38.   char *msg;
  39.   {
  40. +     func_params = FALSE;
  41.       output_error();
  42.       fprintf(stderr, "%s\n", msg);
  43.   }
  44. ***************
  45. *** 565,572 ****
  46.   void
  47.   parse_file ()
  48.   {
  49.       printf("/* %s */\n", cur_file);
  50. -     line_num = 1;
  51.       typedef_names = create_symbol_table();
  52.       yyparse();
  53.   }
  54. --- 566,583 ----
  55.   void
  56.   parse_file ()
  57.   {
  58. +     char *s;
  59. +     if (strlen(cur_file) > 2) {
  60. +     s = cur_file + strlen(cur_file) - 2;
  61. +     if (strcmp(s, ".l") == 0 || strcmp(s, ".y") == 0)
  62. +         BEGIN LEXYACC;
  63. +     }
  64.       printf("/* %s */\n", cur_file);
  65.       typedef_names = create_symbol_table();
  66. +     line_num = 1;
  67. +     ly_count = 0;
  68.       yyparse();
  69. +     destroy_symbol_table(typedef_names);
  70.   }
  71. diff -c old/lex.l ./lex.l
  72. *** old/lex.l    Thu Mar 28 15:41:56 1991
  73. --- ./lex.l    Wed Apr 03 21:52:26 1991
  74. ***************
  75. *** 1,5 ****
  76.   %{
  77. ! /* $Id: lex.l 2.1 91/03/25 11:40:27 cthuang Exp $
  78.    *
  79.    * C function prototype generator
  80.    * Lexical analyzer specification
  81. --- 1,5 ----
  82.   %{
  83. ! /* $Id: lex.l 2.2 91/04/03 21:31:11 cthuang Exp $
  84.    *
  85.    * C function prototype generator
  86.    * Lexical analyzer specification
  87. ***************
  88. *** 17,22 ****
  89. --- 17,23 ----
  90.   char cur_file[MAX_TEXT_LENGTH];    /* current file name */
  91.   int line_num = 1;        /* current line number in file */
  92.   static int curly = 0;        /* number of curly brace nesting levels */
  93. + static int ly_count = 0;    /* number of occurances of %% */
  94.   
  95.   typedef struct {
  96.       FILE *fp;
  97. ***************
  98. *** 29,38 ****
  99.   static void do_include();
  100.   %}
  101.   
  102. ! %s CPP1 CPP2 INIT1 INIT2 CURLY COMMENT
  103.   %%
  104.   
  105.   \n            ++line_num;
  106.   
  107.   <INITIAL>^#{WS}*    BEGIN CPP1;
  108.   <CPP1>define{WS}+{ID}.*\\$    {
  109. --- 30,47 ----
  110.   static void do_include();
  111.   %}
  112.   
  113. ! %s CPP1 CPP2 INIT1 INIT2 CURLY COMMENT LEXYACC
  114.   %%
  115.   
  116.   \n            ++line_num;
  117. + <LEXYACC>^"%%"        {
  118. +                 if (++ly_count >= 2)
  119. +                 BEGIN INITIAL;
  120. +             }
  121. + <LEXYACC>^"%{"        BEGIN INITIAL;
  122. + <LEXYACC>.        ;
  123. + <INITIAL>^"%}"        BEGIN LEXYACC;
  124.   
  125.   <INITIAL>^#{WS}*    BEGIN CPP1;
  126.   <CPP1>define{WS}+{ID}.*\\$    {
  127. diff -c old/Makefile ./Makefile
  128. *** old/Makefile    Wed Apr 03 21:42:28 1991
  129. --- ./Makefile    Wed Apr 03 21:52:26 1991
  130. ***************
  131. *** 1,4 ****
  132. ! # $Id: Makefile 2.2 91/03/30 13:19:06 cthuang Exp $
  133.   #
  134.   # MSDOS makefile for C prototype generator
  135.   
  136. --- 1,4 ----
  137. ! # $Id: Makefile 2.3 91/04/03 21:26:50 cthuang Exp $
  138.   #
  139.   # MSDOS makefile for C prototype generator
  140.   
  141. ***************
  142. *** 34,40 ****
  143.       $(LEX) lex.l
  144.   
  145.   cproto.man: cproto.1
  146. !     cawf -man $*.1 >$@
  147.   
  148.   TAGS: $(SOURCES)
  149.       etags -t $(SOURCES)
  150. --- 34,40 ----
  151.       $(LEX) lex.l
  152.   
  153.   cproto.man: cproto.1
  154. !     cawf -man $*.1 | bsfilt - >$@
  155.   
  156.   TAGS: $(SOURCES)
  157.       etags -t $(SOURCES)
  158. ***************
  159. *** 63,71 ****
  160.   zip:
  161.       pkzip -u cproto README CHANGES Makefile.* *.1 *.c *.h grammar.y lex.l
  162.   
  163. ! ci:
  164.       ci -u2 $(DIST1) $(DIST3)
  165.       ci -u2 $(DIST4)
  166.   
  167.   # DO NOT DELETE THIS LINE -- make depend depends on it.
  168.   
  169. --- 63,75 ----
  170.   zip:
  171.       pkzip -u cproto README CHANGES Makefile.* *.1 *.c *.h grammar.y lex.l
  172.   
  173. ! ci: rmcr
  174.       ci -u2 $(DIST1) $(DIST3)
  175.       ci -u2 $(DIST4)
  176. + rmcr:
  177. +     rmcr $(DIST1) $(DIST3)
  178. +     rmcr $(DIST4)
  179.   
  180.   # DO NOT DELETE THIS LINE -- make depend depends on it.
  181.   
  182. diff -c old/patchlev.h ./patchlev.h
  183. *** old/patchlev.h    Wed Apr 03 21:42:30 1991
  184. --- ./patchlev.h    Wed Apr 03 21:52:28 1991
  185. ***************
  186. *** 1,1 ****
  187. ! #define PATCHLEVEL 1
  188. --- 1,1 ----
  189. ! #define PATCHLEVEL 2
  190. diff -c old/symbol.c ./symbol.c
  191. *** old/symbol.c    Thu Mar 28 15:42:00 1991
  192. --- ./symbol.c    Wed Apr 03 21:52:32 1991
  193. ***************
  194. *** 1,4 ****
  195. ! /* $Id: symbol.c 2.1 91/02/28 11:16:35 cthuang Exp $
  196.    *
  197.    * Symbol table maintenance. Implements an abstract data type called
  198.    * the symbol table.
  199. --- 1,4 ----
  200. ! /* $Id: symbol.c 2.2 91/04/03 21:30:54 cthuang Exp $
  201.    *
  202.    * Symbol table maintenance. Implements an abstract data type called
  203.    * the symbol table.
  204. ***************
  205. *** 7,12 ****
  206. --- 7,13 ----
  207.   #include "config.h"
  208.   #include "symbol.h"
  209.   
  210.   /* Create a symbol table.
  211.    * Return a pointer to the symbol table or NULL if an error occurs.
  212.    */
  213. ***************
  214. *** 24,36 ****
  215.   }
  216.   
  217.   
  218.   /* This is a simple hash function mapping a symbol name to a hash bucket. */
  219.   
  220. ! static int
  221.   hash (name)
  222.   char *name;
  223.   {
  224. !     return (name[0] + name[1] + strlen(name)) % SYM_MAX_HASH;
  225.   }
  226.   
  227.   
  228. --- 25,65 ----
  229.   }
  230.   
  231.   
  232. + /* Free the memory allocated to the symbol table.
  233. +  */
  234. + void
  235. + destroy_symbol_table (symtab)
  236. + SymbolTable *symtab;
  237. + {
  238. +     int i;
  239. +     Symbol *sym, *next;
  240. +     for (i = 0; i < SYM_MAX_HASH; ++i) {
  241. +     sym = symtab->bucket[i];
  242. +     while (sym != NULL) {
  243. +         next = sym->next;
  244. +         free(sym->name);
  245. +         free(sym);
  246. +         sym = next;
  247. +     }
  248. +     }
  249. + }
  250.   /* This is a simple hash function mapping a symbol name to a hash bucket. */
  251.   
  252. ! static unsigned int
  253.   hash (name)
  254.   char *name;
  255.   {
  256. !     char *s;
  257. !     unsigned int h;
  258. !     h = 0;
  259. !     s = name;
  260. !     while (*s != '\0')
  261. !     h += *s++;
  262. !     return h % SYM_MAX_HASH;
  263.   }
  264.   
  265.   
  266. diff -c old/symbol.h ./symbol.h
  267. *** old/symbol.h    Thu Mar 28 15:41:58 1991
  268. --- ./symbol.h    Wed Apr 03 21:52:30 1991
  269. ***************
  270. *** 1,4 ****
  271. ! /* $Id: symbol.h 2.1 91/02/28 11:16:22 cthuang Exp $
  272.    *
  273.    * Definitions for a symbol table
  274.    */
  275. --- 1,4 ----
  276. ! /* $Id: symbol.h 2.2 91/04/03 21:30:33 cthuang Exp $
  277.    *
  278.    * Definitions for a symbol table
  279.    */
  280. ***************
  281. *** 18,23 ****
  282. --- 18,24 ----
  283.   } SymbolTable;
  284.   
  285.   extern SymbolTable *create_symbol_table();    /* Create symbol table */
  286. + extern void destroy_symbol_table();        /* Create symbol table */
  287.   extern Symbol *find_symbol();            /* Lookup symbol name */
  288.   extern Symbol *new_symbol();            /* Define new symbol */
  289.   
  290.