cthuang@contact.UUCP (Chin Huang) (04/10/91)
Submitted-by: Chin Huang <cthuang@contact.UUCP> Posting-number: Volume 18, Issue 6 Archive-name: cproto/patch02 Patch-To: cproto: Volume 17, Issue 70-71 Here is patch 2 to cproto, a C function prototype generator. This patch enables cproto to scan lex and yacc source files for function definitions. It also fixes a problem that may cause segmentation faults. #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of shell archive." # Contents: patch2 # Wrapped by ibmpc@laphroig.UUCP on Thu Apr 04 16:53:33 1991 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f patch2 -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"patch2\" else echo shar: Extracting \"patch2\" \(6854 characters\) sed "s/^X//" >patch2 <<'END_OF_patch2' Xdiff -c old/CHANGES ./CHANGES X*** old/CHANGES Wed Apr 03 21:42:20 1991 X--- ./CHANGES Wed Apr 03 21:52:24 1991 X*************** X*** 1,5 **** X--- 1,15 ---- X Version 2 X X+ Patchlevel 2 X+ X+ - Cproto is now able to generate prototypes for functions defined in lex X+ and yacc source files named on the command line. Lex and yacc source X+ files are recognized by the .l or .y extension. X+ - Fix: The memory allocated to the typedef symbol table was not being X+ freed after scanning each source file. X+ - Fix: Failing to reset a variable during error recovery caused X+ segmentation faults. X+ X Patchlevel 1 X X - Fix: Cproto incorrectly generated the parameter "int ..." in Xdiff -c old/grammar.y ./grammar.y X*** old/grammar.y Wed Apr 03 21:42:26 1991 X--- ./grammar.y Wed Apr 03 21:52:28 1991 X*************** X*** 1,4 **** X! /* $Id: grammar.y 2.2 91/03/30 13:19:00 cthuang Exp $ X * X * yacc grammar for C prototype generator X * This was derived from the grammar given in Appendix A of X--- 1,4 ---- X! /* $Id: grammar.y 2.3 91/04/03 21:27:01 cthuang Exp $ X * X * yacc grammar for C prototype generator X * This was derived from the grammar given in Appendix A of X*************** X*** 558,563 **** X--- 558,564 ---- X yyerror (msg) X char *msg; X { X+ func_params = FALSE; X output_error(); X fprintf(stderr, "%s\n", msg); X } X*************** X*** 565,572 **** X void X parse_file () X { X printf("/* %s */\n", cur_file); X- line_num = 1; X typedef_names = create_symbol_table(); X yyparse(); X } X--- 566,583 ---- X void X parse_file () X { X+ char *s; X+ X+ if (strlen(cur_file) > 2) { X+ s = cur_file + strlen(cur_file) - 2; X+ if (strcmp(s, ".l") == 0 || strcmp(s, ".y") == 0) X+ BEGIN LEXYACC; X+ } X+ X printf("/* %s */\n", cur_file); X typedef_names = create_symbol_table(); X+ line_num = 1; X+ ly_count = 0; X yyparse(); X+ destroy_symbol_table(typedef_names); X } Xdiff -c old/lex.l ./lex.l X*** old/lex.l Thu Mar 28 15:41:56 1991 X--- ./lex.l Wed Apr 03 21:52:26 1991 X*************** X*** 1,5 **** X %{ X! /* $Id: lex.l 2.1 91/03/25 11:40:27 cthuang Exp $ X * X * C function prototype generator X * Lexical analyzer specification X--- 1,5 ---- X %{ X! /* $Id: lex.l 2.2 91/04/03 21:31:11 cthuang Exp $ X * X * C function prototype generator X * Lexical analyzer specification X*************** X*** 17,22 **** X--- 17,23 ---- X char cur_file[MAX_TEXT_LENGTH]; /* current file name */ X int line_num = 1; /* current line number in file */ X static int curly = 0; /* number of curly brace nesting levels */ X+ static int ly_count = 0; /* number of occurances of %% */ X X typedef struct { X FILE *fp; X*************** X*** 29,38 **** X static void do_include(); X %} X X! %s CPP1 CPP2 INIT1 INIT2 CURLY COMMENT X %% X X \n ++line_num; X X <INITIAL>^#{WS}* BEGIN CPP1; X <CPP1>define{WS}+{ID}.*\\$ { X--- 30,47 ---- X static void do_include(); X %} X X! %s CPP1 CPP2 INIT1 INIT2 CURLY COMMENT LEXYACC X %% X X \n ++line_num; X+ X+ <LEXYACC>^"%%" { X+ if (++ly_count >= 2) X+ BEGIN INITIAL; X+ } X+ <LEXYACC>^"%{" BEGIN INITIAL; X+ <LEXYACC>. ; X+ <INITIAL>^"%}" BEGIN LEXYACC; X X <INITIAL>^#{WS}* BEGIN CPP1; X <CPP1>define{WS}+{ID}.*\\$ { Xdiff -c old/Makefile ./Makefile X*** old/Makefile Wed Apr 03 21:42:28 1991 X--- ./Makefile Wed Apr 03 21:52:26 1991 X*************** X*** 1,4 **** X! # $Id: Makefile 2.2 91/03/30 13:19:06 cthuang Exp $ X # X # MSDOS makefile for C prototype generator X X--- 1,4 ---- X! # $Id: Makefile 2.3 91/04/03 21:26:50 cthuang Exp $ X # X # MSDOS makefile for C prototype generator X X*************** X*** 34,40 **** X $(LEX) lex.l X X cproto.man: cproto.1 X! cawf -man $*.1 >$@ X X TAGS: $(SOURCES) X etags -t $(SOURCES) X--- 34,40 ---- X $(LEX) lex.l X X cproto.man: cproto.1 X! cawf -man $*.1 | bsfilt - >$@ X X TAGS: $(SOURCES) X etags -t $(SOURCES) X*************** X*** 63,71 **** X zip: X pkzip -u cproto README CHANGES Makefile.* *.1 *.c *.h grammar.y lex.l X X! ci: X ci -u2 $(DIST1) $(DIST3) X ci -u2 $(DIST4) X X # DO NOT DELETE THIS LINE -- make depend depends on it. X X--- 63,75 ---- X zip: X pkzip -u cproto README CHANGES Makefile.* *.1 *.c *.h grammar.y lex.l X X! ci: rmcr X ci -u2 $(DIST1) $(DIST3) X ci -u2 $(DIST4) X+ X+ rmcr: X+ rmcr $(DIST1) $(DIST3) X+ rmcr $(DIST4) X X # DO NOT DELETE THIS LINE -- make depend depends on it. X Xdiff -c old/patchlev.h ./patchlev.h X*** old/patchlev.h Wed Apr 03 21:42:30 1991 X--- ./patchlev.h Wed Apr 03 21:52:28 1991 X*************** X*** 1,1 **** X! #define PATCHLEVEL 1 X--- 1,1 ---- X! #define PATCHLEVEL 2 Xdiff -c old/symbol.c ./symbol.c X*** old/symbol.c Thu Mar 28 15:42:00 1991 X--- ./symbol.c Wed Apr 03 21:52:32 1991 X*************** X*** 1,4 **** X! /* $Id: symbol.c 2.1 91/02/28 11:16:35 cthuang Exp $ X * X * Symbol table maintenance. Implements an abstract data type called X * the symbol table. X--- 1,4 ---- X! /* $Id: symbol.c 2.2 91/04/03 21:30:54 cthuang Exp $ X * X * Symbol table maintenance. Implements an abstract data type called X * the symbol table. X*************** X*** 7,12 **** X--- 7,13 ---- X #include "config.h" X #include "symbol.h" X X+ X /* Create a symbol table. X * Return a pointer to the symbol table or NULL if an error occurs. X */ X*************** X*** 24,36 **** X } X X X /* This is a simple hash function mapping a symbol name to a hash bucket. */ X X! static int X hash (name) X char *name; X { X! return (name[0] + name[1] + strlen(name)) % SYM_MAX_HASH; X } X X X--- 25,65 ---- X } X X X+ /* Free the memory allocated to the symbol table. X+ */ X+ void X+ destroy_symbol_table (symtab) X+ SymbolTable *symtab; X+ { X+ int i; X+ Symbol *sym, *next; X+ X+ for (i = 0; i < SYM_MAX_HASH; ++i) { X+ sym = symtab->bucket[i]; X+ while (sym != NULL) { X+ next = sym->next; X+ free(sym->name); X+ free(sym); X+ sym = next; X+ } X+ } X+ } X+ X+ X /* This is a simple hash function mapping a symbol name to a hash bucket. */ X X! static unsigned int X hash (name) X char *name; X { X! char *s; X! unsigned int h; X! X! h = 0; X! s = name; X! while (*s != '\0') X! h += *s++; X! return h % SYM_MAX_HASH; X } X X Xdiff -c old/symbol.h ./symbol.h X*** old/symbol.h Thu Mar 28 15:41:58 1991 X--- ./symbol.h Wed Apr 03 21:52:30 1991 X*************** X*** 1,4 **** X! /* $Id: symbol.h 2.1 91/02/28 11:16:22 cthuang Exp $ X * X * Definitions for a symbol table X */ X--- 1,4 ---- X! /* $Id: symbol.h 2.2 91/04/03 21:30:33 cthuang Exp $ X * X * Definitions for a symbol table X */ X*************** X*** 18,23 **** X--- 18,24 ---- X } SymbolTable; X X extern SymbolTable *create_symbol_table(); /* Create symbol table */ X+ extern void destroy_symbol_table(); /* Create symbol table */ X extern Symbol *find_symbol(); /* Lookup symbol name */ X extern Symbol *new_symbol(); /* Define new symbol */ X END_OF_patch2 if test 6854 -ne `wc -c <patch2`; then echo shar: \"patch2\" unpacked with wrong size! fi # end of overwriting check fi echo shar: End of shell archive. exit 0 -- Chin Huang cthuang@contact.uucp chin.huang%canrem@lsuc.on.ca exit 0 # Just in case... -- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM Sterling Software, IMD UUCP: uunet!sparky!kent Phone: (402) 291-8300 FAX: (402) 291-4362 Please send comp.sources.misc-related mail to kent@uunet.uu.net.