cthuang@contact.UUCP (Chin Huang) (03/26/91)
Submitted-by: Chin Huang <cthuang@contact.UUCP> Posting-number: Volume 17, Issue 70 Archive-name: cproto/part01 Cproto is a program that generates function prototypes and variable declarations from C language source code. It uses a yacc generated parser, so it isn't confused by complex function definitions as much as other prototype generators. I avoided implementing the entire C language grammar by having the scanner discard everything between braces. An earlier version of cproto appeared in comp.sources.unix. This is an updated version with features added from Eric R. Smith's mkptypes program. Chin -------- #! /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: README CHANGES Makefile Makefile.uni cproto.1 # Wrapped by ibmpc@laphroig.UUCP on Mon Mar 25 11:41:03 1991 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f README -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"README\" else echo shar: Extracting \"README\" \(500 characters\) sed "s/^X//" >README <<'END_OF_README' XCproto is a program that generates function prototypes and variable Xdeclarations from C language source code. It uses a yacc generated Xparser, so it isn't confused by complex function definitions as much Xas other prototype generators. I avoided implementing the entire C Xlanguage grammar by having the scanner discard everything between Xbraces. X XCproto is in the public domain. If you have any comments or find any Xbugs, please let me know. X XChin Huang Xcthuang@contact.uucp Xchin.huang@canrem.uucp END_OF_README if test 500 -ne `wc -c <README`; then echo shar: \"README\" unpacked with wrong size! fi # end of overwriting check fi if test -f CHANGES -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"CHANGES\" else echo shar: Extracting \"CHANGES\" \(1575 characters\) sed "s/^X//" >CHANGES <<'END_OF_CHANGES' XVersion 2 X X- Added formal parameter promotion. X- Added prototype style that surrounds prototypes with a guard macro. X- Handles C++ style comment //. X- Nifty new way to set prototype output format. X- Got rid of the shell wrapper used to pipe the input through the C X preprocessor (cpp). X- For the port to MS-DOS, I modified cproto to run without cpp, but X since I didn't want to reimplement cpp, the program processes only the X #include and #define directives and ignores all others. Macro names X defined by the #define directive are treated like typedef names if X they appear in declaration specifiers. X XVersion 1 X XPatchlevel 3 X X- Fix: identical typedef names and struct tags should be allowed. X For example: X X typedef struct egg_salad egg_salad; X X struct egg_salad { X int mayo; X }; X X void dine(egg_salad l) X { X } X XPatchlevel 2 X X- Fix: A typedef statement should allow a list of typedefs to be declared. X Example: X X typedef int a, *b; X X- Fix: When run with the -v option on this input, cproto did not output X a declaration for variable "b": X X char *a="one"; char *b="two"; X X- The options were renamed. Added new options that change the output X format of the prototypes. X XPatchlevel 1 X X- Fix: Incorrect prototypes were produced for functions that take X function pointer parameters or return a function pointer. For example, X cproto produced an erroneous prototype for this function definition: X X void X (*signal (sig, func))() X int sig; X void (*func)(); X { X /* stuff */ X } X X- The lexical analyser now uses LEX. It should still be compatible with X FLEX. END_OF_CHANGES if test 1575 -ne `wc -c <CHANGES`; then echo shar: \"CHANGES\" unpacked with wrong size! fi # end of overwriting check fi if test -f Makefile -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"Makefile\" else echo shar: Extracting \"Makefile\" \(1405 characters\) sed "s/^X//" >Makefile <<'END_OF_Makefile' X# $Id: makefile 2.1 91/03/25 10:56:54 cthuang Exp $ X# X# MSDOS makefile for C prototype generator X XLEX = lex XYACC = yacc XCC = tcc XCFLAGS = -ml -X $(DEFINES) X XDEFINES = -DMSDOS X XDIST1 = README CHANGES Makefile Makefile.uni cproto.1 XDIST2 = $(SOURCES) XSOURCES = lex.l grammar.y \ X config.h cproto.h patchlev.h semantic.h symbol.h \ X cproto.c semantic.c string.c symbol.c XCSOURCES = cproto.c semantic.c string.c symbol.c y_tab.c XOBJECTS = cproto.obj semantic.obj getopt.obj symbol.obj \ X y_tab.obj X Xall: cproto.exe X Xcproto.exe: $(OBJECTS) X $(CC) $(CFLAGS) $(OBJECTS) X Xy_tab.obj: y_tab.c X $(CC) $(CFLAGS) -c $*.c X Xy_tab.c: grammar.y X $(YACC) grammar.y X Xlex_yy.c: lex.l X $(LEX) lex.l X XTAGS: $(SOURCES) X etags -t $(SOURCES) X Xclean: X erase *.obj X erase *.bak X erase *.log X erase lex_yy.c X erase y_tab.c X erase cproto1.exe X Xlint: X lint -B $(DEFINES) $(CSOURCES) X Xprint: X cpr $(SOURCES) | lpr -J'cproto' X Xshar: X rmcr $(DIST1) X rmcr $(DIST2) X shar $(DIST1) >cproto.sh1 X rmcr cproto.sh1 X shar $(DIST2) >cproto.sh2 X rmcr cproto.sh2 X Xzip: X pkzip -u cproto README CHANGES Makefile.* *.1 *.c *.h grammar.y lex.l X Xci: X ci -r2 -u $(DIST1) X ci -r2 -u $(DIST2) X X# DO NOT DELETE THIS LINE -- make depend depends on it. X Xcproto.obj: config.h cproto.h symbol.h Xsemantic.obj: config.h cproto.h symbol.h semantic.h Xstring.obj: config.h Xsymbol.obj: config.h symbol.h Xy_tab.obj: config.h cproto.h symbol.h semantic.h lex_yy.c END_OF_Makefile if test 1405 -ne `wc -c <Makefile`; then echo shar: \"Makefile\" unpacked with wrong size! fi # end of overwriting check fi if test -f Makefile.uni -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"Makefile.uni\" else echo shar: Extracting \"Makefile.uni\" \(1195 characters\) sed "s/^X//" >Makefile.uni <<'END_OF_Makefile.uni' X# $Id: Makefile.uni 2.1 91/02/28 11:15:54 cthuang Exp $ X# X# UNIX makefile for C prototype generator X XLEX = lex XYACC = yacc XCFLAGS = $(DEFINES) X X# Define SYSV for System V, otherwise BSD is assumed. X#DEFINES = -DSYSV X XDIST1 = README CHANGES Makefile Makefile.dos cproto.1 XDIST2 = $(SOURCES) XSOURCES = lex.l grammar.y \ X config.h cproto.h patchlev.h semantic.h symbol.h \ X cproto.c semantic.c string.c symbol.c XCSOURCES = cproto.c semantic.c string.c symbol.c y.tab.c XOBJECTS = cproto.o semantic.o string.o symbol.o y.tab.o X Xall: cproto X Xcproto: $(OBJECTS) X $(CC) $(CFLAGS) -o $@ $(OBJECTS) X Xy.tab.c: grammar.y X $(YACC) grammar.y X Xlex.yy.c: lex.l X $(LEX) lex.l X XTAGS: $(SOURCES) X etags -t $(SOURCES) X Xclean: X rm *.o *.bak *.log cproto1.exe X Xlint: X lint -B $(DEFINES) $(CSOURCES) X Xprint: X cpr $(SOURCES) | lpr -J'cproto' X Xshar: X shar $(DIST1) >cproto.sh1 X shar $(DIST2) >cproto.sh2 X Xci: X ci -u $(DIST1) $(DIST2) X Xdepend: X makedepend $(CSOURCES) X X# DO NOT DELETE THIS LINE -- make depend depends on it. X Xcproto.o: config.h cproto.h symbol.h Xsemantic.o: config.h cproto.h symbol.h semantic.h Xstring.o: config.h Xsymbol.o: config.h symbol.h Xy.tab.o: config.h cproto.h symbol.h semantic.h lex.yy.c END_OF_Makefile.uni if test 1195 -ne `wc -c <Makefile.uni`; then echo shar: \"Makefile.uni\" unpacked with wrong size! fi # end of overwriting check fi if test -f cproto.1 -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"cproto.1\" else echo shar: Extracting \"cproto.1\" \(3271 characters\) sed "s/^X//" >cproto.1 <<'END_OF_cproto.1' X.\" $Id: cproto.1 2.1 91/03/25 10:13:30 cthuang Exp $ X.\" X.de EX \"Begin example X.ne 5 X.if n .sp 1 X.if t .sp .5 X.nf X.in +.5i X.. X.de EE \"End example X.fi X.in -.5i X.if n .sp 1 X.if t .sp .5 X.. X.TH CPROTO 1 "February 28, 1991" X.SH NAME Xcproto \- generate C function prototypes from C source code X.SH SYNOPSIS X.B cproto X[ X.I option \fP...\fI X] [ X.I file \fP...\fI X] X.SH DESCRIPTION X.B Cproto Xreads C source code files and outputs function prototypes for external Xfunctions defined in the source to standard output. XThe function definitions may be in the old style or ANSI style. XOptionally, X.B cproto Xalso outputs declarations for any external variables defined in the file. XIf no X.I file Xargument is given, X.B cproto Xtakes its input from the standard input. X.SH OPTIONS X.TP X.B \-e XOutput the keyword X.B extern Xin front of each declaration having global scope. X.TP X.BI \-f n XSet the style of function prototype where X.I n Xis a number from 0 to 4. XFor example, consider the function definition X.EX Xmain (argc, argv) Xint argc; Xchar *argv[]; X{ X ... X} X.EE XIf the value is 0, then no prototypes are generated. XWhen set to 1, the output is: X.EX Xint main(/*int argc, char *argv[]*/); X.EE XFor a value of 2, the output has the form: X.EX Xint main(int /*argc*/, char */*argv*/[]); X.EE XThe default value is 3. XIt produces the full function prototype: X.EX Xint main(int argc, char *argv[]); X.EE XA value of 4 produces prototypes guarded by a macro: X.EX Xint main P_((int argc, char *argv[])); X.EE X.TP X.BI \-m name XSet the name of the macro used to guard prototypes when option -f4 is selected. XBy default it is "P_". X.TP X.B \-d XOmit the definition of the prototype macro named by the -m option. X.TP X.B \-p XDisable promotion of formal parameters in function prototypes. XBy default, parameters of type X.B char Xor X.B short Xin traditional style function definitions are promoted to type X.B int Xin the function prototype. XParameters of type X.B float Xget promoted to X.B double Xas well. X.TP X.B \-s XAlso output X.B static Xdeclarations. X.TP X.B \-v XAlso output declarations for variables defined in the file. X.TP X.BI \-F string XSet the format used to output each prototype. XThe string is a template in the form X.EX X" int main ( a, b )" X.EE Xwhere each space in the string may be replaced with whitespace characters. XFor example, the option X.EX X-F"int main(\\n\\ta,\\n\\tb\\n\\t)" X.EE Xwill produce prototypes in the format X.EX Xint main( X int argc, X char *argv[] X ); X.EE X.TP X.BI \-D name\[=value\] XThis option is passed through to the preprocessor and is used to define Xsymbols for use with conditionals such as X.I #ifdef. X.TP X.BI \-U name XThis option is passed through to the preprocessor and is used to remove Xany definitions of this symbol. X.TP X.BI \-I directory XThis option is passed through to the preprocessor and is used to specify Xa directory to search for files that are referenced with X.I #include. X.TP X.B \-V XPrint version information. X.SH AUTHOR XChin Huang Xcthuang@contact.uucp Xchin.huang@canrem.uucp X.SH BUGS XWhen cproto finds an error, it usually outputs the not very descriptive Xmessage "syntax error". X.TP XOptions that take string arguments only interpret the following Xcharacter escape sequences: X.EX X\\n newline X\\t tab X.EE X.SH "SEE ALSO" Xcc(1), Xcpp(1) END_OF_cproto.1 if test 3271 -ne `wc -c <cproto.1`; then echo shar: \"cproto.1\" 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.uucp 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.