├── .gitignore ├── AUTHORS ├── CHANGES ├── MANIFEST ├── Makefile.in ├── README ├── aclocal.m4 ├── config.guess ├── config.sub ├── config_h.in ├── configure ├── configure.in ├── cproto.1 ├── cproto.c ├── cproto.h ├── dump.c ├── dump.h ├── emx ├── Makefile └── README ├── grammar.y ├── install-sh ├── lex.l ├── lintlibs.c ├── msdos ├── README ├── borland.mak ├── micrsoft.lnk ├── micrsoft.mak └── turboc.mak ├── os2 ├── README ├── run_test.cmd └── watcom.mak ├── package ├── cproto.spec └── debian │ ├── changelog │ ├── compat │ ├── control │ ├── copyright │ ├── docs │ ├── rules │ ├── source │ └── format │ └── watch ├── porting ├── README ├── getopt.c ├── getopt.h └── popen.c ├── semantic.c ├── semantic.h ├── strkey.c ├── symbol.c ├── symbol.h ├── system.h ├── testing ├── README ├── apollo.c ├── case01.ref ├── case02.ref ├── case03.ref ├── case04.ref ├── case05.ref ├── case06.ref ├── case07.ref ├── case08.ref ├── case09.ref ├── case10.ref ├── case11.ref ├── case12.ref ├── case13.ref ├── case14.ref ├── case15.ref ├── case16.ref ├── case17.ref ├── case18.ref ├── case19.ref ├── case20.ref ├── case21.ref ├── case22.ref ├── case23.ref ├── case24.ref ├── descrip.mms ├── linux.c ├── make_bat.sh ├── make_dcl.sh ├── makefile ├── run_test.com ├── run_test.sh ├── run_test.txt ├── solaris.c ├── syntax.c ├── test_dos.bat ├── testunix.sh └── turboc.c ├── trace.c ├── trace.h ├── vms ├── README └── descrip.mms ├── win32 ├── README └── watcom.mak └── yyerror.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Backup files 2 | *~ 3 | *.old 4 | *.bak 5 | *.log 6 | *.org 7 | *.orig 8 | *.rej 9 | *.tmp 10 | 11 | # Object files 12 | *.o 13 | *.ko 14 | *.obj 15 | *.elf 16 | 17 | # Precompiled Headers 18 | *.gch 19 | *.pch 20 | 21 | # Libraries 22 | *.lib 23 | *.a 24 | *.la 25 | *.lo 26 | 27 | # Shared objects (inc. Windows DLLs) 28 | *.dll 29 | *.so 30 | *.so.* 31 | *.dylib 32 | 33 | # Executables 34 | *.exe 35 | *.out 36 | *.app 37 | *.i*86 38 | *.x86_64 39 | *.hex 40 | 41 | core 42 | .nfs* 43 | 44 | /config.log 45 | /config.cache 46 | /config.h 47 | /config.status 48 | /default.h 49 | /cproto 50 | /Makefile 51 | /lex.yy.c 52 | /y.tab.c 53 | /.version 54 | /.fname 55 | 56 | /testing/*.dcl 57 | /testing/*.err 58 | /testing/case*.c 59 | /testing/case*.bat 60 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | -- $Id: AUTHORS,v 4.1 2010/07/11 16:43:24 tom Exp $ 2 | cthuang Chin Huang 3 | dickey Thomas E. Dickey 4 | -------------------------------------------------------------------------------- /MANIFEST: -------------------------------------------------------------------------------- 1 | MANIFEST for cproto-4.7l, version v4_7l 2 | -------------------------------------------------------------------------------- 3 | MANIFEST this file 4 | AUTHORS authors 5 | CHANGES summary of changes made to CPROTO 6 | Makefile.in top-level makefile template 7 | README overview of the CPROTO program 8 | aclocal.m4 autoconf macros 9 | config.guess configure utility script 10 | config.sub configure utility script 11 | config_h.in template for config.h 12 | configure configure script 13 | configure.in script for generating 'configure' via autoconf 14 | cproto.1 man-page for CPROTO 15 | cproto.c main program of CPROTO 16 | cproto.h common datatypes and definitions for CPROTO 17 | dump.c debug/trace 18 | dump.h interface of dump.c 19 | grammar.y yacc grammar for CPROTO 20 | install-sh install-script 21 | lex.l lex rules for CPROTO 22 | lintlibs.c functions used for lint-library formatting 23 | semantic.c functions to support yacc grammar (formatting and translation) 24 | semantic.h interface definitions of semantic.c 25 | strkey.c look for a keyword within a string 26 | symbol.c symbol-table support for CPROTO 27 | symbol.h interface definitions for symbol.c 28 | system.h system-dependent definitions, coordinated with config.h 29 | trace.c debugging support for CPROTO 30 | trace.h header for trace.c, dump.c 31 | yyerror.c enhanced error reporting support for yacc/bison 32 | emx subdirectory 33 | emx/Makefile makefile for gcc (EMX) 34 | emx/README description of files in emx directory 35 | msdos subdirectory 36 | msdos/README description of files in msdos directory 37 | msdos/borland.mak makefile for Borland C 38 | msdos/micrsoft.lnk linker-file for Microsoft C 39 | msdos/micrsoft.mak makefile for Microsoft C 40 | msdos/turboc.mak makefile for TurboC 41 | os2 subdirectory 42 | os2/README description of files in os2 directory 43 | os2/run_test.cmd run test-cases on OS/2 44 | os2/watcom.mak makefile for watcom (OS/2) 45 | package subdirectory 46 | package/cproto.spec RPM build-script for cproto 47 | package/debian subdirectory 48 | package/debian/changelog debian build script 49 | package/debian/compat debian build script 50 | package/debian/control debian build script 51 | package/debian/copyright debian build script 52 | package/debian/docs debian build script 53 | package/debian/rules debian build script 54 | package/debian/source subdirectory 55 | package/debian/source/format debian build script 56 | package/debian subdirectory 57 | package/debian/watch debian build script 58 | porting subdirectory 59 | porting/README description of files in CPROTO/PORTING 60 | porting/getopt.c free version of getopt 61 | porting/getopt.h header file for getopt 62 | porting/popen.c fake popen/pclose 63 | testing subdirectory 64 | testing/README description of files in CPROTO/TESTING 65 | testing/apollo.c template for apollo lint-library 66 | testing/case01.ref test case reference: no options 67 | testing/case02.ref test case reference: -f0 68 | testing/case03.ref test case reference: -c -f1 69 | testing/case04.ref test case reference: -c -f2 70 | testing/case05.ref test case reference: -c -f3 71 | testing/case06.ref test case reference: -c -f3 -v 72 | testing/case07.ref test case reference: -c -f3 -v -e 73 | testing/case08.ref test case reference: -c -f3 -v -e -m 74 | testing/case09.ref test case reference: -c -f3 -v + template 75 | testing/case10.ref test case reference: -T 76 | testing/case11.ref test case reference: -l 77 | testing/case12.ref test case reference: -s 78 | testing/case13.ref test case reference: -l -s 79 | testing/case14.ref test case reference: -l -x 80 | testing/case15.ref test case reference: apollo lint library (sr10.3.5) 81 | testing/case16.ref test case reference: -a 82 | testing/case17.ref test case reference: -t 83 | testing/case18.ref test case reference: -f1 84 | testing/case19.ref test case reference: -f2 85 | testing/case20.ref test case reference: -f3 86 | testing/case21.ref test case reference: -f3 -v + template 87 | testing/case22.ref test case reference: -l -a 88 | testing/case23.ref test case reference: -i 89 | testing/case24.ref test case reference: -i -s 90 | testing/descrip.mms VAX MMS-script for CPROTO/TESTING directory 91 | testing/linux.c include all linux files, for testing 92 | testing/make_bat.sh script for making dos-scripts 93 | testing/make_dcl.sh script to generate UNIX/VMS ".dcl" files 94 | testing/makefile UNIX makefile for CPROTO/TESTING directory 95 | testing/run_test.com VAX/VMS test script for CPROTO 96 | testing/run_test.sh UNIX test-script for CPROTO 97 | testing/run_test.txt template for test-scripts 98 | testing/solaris.c template for lint-library on Solaris 99 | testing/syntax.c odds & ends of syntax to use for testing 100 | testing/test_dos.bat dos test script 101 | testing/testunix.sh runs UNIX test scripts 102 | testing/turboc.c test-case for TurboC include-files 103 | vms subdirectory 104 | vms/README description of files in vms directory 105 | vms/descrip.mms makefile for vms 106 | win32 subdirectory 107 | win32/README description of files in win32 directory 108 | win32/watcom.mak makefile for watcom 109 | -------------------------------------------------------------------------------- /Makefile.in: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.in,v 4.21 2014/01/01 15:57:41 tom Exp $ 2 | # 3 | # UNIX template-makefile for C prototype generator 4 | 5 | THIS = cproto 6 | RELEASE = 4_7l 7 | 8 | #### Start of system configuration section. #### 9 | 10 | srcdir = @srcdir@ 11 | VPATH = @srcdir@ 12 | 13 | CC = @CC@ 14 | CPP = @CPP@ 15 | LEX = @LEX@ 16 | YACC = @YACC@ 17 | LINT = @LINT@ 18 | CTAGS = @CTAGS@ 19 | 20 | INSTALL = @INSTALL@ 21 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ 22 | INSTALL_DATA = @INSTALL_DATA@ 23 | 24 | DEFINES = 25 | EXTRA_CFLAGS = @EXTRA_CFLAGS@ 26 | CPPFLAGS = -I. -I$(srcdir) $(DEFINES) -DHAVE_CONFIG_H @CPPFLAGS@ 27 | CFLAGS = @CFLAGS@ $(EXTRA_CFLAGS) 28 | LIBS = @LIBS@ @LEXLIB@ 29 | 30 | prefix = @prefix@ 31 | exec_prefix = @exec_prefix@ 32 | datarootdir = @datarootdir@ 33 | 34 | bindir = @bindir@ 35 | mandir = @mandir@ 36 | manext = 1 37 | 38 | BINDIR = $(DESTDIR)$(bindir) 39 | MANDIR = $(DESTDIR)$(mandir)/man$(manext) 40 | 41 | x = @EXEEXT@ 42 | o = .@OBJEXT@ 43 | 44 | #### End of system configuration section. #### 45 | 46 | SHELL = /bin/sh 47 | @SET_MAKE@ 48 | 49 | PROG = $(THIS)$x 50 | 51 | LDFLAGS = @LDFLAGS@ 52 | 53 | DOC_FILES = \ 54 | README \ 55 | CHANGES \ 56 | $(THIS).1 57 | 58 | MAK_FILES = \ 59 | Makefile.in \ 60 | configure.in \ 61 | aclocal.m4 \ 62 | config_h.in 63 | 64 | H_FILES = \ 65 | yyerror.c \ 66 | system.h \ 67 | $(THIS).h \ 68 | semantic.h \ 69 | symbol.h 70 | 71 | C_FILES = \ 72 | $(THIS).c \ 73 | lintlibs.c \ 74 | semantic.c \ 75 | strkey.c \ 76 | symbol.c 77 | 78 | AUX_FILES = \ 79 | lex.l \ 80 | grammar.y 81 | 82 | JUNK = \ 83 | lex.yy.c \ 84 | y.tab.c 85 | 86 | EXTRA_OBJS = @EXTRA_OBJS@ 87 | OBJECTS = $(THIS)$o lintlibs$o semantic$o strkey$o symbol$o y.tab$o \ 88 | $(EXTRA_OBJS) 89 | SOURCES = $(DOC_FILES) $(MAK_FILES) $(H_FILES) $(C_FILES) $(AUX_FILES) 90 | 91 | all : $(PROG) # $(THIS).man 92 | 93 | install: all installdirs 94 | $(INSTALL_PROGRAM) $(PROG) $(BINDIR)/$(PROG) 95 | - $(INSTALL_DATA) $(srcdir)/$(THIS).1 $(MANDIR)/$(THIS).$(manext) 96 | 97 | installdirs: 98 | mkdir -p $(BINDIR) 99 | - mkdir -p $(MANDIR) 100 | 101 | uninstall: 102 | - rm -f $(BINDIR)/$(PROG) $(MANDIR)/$(THIS).$(manext) 103 | 104 | .c$o: 105 | @RULE_CC@ 106 | @ECHO_CC@$(CC) -c $(CFLAGS) $(CPPFLAGS) $< 107 | 108 | $(PROG) : $(OBJECTS) 109 | @ECHO_LD@$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(OBJECTS) $(LIBS) 110 | 111 | y.tab.c : grammar.y 112 | $(YACC) $(srcdir)/grammar.y 113 | 114 | lex.yy.c : lex.l 115 | $(LEX) $(srcdir)/lex.l 116 | 117 | mostlyclean :: 118 | - rm -f core .nfs* *$o *.bak *.BAK *.out $(JUNK) default.h 119 | 120 | clean :: mostlyclean 121 | - rm -f $(PROG) 122 | - cd $(srcdir)/testing && $(MAKE) $@ 123 | 124 | distclean :: clean 125 | - rm -f config.log config.cache config.status config.h Makefile 126 | - rm -f .version .fname 127 | - cd $(srcdir)/testing && $(MAKE) $@ 128 | 129 | realclean :: distclean 130 | - rm -f tags 131 | - cd $(srcdir)/testing && $(MAKE) $@ 132 | 133 | check: $(PROG) 134 | cd $(srcdir)/testing && $(MAKE) run_test 135 | 136 | # I keep my sources in RCS, and assign a symbolic release to the current patch 137 | # level. The 'manifest' script knows how to build a list of files for a given 138 | # revision -TD 139 | MANIFEST: 140 | manifest -rv$(RELEASE) \ 141 | $(THIS).man \ 142 | $(srcdir)/testing/case*.dcl \ 143 | $(srcdir)/testing/case*.bat 144 | 145 | dist: MANIFEST 146 | - rm -f .fname .files 147 | echo '$(THIS)-$(RELEASE)' >.fname 148 | cat MANIFEST | grep ' ' | egrep -v ' subdirectory$$' | sed -e 's/\ .*//' | uniq >.files 149 | rm -rf `cat .fname` 150 | TOP=`cat .fname`; mkdir $$TOP `cat .files | grep / | sed -e 's@/.*@@' | sed -e s@\^@$$TOP/@ | uniq` 151 | for file in `cat .files`; do \ 152 | ln $(srcdir)/$$file `cat .fname`/$$file \ 153 | || { echo copying $$file instead; cp $$file `cat .fname`/$$file; }; \ 154 | done 155 | tar -cf - `cat .fname` | gzip >`cat .fname`.tgz 156 | rm -rf `cat .fname` .fname .files 157 | 158 | default.h: $(C_FILES) lex.yy.c 159 | ./$(PROG) -e -v -m -M ARGS -d $(DEFINES) $(C_FILES) grammar.y >$@ 160 | 161 | getopt.o : $(srcdir)/porting/getopt.c 162 | $(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/porting/getopt.c 163 | 164 | popen.o : $(srcdir)/porting/popen.c 165 | $(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/porting/popen.c 166 | 167 | lint: $(C_FILES) $(JUNK) 168 | $(LINT) $(CPPFLAGS) $(C_FILES) y.tab.c >$@.out 169 | 170 | llib: $(C_FILES) $(JUNK) 171 | ./$(PROG) -l $(CPPFLAGS) $(C_FILES) y.tab.c >$@.out 172 | 173 | self: $(C_FILES) $(JUNK) 174 | ./$(PROG) $(CPPFLAGS) $(C_FILES) y.tab.c >$@.out 175 | 176 | tags: $(H_FILES) $(C_FILES) $(AUX_FILES) 177 | $(CTAGS) $(C_FILES) $(AUX_FILES) $(H_FILES) 178 | 179 | depend: 180 | makedepend -- $(CPPFLAGS) -- $(C_FILES) y.tab.c 181 | 182 | # DO NOT DELETE THIS LINE -- make depend depends on it. 183 | 184 | cproto$o : cproto.h config.h system.h 185 | lintlibs$o : cproto.h config.h system.h semantic.h symbol.h 186 | semantic$o : cproto.h config.h system.h semantic.h 187 | strkey$o : cproto.h config.h system.h 188 | symbol$o : cproto.h config.h system.h symbol.h 189 | y.tab$o : cproto.h config.h system.h symbol.h semantic.h lex.yy.c yyerror.c 190 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Cproto is a program that generates function prototypes and variable 2 | declarations from C source code. It can also convert function definitions 3 | between the old style and the ANSI C style. This conversion overwrites the 4 | original files, so make a backup copy of your files in case something goes 5 | wrong. 6 | 7 | The program isn't confused by complex function definitions as much as other 8 | prototype generators because it uses a yacc generated parser. By ignoring all 9 | the input between braces, I avoided implementing the entire C language grammar. 10 | 11 | Cproto is in the public domain, except for the configure script which is 12 | copyrighted by the Free Software Foundation, Inc. 13 | 14 | Chin Huang 15 | 16 | Thomas Dickey 17 | dickey@invisible-island.net 18 | -------------------------------------------------------------------------------- /config_h.in: -------------------------------------------------------------------------------- 1 | /* @configure_input@ */ 2 | /* $Id: config_h.in,v 4.2 1995/01/01 19:34:59 cthuang Exp $ */ 3 | @DEFS@ 4 | -------------------------------------------------------------------------------- /configure.in: -------------------------------------------------------------------------------- 1 | dnl Process this file with 'autoconf' to produce a 'configure' script 2 | dnl $Id: configure.in,v 4.16 2014/01/01 15:48:47 tom Exp $ 3 | AC_REVISION($Revision: 4.16 $) 4 | AC_PREREQ(2.52.20030208) 5 | AC_INIT(cproto.c) 6 | AC_CONFIG_HEADER(config.h:config_h.in) 7 | CF_CHECK_CACHE 8 | 9 | CF_PROG_CC 10 | AC_PROG_CPP 11 | AC_PROG_LEX 12 | AC_PROG_MAKE_SET 13 | AC_PROG_YACC 14 | AC_PROG_INSTALL 15 | CF_MAKE_TAGS 16 | CF_PROG_LINT 17 | 18 | CF_XOPEN_SOURCE 19 | 20 | CF_WITH_WARNINGS 21 | CF_DISABLE_ECHO 22 | 23 | if test -n "$LINT" ; then 24 | cf_have_lint=yes 25 | else 26 | cf_have_lint=no 27 | fi 28 | 29 | AC_ARG_ENABLE(llib, 30 | [ --enable-llib enable lint-library (llib) support], 31 | [cf_enable_llib=$enableval], 32 | [cf_enable_llib=$cf_have_lint]) 33 | 34 | if test "$cf_enable_llib" = yes ; then 35 | AC_DEFINE(OPT_LINTLIBRARY) 36 | fi 37 | 38 | ### extra things that we'll substitute in the makefile 39 | dnl AC_SUBST(LIBS) 40 | AC_SUBST(EXTRA_OBJS) 41 | 42 | AC_CONST 43 | AC_STDC_HEADERS 44 | AC_HAVE_HEADERS(stdlib.h unistd.h) 45 | AC_HAVE_HEADERS(getopt.h string.h memory.h) 46 | 47 | AC_HAVE_FUNCS(getopt popen strstr tmpfile link unlink) 48 | 49 | if test "x$ac_cv_func_getopt" = xno 50 | then 51 | CPPFLAGS="$CPPFLAGS -I\$(srcdir)/porting" 52 | EXTRA_OBJS="$EXTRA_OBJS getopt.o" 53 | fi 54 | 55 | if test "x$ac_cv_func_popen" = xno 56 | then 57 | CPPFLAGS="$CPPFLAGS -I\$(srcdir)/porting" 58 | EXTRA_OBJS="$EXTRA_OBJS popen.o" 59 | fi 60 | 61 | ### special configuration tests 62 | CF_MKSTEMP 63 | CF_SIZE_T 64 | CF_YACC_ERROR 65 | CF_POPEN_TEST 66 | 67 | ### debugging/testing 68 | AC_ARG_WITH(trace, 69 | [ --with-trace use trace.c for memory-testing],[ 70 | AC_HEADER_TIME 71 | AC_HAVE_FUNCS(gettimeofday) 72 | AC_DEFINE(DOALLOC,10000) 73 | EXTRA_OBJS="$EXTRA_OBJS trace.o dump.o"]) 74 | CF_DISABLE_LEAKS 75 | 76 | echo setting other definitions 77 | AC_DEFINE_UNQUOTED(CPP,"$CPP") 78 | 79 | ### output makefile and config.h 80 | AC_OUTPUT(Makefile,,,cat) 81 | CF_MAKE_DOCS(cproto,1) 82 | -------------------------------------------------------------------------------- /cproto.1: -------------------------------------------------------------------------------- 1 | .\" $Id: cproto.1,v 4.9 2010/07/14 09:43:24 tom Exp $ 2 | .\" 3 | .de EX \"Begin example 4 | .ne 5 5 | .if n .sp 1 6 | .if t .sp .5 7 | .nf 8 | .in +5n 9 | .. 10 | .de EE \"End example 11 | .fi 12 | .in -5n 13 | .if n .sp 1 14 | .if t .sp .5 15 | .. 16 | .TH CPROTO 1 "July 2010" 17 | . 18 | .SH NAME 19 | cproto \- generate C function prototypes and convert function definitions 20 | . 21 | .SH SYNOPSIS 22 | .B cproto 23 | [ 24 | .I option \fP...\fI 25 | ] [ 26 | .I file \fP...\fI 27 | ] 28 | . 29 | .SH DESCRIPTION 30 | .B Cproto 31 | generates function prototypes for 32 | functions defined in the specified C source files to the standard output. 33 | The function definitions may be in the old style or ANSI C style. 34 | Optionally, 35 | .B cproto 36 | also outputs declarations for variables defined in the files. 37 | If no 38 | .I file 39 | argument is given, 40 | .B cproto 41 | reads its input from the standard input. 42 | .LP 43 | By giving a command line option, 44 | .B cproto 45 | will also convert function definitions in the specified files from the 46 | old style to the ANSI C style. 47 | The original source files along with files specified by 48 | .EX 49 | #include "file" 50 | .EE 51 | directives appearing in the source code will be overwritten 52 | with the converted code. 53 | If no file names are given on the command line, then the program reads 54 | the source code from the standard input and outputs the converted source 55 | to the standard output. 56 | .LP 57 | If any comments appear in the parameter declarations for a function definition, 58 | such as in the example, 59 | .EX 60 | main (argc, argv) 61 | int argc; /* number of arguments */ 62 | char *argv[]; /* arguments */ 63 | { 64 | } 65 | .EE 66 | then the converted function definition will have the form 67 | .EX 68 | int 69 | main ( 70 | int argc, /* number of arguments */ 71 | char *argv[] /* arguments */ 72 | ) 73 | { 74 | } 75 | .EE 76 | Otherwise, the converted function definition will look like 77 | .EX 78 | int 79 | main (int argc, char *argv[]) 80 | { 81 | } 82 | .EE 83 | .LP 84 | .B Cproto 85 | can optionally convert function definitions from the ANSI style to the old 86 | style. 87 | In this mode, the program also converts function declarators and prototypes 88 | that appear outside function bodies. 89 | This is not a complete ANSI C to old C conversion. 90 | The program does not change anything within function bodies. 91 | .LP 92 | .B Cproto 93 | can optionally generate source in lint\-library format. 94 | This is useful in environments where the \fBlint\fR utility is 95 | used to supplement prototype checking of your program. 96 | . 97 | .SH OPTIONS 98 | .TP 99 | .B \-e 100 | Output the keyword 101 | .B extern 102 | in front of every generated prototype or declaration that has global scope. 103 | .TP 104 | .BI \-f " n" 105 | Set the style of generated function prototypes where 106 | .I n 107 | is a number from 0 to 3. 108 | For example, consider the function definition 109 | .EX 110 | main (argc, argv) 111 | int argc; 112 | char *argv[]; 113 | { 114 | } 115 | .EE 116 | If the value is 0, then no prototypes are generated. 117 | When set to 1, the output is: 118 | .EX 119 | int main(/*int argc, char *argv[]*/); 120 | .EE 121 | For a value of 2, the output has the form: 122 | .EX 123 | int main(int /*argc*/, char */*argv*/[]); 124 | .EE 125 | The default value is 3. 126 | It produces the full function prototype: 127 | .EX 128 | int main(int argc, char *argv[]); 129 | .EE 130 | .TP 131 | .B \-l 132 | Generate text for a lint\-library (overrides the "\fB\-f\fR" option). 133 | The output includes the comment 134 | .EX 135 | /* LINTLIBRARY */ 136 | .EE 137 | Special comments LINT_EXTERN and LINT_PREPRO (a la "VARARGS") 138 | respectively turn on the "\-x" 139 | option and copy comment\-text to the output (for preprocessing in \fBlint\fR). 140 | Use the comment 141 | .EX 142 | /* LINT_EXTERN2 */ 143 | .EE 144 | to include externs defined in the first level of include\-files. 145 | Use the comment 146 | .EX 147 | /* LINT_SHADOWED */ 148 | .EE 149 | to cause 150 | .B cproto 151 | to put "#undef" directives before each lint library declaration 152 | (i.e., to avoid conflicts with macros that happen to have to have 153 | the same name as the functions, thus causing syntax errors). 154 | .P 155 | Note that these special comments 156 | are not supported under VAX/VMS, since there is no 157 | equivalent for the "\-C" option of cpp with VAX\-C. 158 | .TP 159 | .B \-c 160 | The parameter comments in the prototypes generated by 161 | the \-f1 and \-f2 options are omitted by default. 162 | Use this option to enable the output of these comments. 163 | .TP 164 | .B \-m 165 | Put a macro around the parameter list of every generated prototype. 166 | For example: 167 | .EX 168 | int main P_((int argc, char *argv[])); 169 | .EE 170 | .TP 171 | .BI \-M " name" 172 | Set the name of the macro used to surround prototype parameter lists 173 | when option \-m is selected. 174 | The default is "P_". 175 | .TP 176 | .B \-d 177 | Omit the definition of the prototype macro used by the \-m option. 178 | .TP 179 | .BI \-o " file" 180 | Specify the name of the output file (default: standard output). 181 | .TP 182 | .BI \-O " file" 183 | Specify the name of the error file (default: standard error). 184 | .TP 185 | .B \-p 186 | Disable promotion of formal parameters in old style function definitions. 187 | By default, parameters of type 188 | .B char 189 | or 190 | .B short 191 | in old style function definitions are promoted to type 192 | .B int 193 | in the function prototype or converted ANSI C function definition. 194 | Parameters of type 195 | .B float 196 | get promoted to 197 | .B double 198 | as well. 199 | .TP 200 | .B \-q 201 | Do not output any error messages when the program cannot read the 202 | file specified in an 203 | .I #include 204 | directive. 205 | .TP 206 | .B \-s 207 | By default, 208 | .B cproto 209 | only generates declarations for functions and variables having global scope. 210 | This option will output 211 | .B static 212 | declarations as well. 213 | .TP 214 | .B \-S 215 | Output only static declarations. 216 | .TP 217 | .B \-i 218 | By default, 219 | .B cproto 220 | only generates declarations for functions and variables having global scope. 221 | This option will output 222 | .B inline 223 | declarations as well. 224 | .TP 225 | .B \-T 226 | Copy type definitions from each file. 227 | (Definitions in included\-files are copied, unlike the "\-l" option). 228 | .TP 229 | .B \-v 230 | Also output declarations for variables defined in the source. 231 | .TP 232 | .B \-x 233 | This option causes procedures and variables which are declared "extern" 234 | to be included in the output. 235 | .TP 236 | .BI \-X " level" 237 | This option limits the include\-file level from which declarations are extracted 238 | by examining the preprocessor output. 239 | .TP 240 | .B \-a 241 | Convert function definitions from the old style to the ANSI C style. 242 | .TP 243 | .B \-t 244 | Convert function definitions from the ANSI C style to the traditional style. 245 | .TP 246 | .B \-b 247 | Rewrite function definition heads to include both old style and new style 248 | declarations separated by a conditional compilation directive. 249 | For example, the program can generate this function definition: 250 | .EX 251 | #ifdef ANSI_FUNC 252 | 253 | int 254 | main (int argc, char *argv[]) 255 | #else 256 | 257 | int 258 | main (argc, argv) 259 | int argc; 260 | char *argv[] 261 | #endif 262 | { 263 | } 264 | .EE 265 | .TP 266 | .BI \-B " directive" 267 | Set the conditional compilation directive to output at the beginning of 268 | function definitions generated by the \-b option. 269 | The default is 270 | .EX 271 | #ifdef ANSI_FUNC 272 | .EE 273 | .LP 274 | .nf 275 | .BI \-P " template" 276 | .BI \-F " template" 277 | .BI \-C " template" 278 | .fi 279 | .in +5n 280 | Set the output format for generated prototypes, function definitions, 281 | and function definitions with parameter comments respectively. 282 | The format is specified by a template in the form 283 | .EX 284 | " int f ( a, b )" 285 | .EE 286 | but you may replace each space in this string with any number of 287 | whitespace characters. 288 | For example, the option 289 | .EX 290 | \-F"int f(\\n\\ta,\\n\\tb\\n\\t)" 291 | .EE 292 | will produce 293 | .EX 294 | int main( 295 | int argc, 296 | char *argv[] 297 | ) 298 | .EE 299 | .TP 300 | .BI \-D " name[=value]" 301 | This option is passed through to the preprocessor and is used to define 302 | symbols for use with conditionals such as 303 | .I #ifdef. 304 | .TP 305 | .BI \-U " name" 306 | This option is passed through to the preprocessor and is used to remove 307 | any definitions of this symbol. 308 | .TP 309 | .BI \-I " directory" 310 | This option is passed through to the preprocessor and is used to specify 311 | a directory to search for files that are referenced with 312 | .I #include. 313 | .TP 314 | .BI \-E " cpp" 315 | Pipe the input files through the specified C preprocessor command 316 | when generating prototypes. 317 | By default, the program uses /lib/cpp. 318 | .TP 319 | .BI \-E " 0" 320 | Do not run the C preprocessor. 321 | .TP 322 | .B \-V 323 | Print version information. 324 | . 325 | .SH ENVIRONMENT 326 | The environment variable CPROTO is scanned for 327 | a list of options in the same format as the command line options. 328 | Options given on the command line override any corresponding 329 | environment option. 330 | . 331 | .SH BUGS 332 | If an un\-tagged struct, union or enum declaration appears in 333 | a generated function prototype or converted function definition, 334 | the content of the declaration between the braces is empty. 335 | .LP 336 | The program does not pipe the source files through the C preprocessor when 337 | it is converting function definitions. 338 | Instead, it tries to handle preprocessor directives and macros itself 339 | and can be confused by tricky macro expansions. 340 | The conversion also discards some comments in the function definition 341 | head. 342 | .LP 343 | The \-v option does not generate declarations for variables defined with the 344 | .B extern 345 | specifier. 346 | This doesn't strictly conform to the C language standard but this rule 347 | was implemented because include files commonly declare variables this way. 348 | .LP 349 | When the program encounters an error, it usually outputs the not very 350 | descriptive message "syntax error". 351 | (Your configuration may allow the extended error reporting in yyerror.c). 352 | .LP 353 | Options that take string arguments only interpret the following 354 | character escape sequences: 355 | .EX 356 | \\n newline 357 | \\s space 358 | \\t tab 359 | .EE 360 | .LP 361 | VARARGS comments don't get passed through on systems whose C preprocessors 362 | don't support this (e.g., VAX/VMS, MS\-DOS). 363 | . 364 | .SH AUTHOR 365 | .nf 366 | Chin Huang 367 | cthuang@vex.net 368 | cthuang@interlog.com 369 | .sp 370 | Thomas Dickey 371 | dickey@invisible\-island.net 372 | modifications to support lint library, type\-copying, and port to VAX/VMS. 373 | .fi 374 | . 375 | .SH "SEE ALSO" 376 | cc(1), 377 | cpp(1) 378 | -------------------------------------------------------------------------------- /cproto.h: -------------------------------------------------------------------------------- 1 | /* $Id: cproto.h,v 4.18 2013/10/25 20:28:26 tom Exp $ 2 | * 3 | * Declarations for C function prototype generator 4 | */ 5 | #ifndef CPROTO_H 6 | #define CPROTO_H 7 | 8 | #ifdef HAVE_CONFIG_H 9 | #include 10 | #endif 11 | 12 | #ifndef BISON_HAS_YYTNAME 13 | #define BISON_HAS_YYTNAME 0 14 | #endif 15 | 16 | #ifndef YACC_HAS_YYNAME 17 | #define YACC_HAS_YYNAME 0 18 | #endif 19 | 20 | #ifndef YACC_HAS_YYTOKS 21 | #define YACC_HAS_YYTOKS 0 22 | #endif 23 | 24 | #ifndef YACC_HAS_YYTOKS_2 25 | #define YACC_HAS_YYTOKS_2 0 26 | #endif 27 | 28 | #ifndef HAVE_LINK 29 | #define HAVE_LINK 0 30 | #endif 31 | 32 | #ifndef HAVE_POPEN_PROTOTYPE 33 | #define HAVE_POPEN_PROTOTYPE 0 34 | #endif 35 | 36 | #ifndef HAVE_LIBDBMALLOC 37 | #define HAVE_LIBDBMALLOC 0 38 | #endif 39 | 40 | #ifndef HAVE_LIBDMALLOC 41 | #define HAVE_LIBDMALLOC 0 42 | #endif 43 | 44 | #include 45 | 46 | #ifndef GCC_PRINTFLIKE 47 | #if defined(GCC_PRINTF) && !defined(printf) 48 | #define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var))) 49 | #else 50 | #define GCC_PRINTFLIKE(fmt,var) /*nothing */ 51 | #endif 52 | #endif 53 | 54 | #ifndef GCC_SCANFLIKE 55 | #if defined(GCC_SCANF) && !defined(scanf) 56 | #define GCC_SCANFLIKE(fmt,var) __attribute__((format(scanf,fmt,var))) 57 | #else 58 | #define GCC_SCANFLIKE(fmt,var) /*nothing */ 59 | #endif 60 | #endif 61 | 62 | #ifndef GCC_NORETURN 63 | #define GCC_NORETURN /* nothing */ 64 | #endif 65 | 66 | #ifndef GCC_UNUSED 67 | #define GCC_UNUSED /* nothing */ 68 | #endif 69 | 70 | #if HAVE_LIBDMALLOC || HAVE_LIBDBMALLOC || defined(DOALLOC) 71 | #undef NO_LEAKS 72 | #define NO_LEAKS 1 73 | #endif 74 | 75 | #ifdef lint 76 | #define NEW(type) (type *)0 77 | #else 78 | #define NEW(type) (type *)xmalloc(sizeof(type)) 79 | #endif 80 | 81 | #ifndef UCH 82 | #define UCH(c) ((unsigned char)(c)) 83 | #endif 84 | 85 | /* Useful constants (mainly to avoid problems balancing parentheses...) */ 86 | #define ELLIPSIS "..." 87 | #define PAREN_L '(' 88 | #define PAREN_R ')' 89 | #define SQUARE_L '[' 90 | #define SQUARE_R ']' 91 | #define CURL_L '{' 92 | #define CURL_R '}' 93 | #define COMMENT_BEGIN "/*" 94 | #define COMMENT_END "*/" 95 | 96 | /* Boolean type */ 97 | typedef char boolean; 98 | 99 | /* Source file text */ 100 | typedef struct text { 101 | char text[MAX_TEXT_SIZE]; /* source text */ 102 | long begin; /* offset in temporary file */ 103 | } Text; 104 | 105 | /* This is a list of function parameters. */ 106 | typedef struct parameter_list { 107 | struct parameter *first; /* pointer to first parameter in list */ 108 | struct parameter *last; /* pointer to last parameter in list */ 109 | long begin_comment; /* begin offset of comment */ 110 | long end_comment; /* end offset of comment */ 111 | char *comment; /* comment at start of parameter list */ 112 | } ParameterList; 113 | 114 | /* Declaration specifier flags */ 115 | #define DS_NONE 0 /* default */ 116 | #define DS_EXTERN 1 /* contains "extern" specifier */ 117 | #define DS_STATIC 2 /* contains "static" specifier */ 118 | #define DS_CHAR 4 /* contains "char" type specifier */ 119 | #define DS_SHORT 8 /* contains "short" type specifier */ 120 | #define DS_FLOAT 16 /* contains "float" type specifier */ 121 | #define DS_INLINE 32 /* contains "inline" specifier */ 122 | #define DS_JUNK 64 /* we're not interested in this declaration */ 123 | 124 | /* This structure stores information about a declaration specifier. */ 125 | typedef struct decl_spec { 126 | unsigned short flags; /* flags defined above */ 127 | char *text; /* source text */ 128 | long begin; /* offset in temporary file */ 129 | } DeclSpec; 130 | 131 | /* Styles of function definitions */ 132 | #if OPT_LINTLIBRARY 133 | #define FUNC_UNKNOWN -1 /* unspecified */ 134 | #else 135 | #define FUNC_UNKNOWN 0 /* unspecified (same as FUNC_NONE) */ 136 | #endif 137 | #define FUNC_NONE 0 /* not a function definition */ 138 | #define FUNC_TRADITIONAL 1 /* traditional style */ 139 | #define FUNC_ANSI 2 /* ANSI style */ 140 | #define FUNC_BOTH 3 /* both styles */ 141 | typedef int FuncDefStyle; 142 | 143 | /* This structure stores information about a declarator. */ 144 | typedef struct declarator { 145 | char *name; /* name of variable or function */ 146 | char *text; /* source text */ 147 | long begin; /* offset in temporary file */ 148 | long begin_comment; /* begin offset of comment */ 149 | long end_comment; /* end offset of comment */ 150 | FuncDefStyle func_def; /* style of function definition */ 151 | ParameterList params; /* function parameters */ 152 | boolean pointer; /* TRUE if it declares a pointer */ 153 | struct declarator *head; /* head function declarator */ 154 | struct declarator *func_stack; /* stack of function declarators */ 155 | struct declarator *next; /* next declarator in list */ 156 | } Declarator; 157 | 158 | /* This is a list of declarators. */ 159 | typedef struct declarator_list { 160 | Declarator *first; /* pointer to first declarator in list */ 161 | Declarator *last; /* pointer to last declarator in list */ 162 | } DeclaratorList; 163 | 164 | /* This structure stores information about a function parameter. */ 165 | typedef struct parameter { 166 | struct parameter *next; /* next parameter in list */ 167 | DeclSpec decl_spec; 168 | Declarator *declarator; 169 | char *comment; /* comment following the parameter */ 170 | } Parameter; 171 | 172 | /* parser stack entry type */ 173 | typedef union { 174 | Text text; 175 | DeclSpec decl_spec; 176 | Parameter *parameter; 177 | ParameterList param_list; 178 | Declarator *declarator; 179 | DeclaratorList decl_list; 180 | } YYSTYPE; 181 | 182 | /* Prototype styles */ 183 | #if OPT_LINTLIBRARY 184 | #define PROTO_ANSI_LLIB -2 /* form ANSI lint-library source */ 185 | #define PROTO_LINTLIBRARY -1 /* form lint-library source */ 186 | #endif 187 | #define PROTO_NONE 0 /* do not output any prototypes */ 188 | #define PROTO_TRADITIONAL 1 /* comment out parameters */ 189 | #define PROTO_ABSTRACT 2 /* comment out parameter names */ 190 | #define PROTO_ANSI 3 /* ANSI C prototype */ 191 | typedef int PrototypeStyle; 192 | 193 | #define ansiLintLibrary() (proto_style == PROTO_ANSI_LLIB) 194 | #define knrLintLibrary() (proto_style == PROTO_LINTLIBRARY) 195 | #define lintLibrary() (knrLintLibrary() || ansiLintLibrary()) 196 | 197 | /* The role of a function declarator */ 198 | #define FUNC_OTHER 0 /* miscellaneous declaration */ 199 | #define FUNC_PROTO 1 /* prototype */ 200 | #define FUNC_DEF 2 /* function definition */ 201 | typedef int FuncDeclRole; 202 | 203 | /* Prototype/function definition output formats */ 204 | #define FMT_OTHER 0 /* miscellaneous */ 205 | #define FMT_PROTO 1 /* prototype */ 206 | #define FMT_FUNC 2 /* function definition */ 207 | #define FMT_FUNC_COMMENT 3 /* func. def. with parameter comments */ 208 | typedef int FuncFormatType; 209 | 210 | /* select scope of declarations to output */ 211 | #define SCOPE_STATIC 1 /* only output declarations with local scope */ 212 | #define SCOPE_EXTERN 2 /* only output declarations with global scope */ 213 | #define SCOPE_ALL 3 /* output all declarations */ 214 | typedef int Scope; 215 | 216 | /* Prototype/function definition output format */ 217 | typedef struct func_format { 218 | const char *decl_spec_prefix; /* output before declaration specifier */ 219 | const char *declarator_prefix; /* output before declarator name */ 220 | const char *declarator_suffix; /* output before '(' of parameter list */ 221 | const char *first_param_prefix; /* output before first parameter */ 222 | const char *middle_param_prefix; /* output before each subsequent parameter */ 223 | const char *last_param_suffix; /* output after last parameter */ 224 | } FuncFormat; 225 | 226 | /* Program options */ 227 | extern boolean extern_out; 228 | extern Scope scope_out; 229 | extern boolean inline_out; 230 | #if OPT_LINTLIBRARY 231 | extern boolean types_out; 232 | extern boolean lint_shadowed; 233 | #endif 234 | extern boolean variables_out; 235 | extern boolean promote_param; 236 | extern PrototypeStyle proto_style; 237 | extern FuncDefStyle func_style; 238 | extern boolean proto_macro; 239 | extern boolean define_macro; 240 | extern const char *macro_name; 241 | extern boolean proto_comments; 242 | extern boolean file_comments; 243 | extern boolean quiet; 244 | extern const char *func_directive; 245 | extern unsigned num_inc_dir; 246 | extern char **inc_dir; 247 | extern FuncFormat fmt[4]; 248 | 249 | /* Global declarations */ 250 | extern char *progname; 251 | extern int varargs_num; /* supports varargs-comment */ 252 | extern char *varargs_str; /* additional info, such as PRINTFLIKEnn */ 253 | extern unsigned extern_in; /* supports "LINT_EXTERNnn" */ 254 | extern int do_tracking; /* supports "-X" option */ 255 | extern int exitlike_func; /* supports noreturn-attribute */ 256 | extern unsigned in_include; /* current include-level */ 257 | extern int debug_trace; 258 | extern char base_file[]; 259 | 260 | /* cproto.c */ 261 | #if HAVE_LIBDBMALLOC 262 | extern void ExitProgram(int code); 263 | #define exit(code) ExitProgram(code) 264 | #endif 265 | #if !HAVE_LIBDMALLOC 266 | #ifdef NO_LEAKS 267 | extern void *xRealloc(void *p, unsigned n, char *f, int l); 268 | extern void *xMalloc(unsigned n, char *f, int l); 269 | extern char *xStrdup(const char *s, char *f, int l); 270 | #define xrealloc(p,n) xRealloc(p, n, __FILE__, __LINE__) 271 | #define xmalloc(n) xMalloc(n, __FILE__, __LINE__) 272 | #define xstrdup(s) xStrdup(s, __FILE__, __LINE__) 273 | #else 274 | extern void *xrealloc(void *p, size_t n); 275 | extern void *xmalloc(size_t n); 276 | extern char *xstrdup(const char *src); 277 | #endif 278 | #endif /* !HAVE_LIBDMALLOC */ 279 | extern void put_error(void); 280 | extern int is_path_sep(int ch); 281 | extern char *trim_path_sep(char *s); 282 | 283 | /* lintlibs.c */ 284 | #if OPT_LINTLIBRARY 285 | extern void put_string(FILE *outf, const char *s); 286 | extern void put_char(FILE *outf, int c); 287 | extern void put_newline(FILE *outf); 288 | extern void put_blankline(FILE *outf); 289 | extern void put_padded(FILE *outf, const char *s); 290 | extern void fmt_library(int code); 291 | extern void begin_tracking(void); 292 | extern int already_declared(char *name); 293 | extern void track_in(void); 294 | extern int want_typedef(void); 295 | extern void begin_typedef(void); 296 | extern void copy_typedef(const char *s); 297 | extern void end_typedef(void); 298 | extern void imply_typedef(const char *s); 299 | extern char *implied_typedef(void); 300 | extern void indent(FILE *outf); 301 | extern int lint_ellipsis(Parameter * p); 302 | #if OPT_LINTLIBRARY 303 | extern void flush_varargs(void); 304 | #else 305 | #define flush_varargs() /* nothing */ 306 | #endif 307 | extern void ellipsis_varargs(Declarator * d); 308 | extern char *supply_parm(int count); 309 | extern int is_actual_func(Declarator * d); 310 | extern void put_body(FILE *outf, DeclSpec * decl_spec, Declarator * declarator); 311 | # ifdef NO_LEAKS 312 | extern void free_lintlibs(void); 313 | # endif 314 | #else 315 | #define put_string(fp,S) fputs(S, fp) 316 | #define put_char(fp,C) fputc(C, fp) 317 | #define put_padded(fp,S) fprintf(fp, "%s ", S) 318 | #define put_body(fp,s,d) put_string(fp,";\n") 319 | #define track_in() 320 | #define begin_typedef() 321 | #define copy_typedef() 322 | #define end_typedef() 323 | #define imply_typedef(s) 324 | #define implied_typedef() ((char *)0) 325 | #endif 326 | 327 | /* strkey.c */ 328 | extern char *strkey(char *src, const char *key); 329 | extern void strcut(char *src, const char *key); 330 | 331 | /* grammar.y */ 332 | extern boolean is_typedef_name(char *name); 333 | extern char *cur_file_name(void); 334 | extern unsigned cur_line_num(void); 335 | extern FILE *cur_tmp_file(void); 336 | extern void cur_file_changed(void); 337 | extern long cur_begin_comment(void); 338 | extern char *cur_text(void); 339 | extern void pop_file(int closed); 340 | extern void init_parser(void); 341 | extern void process_file(FILE *infile, const char *name); 342 | #ifdef NO_LEAKS 343 | extern void free_lexer(void); 344 | extern void free_parser(void); 345 | #endif 346 | 347 | /* workaround for one of the bugs in bison 1.875 */ 348 | #ifdef YYBISON 349 | #define YYSTYPE YYSTYPE 350 | #endif 351 | 352 | #ifdef HAVE_MKSTEMP 353 | #define call_mktemp(s) mkstemp(s) 354 | #else 355 | #define call_mktemp(s) mktemp(s) 356 | #endif 357 | 358 | #define type_realloc(type,ptr,size) \ 359 | (((ptr) != 0) \ 360 | ? (type *) xrealloc(ptr, (size) * sizeof(type)) \ 361 | : (type *) xmalloc((size) * sizeof(type))) 362 | 363 | #endif /* CPROTO_H */ 364 | -------------------------------------------------------------------------------- /dump.c: -------------------------------------------------------------------------------- 1 | /* $Id: dump.c,v 4.5 2011/01/02 19:17:15 tom Exp $ 2 | * 3 | * useful dumps for cproto 4 | */ 5 | #include 6 | #include 7 | 8 | static char *whatFuncDefStyle(FuncDefStyle func_def); 9 | static char *flagsDeclSpec(int flags); 10 | 11 | #define PAD char pad[80]; sprintf(pad, "%-*s", level * 3, ".") 12 | 13 | #ifndef DEBUG 14 | #define DEBUG 0 15 | #endif 16 | 17 | #if DEBUG > 1 18 | #define SHOW_CMTS(p) Trace p; 19 | #else 20 | #define SHOW_CMTS(p) 21 | #endif 22 | 23 | static char * 24 | whatFuncDefStyle(FuncDefStyle func_def) /* style of function definition */ 25 | { 26 | switch (func_def) { 27 | case FUNC_NONE: 28 | return "FUNC_NONE"; 29 | case FUNC_TRADITIONAL: 30 | return "FUNC_TRADITIONAL"; 31 | case FUNC_ANSI: 32 | return "FUNC_ANSI"; 33 | case FUNC_BOTH: 34 | return "FUNC_BOTH"; 35 | } 36 | return "?"; 37 | } 38 | 39 | void 40 | dump_parameter(Parameter * p, int level) 41 | { 42 | dump_declarator(p->declarator, level + 1); 43 | dump_decl_spec(&(p->decl_spec), level + 1); 44 | } 45 | 46 | void 47 | dump_param_list(ParameterList * p, int level) 48 | { 49 | struct parameter *q; 50 | 51 | for (q = p->first; q != 0; q = q->next) { 52 | dump_parameter(q, level); 53 | } 54 | } 55 | 56 | void 57 | dump_declarator(Declarator * d, int level) 58 | { 59 | PAD; 60 | Trace("%sdeclarator %p\n", pad, d); 61 | Trace("%s name /%s/\n", pad, d->name); 62 | Trace("%s text /%s/\n", pad, d->text); 63 | SHOW_CMTS(("%s begin %ld\n", pad, d->begin)) 64 | SHOW_CMTS(("%s begin_comment %ld\n", pad, d->begin_comment)) 65 | SHOW_CMTS(("%s end_comment %ld\n", pad, d->end_comment)) 66 | Trace("%s func_def %s\n", pad, whatFuncDefStyle(d->func_def)); 67 | 68 | #if DEBUG > 1 69 | if (d->func_def != FUNC_NONE) { 70 | Trace("%s >PARAMS of %p\n", pad, d); 71 | dump_param_list(&(d->params), level + 1); 72 | } 73 | #endif 74 | Trace("%s pointer %s\n", pad, d->pointer ? "YES" : "NO"); 75 | 76 | if (d->head != 0 && d != d->head) { 77 | Trace("%s >HEAD of %p\n", pad, d); 78 | dump_declarator(d->head, level + 1); 79 | } 80 | if (d->func_stack != 0) { 81 | Trace("%s >FUNC_STACK of %p\n", pad, d); 82 | dump_declarator(d->func_stack, level + 1); 83 | } 84 | if (d->next != 0) { 85 | Trace("%s >NEXT of %p\n", pad, d); 86 | dump_declarator(d->next, level + 1); 87 | } 88 | } 89 | 90 | static char * 91 | flagsDeclSpec(int flags) 92 | { 93 | static char temp[100]; 94 | static struct { 95 | int mask; 96 | char *text; 97 | } table[] = { 98 | { 99 | DS_EXTERN, "extern" 100 | }, 101 | { 102 | DS_STATIC, "static" 103 | }, 104 | { 105 | DS_CHAR, "char" 106 | }, 107 | { 108 | DS_SHORT, "short" 109 | }, 110 | { 111 | DS_FLOAT, "float" 112 | }, 113 | { 114 | DS_JUNK, "junk" 115 | }, 116 | }; 117 | unsigned j; 118 | *temp = 0; 119 | for (j = 0; j < sizeof(table) / sizeof(table[0]); j++) { 120 | if (flags & table[j].mask) { 121 | if (*temp) 122 | (void) strcat(temp, ","); 123 | (void) strcat(temp, table[j].text); 124 | } 125 | } 126 | return temp; 127 | } 128 | 129 | void 130 | dump_decl_spec(DeclSpec * d, int level) 131 | { 132 | PAD; 133 | Trace("%sdecl_spec %p\n", pad, d); 134 | Trace("%s flags %s\n", pad, flagsDeclSpec(d->flags)); 135 | Trace("%s text /%s/\n", pad, d->text); 136 | SHOW_CMTS(("%s begin %ld\n", pad, d->begin)) 137 | } 138 | -------------------------------------------------------------------------------- /dump.h: -------------------------------------------------------------------------------- 1 | /* $Id: dump.h,v 4.6 2011/01/02 19:13:03 tom Exp $ */ 2 | 3 | #ifndef DUMP_H 4 | #define DUMP_H 5 | 6 | #include 7 | 8 | extern void dump_parameter(Parameter *p, int level); 9 | extern void dump_param_list(ParameterList *p, int level); 10 | extern void dump_declarator(Declarator *d, int level); 11 | extern void dump_decl_spec(DeclSpec *d, int level); 12 | 13 | #endif /* DUMP_H */ 14 | -------------------------------------------------------------------------------- /emx/Makefile: -------------------------------------------------------------------------------- 1 | # $Id: Makefile,v 4.3 1998/01/22 19:49:36 cthuang Exp $ 2 | # 3 | # EMX makefile for C prototype generator 4 | 5 | PROGRAM = cproto 6 | DEFINES = 7 | INCLUDES = -I.. 8 | 9 | LEX = lex 10 | YACC = yacc 11 | CC = gcc 12 | CFLAGS = $(DEFINES) $(INCLUDES) 13 | LIBS = 14 | 15 | VPATH = .. 16 | 17 | O = .o 18 | OBJECTS = \ 19 | cproto$(O) \ 20 | lintlibs$(O) \ 21 | semantic$(O) \ 22 | strkey$(O) \ 23 | symbol$(O) \ 24 | y_tab$(O) 25 | 26 | all: cproto.exe 27 | 28 | cproto.exe: $(OBJECTS) 29 | $(CC) $(CFLAGS) -o $@ $(OBJECTS) $(LIBS) 30 | 31 | cproto.man: cproto.1 32 | cawf -man $*.1 | bsfilt - >$*.man 33 | 34 | clean: 35 | -del $(PROGRAM).exe 36 | -del *$(O) 37 | -del *.bak 38 | -del *.log 39 | 40 | # DO NOT DELETE THIS LINE -- make depend depends on it. 41 | 42 | cproto.o: system.h cproto.h symbol.h 43 | lintlibs.o: system.h cproto.h symbol.h semantic.h 44 | semantic.o: system.h cproto.h symbol.h semantic.h 45 | strkey.o: cproto.h system.h 46 | symbol.o: system.h cproto.h symbol.h 47 | y_tab.o: lex_yy.c system.h cproto.h symbol.h semantic.h 48 | -------------------------------------------------------------------------------- /emx/README: -------------------------------------------------------------------------------- 1 | The files in this directory are used to build using EMX. 2 | 3 | Makefile makefile for EMX 4 | -------------------------------------------------------------------------------- /install-sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # install - install a program, script, or datafile 4 | # 5 | # This originates from X11R5 (mit/util/scripts/install.sh), which was 6 | # later released in X11R6 (xc/config/util/install.sh) with the 7 | # following copyright and license. 8 | # 9 | # Copyright (C) 1994 X Consortium 10 | # 11 | # Permission is hereby granted, free of charge, to any person obtaining a copy 12 | # of this software and associated documentation files (the "Software"), to 13 | # deal in the Software without restriction, including without limitation the 14 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | # sell copies of the Software, and to permit persons to whom the Software is 16 | # furnished to do so, subject to the following conditions: 17 | # 18 | # The above copyright notice and this permission notice shall be included in 19 | # all copies or substantial portions of the Software. 20 | # 21 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 25 | # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 26 | # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | # 28 | # Except as contained in this notice, the name of the X Consortium shall not 29 | # be used in advertising or otherwise to promote the sale, use or other deal- 30 | # ings in this Software without prior written authorization from the X Consor- 31 | # tium. 32 | # 33 | # 34 | # FSF changes to this file are in the public domain. 35 | # 36 | # Calling this script install-sh is preferred over install.sh, to prevent 37 | # `make' implicit rules from creating a file called install from it 38 | # when there is no Makefile. 39 | # 40 | # This script is compatible with the BSD install script, but was written 41 | # from scratch. It can only install one file at a time, a restriction 42 | # shared with many OS's install programs. 43 | 44 | 45 | # set DOITPROG to echo to test this script 46 | 47 | # Don't use :- since 4.3BSD and earlier shells don't like it. 48 | doit="${DOITPROG-}" 49 | 50 | 51 | # put in absolute paths if you don't have them in your path; or use env. vars. 52 | 53 | mvprog="${MVPROG-mv}" 54 | cpprog="${CPPROG-cp}" 55 | chmodprog="${CHMODPROG-chmod}" 56 | chownprog="${CHOWNPROG-chown}" 57 | chgrpprog="${CHGRPPROG-chgrp}" 58 | stripprog="${STRIPPROG-strip}" 59 | rmprog="${RMPROG-rm}" 60 | mkdirprog="${MKDIRPROG-mkdir}" 61 | 62 | transformbasename="" 63 | transform_arg="" 64 | instcmd="$mvprog" 65 | chmodcmd="$chmodprog 0755" 66 | chowncmd="" 67 | chgrpcmd="" 68 | stripcmd="" 69 | rmcmd="$rmprog -f" 70 | mvcmd="$mvprog" 71 | src="" 72 | dst="" 73 | dir_arg="" 74 | 75 | while [ x"$1" != x ]; do 76 | case $1 in 77 | -c) instcmd=$cpprog 78 | shift 79 | continue;; 80 | 81 | -d) dir_arg=true 82 | shift 83 | continue;; 84 | 85 | -m) chmodcmd="$chmodprog $2" 86 | shift 87 | shift 88 | continue;; 89 | 90 | -o) chowncmd="$chownprog $2" 91 | shift 92 | shift 93 | continue;; 94 | 95 | -g) chgrpcmd="$chgrpprog $2" 96 | shift 97 | shift 98 | continue;; 99 | 100 | -s) stripcmd=$stripprog 101 | shift 102 | continue;; 103 | 104 | -t=*) transformarg=`echo $1 | sed 's/-t=//'` 105 | shift 106 | continue;; 107 | 108 | -b=*) transformbasename=`echo $1 | sed 's/-b=//'` 109 | shift 110 | continue;; 111 | 112 | *) if [ x"$src" = x ] 113 | then 114 | src=$1 115 | else 116 | # this colon is to work around a 386BSD /bin/sh bug 117 | : 118 | dst=$1 119 | fi 120 | shift 121 | continue;; 122 | esac 123 | done 124 | 125 | if [ x"$src" = x ] 126 | then 127 | echo "$0: no input file specified" >&2 128 | exit 1 129 | else 130 | : 131 | fi 132 | 133 | if [ x"$dir_arg" != x ]; then 134 | dst=$src 135 | src="" 136 | 137 | if [ -d "$dst" ]; then 138 | instcmd=: 139 | chmodcmd="" 140 | else 141 | instcmd=$mkdirprog 142 | fi 143 | else 144 | 145 | # Waiting for this to be detected by the "$instcmd $src $dsttmp" command 146 | # might cause directories to be created, which would be especially bad 147 | # if $src (and thus $dsttmp) contains '*'. 148 | 149 | if [ -f "$src" ] || [ -d "$src" ] 150 | then 151 | : 152 | else 153 | echo "$0: $src does not exist" >&2 154 | exit 1 155 | fi 156 | 157 | if [ x"$dst" = x ] 158 | then 159 | echo "$0: no destination specified" >&2 160 | exit 1 161 | else 162 | : 163 | fi 164 | 165 | # If destination is a directory, append the input filename; if your system 166 | # does not like double slashes in filenames, you may need to add some logic 167 | 168 | if [ -d "$dst" ] 169 | then 170 | dst=$dst/`basename "$src"` 171 | else 172 | : 173 | fi 174 | fi 175 | 176 | ## this sed command emulates the dirname command 177 | dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` 178 | 179 | # Make sure that the destination directory exists. 180 | # this part is taken from Noah Friedman's mkinstalldirs script 181 | 182 | # Skip lots of stat calls in the usual case. 183 | if [ ! -d "$dstdir" ]; then 184 | defaultIFS=' 185 | ' 186 | IFS="${IFS-$defaultIFS}" 187 | 188 | oIFS=$IFS 189 | # Some sh's can't handle IFS=/ for some reason. 190 | IFS='%' 191 | set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` 192 | IFS=$oIFS 193 | 194 | pathcomp='' 195 | 196 | while [ $# -ne 0 ] ; do 197 | pathcomp=$pathcomp$1 198 | shift 199 | 200 | if [ ! -d "$pathcomp" ] ; 201 | then 202 | $mkdirprog "$pathcomp" 203 | else 204 | : 205 | fi 206 | 207 | pathcomp=$pathcomp/ 208 | done 209 | fi 210 | 211 | if [ x"$dir_arg" != x ] 212 | then 213 | $doit $instcmd "$dst" && 214 | 215 | if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi && 216 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi && 217 | if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi && 218 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi 219 | else 220 | 221 | # If we're going to rename the final executable, determine the name now. 222 | 223 | if [ x"$transformarg" = x ] 224 | then 225 | dstfile=`basename "$dst"` 226 | else 227 | dstfile=`basename "$dst" $transformbasename | 228 | sed $transformarg`$transformbasename 229 | fi 230 | 231 | # don't allow the sed command to completely eliminate the filename 232 | 233 | if [ x"$dstfile" = x ] 234 | then 235 | dstfile=`basename "$dst"` 236 | else 237 | : 238 | fi 239 | 240 | # Make a couple of temp file names in the proper directory. 241 | 242 | dsttmp=$dstdir/#inst.$$# 243 | rmtmp=$dstdir/#rm.$$# 244 | 245 | # Trap to clean up temp files at exit. 246 | 247 | trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0 248 | trap '(exit $?); exit' 1 2 13 15 249 | 250 | # Move or copy the file name to the temp name 251 | 252 | $doit $instcmd "$src" "$dsttmp" && 253 | 254 | # and set any options; do chmod last to preserve setuid bits 255 | 256 | # If any of these fail, we abort the whole thing. If we want to 257 | # ignore errors from any of these, just make sure not to ignore 258 | # errors from the above "$doit $instcmd $src $dsttmp" command. 259 | 260 | if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi && 261 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi && 262 | if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi && 263 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi && 264 | 265 | # Now remove or move aside any old file at destination location. We try this 266 | # two ways since rm can't unlink itself on some systems and the destination 267 | # file might be busy for other reasons. In this case, the final cleanup 268 | # might fail but the new file should still install successfully. 269 | 270 | { 271 | if [ -f "$dstdir/$dstfile" ] 272 | then 273 | $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null || 274 | $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null || 275 | { 276 | echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 277 | (exit 1); exit 278 | } 279 | else 280 | : 281 | fi 282 | } && 283 | 284 | # Now rename the file to the real destination. 285 | 286 | $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" 287 | 288 | fi && 289 | 290 | # The final little trick to "correctly" pass the exit status to the exit trap. 291 | 292 | { 293 | (exit 0); exit 294 | } 295 | -------------------------------------------------------------------------------- /lintlibs.c: -------------------------------------------------------------------------------- 1 | /* $Id: lintlibs.c,v 4.21 2011/01/02 19:24:03 tom Exp $ 2 | * 3 | * C prototype/lint-library generator 4 | * These routines implement the semantic actions for lint libraries executed by 5 | * the yacc parser. 6 | */ 7 | #include 8 | #include 9 | 10 | #if OPT_LINTLIBRARY 11 | 12 | unsigned in_include; 13 | 14 | static SymbolTable *include_list; 15 | static SymbolTable *declared_list; 16 | 17 | static int in_typedef; 18 | static int blank_lines; /* used to filter blank lines from typedefs */ 19 | 20 | static int implied_cnt; /* state-count associated with implied_buf */ 21 | static char *implied_buf; 22 | 23 | static char quote_l = '"'; 24 | static char quote_r = '"'; 25 | 26 | /* 27 | * Output a string to standard output, keeping track of the trailing newlines 28 | * to make it simple to format with blank lines. 29 | */ 30 | void 31 | put_string(FILE *outf, const char *s) 32 | { 33 | if (*s != '\0') { 34 | fputs(s, outf); 35 | if (outf == stdout) { /* ensure we aren't doing temp-file! */ 36 | while (*s != '\0') { 37 | if (*s++ == '\n') 38 | blank_lines++; 39 | else 40 | blank_lines = 0; 41 | } 42 | } 43 | } 44 | } 45 | 46 | /* 47 | * Output a single character 48 | */ 49 | void 50 | put_char(FILE *outf, int c) 51 | { 52 | static char s[] = "?"; 53 | s[0] = (char) c; 54 | put_string(outf, s); 55 | } 56 | 57 | /* 58 | * Write a newline, taking care not to make a blank line 59 | */ 60 | void 61 | put_newline(FILE *outf) 62 | { 63 | while (!blank_lines) 64 | put_string(outf, "\n"); 65 | } 66 | 67 | /* 68 | * Make a blank line (limited to 2 successive newlines) 69 | */ 70 | void 71 | put_blankline(FILE *outf) 72 | { 73 | while (blank_lines < 2) 74 | put_string(outf, "\n"); 75 | } 76 | 77 | /* 78 | * Put a token, padded by a tab if it is short enough 79 | */ 80 | void 81 | put_padded(FILE *outf, const char *s) 82 | { 83 | put_string(outf, s); 84 | put_char(outf, (lintLibrary() && strlen(s) < 8) ? '\t' : ' '); 85 | } 86 | 87 | /* 88 | * Format lint-library so that we put a blank line before each item that may 89 | * take up multiple lines: 90 | * 0) functions 91 | * 1) typedefs (explicit and implied) 92 | * as well as when transitioning to 93 | * 2) variable declarations 94 | * 95 | * If the "-T" option is set, we skip a blank line around typedefs. 96 | */ 97 | void 98 | fmt_library(int code) 99 | { 100 | if (lintLibrary() || types_out) { 101 | static int save; 102 | 103 | if (!lintLibrary() && code == 0) 104 | code = 3; 105 | if (code <= 1 || code != save) 106 | put_blankline(stdout); 107 | save = code; 108 | } 109 | } 110 | 111 | /* 112 | * conversion for names so test-diffs are less 113 | * (patch: should use relpath) 114 | */ 115 | static char * 116 | strip_name(char *s) 117 | { 118 | #ifdef vms 119 | static char stripped[BUFSIZ]; 120 | auto int len = strlen(getwd(stripped)); 121 | if (strlen(s) > len 122 | && !strncmp(s, stripped, len)) 123 | s += len; 124 | s = (vms2name(stripped, s)); 125 | #else 126 | static char GccLeaf[] = "/gcc-lib/"; 127 | static char IncLeaf[] = "/include/"; 128 | char *t; 129 | unsigned n; 130 | size_t len; 131 | int standard = FALSE; 132 | 133 | for (n = 1; n < num_inc_dir; n++) { 134 | len = strlen(inc_dir[n]); 135 | if (!strncmp(inc_dir[n], s, len) 136 | && is_path_sep(s[len])) { 137 | standard = TRUE; 138 | s += len + 1; 139 | quote_l = '<'; 140 | quote_r = '>'; 141 | break; 142 | } 143 | } 144 | if (!standard) { 145 | quote_l = 146 | quote_r = '"'; 147 | if (*s == '.' && is_path_sep(s[1])) 148 | s += 2; 149 | else if ((t = strstr(s, GccLeaf)) != 0 150 | && (t = strstr(t, IncLeaf)) != 0) { 151 | s = t + sizeof(IncLeaf) - 1; 152 | quote_l = '<'; 153 | quote_r = '>'; 154 | } 155 | } 156 | #endif 157 | return s; 158 | } 159 | #define CUR_FILE strip_name(cur_file_name()) 160 | 161 | static unsigned base_level; 162 | static unsigned inc_depth = 0; 163 | static char **inc_stack = 0; 164 | 165 | static char * 166 | get_inc_stack(unsigned n) 167 | { 168 | return (((int) n) < 0 || n >= inc_depth) ? 0 : inc_stack[n]; 169 | } 170 | 171 | #ifdef DEBUG 172 | static void 173 | dump_stack(char *tag) 174 | { 175 | unsigned j; 176 | printf("/* stack%s:%s", tag, cur_file_name()); 177 | for (j = 0; j <= in_include; j++) 178 | printf("\n\t%d%s:%s", j, 179 | j == base_level ? "*" : "", 180 | get_inc_stack(j) ? get_inc_stack(j) : "?"); 181 | printf(" */\n"); 182 | } 183 | #endif /* DEBUG */ 184 | 185 | static void 186 | free_inc_stack(unsigned n) 187 | { 188 | if (get_inc_stack(n) != 0) { 189 | free(inc_stack[n]); 190 | inc_stack[n] = 0; 191 | } 192 | } 193 | 194 | static void 195 | make_inc_stack(unsigned n, char *s) 196 | { 197 | if (n != 0) { 198 | unsigned need = (n | 31) + 1; 199 | 200 | free_inc_stack(n); 201 | if (n > inc_depth) { 202 | inc_stack = type_realloc(char *, inc_stack, need); 203 | while (inc_depth < need) 204 | inc_stack[inc_depth++] = 0; 205 | inc_depth = need; 206 | } 207 | inc_stack[n] = xstrdup(s); 208 | } 209 | } 210 | 211 | /* 212 | * Keep track of include-files so that we only include each once. 213 | */ 214 | static int 215 | already_included(char *path) 216 | { 217 | if (!include_list) 218 | include_list = new_symbol_table(); 219 | if (find_symbol(include_list, path) != NULL) 220 | return TRUE; 221 | new_symbol(include_list, path, NULL, DS_NONE); 222 | return FALSE; 223 | } 224 | 225 | /* 226 | * Keep track of variables that may have been implicitly declared via 227 | * include-files so that we declare them only once in the lint library 228 | * output. 229 | */ 230 | int 231 | already_declared(char *name) 232 | { 233 | if (declared_list == 0) 234 | declared_list = new_symbol_table(); 235 | if (find_symbol(declared_list, name) == 0) { 236 | (void) new_symbol(declared_list, name, 0, 0); 237 | return FALSE; 238 | } 239 | return TRUE; 240 | } 241 | 242 | /* 243 | * Initialize state for 'track_in()' 244 | */ 245 | static int InitTracking; 246 | 247 | void 248 | begin_tracking(void) 249 | { 250 | InitTracking = FALSE; 251 | } 252 | 253 | static int 254 | c_suffix(char *path) 255 | { 256 | char *last = path + strlen(path); 257 | #ifdef vms 258 | char *vers = strrchr(path, ';'); 259 | if (vers != 0) 260 | last = vers; 261 | #endif 262 | return ((last - path) > 2 && !strcmp(last - 2, ".c")); 263 | } 264 | 265 | /* 266 | * Keep track of "include files" that we always want to filter out (ignore). 267 | */ 268 | static int 269 | ignored(char *path) 270 | { 271 | if (strcmp(path, "") == 0 272 | || strcmp(path, "") == 0) 273 | return TRUE; 274 | return FALSE; 275 | } 276 | 277 | static const char * 278 | skip_dot(const char *a) 279 | { 280 | if (!strncmp(a, "./", (size_t) 2)) 281 | a += 2; 282 | return a; 283 | } 284 | 285 | static int 286 | same_file(const char *a, const char *b) 287 | { 288 | return !strcmp(skip_dot(a), skip_dot(b)); 289 | } 290 | 291 | /* 292 | * For lint-library, we want to keep track of what file we are in so that we 293 | * can generate appropriate comments and include-statements. 294 | * 295 | * The main program 'cproto' is invoked with 'cpp' once for each C-file, 296 | * relying on it to spit out "#" comments which identify the name and line 297 | * number of each processed file. After the first '#' comment, all others 298 | * refer to included files. 299 | */ 300 | void 301 | track_in(void) 302 | { 303 | static char old_file[MAX_TEXT_SIZE]; /* from last call */ 304 | auto int show = lintLibrary(); 305 | 306 | if (!show && !do_tracking && !debug_trace) 307 | return; 308 | 309 | #ifdef DEBUG 310 | printf("/* track_in: in_include=%d line_num=%d base_file=%s */\n", 311 | in_include, cur_line_num(), base_file); 312 | dump_stack("-before"); 313 | #endif /* DEBUG */ 314 | 315 | if (cur_line_num() == 0) { /* begin new (nested?) file */ 316 | if (!InitTracking) { 317 | InitTracking = TRUE; 318 | /* yacc may omit first cpp-line! */ 319 | in_include = 320 | base_level = (unsigned) !same_file(cur_file_name(), base_file); 321 | make_inc_stack(0, base_file); 322 | } else if (same_file(cur_file_name(), base_file)) { 323 | flush_varargs(); 324 | in_include = 0; /* reset level */ 325 | } else { 326 | make_inc_stack(in_include, old_file); 327 | if (in_include++ == 0) { 328 | char *s = CUR_FILE; 329 | if (show && !already_included(s) && !ignored(s)) { 330 | fmt_library(4); 331 | put_string(stdout, "#include "); 332 | put_char(stdout, quote_l); 333 | put_string(stdout, s); 334 | put_char(stdout, quote_r); 335 | put_newline(stdout); 336 | } 337 | if (debug_trace) 338 | fprintf(stderr, "++ %s\n", cur_file_name()); 339 | } 340 | make_inc_stack(in_include, cur_file_name()); 341 | } 342 | (void) strcpy(old_file, cur_file_name()); 343 | } else if (same_file(cur_file_name(), base_file)) { 344 | in_include = 0; /* kludgy bison! */ 345 | (void) strcpy(old_file, cur_file_name()); 346 | } else if (!same_file(old_file, cur_file_name())) { /* continue/unnest ? */ 347 | unsigned n; 348 | int found; 349 | char *s = cur_file_name(); 350 | #ifdef DEBUG 351 | char temp[80]; 352 | #endif 353 | 354 | flush_varargs(); 355 | for (n = in_include, found = FALSE; (int) n >= 0; n--) { 356 | if (same_file(get_inc_stack(n), s)) { 357 | found = TRUE; 358 | in_include--; 359 | break; 360 | } 361 | } 362 | if (!found) { 363 | /* 364 | * There's two kinds of broken programs that can cause 365 | * us to lose sync at this point: (1) programs such as 366 | * yacc that don't reference the grammar file, instead 367 | * referencing the generated file, and (2) broken 368 | * preprocessors (such as on OSF/1) that neglect to 369 | * report line #1 on headers that are rejected due to 370 | * prior inclusion. 371 | * 372 | * If the source file's extension is ".h", we'll assume 373 | * the latter case (i.e., just report it). The former 374 | * case requires that we reset the stack. 375 | */ 376 | #ifdef DEBUG 377 | sprintf(temp, "/* lost sync @%d: ", cur_line_num() + 1); 378 | put_blankline(stdout); 379 | put_string(stdout, temp); 380 | put_string(stdout, s); 381 | put_string(stdout, " */\n"); 382 | #endif 383 | if (in_include == 1 && c_suffix(s)) { 384 | /* yacc did it again! */ 385 | in_include = 0; 386 | make_inc_stack(in_include, strcpy(base_file, s)); 387 | #ifdef DEBUG 388 | put_string(stdout, "/* processed "); 389 | put_string(stdout, s); 390 | put_string(stdout, " */\n"); 391 | #endif 392 | } 393 | } 394 | (void) strcpy(old_file, get_inc_stack(in_include)); 395 | } 396 | #ifdef DEBUG 397 | dump_stack("-after"); 398 | #endif /* DEBUG */ 399 | } 400 | 401 | /* 402 | * Copy/append to 'implied_buf[]' 403 | */ 404 | static void 405 | add2implied_buf(const char *s, int append) 406 | { 407 | static size_t implied_len; /* current strlen(implied_buf) */ 408 | static size_t implied_max; /* maximum size of implied_buf */ 409 | 410 | if (!append) 411 | implied_len = 0; 412 | implied_len += strlen(s); 413 | 414 | if (implied_buf == 0) 415 | *(implied_buf = (char *) malloc(implied_max = BUFSIZ)) = '\0'; 416 | if (implied_max < implied_len + 2) 417 | implied_buf = (char *) realloc(implied_buf, implied_max += 418 | implied_len + 2); 419 | if (!append) 420 | *implied_buf = '\0'; 421 | (void) strcat(implied_buf, s); 422 | } 423 | 424 | /* 425 | * If the "-t" option is set (or if we are generating a lint-library), we 426 | * intercept tokens which are part of a typedef, copying them to the output. 427 | * 428 | * The 'imply_typedef()' entrypoint is called from the grammar for the special 429 | * cases of struct/union/enum when we expect to be getting curly-braces which 430 | * define the structure. If no curly-braces are found by the end of the 431 | * rule, we can discard the buffer. 432 | */ 433 | int 434 | want_typedef(void) 435 | { 436 | if (lintLibrary()) { 437 | if (in_include == 0) 438 | return (TRUE); 439 | } else if (types_out) { 440 | return (TRUE); 441 | } 442 | return (FALSE); 443 | } 444 | 445 | void 446 | begin_typedef(void) 447 | { 448 | if (want_typedef()) { 449 | in_typedef = TRUE; 450 | fmt_library(1); 451 | copy_typedef("typedef"); 452 | } 453 | } 454 | 455 | void 456 | copy_typedef(const char *s) 457 | { 458 | if (!strcmp(s, "/*") 459 | || *s == '#') ; /* ignore */ 460 | else if (in_typedef) { 461 | if (*s == '\n') 462 | put_newline(stdout); 463 | else 464 | put_string(stdout, s); 465 | } else if (implied_cnt > 0) { /* "KEY ID {" ? */ 466 | add2implied_buf(s, TRUE); 467 | if (!isspace(UCH(*s))) 468 | implied_cnt--; 469 | if ((implied_cnt == 2 || implied_cnt == 1) 470 | && !strcmp(s, "{")) { 471 | implied_cnt = 9999; 472 | } 473 | } 474 | } 475 | 476 | void 477 | end_typedef(void) 478 | { 479 | copy_typedef("\n"); 480 | in_typedef = FALSE; 481 | (void) implied_typedef(); 482 | } 483 | 484 | void 485 | imply_typedef(const char *s) 486 | { 487 | if (!in_typedef && want_typedef()) { 488 | add2implied_buf(s, FALSE); 489 | implied_cnt = 3; 490 | } 491 | } 492 | 493 | char * 494 | implied_typedef(void) 495 | { 496 | if (implied_cnt > 0) { 497 | implied_cnt = 0; 498 | return (implied_buf); 499 | } 500 | return (0); 501 | } 502 | 503 | /* 504 | * Indent lint-library stuff to make it readable 505 | */ 506 | void 507 | indent(FILE *outf) 508 | { 509 | put_string(outf, "\n\t\t"); 510 | } 511 | 512 | /* Test for the special case of an ellipsis-parameter when trying to make a 513 | * lint-library 514 | */ 515 | int 516 | lint_ellipsis(Parameter * p) 517 | { 518 | return (knrLintLibrary() 519 | && (!strcmp(p->declarator->name, ELLIPSIS))); 520 | } 521 | 522 | /* 523 | * Reset the data used for "VARARGS" comment. Actually, reset almost any 524 | * special attribute that's attached to a function, so we don't accidentally 525 | * propagate it to the next function (or data) to be output. 526 | */ 527 | void 528 | flush_varargs(void) 529 | { 530 | exitlike_func = FALSE; 531 | 532 | varargs_num = 0; 533 | if (varargs_str != 0) { 534 | free(varargs_str); 535 | varargs_str = 0; 536 | } 537 | } 538 | 539 | /* If either we received a "VARARGS" comment in the lexical scanner, or if the 540 | * parameter list contains an ellipsis, generate a corresponding "VARARGS" 541 | * comment for lint-library output. 542 | */ 543 | void 544 | ellipsis_varargs(Declarator * d) 545 | { 546 | int count; 547 | Parameter *p; 548 | 549 | fmt_library(0); 550 | for (p = d->params.first, count = 0; p != 0; p = p->next, count++) 551 | if (lint_ellipsis(p)) { 552 | varargs_num = count; 553 | break; 554 | } 555 | if (varargs_num != 0) { 556 | put_string(stdout, "\t/* VARARGS"); 557 | if (varargs_num > 0) { 558 | printf("%d", varargs_num); 559 | if (varargs_str != 0) { 560 | put_char(stdout, ' '); 561 | put_string(stdout, varargs_str); 562 | } 563 | } 564 | flush_varargs(); 565 | put_string(stdout, " */\n"); 566 | } 567 | } 568 | 569 | /* (Attempt to) create a parameter name for lint-library applications in which 570 | * we are starting from a function prototype which has no explicit parameter 571 | * name. 572 | */ 573 | char * 574 | supply_parm(int count) 575 | { 576 | static char temp[80]; 577 | (void) sprintf(temp, "p%d", count); 578 | while (is_typedef_name(temp) && (strlen(temp) < sizeof(temp) - 1)) 579 | (void) strcat(temp, "_"); 580 | return (temp); 581 | } 582 | 583 | /* 584 | * (Attempt to) distinguish between declarators for functions and for 585 | * function pointers. 586 | */ 587 | int 588 | is_actual_func(Declarator * d) 589 | { 590 | if (lintLibrary() && (d->func_def != FUNC_NONE)) { 591 | if (d->func_stack->text[0] == PAREN_L 592 | && d->func_stack->text[1] == '*') { 593 | if (strstr(d->func_stack->text, "()") != 0) 594 | return TRUE; 595 | } else { 596 | return TRUE; 597 | } 598 | } 599 | return FALSE; 600 | } 601 | 602 | /* 603 | * Output the body (or terminating semicolon) of a procedure 604 | */ 605 | void 606 | put_body( 607 | FILE *outf, 608 | DeclSpec * decl_spec, /* declaration specifier */ 609 | Declarator * declarator) 610 | { 611 | const char *spec_text; 612 | 613 | if (is_actual_func(declarator)) { 614 | strcut(decl_spec->text, "static"); 615 | strcut(decl_spec->text, "extern"); 616 | indent(outf); 617 | put_char(outf, CURL_L); 618 | if (!*(spec_text = decl_spec->text)) 619 | spec_text = "void"; 620 | if (exitlike_func) { 621 | put_string(outf, " for(;;); /* no return */ "); 622 | } else if (!strcmp(spec_text, "void") 623 | && declarator->text[0] != '*' 624 | && declarator->func_stack->func_def == FUNC_NONE) { 625 | put_string(outf, " /* void */ "); 626 | } else { 627 | put_string(outf, " return(*("); 628 | if (declarator->func_stack->func_def == FUNC_NONE) { 629 | put_string(outf, spec_text); 630 | put_char(outf, ' '); 631 | if (declarator->pointer) { 632 | char *s = declarator->text; 633 | while (*s++ == '*') 634 | put_char(outf, '*'); 635 | } 636 | put_char(outf, '*'); 637 | } else { 638 | put_string(outf, spec_text); 639 | put_string(outf, "(*)()"); 640 | } 641 | put_string(outf, ")0); "); 642 | } 643 | put_char(outf, CURL_R); 644 | } else { 645 | if (proto_style == PROTO_LINTLIBRARY 646 | || proto_style == PROTO_ANSI_LLIB) { 647 | /* SVR4 lint complains if we declare const data without an 648 | * initializer. 649 | */ 650 | if (strkey(decl_spec->text, "const") != NULL 651 | || strkey(declarator->text, "const") != NULL) { 652 | put_string(outf, " = {0}"); 653 | } 654 | } 655 | put_string(outf, ";"); 656 | } 657 | put_newline(outf); 658 | exitlike_func = FALSE; 659 | } 660 | 661 | #ifdef NO_LEAKS 662 | void 663 | free_lintlibs(void) 664 | { 665 | unsigned n; 666 | 667 | if (implied_buf != 0) 668 | free(implied_buf); 669 | if (inc_stack != 0) { 670 | for (n = 0; n < inc_depth; n++) 671 | free_inc_stack(n); 672 | free(inc_stack); 673 | } 674 | if (include_list != 0) 675 | free_symbol_table(include_list); 676 | if (declared_list != 0) 677 | free_symbol_table(declared_list); 678 | } 679 | #endif 680 | 681 | #endif /* OPT_LINTLIBRARY */ 682 | -------------------------------------------------------------------------------- /msdos/README: -------------------------------------------------------------------------------- 1 | The files in this directory are used to build on MS-DOS. 2 | 3 | turboc.mak makefile for Turbo C/C++ 3.0 for MS-DOS 4 | borland.mak makefile for Borland C for MS-DOS 5 | micrsoft.mak makefile for Microsoft C 6 | -------------------------------------------------------------------------------- /msdos/borland.mak: -------------------------------------------------------------------------------- 1 | # $Id: borland.mak,v 4.2 2005/12/08 20:34:07 tom Exp $ 2 | # 3 | # Borland C++ makefile for C prototype generator 4 | 5 | # Define MSDOS for MS-DOS compatibility. 6 | # Define TURBO_CPP to pipe the input through the Turbo C preprocessor. 7 | DEFINES = -DMSDOS -DTURBO_CPP 8 | 9 | LEX = lex 10 | YACC = yacc 11 | CC = bcc 12 | CFLAGS = -mc $(DEFINES) -w-pin -w-pro 13 | LIBS = \bc\lib\wildargs.obj 14 | 15 | DIST1 = README CHANGES cproto.man 16 | DIST2 = cproto.1 borland.mak micrsoft.mak makefile.in lex.l grammar.y 17 | DIST3 = system.h cproto.h patchlev.h semantic.h symbol.h 18 | DIST4 = cproto.c popen.c lintlibs.c semantic.c strkey.c symbol.c 19 | 20 | OBJECTS = cproto.obj lintlibs.obj getopt.obj popen.obj semantic.obj strkey.obj symbol.obj y_tab.obj 21 | 22 | all: cproto.exe 23 | 24 | cproto.exe: $(OBJECTS) 25 | $(CC) $(CFLAGS) -e$*.exe $(OBJECTS) $(LIBS) 26 | 27 | y_tab.obj: y_tab.c lex_yy.c system.h cproto.h symbol.h semantic.h 28 | $(CC) $(CFLAGS) -c $*.c 29 | 30 | y_tab.c: grammar.y 31 | $(YACC) grammar.y 32 | 33 | lex_yy.c: lex.l 34 | $(LEX) lex.l 35 | 36 | cproto.man: cproto.1 37 | cawf -man $*.1 | bsfilt - >$*.man 38 | 39 | clean: 40 | erase *.obj 41 | erase *.bak 42 | erase *.log 43 | erase lex_yy.c 44 | erase y_tab.c 45 | erase cproto.exe 46 | 47 | ci: 48 | ci -u3 $(DIST2) $(DIST3) 49 | ci -u3 $(DIST4) 50 | 51 | shar: 52 | shar $(DIST1) $(DIST2) >cproto.sh1 53 | shar $(DIST3) $(DIST4) >cproto.sh2 54 | 55 | # DO NOT DELETE THIS LINE -- make depend depends on it. 56 | 57 | cproto.obj: system.h cproto.h symbol.h 58 | lintlibs.obj: system.h cproto.h symbol.h semantic.h 59 | popen.obj: system.h cproto.h 60 | semantic.obj: system.h cproto.h symbol.h semantic.h 61 | strkey.obj: cproto.h system.h 62 | symbol.obj: system.h cproto.h symbol.h 63 | -------------------------------------------------------------------------------- /msdos/micrsoft.lnk: -------------------------------------------------------------------------------- 1 | CPROTO.OBJ + 2 | LINTLIBS.OBJ + 3 | GETOPT.OBJ + 4 | SEMANTIC.OBJ + 5 | STRKEY.OBJ + 6 | SYMBOL.OBJ + 7 | YTAB.OBJ + 8 | POPEN.OBJ 9 | cproto.exe 10 | cproto.map 11 | d:\msc60ax\lib\llibce.lib 12 | ; 13 | -------------------------------------------------------------------------------- /msdos/micrsoft.mak: -------------------------------------------------------------------------------- 1 | # $Id: micrsoft.mak,v 4.2 2005/12/08 20:34:07 tom Exp $ 2 | # 3 | # Microsoft C makefile for C prototype generator 4 | # tested with: 5 | # nmake 1.11. 6 | # cl 6.00ax. 7 | 8 | # Define MSDOS for MS-DOS compatibility. 9 | # Define TURBO_CPP to pipe the input through the Turbo C preprocessor. 10 | DEFINES = -DMSDOS -DSTDC_HEADERS 11 | 12 | MSC_TOP = d:\msc60ax 13 | 14 | # names from MKS tools (ran out of memory in lex; used unix output) 15 | Y_TAB = ytab 16 | LEX_YY = lex_yy 17 | 18 | LEX = lex 19 | YACC = yacc 20 | CC = cl 21 | LINK = link 22 | CFLAGS = -EM -AL $(DEFINES) 23 | LIBS = $(MSC_TOP)\lib\setargv.obj 24 | LDFLAGS = /F 1000 25 | 26 | DIST1 = README CHANGES cproto.man 27 | DIST2 = cproto.1 borland.mak micrsoft.mak makefile.in lex.l grammar.y 28 | DIST3 = system.h cproto.h patchlev.h semantic.h symbol.h 29 | DIST4 = cproto.c lintlibs.c popen.c semantic.c strkey.c symbol.c 30 | 31 | OBJECTS = cproto.obj lintlibs.obj getopt.obj semantic.obj strkey.obj symbol.obj $(Y_TAB).obj popen.obj 32 | 33 | all: cproto.exe 34 | 35 | cproto.exe: $(OBJECTS) micrsoft.lnk 36 | $(LINK) @micrsoft.lnk 37 | 38 | micrsoft.lnk: 39 | for %%i in ( *.obj ) do echo %%i + >>$@ 40 | echo >>$@ 41 | echo cproto.exe >>$@ 42 | echo >>$@ 43 | echo $(LIBS); >>$@ 44 | 45 | $(Y_TAB).obj: $(Y_TAB).c $(LEX_YY).c system.h cproto.h symbol.h semantic.h 46 | $(CC) $(CFLAGS) -c $*.c 47 | 48 | $(Y_TAB).c: grammar.y 49 | $(YACC) grammar.y 50 | 51 | $(LEX_YY).c: lex.l 52 | $(LEX) lex.l 53 | 54 | cproto.man: cproto.1 55 | cawf -man $*.1 | bsfilt - >$*.man 56 | 57 | clean: 58 | erase *.obj 59 | erase *.bak 60 | erase *.log 61 | erase $(LEX_YY).c 62 | erase $(Y_TAB).c 63 | erase micrsoft.lnk 64 | erase cproto.exe 65 | 66 | ci: 67 | ci -u3 $(DIST2) $(DIST3) 68 | ci -u3 $(DIST4) 69 | 70 | shar: 71 | shar $(DIST1) $(DIST2) >cproto.sh1 72 | shar $(DIST3) $(DIST4) >cproto.sh2 73 | 74 | # DO NOT DELETE THIS LINE -- make depend depends on it. 75 | 76 | cproto.obj: system.h cproto.h 77 | lintlibs.obj: system.h cproto.h symbol.h semantic.h 78 | popen.obj: system.h cproto.h 79 | semantic.obj: system.h cproto.h symbol.h semantic.h 80 | strkey.obj: cproto.h system.h 81 | symbol.obj: system.h cproto.h symbol.h 82 | -------------------------------------------------------------------------------- /msdos/turboc.mak: -------------------------------------------------------------------------------- 1 | # $Id: turboc.mak,v 4.3 2005/12/08 20:34:07 tom Exp $ 2 | # 3 | # Turbo C/C++ makefile for C prototype generator 4 | # (adapted from PRJ2MAK output) 5 | .AUTODEPEND 6 | 7 | # Define MSDOS for MS-DOS compatibility. 8 | # Define TURBO_CPP to pipe the input through the Turbo C preprocessor. 9 | DEFINES = MSDOS;TURBO_CPP 10 | 11 | # There's no standard for the names produced by lex clones on MSDOS: 12 | # FLEX produces LEXYY.C 13 | # MKS LEX produces LEX_YY.C (I think) 14 | #LEX = lex 15 | #LEX_OUT=lex_yy 16 | LEX = flex 17 | LEX_OUT=lexyy 18 | 19 | #YACC = yacc 20 | YACC = byacc 21 | #YACC = bison -o y_tab.c 22 | 23 | # *Translator Definitions* 24 | CC = tcc +cproto.cfg 25 | MODEL = l 26 | TLIB = tlib 27 | TLINK = tlink 28 | LIBPATH = C:\TC\LIB 29 | LIBS = $(LIBPATH)\wildargs.obj 30 | INCLUDEPATH = .;\tc\include 31 | 32 | DOC_FILES = \ 33 | README \ 34 | CHANGES \ 35 | cproto.man \ 36 | cproto.1 37 | 38 | MAK_FILES = \ 39 | makefile.in configure.in \ 40 | turboc.mak \ 41 | borland.mak \ 42 | micrsoft.mak 43 | 44 | DIST2 = lex.l grammar.y 45 | DIST3 = system.h cproto.h patchlev.h semantic.h symbol.h 46 | DIST4 = cproto.c popen.c lintlibs.c semantic.c strkey.c symbol.c 47 | 48 | OBJECTS = \ 49 | cproto.obj \ 50 | lintlibs.obj \ 51 | getopt.obj \ 52 | popen.obj \ 53 | semantic.obj \ 54 | strkey.obj \ 55 | symbol.obj \ 56 | y_tab.obj 57 | 58 | all: cproto.exe 59 | 60 | y_tab.obj : cproto.cfg \ 61 | y_tab.c $(LEX_OUT).c system.h cproto.h symbol.h semantic.h 62 | $(CC) -w-rch -c {$*.c } 63 | 64 | y_tab.c : grammar.y 65 | $(YACC) grammar.y 66 | 67 | $(LEX_OUT).c: lex.l 68 | $(LEX) lex.l 69 | 70 | cproto.man: cproto.1 71 | cawf -man $*.1 | bsfilt - >$*.man 72 | 73 | clean: 74 | erase *.$$$ 75 | erase cproto.cfg 76 | erase *.out 77 | erase *.obj 78 | erase *.bak 79 | erase *.log 80 | erase $(LEX_OUT).c 81 | erase y_tab.c 82 | erase cproto.exe 83 | 84 | # *Implicit Rules* 85 | .c.obj: 86 | $(CC) -c {$< } 87 | 88 | .cpp.obj: 89 | $(CC) -c {$< } 90 | 91 | # *Explicit Rules* 92 | cproto.exe: cproto.cfg $(OBJECTS) 93 | $(TLINK) /v/x/c/L$(LIBPATH) @&&| 94 | c0$(MODEL).obj+ 95 | cproto.obj + 96 | lintlibs.obj + 97 | getopt.obj + 98 | popen.obj + 99 | semantic.obj + 100 | strkey.obj + 101 | symbol.obj + 102 | y_tab.obj + 103 | $(LIBS) 104 | cproto 105 | # no map file 106 | emu.lib+ 107 | math$(MODEL).lib+ 108 | c$(MODEL).lib 109 | | 110 | 111 | # *Compiler Configuration File* 112 | cproto.cfg: turboc.mak 113 | copy &&| 114 | -m$(MODEL) 115 | -v 116 | -vi- 117 | -w-ret 118 | -w-nci 119 | -w-inl 120 | -wpin 121 | -wamb 122 | -wamp 123 | -w-par 124 | -wasm 125 | -wcln 126 | -w-cpt 127 | -wdef 128 | -w-dup 129 | -w-pia 130 | -wsig 131 | -wnod 132 | -w-ill 133 | -w-sus 134 | -wstv 135 | -wucp 136 | -wuse 137 | -w-ext 138 | -w-ias 139 | -w-ibc 140 | -w-pre 141 | -w-nst 142 | -I$(INCLUDEPATH) 143 | -L$(LIBPATH) 144 | -D$(DEFINES);STDC_HEADERS=1;USE_$(LEX);YY_USE_PROTOS 145 | | cproto.cfg 146 | 147 | # DO NOT DELETE THIS LINE -- make depend depends on it. 148 | 149 | cproto.obj : cproto.cfg system.h cproto.h symbol.h 150 | lintlibs.obj : cproto.cfg system.h cproto.h symbol.h semantic.h 151 | popen.obj : cproto.cfg system.h cproto.h 152 | semantic.obj : cproto.cfg system.h cproto.h symbol.h semantic.h 153 | strkey.obj : cproto.cfg cproto.h system.h 154 | symbol.obj : cproto.cfg system.h cproto.h symbol.h 155 | -------------------------------------------------------------------------------- /os2/README: -------------------------------------------------------------------------------- 1 | The files in this directory are used to build and test on OS/2. 2 | 3 | watcom.mak makefile for Watcom C/C++ 4 | 5 | run_test.cmd REXX script to run the regression tests 6 | -------------------------------------------------------------------------------- /os2/run_test.cmd: -------------------------------------------------------------------------------- 1 | /* REXX script to run cproto tests. */ 2 | /* $Id: run_test.cmd,v 4.2 1998/01/22 19:49:38 cthuang Exp $ */ 3 | "@echo off" 4 | 5 | testDir = "..\testing" 6 | casesFile = testDir||"\run_test.txt" 7 | sourceFile = testDir||"\syntax.c" 8 | logFile = "run_test.out" 9 | 10 | echo "Test log" ">" logFile 11 | 12 | linein(casesFile,1,0); 13 | do while lines(casesFile) > 0 14 | parse value linein(casesFile) with caseID '=' platforms '=' options 15 | if left(caseID, 4) = "CASE" & pos("os2", platforms) > 0 then do 16 | say caseID 17 | 18 | baseName = "case"||substr(caseID, 6, 2) 19 | inputFile = baseName||".c" 20 | outputFile = baseName||".out" 21 | refFile = testDir||"\"||baseName||".ref" 22 | 23 | copy sourceFile inputFile ">nul" 24 | cproto options inputFile ">" outputFile 25 | echo n "|" comp outputFile refFile ">>" logFile 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /os2/watcom.mak: -------------------------------------------------------------------------------- 1 | # $Id: watcom.mak,v 4.3 1998/01/22 19:49:39 cthuang Exp $ 2 | # 3 | # Watcom makefile for C prototype generator 4 | # To use this file, do 5 | # 6 | # wmake /u /f watcom.mak 7 | 8 | PROGRAM = cproto 9 | DEFINES = 10 | INCLUDES = -I.. -I..\porting 11 | 12 | LEX = lex 13 | YACC = yacc 14 | CC = wcl386 15 | CFLAGS = $(DEFINES) $(INCLUDES) 16 | LIBS = 17 | 18 | .c: .. 19 | 20 | .c.obj: .AUTODEPEND 21 | $(CC) $(CFLAGS) /c $< 22 | 23 | O = .obj 24 | OBJECTS = \ 25 | cproto$(O) \ 26 | getopt$(O) \ 27 | lintlibs$(O) \ 28 | semantic$(O) \ 29 | strkey$(O) \ 30 | symbol$(O) \ 31 | y_tab$(O) 32 | 33 | all: $(PROGRAM).exe 34 | 35 | $(PROGRAM).exe: $(OBJECTS) 36 | $(CC) $(CFLAGS) /fe=$@ $(OBJECTS) $(LIBS) 37 | 38 | getopt$(O): ..\porting\getopt.c 39 | $(CC) $(CFLAGS) /c ..\porting\getopt.c 40 | 41 | cproto.man: cproto.1 42 | cawf -man $*.1 | bsfilt - >$*.man 43 | 44 | clean: 45 | -del $(PROGRAM).exe 46 | -del *$(O) 47 | -del *.err 48 | -del *.log 49 | -del *.out 50 | -del case*.c 51 | 52 | test: 53 | run_test 54 | -------------------------------------------------------------------------------- /package/cproto.spec: -------------------------------------------------------------------------------- 1 | Summary: cproto - generate C function prototypes and convert function definitions 2 | %define AppProgram cproto 3 | %define AppVersion 4.7l 4 | # $XTermId: cproto.spec,v 1.5 2014/01/01 15:30:54 tom Exp $ 5 | Name: %{AppProgram} 6 | Version: %{AppVersion} 7 | Release: 1 8 | License: Public Domain 9 | Group: Applications/Development 10 | URL: ftp://invisible-island.net/%{AppProgram} 11 | Source0: %{AppProgram}-%{AppVersion}.tgz 12 | Packager: Thomas Dickey 13 | 14 | %description 15 | Cproto generates function prototypes for functions defined in the specified C 16 | source files to the standard output. The function definitions may be in the 17 | old style or ANSI C style. Optionally, cproto also outputs declarations for 18 | variables defined in the files. 19 | 20 | %prep 21 | 22 | %setup -q -n %{AppProgram}-%{AppVersion} 23 | 24 | %build 25 | 26 | INSTALL_PROGRAM='${INSTALL}' \ 27 | ./configure \ 28 | --target %{_target_platform} \ 29 | --prefix=%{_prefix} \ 30 | --bindir=%{_bindir} \ 31 | --libdir=%{_libdir} \ 32 | --mandir=%{_mandir} 33 | 34 | make 35 | 36 | %install 37 | [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT 38 | 39 | make install DESTDIR=$RPM_BUILD_ROOT 40 | 41 | strip $RPM_BUILD_ROOT%{_bindir}/%{AppProgram} 42 | 43 | %clean 44 | [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT 45 | 46 | %files 47 | %defattr(-,root,root) 48 | %{_prefix}/bin/%{AppProgram} 49 | %{_mandir}/man1/%{AppProgram}.* 50 | 51 | %changelog 52 | # each patch should add its ChangeLog entries here 53 | 54 | * Sun Jan 02 2011 Thomas Dickey 55 | - cproto 4.7j 56 | 57 | * Wed Jul 14 2010 Thomas Dickey 58 | - initial version 59 | -------------------------------------------------------------------------------- /package/debian/changelog: -------------------------------------------------------------------------------- 1 | cproto (4.7l) unstable; urgency=low 2 | 3 | * correct configure-check for yyname vs yytname 4 | 5 | -- Thomas E. Dickey Wed, 01 Jan 2014 10:31:44 -0500 6 | 7 | cproto (4.7k) unstable; urgency=low 8 | 9 | * update configure scripts 10 | 11 | -- Thomas E. Dickey Fri, 25 Oct 2013 04:28:30 -0400 12 | 13 | cproto (4.7j) unstable; urgency=low 14 | 15 | * minor fix to lint-library check for function vs function-pointer. 16 | 17 | -- Thomas E. Dickey Sun, 02 Jan 2011 14:33:51 -0500 18 | 19 | cproto (4.7i) unstable; urgency=low 20 | 21 | * Add package scripts to upstream source, for test-builds. 22 | 23 | -- Thomas E. Dickey Wed, 14 Jul 2010 04:59:59 -0400 24 | -------------------------------------------------------------------------------- /package/debian/compat: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /package/debian/control: -------------------------------------------------------------------------------- 1 | Source: cproto 2 | Maintainer: Thomas E. Dickey 3 | Section: devel 4 | Priority: extra 5 | Standards-Version: 3.8.4 6 | Build-Depends: debhelper (>= 5) 7 | Homepage: http://invisible-island.net/cproto/ 8 | 9 | Package: cproto 10 | Architecture: any 11 | Depends: ${shlibs:Depends}, ${misc:Depends} 12 | Description: generate C function prototypes and convert function definitions 13 | Cproto generates function prototypes for functions defined in the specified C 14 | source files to the standard output. The function definitions may be in the 15 | old style or ANSI C style. Optionally, cproto also outputs declarations for 16 | variables defined in the files. 17 | -------------------------------------------------------------------------------- /package/debian/copyright: -------------------------------------------------------------------------------- 1 | Upstream source http://invisible-island.net/cproto/cproto.html 2 | 3 | cproto is in the public domain; changes made to it by the current 4 | maintainer are likewise unrestricted. That applies to most of the files. 5 | A few files (currently those related to autoconf scripting) have other 6 | licenses as noted here. 7 | 8 | Current cproto upstream maintainer: Thomas Dickey 9 | 10 | ------------------------------------------------------------------------------- 11 | 12 | Files: aclocal.m4 13 | Licence: other-BSD 14 | Copyright: 1994-2013,2014 by Thomas E. Dickey 15 | Permission is hereby granted, free of charge, to any person obtaining a 16 | copy of this software and associated documentation files (the 17 | "Software"), to deal in the Software without restriction, including 18 | without limitation the rights to use, copy, modify, merge, publish, 19 | distribute, distribute with modifications, sublicense, and/or sell 20 | copies of the Software, and to permit persons to whom the Software is 21 | furnished to do so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included 24 | in all copies or portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 27 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 28 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 29 | IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 30 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 31 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 32 | THE USE OR OTHER DEALINGS IN THE SOFTWARE. 33 | 34 | Except as contained in this notice, the name(s) of the above copyright 35 | holders shall not be used in advertising or otherwise to promote the 36 | sale, use or other dealings in this Software without prior written 37 | authorization. 38 | 39 | Files: install-sh 40 | Copyright: 1994 X Consortium 41 | Licence: other-BSD 42 | Permission is hereby granted, free of charge, to any person obtaining a copy 43 | of this software and associated documentation files (the "Software"), to 44 | deal in the Software without restriction, including without limitation the 45 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 46 | sell copies of the Software, and to permit persons to whom the Software is 47 | furnished to do so, subject to the following conditions: 48 | 49 | The above copyright notice and this permission notice shall be included in 50 | all copies or substantial portions of the Software. 51 | 52 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 53 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 54 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 55 | X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 56 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 57 | TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 58 | 59 | Except as contained in this notice, the name of the X Consortium shall not 60 | be used in advertising or otherwise to promote the sale, use or other deal- 61 | ings in this Software without prior written authorization from the X Consor- 62 | tium. 63 | 64 | FSF changes to this file are in the public domain. 65 | 66 | Calling this script install-sh is preferred over install.sh, to prevent 67 | `make' implicit rules from creating a file called install from it 68 | when there is no Makefile. 69 | 70 | This script is compatible with the BSD install script, but was written 71 | from scratch. It can only install one file at a time, a restriction 72 | shared with many OS's install programs. 73 | 74 | Files: debian/* 75 | Copyright: 2010-2013,2014 Thomas E. Dickey 76 | Licence: other-BSD 77 | Permission to use, copy, modify, and distribute this software and its 78 | documentation for any purpose and without fee is hereby granted, 79 | provided that the above copyright notice appear in all copies and that 80 | both that copyright notice and this permission notice appear in 81 | supporting documentation, and that the name of the above listed 82 | copyright holder(s) not be used in advertising or publicity pertaining 83 | to distribution of the software without specific, written prior 84 | permission. 85 | 86 | THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD 87 | TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 88 | AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE 89 | LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 90 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 91 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 92 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 93 | 94 | On Debian systems, the complete text of the GNU General 95 | Public License can be found in '/usr/share/common-licenses/GPL-2' 96 | -------------------------------------------------------------------------------- /package/debian/docs: -------------------------------------------------------------------------------- 1 | README 2 | -------------------------------------------------------------------------------- /package/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | # MAde with the aid of dh_make, by Craig Small 3 | # Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess. 4 | # Some lines taken from debmake, by Cristoph Lameter. 5 | 6 | # Uncomment this to turn on verbose mode. 7 | #export DH_VERBOSE=1 8 | 9 | # These are used for cross-compiling and for saving the configure script 10 | # from having to guess our platform (since we know it already) 11 | DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) 12 | DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) 13 | 14 | CFLAGS = 15 | 16 | ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) 17 | CFLAGS += -O0 18 | else 19 | CFLAGS += -O2 20 | endif 21 | ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS))) 22 | INSTALL_PROGRAM += -s 23 | endif 24 | 25 | 26 | configure: configure-stamp 27 | configure-stamp: 28 | dh_testdir 29 | 30 | CFLAGS="$(CFLAGS)" ./configure \ 31 | --host=$(DEB_HOST_GNU_TYPE) \ 32 | --build=$(DEB_BUILD_GNU_TYPE) \ 33 | --prefix=/usr \ 34 | --mandir=\$${prefix}/share/man \ 35 | --sysconfdir=/etc 36 | 37 | touch configure-stamp 38 | 39 | build: build-stamp 40 | build-stamp: configure-stamp 41 | dh_testdir 42 | 43 | $(MAKE) 44 | 45 | touch build-stamp 46 | 47 | clean: 48 | dh_testdir 49 | dh_testroot 50 | 51 | [ ! -f Makefile ] || $(MAKE) clean 52 | 53 | rm -f configure-stamp build-stamp install-stamp \ 54 | config.cache config.h config.status config.log makefile 55 | 56 | rm -f *.o cproto 57 | 58 | dh_clean 59 | 60 | install: install-stamp 61 | install-stamp: build-stamp 62 | dh_testdir 63 | dh_testroot 64 | dh_clean -k 65 | dh_installdirs 66 | 67 | $(MAKE) install DESTDIR=$(CURDIR)/debian/cproto 68 | 69 | touch install-stamp 70 | 71 | # Build architecture-independent files here. 72 | binary-indep: build install 73 | # No binary-indep target. 74 | 75 | # Build architecture-dependent files here. 76 | binary-arch: build install 77 | dh_testdir 78 | dh_testroot 79 | dh_installdocs 80 | dh_installexamples 81 | dh_installchangelogs CHANGES 82 | dh_strip 83 | dh_compress 84 | dh_fixperms 85 | dh_installdeb 86 | dh_shlibdeps 87 | dh_gencontrol 88 | dh_md5sums 89 | dh_builddeb 90 | 91 | binary: binary-indep binary-arch 92 | .PHONY: build clean binary-indep binary-arch binary install install-stamp 93 | -------------------------------------------------------------------------------- /package/debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /package/debian/watch: -------------------------------------------------------------------------------- 1 | version=3 2 | 3 | opts=passive ftp://invisible-island.net/cproto/cproto-(\d+)\.tgz \ 4 | debian uupdate 5 | -------------------------------------------------------------------------------- /porting/README: -------------------------------------------------------------------------------- 1 | The files in this directory are needed to build on non-UNIX platforms. 2 | 3 | getopt.c This is a free implementation of the getopt function for 4 | getopt.h systems that don't already have it (such as MS-DOS and VMS). 5 | Some systems that support auto-configuration may need these 6 | files. You'll have to edit the makefile in that case. 7 | 8 | popen.c fakes a pipe open/close by writing to a temporary file. 9 | -------------------------------------------------------------------------------- /porting/getopt.c: -------------------------------------------------------------------------------- 1 | /* $Id: getopt.c,v 4.2 2013/10/25 22:08:08 tom Exp $ */ 2 | 3 | /* ::[[ @(#) getopt.c 1.5 89/03/11 05:40:23 ]]:: */ 4 | 5 | /* 6 | #ifndef LINT 7 | static char sccsid[]="::[[ @(#) getopt.c 1.5 89/03/11 05:40:23 ]]::"; 8 | #endif 9 | */ 10 | 11 | /* 12 | * Here's something you've all been waiting for: the AT&T public domain 13 | * source for getopt(3). It is the code which was given out at the 1985 14 | * UNIFORUM conference in Dallas. I obtained it by electronic mail 15 | * directly from AT&T. The people there assure me that it is indeed 16 | * in the public domain. 17 | * 18 | * There is no manual page. That is because the one they gave out at 19 | * UNIFORUM was slightly different from the current System V Release 2 20 | * manual page. The difference apparently involved a note about the 21 | * famous rules 5 and 6, recommending using white space between an option 22 | * and its first argument, and not grouping options that have arguments. 23 | * Getopt itself is currently lenient about both of these things White 24 | * space is allowed, but not mandatory, and the last option in a group can 25 | * have an argument. That particular version of the man page evidently 26 | * has no official existence, and my source at AT&T did not send a copy. 27 | * The current SVR2 man page reflects the actual behavor of this getopt. 28 | * However, I am not about to post a copy of anything licensed by AT&T. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #define ERR(szz,czz) if(opterr){fprintf(stderr,"%s%s%c\n",argv[0],szz,czz);} 36 | 37 | int opterr = 1; 38 | int optind = 1; 39 | int optopt; 40 | char *optarg; 41 | 42 | int 43 | getopt(int argc, char **argv, const char *opts) 44 | { 45 | static int sp = 1; 46 | register int c; 47 | register char *cp; 48 | 49 | if(sp == 1) { 50 | if(optind >= argc || 51 | argv[optind][0] != '-' || argv[optind][1] == '\0') 52 | return(EOF); 53 | else if(strcmp(argv[optind], "--") == 0) { 54 | optind++; 55 | return(EOF); 56 | } 57 | } 58 | optopt = (c = argv[optind][sp]); 59 | if(c == ':' || (cp=strchr(opts, c)) == NULL) { 60 | ERR(": illegal option -- ", c); 61 | if(argv[optind][++sp] == '\0') { 62 | optind++; 63 | sp = 1; 64 | } 65 | return('?'); 66 | } 67 | if(*++cp == ':') { 68 | if(argv[optind][sp+1] != '\0') 69 | optarg = &argv[optind++][sp+1]; 70 | else if(++optind >= argc) { 71 | ERR(": option requires an argument -- ", c); 72 | sp = 1; 73 | return('?'); 74 | } else 75 | optarg = argv[optind++]; 76 | sp = 1; 77 | } else { 78 | if(argv[optind][++sp] == '\0') { 79 | sp = 1; 80 | optind++; 81 | } 82 | optarg = NULL; 83 | } 84 | return(c); 85 | } 86 | -------------------------------------------------------------------------------- /porting/getopt.h: -------------------------------------------------------------------------------- 1 | /* $Id: getopt.h,v 4.3 2013/10/25 22:08:17 tom Exp $ */ 2 | 3 | #ifndef OLD_GETOPT_H 4 | #define OLD_GETOPT_H 1 5 | 6 | extern char *optarg; 7 | extern int optind, opterr; 8 | extern int getopt (int argc, char **argv, const char *options); 9 | 10 | #endif /* OLD_GETOPT_H */ 11 | -------------------------------------------------------------------------------- /porting/popen.c: -------------------------------------------------------------------------------- 1 | /* $Id: popen.c,v 4.2 1998/01/08 00:03:28 cthuang Exp $ 2 | * 3 | * Imitate a UNIX pipe in MS-DOS. 4 | */ 5 | #ifdef MSDOS 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "cproto.h" 11 | 12 | static char pipe_name[FILENAME_MAX]; /* name of the temporary file */ 13 | 14 | /* Open a pipe for reading. 15 | */ 16 | FILE * 17 | popen (cmd, type) 18 | char *cmd, *type; 19 | { 20 | char *tmpdir, *argv[30], **arg, *cmdline, *s, opt[FILENAME_MAX]; 21 | int ostdout, status; 22 | 23 | /* Set temporary file name. */ 24 | if ((tmpdir = getenv("TMP")) == NULL) { 25 | pipe_name[0] = '\0'; 26 | } else { 27 | strcpy(pipe_name, tmpdir); 28 | trim_path_sep(pipe_name); 29 | strcat(pipe_name, "/"); 30 | } 31 | strcat(pipe_name, tmpnam(NULL)); 32 | 33 | /* Split the command into an argument array. */ 34 | cmdline = xstrdup(cmd); 35 | arg = argv; 36 | s = strtok(cmdline, " "); 37 | *arg++ = s; 38 | #ifdef TURBO_CPP 39 | sprintf(opt, "-o%s", pipe_name); 40 | *arg++ = opt; 41 | #endif 42 | while ((s = strtok(NULL, " ")) != NULL) { 43 | *arg++ = s; 44 | } 45 | *arg = NULL; 46 | 47 | /* Redirect the program's stdout. */ 48 | ostdout = dup(fileno(stdout)); 49 | #ifdef TURBO_CPP 50 | freopen("nul", "w", stdout); 51 | #else 52 | freopen(pipe_name, "w", stdout); 53 | #endif 54 | 55 | /* Run the program. */ 56 | status = spawnvp(P_WAIT, argv[0], argv); 57 | 58 | /* Restore stdout. */ 59 | dup2(ostdout, fileno(stdout)); 60 | free(cmdline); 61 | 62 | if (status != 0) 63 | return NULL; 64 | 65 | /* Open the intermediate file and return the stream. */ 66 | return fopen(pipe_name, type) ; 67 | } 68 | 69 | /* Close the pipe. 70 | */ 71 | int 72 | pclose (f) 73 | FILE *f; 74 | { 75 | int status; 76 | 77 | status = fclose(f); 78 | unlink(pipe_name); 79 | return status; 80 | } 81 | #endif /* MSDOS */ 82 | -------------------------------------------------------------------------------- /semantic.h: -------------------------------------------------------------------------------- 1 | /* $Id: semantic.h,v 4.6 2011/01/02 19:03:03 tom Exp $ 2 | * 3 | * Declarations of semantic action routines 4 | */ 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #include 11 | 12 | extern void new_decl_spec ( 13 | DeclSpec *decl_spec, const char *text, long offset, int flags); 14 | extern void free_decl_spec ( 15 | DeclSpec *decl_spec); 16 | extern void join_decl_specs ( 17 | DeclSpec *result, DeclSpec *a, DeclSpec *b); 18 | extern void check_untagged ( 19 | DeclSpec *decl_spec); 20 | extern Declarator *new_declarator ( 21 | const char *text, const char *name, long offset); 22 | extern void free_declarator ( 23 | Declarator *d); 24 | extern void new_decl_list ( 25 | DeclaratorList *decl_list, Declarator *declarator); 26 | extern void free_decl_list ( 27 | DeclaratorList *decl_list); 28 | extern void add_decl_list ( 29 | DeclaratorList *to, DeclaratorList *from, Declarator *declarator); 30 | extern Parameter *new_parameter ( 31 | DeclSpec *decl_spec, Declarator *declarator); 32 | extern void free_parameter ( 33 | Parameter *param); 34 | extern void new_param_list ( 35 | ParameterList *param_list, Parameter *param); 36 | extern void free_param_list ( 37 | ParameterList *param_list); 38 | extern void add_param_list ( 39 | ParameterList *to, ParameterList *from, Parameter *param); 40 | extern void new_ident_list ( 41 | ParameterList *param_list); 42 | extern void add_ident_list ( 43 | ParameterList *to, ParameterList *from, const char *name); 44 | extern void set_param_types ( 45 | ParameterList *params, DeclSpec *decl_spec, DeclaratorList *declarators); 46 | extern void gen_declarations ( 47 | DeclSpec *decl_spec, DeclaratorList *decl_list); 48 | extern void gen_prototype ( 49 | DeclSpec *decl_spec, Declarator *declarator); 50 | extern void gen_func_declarator ( 51 | Declarator *declarator); 52 | extern void gen_func_definition ( 53 | DeclSpec *decl_spec, Declarator *declarator); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | -------------------------------------------------------------------------------- /strkey.c: -------------------------------------------------------------------------------- 1 | /* $Id: strkey.c,v 4.9 2011/01/02 19:24:03 tom Exp $ 2 | * 3 | * Some string handling routines 4 | */ 5 | #include 6 | #include 7 | 8 | #define LETTER(c) (isalnum(UCH(c)) || (c == '_') || (c == '$')) 9 | 10 | /* 11 | * Return a pointer to the first occurence of the given keyword in the string 12 | * or NULL if not found. Unlike 'strstr()', which verifies that the match is 13 | * against an identifier-token. 14 | */ 15 | char * 16 | strkey(char *src, const char *key) 17 | { 18 | if (src != 0 && key != 0) { 19 | register char *s = src, *d; 20 | register size_t len = strlen(key); 21 | 22 | while (*s) { 23 | if (!LETTER(*s)) { 24 | s++; 25 | } else { 26 | for (d = s; LETTER(*d); d++) ; 27 | if ((d - s) == (int) len && !strncmp(s, key, len)) 28 | return s; 29 | s = d; 30 | } 31 | } 32 | } 33 | return NULL; 34 | } 35 | 36 | /* 37 | * Delete a specified keyword from a string if it appears there 38 | */ 39 | void 40 | strcut(char *src, const char *key) 41 | { 42 | register char *s, *d; 43 | 44 | if ((s = strkey(src, key)) != '\0') { 45 | d = s + strlen(key); 46 | while (*d != '\0' && !LETTER(*d)) 47 | d++; 48 | while ((*s++ = *d++) != '\0') ; 49 | } 50 | } 51 | 52 | /* Search for a substring within the given string. 53 | * Return a pointer to the first occurence within the string, 54 | * or NULL if not found. 55 | */ 56 | #if !HAVE_STRSTR 57 | char * 58 | strstr(char *src, char *key) 59 | { 60 | char *s; 61 | int keylen; 62 | 63 | if ((keylen = strlen(key)) == 0) 64 | return src; 65 | 66 | s = strchr(src, *key); 67 | while (s != NULL) { 68 | if (strncmp(s, key, keylen) == 0) 69 | return s; 70 | s = strchr(s + 1, *key); 71 | } 72 | return NULL; 73 | } 74 | #endif 75 | -------------------------------------------------------------------------------- /symbol.c: -------------------------------------------------------------------------------- 1 | /* $Id: symbol.c,v 4.9 2011/01/02 19:17:15 tom Exp $ 2 | * 3 | * Implements a symbol table abstract data type. 4 | */ 5 | #include 6 | 7 | /* Create a symbol table. 8 | * Return a pointer to the symbol table or NULL if an error occurs. 9 | */ 10 | SymbolTable * 11 | new_symbol_table(void) 12 | { 13 | SymbolTable *symtab; 14 | int i; 15 | 16 | if ((symtab = NEW(SymbolTable)) != NULL) { 17 | for (i = 0; i < SYM_MAX_HASH; ++i) 18 | symtab->bucket[i] = NULL; 19 | } 20 | return symtab; 21 | } 22 | 23 | /* Free the memory allocated to the symbol table. 24 | */ 25 | void 26 | free_symbol_table(SymbolTable * symtab) 27 | { 28 | int i; 29 | Symbol *sym, *next; 30 | 31 | for (i = 0; i < SYM_MAX_HASH; ++i) { 32 | sym = symtab->bucket[i]; 33 | while (sym != NULL) { 34 | next = sym->next; 35 | if (sym->name != 0) 36 | free(sym->name); 37 | if (sym->value != 0) 38 | free(sym->value); 39 | free(sym); 40 | sym = next; 41 | } 42 | } 43 | free(symtab); 44 | } 45 | 46 | /* This is a simple hash function mapping a symbol name to a hash bucket. */ 47 | 48 | static unsigned 49 | hash(const char *name) 50 | { 51 | const char *s; 52 | unsigned h; 53 | 54 | h = 0; 55 | s = name; 56 | while (*s != '\0') 57 | h = (h << 1) ^ (unsigned char) (*s++); 58 | return h % SYM_MAX_HASH; 59 | } 60 | 61 | /* Search the list of symbols for the symbol . 62 | * Return a pointer to the symbol or NULL if not found. 63 | */ 64 | static Symbol * 65 | search_symbol_list(Symbol * list, const char *name) 66 | { 67 | Symbol *sym; 68 | 69 | for (sym = list; sym != NULL; sym = sym->next) { 70 | if (strcmp(sym->name, name) == 0) 71 | return sym; 72 | } 73 | return NULL; 74 | } 75 | 76 | /* Look for symbol in symbol table . 77 | * Return a pointer to the symbol or NULL if not found. 78 | */ 79 | Symbol * 80 | find_symbol(SymbolTable * symtab, const char *name) 81 | { 82 | return search_symbol_list(symtab->bucket[hash(name)], name); 83 | } 84 | 85 | /* If the symbol does not already exist in symbol table , 86 | * then add the symbol to the symbol table. 87 | * Return a pointer to the symbol. 88 | */ 89 | Symbol * 90 | new_symbol( 91 | SymbolTable * symtab, /* symbol table */ 92 | const char *name, /* symbol name */ 93 | const char *value, /* symbol value */ 94 | int flags) /* symbol attributes */ 95 | { 96 | Symbol *sym; 97 | unsigned i; 98 | 99 | if ((sym = find_symbol(symtab, name)) == NULL) { 100 | sym = NEW(Symbol); 101 | sym->name = xstrdup(name); 102 | i = hash(name); 103 | sym->next = symtab->bucket[i]; 104 | symtab->bucket[i] = sym; 105 | } else { 106 | free(sym->value); 107 | } 108 | sym->value = (value != NULL) ? xstrdup(value) : NULL; 109 | sym->flags = (short) flags; 110 | return sym; 111 | } 112 | -------------------------------------------------------------------------------- /symbol.h: -------------------------------------------------------------------------------- 1 | /* $Id: symbol.h,v 4.4 2011/01/02 19:17:41 tom Exp $ 2 | * 3 | * A symbol table is a collection of string identifiers stored in a 4 | * hash table. 5 | */ 6 | #ifndef SYMBOL_H 7 | #define SYMBOL_H 8 | 9 | #include 10 | 11 | typedef struct symbol { 12 | struct symbol *next; /* next symbol in list */ 13 | char *name; /* name of symbol */ 14 | char *value; /* value of symbol (for defines) */ 15 | short flags; /* symbol attributes */ 16 | } Symbol; 17 | 18 | /* The hash table length should be a prime number. */ 19 | #define SYM_MAX_HASH 251 20 | 21 | typedef struct symbol_table { 22 | Symbol *bucket[SYM_MAX_HASH]; /* hash buckets */ 23 | } SymbolTable; 24 | 25 | extern SymbolTable *new_symbol_table /* Create symbol table */ 26 | (void); 27 | extern void free_symbol_table /* Destroy symbol table */ 28 | (SymbolTable *s); 29 | extern Symbol *find_symbol /* Lookup symbol name */ 30 | (SymbolTable *s, const char *n); 31 | extern Symbol *new_symbol /* Define new symbol */ 32 | (SymbolTable *s, const char *n, const char *v, int f); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /system.h: -------------------------------------------------------------------------------- 1 | /* $Id: system.h,v 4.13 2011/01/02 19:23:38 tom Exp $ 2 | * 3 | * cproto configuration and system dependencies 4 | */ 5 | #ifndef SYSTEM_H 6 | #define SYSTEM_H 7 | 8 | #include 9 | #include 10 | 11 | #ifndef TRUE 12 | #define TRUE (1) 13 | #endif 14 | 15 | #ifndef FALSE 16 | #define FALSE (0) 17 | #endif 18 | 19 | /* Watcom C++ predefines __DOS__ when the target platform is MS-DOS */ 20 | /* Borland C++ for MS-DOS predefines __MSDOS__ */ 21 | #if defined(__DOS__) || defined(__MSDOS__) 22 | #ifndef MSDOS 23 | #define MSDOS 24 | #endif 25 | #endif 26 | 27 | /* Watcom C++ predefines __OS2__ when the target platform is OS/2 */ 28 | #ifdef __OS2__ 29 | #ifndef OS2 30 | #define OS2 31 | #endif 32 | #endif 33 | 34 | /* Watcom C++ predefines __NT__ when the target platform is Windows NT */ 35 | #ifdef __NT__ 36 | #ifndef WIN32 37 | #define WIN32 38 | #endif 39 | #endif 40 | 41 | /* Turbo C preprocessor */ 42 | #ifdef __TURBOC__ 43 | #define YY_READ_BUF_SIZE 256 /* patch */ 44 | #define HAVE_TMPFILE 1 45 | #define HAVE_GETOPT_H 1 /* use the one from porting-directory */ 46 | #include /* declares 'read()' for flex */ 47 | #endif 48 | 49 | #ifdef TURBO_CPP 50 | #define CPP "cpp -P-" 51 | #endif 52 | 53 | /* EMX C preprocessor */ 54 | #ifdef __EMX__ 55 | #ifndef CPP 56 | #define CPP "cpp" 57 | #endif 58 | #endif 59 | 60 | /* Watcom C preprocessor */ 61 | #ifdef __WATCOMC__ 62 | #ifndef CPP 63 | #define CPP "wcl386 /p" 64 | #endif 65 | #define HAVE_POPEN_PROTOTYPE 1 66 | #define popen _popen 67 | #define pclose _pclose 68 | #define HAVE_TMPFILE 1 69 | #endif 70 | 71 | /* Microsoft C preprocessor */ 72 | #ifdef M_I86 73 | #ifndef CPP 74 | #define CPP "cl /E /nologo" 75 | #endif 76 | #define HAVE_TMPFILE 1 77 | #endif 78 | 79 | /* Vax C */ 80 | #ifdef vms 81 | #ifndef CPP 82 | #define CPP "cc /preprocess_only=%s" 83 | #endif 84 | #define unlink remove 85 | #define HAVE_TMPFILE 1 86 | #define HAVE_GETOPT_H 1 87 | #define USE_flex 1 88 | #define CURRENT_DIR "[]" 89 | #endif 90 | 91 | /* Set configuration parameters for systems on which we cannot run autoconf. 92 | * (Assumes Posix unless overridden). 93 | */ 94 | #ifndef HAVE_GETOPT_H 95 | #define HAVE_GETOPT_H 0 96 | #endif 97 | 98 | #ifndef HAVE_LIBDBMALLOC 99 | #define HAVE_LIBDBMALLOC 0 100 | #endif 101 | 102 | #ifndef HAVE_LIBDMALLOC 103 | #define HAVE_LIBDMALLOC 0 104 | #endif 105 | 106 | #ifndef HAVE_STDLIB_H 107 | #define HAVE_STDLIB_H 1 108 | #endif 109 | 110 | #ifndef HAVE_STRING_H 111 | #define HAVE_STRING_H 1 112 | #endif 113 | 114 | #ifndef HAVE_STRSTR 115 | #define HAVE_STRSTR 1 116 | #endif 117 | 118 | #ifndef HAVE_UNISTD_H 119 | #define HAVE_UNISTD_H 0 120 | #endif 121 | 122 | #ifndef STDC_HEADERS 123 | #define STDC_HEADERS 1 124 | #endif 125 | 126 | /* Default C preprocessor on UNIX systems */ 127 | #ifndef MSDOS 128 | #ifndef CPP 129 | #define CPP "/lib/cpp" 130 | #endif 131 | #endif 132 | 133 | /* maximum include file nesting (for parsing externs) */ 134 | #ifndef MAX_INC_DEPTH 135 | #define MAX_INC_DEPTH 999999 136 | #endif 137 | 138 | /* string denoting current-directory, for includes */ 139 | #ifndef CURRENT_DIR 140 | #define CURRENT_DIR "." 141 | #endif 142 | 143 | /* maximum text buffer size (for tokens) */ 144 | #ifndef MAX_TEXT_SIZE 145 | #define MAX_TEXT_SIZE 4096 146 | #endif 147 | 148 | #if HAVE_STDLIB_H 149 | #include 150 | #else 151 | extern char *malloc (size_t n); 152 | extern char *realloc (char *p, size_t n); 153 | extern char *getenv (const char *v); 154 | #endif 155 | 156 | /* Declare argument for exit() function */ 157 | #ifdef vms 158 | #include 159 | #define EXIT_SUCCESS (STS$M_INHIB_MSG | STS$K_SUCCESS) 160 | #define EXIT_FAILURE (STS$M_INHIB_MSG | STS$K_ERROR) 161 | #else 162 | #ifndef EXIT_SUCCESS 163 | #define EXIT_SUCCESS (0) 164 | #endif 165 | #ifndef EXIT_FAILURE 166 | #define EXIT_FAILURE (1) 167 | #endif 168 | #endif /* vms */ 169 | 170 | #if HAVE_UNISTD_H 171 | #include 172 | #endif 173 | 174 | #if STDC_HEADERS || HAVE_STRING_H 175 | # include 176 | /* An ANSI string.h and pre-ANSI memory.h might conflict. */ 177 | # if !STDC_HEADERS && HAVE_MEMORY_H 178 | # include 179 | # endif /* not STDC_HEADERS and HAVE_MEMORY_H */ 180 | #else /* not STDC_HEADERS and not HAVE_STRING_H */ 181 | # include 182 | # define strchr index 183 | # define strrchr rindex 184 | extern char *strstr (const char *s, const char *p); 185 | /* memory.h and strings.h conflict on some systems. */ 186 | #endif /* not STDC_HEADERS and not HAVE_STRING_H */ 187 | 188 | /* 189 | * The DOALLOC symbol controls whether we compile in the simple memory tests 190 | * in 'trace.c' (use dbmalloc for more rigorous testing). 191 | */ 192 | #ifdef DOALLOC 193 | #include 194 | #endif /* DOALLOC */ 195 | 196 | /* 197 | * Lint libraries are useful only on systems that are likely to have lint. 198 | * The OPT_LINTLIBRARY symbol controls whether we compile in the lint library 199 | * support. 200 | */ 201 | #ifndef OPT_LINTLIBRARY 202 | # define OPT_LINTLIBRARY 0 203 | #endif 204 | 205 | #if BISON_HAS_YYTNAME || YACC_HAS_YYTOKS || YACC_HAS_YYTOKS_2 || YACC_HAS_YYNAME 206 | # define YYDEBUG 1 207 | #endif 208 | 209 | #if HAVE_LIBDMALLOC 210 | #include /* Gray Watson's library */ 211 | #endif 212 | 213 | #if HAVE_LIBDBMALLOC 214 | #include /* Conor Cahill's library */ 215 | #endif 216 | 217 | #endif /* SYSTEM_H */ 218 | -------------------------------------------------------------------------------- /testing/README: -------------------------------------------------------------------------------- 1 | $Id: README,v 4.3 1995/01/06 23:42:14 tom Exp $ 2 | 3 | CPROTO/TESTING 4 | 5 | There's several types of files in this directory, distinguished by their 6 | suffixes. 7 | 8 | makefile 9 | a UNIX makefile used to coordinate files and to invoke the 10 | UNIX master test script 'run_test.sh'. 11 | 12 | case*.bat 13 | MSDOS scripts automatically generated to run test cases. 14 | 15 | test_dos.bat 16 | The master MSDOS test script. 17 | 18 | syntax.c 19 | The test data (contains some intentional errors, and all of 20 | the interesting tests that can be made portable across all 21 | platforms). 22 | 23 | apollo.c 24 | linux.c 25 | solaris.c 26 | turboc.c 27 | These are lint library templates, used for exercising cproto. 28 | They include as many of the system's include files as possible, 29 | in an attempt to find lexical/grammar problems with cproto. 30 | 31 | run_test.com 32 | The VMS master test script. 33 | 34 | case*.dcl 35 | UNIX+VMS scripts automatically generated to run test cases. 36 | (They don't have a ".com" suffix because that would create 37 | problems on MSDOS). 38 | 39 | descrip.mms 40 | The VMS equivalent of 'makefile'. 41 | 42 | case*.ref 43 | Reference files obtained by running the test scripts. 44 | 45 | make_bat.sh 46 | The script that generates case*.bat 47 | 48 | make_dcl.sh 49 | The script that generates case*.dcl 50 | 51 | run_test.sh 52 | The master UNIX test script 53 | 54 | testunix.sh 55 | The UNIX test script that actually does all of the work 56 | 57 | run_test.txt 58 | The test list, from which the case*.dcl, case*.bat files 59 | are generated. 60 | 61 | -------------------------------------------------------------------------------- /testing/apollo.c: -------------------------------------------------------------------------------- 1 | #define const 2 | /* LINT_PREPRO6 3 | #undef COMPLETE_SR10_2 4 | #ifdef __STDC__ 5 | #ident Standard LLIB 6 | #else 7 | #ident Traditional LLIB 8 | #endif 9 | */ 10 | 11 | /* LINT_EXTERN */ 12 | #include 13 | 14 | /* */ 15 | #include 16 | /* */ 17 | /* */ 18 | /* */ 19 | 20 | #include 21 | 22 | /* (see below) */ 23 | /* (separate) */ 24 | /* (separate) */ 25 | 26 | #ifdef COMPLETE_SR10_2 27 | #include 28 | #include 29 | #include 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | /* */ 36 | /* */ 37 | 38 | #ifdef COMPLETE_SR10_2 39 | #include 40 | #include 41 | #include 42 | #include 43 | #endif 44 | 45 | /* (missing?) */ 46 | /* (lint can't eat prototype-in!) */ 47 | /* (missing?) */ 48 | /* */ 49 | 50 | #ifdef COMPLETE_SR10_2 51 | #include 52 | #endif 53 | #include 54 | #ifdef COMPLETE_SR10_2 55 | #include 56 | #include 57 | #include 58 | /* */ 59 | /* */ 60 | #include 61 | #include 62 | /* */ 63 | #include 64 | #include 65 | #include 66 | #endif 67 | 68 | #include 69 | /* */ 70 | 71 | #ifdef COMPLETE_SR10_2 72 | #include 73 | #include 74 | #endif 75 | 76 | #include 77 | 78 | #ifdef COMPLETE_SR10_2 79 | #include 80 | #include 81 | #include 82 | #include 83 | #include 84 | #include 85 | #include 86 | #include 87 | /* */ 88 | #include 89 | /* */ 90 | /* */ 91 | #include 92 | #include 93 | #include 94 | #include 95 | #include 96 | #include 97 | /* */ 98 | #include 99 | /* */ 100 | #include 101 | #include 102 | #include 103 | #include 104 | #include 105 | #endif 106 | 107 | /* patch:#include */ 108 | #include 109 | #include 110 | 111 | #ifdef COMPLETE_SR10_2 112 | /* */ 113 | #include 114 | #include 115 | 116 | #include 117 | #endif 118 | -------------------------------------------------------------------------------- /testing/case01.ref: -------------------------------------------------------------------------------- 1 | /* case01.c */ 2 | void badFunc(int *badStyle); 3 | int dots_0(int p1); 4 | int dots_1(int p1, ...); 5 | int dots_3(int p1, char p2, ...); 6 | _FIRST *func1(void); 7 | _FIRST *func2(_FIRST *p1, int p2[], float p); 8 | int *(func_func)(void); 9 | int main(register argc, char **argv); 10 | int veryfunny(char *a, long b, long c); 11 | int program(string argv[], struct alpha y, int zz, int z1, int z2, int z3); 12 | int junk0(void); 13 | int junk1(void); 14 | int junk2(void); 15 | int junk3(void); 16 | BONG *junk4(void); 17 | extern_junk *foo(void); 18 | void_junk *foo2a(void); 19 | void_junk *foo2(void); 20 | void_junk *foo_void(void_junk void_int); 21 | void (*Sigdisp(int sig, void (*func)(int sig)))(int sig1); 22 | void (*sigdisp2(int sig, void (*func)(int sig)))(int sig2); 23 | int (*K_R_INT_ptr(long *p1, int p2))(void); 24 | void (*K_R_VOID_ptr(long *p1, int p2))(void); 25 | int *K_R_int_ptr(long *p1, int p2); 26 | void *K_R_void_ptr(long *p1, int p2); 27 | int K_R_int_val(long *p1, int p2); 28 | int K_R_int_val2(long *p1, int p2); 29 | void K_R_void_val(long *p1, int p2); 30 | int K_R_void_val2(long *p1, int p2); 31 | -------------------------------------------------------------------------------- /testing/case02.ref: -------------------------------------------------------------------------------- 1 | /* case02.c */ 2 | -------------------------------------------------------------------------------- /testing/case03.ref: -------------------------------------------------------------------------------- 1 | /* case03.c */ 2 | void badFunc(/*int *badStyle*/); 3 | int dots_0(/*int p1*/); 4 | int dots_1(/*int p1, ...*/); 5 | int dots_3(/*int p1, char p2, ...*/); 6 | _FIRST *func1(/*void*/); 7 | _FIRST *func2(/*_FIRST *p1, int p2[], float p*/); 8 | int *(func_func)(/*void*/); 9 | int main(/*register argc, char **argv*/); 10 | int veryfunny(/*char *a, long b, long c*/); 11 | int program(/*string argv[], struct alpha y, int zz, int z1, int z2, int z3*/); 12 | int junk0(/*void*/); 13 | int junk1(/*void*/); 14 | int junk2(/*void*/); 15 | int junk3(/*void*/); 16 | BONG *junk4(/*void*/); 17 | extern_junk *foo(/*void*/); 18 | void_junk *foo2a(/*void*/); 19 | void_junk *foo2(/*void*/); 20 | void_junk *foo_void(/*void_junk void_int*/); 21 | void (*Sigdisp(/*int sig, void (*func)(int sig)*/))(/*int sig1*/); 22 | void (*sigdisp2(/*int sig, void (*func)(int sig)*/))(/*int sig2*/); 23 | int (*K_R_INT_ptr(/*long *p1, int p2*/))(/*void*/); 24 | void (*K_R_VOID_ptr(/*long *p1, int p2*/))(/*void*/); 25 | int *K_R_int_ptr(/*long *p1, int p2*/); 26 | void *K_R_void_ptr(/*long *p1, int p2*/); 27 | int K_R_int_val(/*long *p1, int p2*/); 28 | int K_R_int_val2(/*long *p1, int p2*/); 29 | void K_R_void_val(/*long *p1, int p2*/); 30 | int K_R_void_val2(/*long *p1, int p2*/); 31 | -------------------------------------------------------------------------------- /testing/case04.ref: -------------------------------------------------------------------------------- 1 | /* case04.c */ 2 | void badFunc(int */*badStyle*/); 3 | int dots_0(int /*p1*/); 4 | int dots_1(int /*p1*/, ...); 5 | int dots_3(int /*p1*/, char /*p2*/, ...); 6 | _FIRST *func1(void); 7 | _FIRST *func2(_FIRST */*p1*/, int /*p2*/[], float /*p*/); 8 | int *(func_func)(void); 9 | int main(register /*argc*/, char **/*argv*/); 10 | int veryfunny(char */*a*/, long /*b*/, long /*c*/); 11 | int program(string /*argv*/[], struct alpha /*y*/, int /*zz*/, int /*z1*/, int /*z2*/, int /*z3*/); 12 | int junk0(void); 13 | int junk1(void); 14 | int junk2(void); 15 | int junk3(void); 16 | BONG *junk4(void); 17 | extern_junk *foo(void); 18 | void_junk *foo2a(void); 19 | void_junk *foo2(void); 20 | void_junk *foo_void(void_junk /*void_int*/); 21 | void (*Sigdisp(int /*sig*/, void (* /*func*/)(int /*sig*/)))(int /*sig1*/); 22 | void (*sigdisp2(int /*sig*/, void (* /*func*/)(int /*sig*/)))(int /*sig2*/); 23 | int (*K_R_INT_ptr(long */*p1*/, int /*p2*/))(void); 24 | void (*K_R_VOID_ptr(long */*p1*/, int /*p2*/))(void); 25 | int *K_R_int_ptr(long */*p1*/, int /*p2*/); 26 | void *K_R_void_ptr(long */*p1*/, int /*p2*/); 27 | int K_R_int_val(long */*p1*/, int /*p2*/); 28 | int K_R_int_val2(long */*p1*/, int /*p2*/); 29 | void K_R_void_val(long */*p1*/, int /*p2*/); 30 | int K_R_void_val2(long */*p1*/, int /*p2*/); 31 | -------------------------------------------------------------------------------- /testing/case05.ref: -------------------------------------------------------------------------------- 1 | /* case05.c */ 2 | void badFunc(int *badStyle); 3 | int dots_0(int p1); 4 | int dots_1(int p1, ...); 5 | int dots_3(int p1, char p2, ...); 6 | _FIRST *func1(void); 7 | _FIRST *func2(_FIRST *p1, int p2[], float p); 8 | int *(func_func)(void); 9 | int main(register argc, char **argv); 10 | int veryfunny(char *a, long b, long c); 11 | int program(string argv[], struct alpha y, int zz, int z1, int z2, int z3); 12 | int junk0(void); 13 | int junk1(void); 14 | int junk2(void); 15 | int junk3(void); 16 | BONG *junk4(void); 17 | extern_junk *foo(void); 18 | void_junk *foo2a(void); 19 | void_junk *foo2(void); 20 | void_junk *foo_void(void_junk void_int); 21 | void (*Sigdisp(int sig, void (*func)(int sig)))(int sig1); 22 | void (*sigdisp2(int sig, void (*func)(int sig)))(int sig2); 23 | int (*K_R_INT_ptr(long *p1, int p2))(void); 24 | void (*K_R_VOID_ptr(long *p1, int p2))(void); 25 | int *K_R_int_ptr(long *p1, int p2); 26 | void *K_R_void_ptr(long *p1, int p2); 27 | int K_R_int_val(long *p1, int p2); 28 | int K_R_int_val2(long *p1, int p2); 29 | void K_R_void_val(long *p1, int p2); 30 | int K_R_void_val2(long *p1, int p2); 31 | -------------------------------------------------------------------------------- /testing/case06.ref: -------------------------------------------------------------------------------- 1 | /* case06.c */ 2 | char x6; 3 | short x7; 4 | int x8; 5 | long x9; 6 | float x10; 7 | double x11; 8 | signed x12; 9 | unsigned x13; 10 | x4t x17; 11 | const x18; 12 | volatile x19; 13 | void badFunc(int *badStyle); 14 | _FIRST first; 15 | _FIRST last; 16 | _FIRST first_last[]; 17 | struct _second _SECOND; 18 | int i[]; 19 | float f[]; 20 | int array[][10][20]; 21 | int dots_0(int p1); 22 | int dots_1(int p1, ...); 23 | int dots_3(int p1, char p2, ...); 24 | _FIRST *func1(void); 25 | _FIRST *func2(_FIRST *p1, int p2[], float p); 26 | int *(func_func)(void); 27 | bool a1; 28 | struct zip2 z2; 29 | struct {} z3; 30 | enum zap1 what; 31 | enum zap2 what2; 32 | enum {} what3; 33 | int main(register argc, char **argv); 34 | int veryfunny(char *a, long b, long c); 35 | int program(string argv[], struct alpha y, int zz, int z1, int z2, int z3); 36 | int junk0(void); 37 | int junk1(void); 38 | int junk2(void); 39 | int junk3(void); 40 | BONG *junk4(void); 41 | extern_junk *foo(void); 42 | void_junk *foo2a(void); 43 | void_junk *foo2(void); 44 | void_junk *foo_void(void_junk void_int); 45 | void (*Sigdisp(int sig, void (*func)(int sig)))(int sig1); 46 | void (*sigdisp2(int sig, void (*func)(int sig)))(int sig2); 47 | int (*K_R_INT_ptr(long *p1, int p2))(void); 48 | void (*K_R_VOID_ptr(long *p1, int p2))(void); 49 | int *K_R_int_ptr(long *p1, int p2); 50 | void *K_R_void_ptr(long *p1, int p2); 51 | int K_R_int_val(long *p1, int p2); 52 | int K_R_int_val2(long *p1, int p2); 53 | void K_R_void_val(long *p1, int p2); 54 | int K_R_void_val2(long *p1, int p2); 55 | long long xxx; 56 | char *xxs; 57 | -------------------------------------------------------------------------------- /testing/case07.ref: -------------------------------------------------------------------------------- 1 | /* case07.c */ 2 | extern char x6; 3 | extern short x7; 4 | extern int x8; 5 | extern long x9; 6 | extern float x10; 7 | extern double x11; 8 | extern signed x12; 9 | extern unsigned x13; 10 | extern x4t x17; 11 | extern const x18; 12 | extern volatile x19; 13 | extern void badFunc(int *badStyle); 14 | extern _FIRST first; 15 | extern _FIRST last; 16 | extern _FIRST first_last[]; 17 | extern struct _second _SECOND; 18 | extern int i[]; 19 | extern float f[]; 20 | extern int array[][10][20]; 21 | extern int dots_0(int p1); 22 | extern int dots_1(int p1, ...); 23 | extern int dots_3(int p1, char p2, ...); 24 | extern _FIRST *func1(void); 25 | extern _FIRST *func2(_FIRST *p1, int p2[], float p); 26 | extern int *(func_func)(void); 27 | extern bool a1; 28 | extern struct zip2 z2; 29 | extern struct {} z3; 30 | extern enum zap1 what; 31 | extern enum zap2 what2; 32 | extern enum {} what3; 33 | extern int main(register argc, char **argv); 34 | extern int veryfunny(char *a, long b, long c); 35 | extern int program(string argv[], struct alpha y, int zz, int z1, int z2, int z3); 36 | extern int junk0(void); 37 | extern int junk1(void); 38 | extern int junk2(void); 39 | extern int junk3(void); 40 | extern BONG *junk4(void); 41 | extern extern_junk *foo(void); 42 | extern void_junk *foo2a(void); 43 | extern void_junk *foo2(void); 44 | extern void_junk *foo_void(void_junk void_int); 45 | extern void (*Sigdisp(int sig, void (*func)(int sig)))(int sig1); 46 | extern void (*sigdisp2(int sig, void (*func)(int sig)))(int sig2); 47 | extern int (*K_R_INT_ptr(long *p1, int p2))(void); 48 | extern void (*K_R_VOID_ptr(long *p1, int p2))(void); 49 | extern int *K_R_int_ptr(long *p1, int p2); 50 | extern void *K_R_void_ptr(long *p1, int p2); 51 | extern int K_R_int_val(long *p1, int p2); 52 | extern int K_R_int_val2(long *p1, int p2); 53 | extern void K_R_void_val(long *p1, int p2); 54 | extern int K_R_void_val2(long *p1, int p2); 55 | extern long long xxx; 56 | extern char *xxs; 57 | -------------------------------------------------------------------------------- /testing/case08.ref: -------------------------------------------------------------------------------- 1 | #if __STDC__ || defined(__cplusplus) 2 | #define P_(s) s 3 | #else 4 | #define P_(s) () 5 | #endif 6 | 7 | /* case08.c */ 8 | extern char x6; 9 | extern short x7; 10 | extern int x8; 11 | extern long x9; 12 | extern float x10; 13 | extern double x11; 14 | extern signed x12; 15 | extern unsigned x13; 16 | extern x4t x17; 17 | extern const x18; 18 | extern volatile x19; 19 | extern void badFunc P_((int *badStyle)); 20 | extern _FIRST first; 21 | extern _FIRST last; 22 | extern _FIRST first_last[]; 23 | extern struct _second _SECOND; 24 | extern int i[]; 25 | extern float f[]; 26 | extern int array[][10][20]; 27 | extern int dots_0 P_((int p1)); 28 | extern int dots_1 P_((int p1, ...)); 29 | extern int dots_3 P_((int p1, char p2, ...)); 30 | extern _FIRST *func1 P_((void)); 31 | extern _FIRST *func2 P_((_FIRST *p1, int p2[], float p)); 32 | extern int *(func_func) P_((void)); 33 | extern bool a1; 34 | extern struct zip2 z2; 35 | extern struct {} z3; 36 | extern enum zap1 what; 37 | extern enum zap2 what2; 38 | extern enum {} what3; 39 | extern int main P_((register argc, char **argv)); 40 | extern int veryfunny P_((char *a, long b, long c)); 41 | extern int program P_((string argv[], struct alpha y, int zz, int z1, int z2, int z3)); 42 | extern int junk0 P_((void)); 43 | extern int junk1 P_((void)); 44 | extern int junk2 P_((void)); 45 | extern int junk3 P_((void)); 46 | extern BONG *junk4 P_((void)); 47 | extern extern_junk *foo P_((void)); 48 | extern void_junk *foo2a P_((void)); 49 | extern void_junk *foo2 P_((void)); 50 | extern void_junk *foo_void P_((void_junk void_int)); 51 | extern void (*Sigdisp P_((int sig, void (*func)(int sig)))) P_((int sig1)); 52 | extern void (*sigdisp2 P_((int sig, void (*func)(int sig)))) P_((int sig2)); 53 | extern int (*K_R_INT_ptr P_((long *p1, int p2))) P_((void)); 54 | extern void (*K_R_VOID_ptr P_((long *p1, int p2))) P_((void)); 55 | extern int *K_R_int_ptr P_((long *p1, int p2)); 56 | extern void *K_R_void_ptr P_((long *p1, int p2)); 57 | extern int K_R_int_val P_((long *p1, int p2)); 58 | extern int K_R_int_val2 P_((long *p1, int p2)); 59 | extern void K_R_void_val P_((long *p1, int p2)); 60 | extern int K_R_void_val2 P_((long *p1, int p2)); 61 | extern long long xxx; 62 | extern char *xxs; 63 | 64 | #undef P_ 65 | -------------------------------------------------------------------------------- /testing/case09.ref: -------------------------------------------------------------------------------- 1 | /* case09.c */ 2 | char x6; 3 | short x7; 4 | int x8; 5 | long x9; 6 | float x10; 7 | double x11; 8 | signed x12; 9 | unsigned x13; 10 | x4t x17; 11 | const x18; 12 | volatile x19; 13 | void badFunc( 14 | int *badStyle 15 | ); 16 | _FIRST first; 17 | _FIRST last; 18 | _FIRST first_last[]; 19 | struct _second _SECOND; 20 | int i[]; 21 | float f[]; 22 | int array[][10][20]; 23 | int dots_0( 24 | int p1 25 | ); 26 | int dots_1( 27 | int p1, 28 | ... 29 | ); 30 | int dots_3( 31 | int p1, 32 | char p2, 33 | ... 34 | ); 35 | _FIRST *func1(void); 36 | _FIRST *func2( 37 | _FIRST *p1, 38 | int p2[], 39 | float p 40 | ); 41 | int *(func_func)(void); 42 | bool a1; 43 | struct zip2 z2; 44 | struct {} z3; 45 | enum zap1 what; 46 | enum zap2 what2; 47 | enum {} what3; 48 | int main( 49 | register argc, 50 | char **argv 51 | ); 52 | int veryfunny( 53 | char *a, 54 | long b, 55 | long c 56 | ); 57 | int program( 58 | string argv[], 59 | struct alpha y, 60 | int zz, 61 | int z1, 62 | int z2, 63 | int z3 64 | ); 65 | int junk0(void); 66 | int junk1(void); 67 | int junk2(void); 68 | int junk3(void); 69 | BONG *junk4(void); 70 | extern_junk *foo(void); 71 | void_junk *foo2a(void); 72 | void_junk *foo2(void); 73 | void_junk *foo_void( 74 | void_junk void_int 75 | ); 76 | void (*Sigdisp( 77 | int sig, 78 | void (*func)(int sig) 79 | ))(int sig1); 80 | void (*sigdisp2( 81 | int sig, 82 | void (*func)(int sig) 83 | ))(int sig2); 84 | int (*K_R_INT_ptr( 85 | long *p1, 86 | int p2 87 | ))(void); 88 | void (*K_R_VOID_ptr( 89 | long *p1, 90 | int p2 91 | ))(void); 92 | int *K_R_int_ptr( 93 | long *p1, 94 | int p2 95 | ); 96 | void *K_R_void_ptr( 97 | long *p1, 98 | int p2 99 | ); 100 | int K_R_int_val( 101 | long *p1, 102 | int p2 103 | ); 104 | int K_R_int_val2( 105 | long *p1, 106 | int p2 107 | ); 108 | void K_R_void_val( 109 | long *p1, 110 | int p2 111 | ); 112 | int K_R_void_val2( 113 | long *p1, 114 | int p2 115 | ); 116 | long long xxx; 117 | char *xxs; 118 | -------------------------------------------------------------------------------- /testing/case10.ref: -------------------------------------------------------------------------------- 1 | /* case10.c */ 2 | 3 | typedef int x4t; 4 | 5 | struct x14; 6 | 7 | union x15; 8 | 9 | enum x16; 10 | 11 | x4t; 12 | 13 | typedef struct _first { 14 | int a:5; 15 | struct { 16 | int a,b; 17 | } b_struct; 18 | char b:16, b1:1; 19 | long c:16, c1; 20 | short d:16, d1:8, d2; 21 | unsigned e:16; 22 | float f; 23 | double g; 24 | struct _first *link; 25 | } _FIRST; 26 | 27 | typedef int badStyle; 28 | 29 | void badFunc(int *badStyle); 30 | 31 | struct _second { 32 | enum {true, false} bool; 33 | enum {wrong=1, right=3} values; 34 | }; 35 | 36 | int dots_0(int p1); 37 | int dots_1(int p1, ...); 38 | int dots_3(int p1, char p2, ...); 39 | _FIRST *func1(void); 40 | _FIRST *func2(_FIRST *p1, int p2[], float p); 41 | int *(func_func)(void); 42 | 43 | typedef int bool; 44 | 45 | struct ZIP1 { int x1, y1; }; 46 | 47 | struct zip2 { int x2, y2; }; 48 | struct { int x3, y3; }; 49 | 50 | struct ZIP4 { int x4, y4; }; 51 | 52 | struct zip5 { int x5, y5; }; 53 | struct zip6 { int x6, y6; }; 54 | struct { int x7, y7; }; 55 | struct { int x8, y8; }; 56 | enum zap1 { a,b,c,d }; 57 | enum {a9,b9,c9,d9}; 58 | 59 | typedef struct bong { 60 | int (*func)(); 61 | } BONG; 62 | 63 | typedef char *string; 64 | 65 | int main(register argc, char **argv); 66 | int veryfunny(char *a, long b, long c); 67 | int program(string argv[], struct alpha { int x,z; } y, int zz, int z1, int z2, int z3); 68 | int junk0(void); 69 | int junk1(void); 70 | int junk2(void); 71 | int junk3(void); 72 | BONG *junk4(void); 73 | 74 | typedef int extern_junk; 75 | 76 | extern_junk *foo(void); 77 | 78 | typedef int void_junk; 79 | 80 | void_junk *foo2a(void); 81 | void_junk *foo2(void); 82 | void_junk *foo_void(void_junk void_int); 83 | void (*Sigdisp(int sig, void (*func)(int sig)))(int sig1); 84 | void (*sigdisp2(int sig, void (*func)(int sig)))(int sig2); 85 | int (*K_R_INT_ptr(long *p1, int p2))(void); 86 | void (*K_R_VOID_ptr(long *p1, int p2))(void); 87 | int *K_R_int_ptr(long *p1, int p2); 88 | void *K_R_void_ptr(long *p1, int p2); 89 | int K_R_int_val(long *p1, int p2); 90 | int K_R_int_val2(long *p1, int p2); 91 | void K_R_void_val(long *p1, int p2); 92 | int K_R_void_val2(long *p1, int p2); 93 | -------------------------------------------------------------------------------- /testing/case11.ref: -------------------------------------------------------------------------------- 1 | /* LINTLIBRARY */ 2 | 3 | /* case11.c */ 4 | 5 | typedef int x4t; 6 | 7 | char x6; 8 | short x7; 9 | int x8; 10 | long x9; 11 | float x10; 12 | double x11; 13 | signed x12; 14 | unsigned x13; 15 | 16 | struct x14; 17 | 18 | union x15; 19 | 20 | enum x16; 21 | 22 | x4t; 23 | 24 | x4t x17; 25 | const x18 = {0}; 26 | volatile x19; 27 | 28 | typedef struct _first { 29 | int a:5; 30 | struct { 31 | int a,b; 32 | } b_struct; 33 | char b:16, b1:1; 34 | long c:16, c1; 35 | short d:16, d1:8, d2; 36 | unsigned e:16; 37 | float f; 38 | double g; 39 | struct _first *link; 40 | } _FIRST; 41 | 42 | typedef int badStyle; 43 | 44 | void badFunc(badStyle) 45 | int *badStyle; 46 | { /* void */ } 47 | 48 | _FIRST first; 49 | _FIRST last; 50 | _FIRST first_last[]; 51 | struct _second { 52 | enum {true, false} bool; 53 | enum {wrong=1, right=3} values; 54 | } _SECOND; 55 | int i[]; 56 | float f[]; 57 | int array[][10][20]; 58 | 59 | int dots_0(p1) 60 | int p1; 61 | { return(*(int *)0); } 62 | 63 | /* VARARGS1 */ 64 | int dots_1(p1) 65 | int p1; 66 | { return(*(int *)0); } 67 | 68 | /* VARARGS2 */ 69 | int dots_3(p1, p2) 70 | int p1; 71 | char p2; 72 | { return(*(int *)0); } 73 | 74 | _FIRST *func1() 75 | { return(*(_FIRST **)0); } 76 | 77 | _FIRST *func2(p1, p2, p) 78 | _FIRST *p1; 79 | int p2[]; 80 | float p; 81 | { return(*(_FIRST **)0); } 82 | 83 | int *(func_func)() 84 | { return(*(int **)0); } 85 | 86 | typedef int bool; 87 | 88 | bool a1; 89 | 90 | struct ZIP1 { int x1, y1; }; 91 | 92 | struct zip2 { int x2, y2; } z2; 93 | struct { int x3, y3; } z3; 94 | 95 | struct ZIP4 { int x4, y4; }; 96 | 97 | enum zap1 { a,b,c,d } what; 98 | enum zap2 what2; 99 | enum {a9,b9,c9,d9} what3; 100 | 101 | typedef struct bong { 102 | int (*func)(); 103 | } BONG; 104 | 105 | typedef char *string; 106 | 107 | void main(argc, argv) 108 | int argc; 109 | char **argv; 110 | { /* void */ } 111 | 112 | /* VARARGS */ 113 | int veryfunny(a, b, c) 114 | char *a; 115 | long b; 116 | long c; 117 | { return(*(int *)0); } 118 | 119 | /* VARARGS3 */ 120 | int program(argv, y, zz, z1, z2, z3) 121 | string argv[]; 122 | struct alpha { int x,z; } y; 123 | int zz; 124 | int z1; 125 | int z2; 126 | int z3; 127 | { return(*(int *)0); } 128 | 129 | void junk0() 130 | { /* void */ } 131 | 132 | int junk1() 133 | { return(*(int *)0); } 134 | 135 | void junk2() 136 | { /* void */ } 137 | 138 | int junk3() 139 | { return(*(int *)0); } 140 | 141 | BONG *junk4() 142 | { return(*(BONG **)0); } 143 | 144 | typedef int extern_junk; 145 | 146 | extern_junk *foo() 147 | { return(*(extern_junk **)0); } 148 | 149 | typedef int void_junk; 150 | 151 | void_junk *foo2a() 152 | { return(*(void_junk **)0); } 153 | 154 | void_junk *foo2() 155 | { return(*(void_junk **)0); } 156 | 157 | void_junk *foo_void(void_int) 158 | void_junk void_int; 159 | { return(*(void_junk **)0); } 160 | 161 | void (*Sigdisp(sig, func))() 162 | int sig; 163 | void (*func)(); 164 | { return(*(void(*)())0); } 165 | 166 | void (*sigdisp2(sig, func))() 167 | int sig; 168 | void (*func)(); 169 | { return(*(void(*)())0); } 170 | 171 | int (*K_R_INT_ptr(p1, p2))() 172 | long *p1; 173 | int p2; 174 | { return(*(int(*)())0); } 175 | 176 | void (*K_R_VOID_ptr(p1, p2))() 177 | long *p1; 178 | int p2; 179 | { return(*(void(*)())0); } 180 | 181 | int *K_R_int_ptr(p1, p2) 182 | long *p1; 183 | int p2; 184 | { return(*(int **)0); } 185 | 186 | void *K_R_void_ptr(p1, p2) 187 | long *p1; 188 | int p2; 189 | { return(*(void **)0); } 190 | 191 | int K_R_int_val(p1, p2) 192 | long *p1; 193 | int p2; 194 | { return(*(int *)0); } 195 | 196 | int K_R_int_val2(p1, p2) 197 | long *p1; 198 | int p2; 199 | { return(*(int *)0); } 200 | 201 | void K_R_void_val(p1, p2) 202 | long *p1; 203 | int p2; 204 | { /* void */ } 205 | 206 | void K_R_void_val2(p1, p2) 207 | long *p1; 208 | int p2; 209 | { /* void */ } 210 | 211 | long long xxx; 212 | char *xxs; 213 | -------------------------------------------------------------------------------- /testing/case12.ref: -------------------------------------------------------------------------------- 1 | /* case12.c */ 2 | void badFunc(int *badStyle); 3 | int dots_0(int p1); 4 | int dots_1(int p1, ...); 5 | int dots_3(int p1, char p2, ...); 6 | _FIRST *func1(void); 7 | _FIRST *func2(_FIRST *p1, int p2[], float p); 8 | int *(func_func)(void); 9 | int main(register argc, char **argv); 10 | int veryfunny(char *a, long b, long c); 11 | int program(string argv[], struct alpha y, int zz, int z1, int z2, int z3); 12 | int junk0(void); 13 | int junk1(void); 14 | int junk2(void); 15 | int junk3(void); 16 | BONG *junk4(void); 17 | extern_junk *foo(void); 18 | void_junk *foo2a(void); 19 | void_junk *foo2(void); 20 | void_junk *foo_void(void_junk void_int); 21 | static void_junk *foo_void2(void); 22 | void (*Sigdisp(int sig, void (*func)(int sig)))(int sig1); 23 | void (*sigdisp2(int sig, void (*func)(int sig)))(int sig2); 24 | int (*K_R_INT_ptr(long *p1, int p2))(void); 25 | void (*K_R_VOID_ptr(long *p1, int p2))(void); 26 | int *K_R_int_ptr(long *p1, int p2); 27 | void *K_R_void_ptr(long *p1, int p2); 28 | int K_R_int_val(long *p1, int p2); 29 | int K_R_int_val2(long *p1, int p2); 30 | void K_R_void_val(long *p1, int p2); 31 | int K_R_void_val2(long *p1, int p2); 32 | -------------------------------------------------------------------------------- /testing/case13.ref: -------------------------------------------------------------------------------- 1 | /* LINTLIBRARY */ 2 | 3 | /* case13.c */ 4 | 5 | static x2; 6 | 7 | typedef int x4t; 8 | 9 | char x6; 10 | short x7; 11 | int x8; 12 | long x9; 13 | float x10; 14 | double x11; 15 | signed x12; 16 | unsigned x13; 17 | 18 | struct x14; 19 | 20 | union x15; 21 | 22 | enum x16; 23 | 24 | x4t; 25 | 26 | x4t x17; 27 | const x18 = {0}; 28 | volatile x19; 29 | 30 | typedef struct _first { 31 | int a:5; 32 | struct { 33 | int a,b; 34 | } b_struct; 35 | char b:16, b1:1; 36 | long c:16, c1; 37 | short d:16, d1:8, d2; 38 | unsigned e:16; 39 | float f; 40 | double g; 41 | struct _first *link; 42 | } _FIRST; 43 | 44 | typedef int badStyle; 45 | 46 | void badFunc(badStyle) 47 | int *badStyle; 48 | { /* void */ } 49 | 50 | _FIRST first; 51 | _FIRST last; 52 | _FIRST first_last[]; 53 | struct _second { 54 | enum {true, false} bool; 55 | enum {wrong=1, right=3} values; 56 | } _SECOND; 57 | int i[]; 58 | float f[]; 59 | int array[][10][20]; 60 | 61 | int dots_0(p1) 62 | int p1; 63 | { return(*(int *)0); } 64 | 65 | /* VARARGS1 */ 66 | int dots_1(p1) 67 | int p1; 68 | { return(*(int *)0); } 69 | 70 | /* VARARGS2 */ 71 | int dots_3(p1, p2) 72 | int p1; 73 | char p2; 74 | { return(*(int *)0); } 75 | 76 | _FIRST *func1() 77 | { return(*(_FIRST **)0); } 78 | 79 | _FIRST *func2(p1, p2, p) 80 | _FIRST *p1; 81 | int p2[]; 82 | float p; 83 | { return(*(_FIRST **)0); } 84 | 85 | int *(func_func)() 86 | { return(*(int **)0); } 87 | 88 | typedef int bool; 89 | 90 | bool a1; 91 | static bool a2; 92 | 93 | struct ZIP1 { int x1, y1; }; 94 | 95 | struct zip2 { int x2, y2; } z2; 96 | struct { int x3, y3; } z3; 97 | 98 | struct ZIP4 { int x4, y4; }; 99 | 100 | static struct zip5 { int x5, y5; } z5; 101 | static struct zip6 { int x6, y6; } z6; 102 | static struct zip6 { int x6, y6; } w6; 103 | static struct { int x7, y7; } z7; 104 | static struct { int x8, y8; } z8; 105 | static struct { int x8, y8; } w8; 106 | enum zap1 { a,b,c,d } what; 107 | enum zap2 what2; 108 | enum {a9,b9,c9,d9} what3; 109 | static char *zap; 110 | 111 | typedef struct bong { 112 | int (*func)(); 113 | } BONG; 114 | 115 | typedef char *string; 116 | 117 | void main(argc, argv) 118 | int argc; 119 | char **argv; 120 | { /* void */ } 121 | 122 | /* VARARGS */ 123 | int veryfunny(a, b, c) 124 | char *a; 125 | long b; 126 | long c; 127 | { return(*(int *)0); } 128 | 129 | /* VARARGS3 */ 130 | int program(argv, y, zz, z1, z2, z3) 131 | string argv[]; 132 | struct alpha { int x,z; } y; 133 | int zz; 134 | int z1; 135 | int z2; 136 | int z3; 137 | { return(*(int *)0); } 138 | 139 | void junk0() 140 | { /* void */ } 141 | 142 | int junk1() 143 | { return(*(int *)0); } 144 | 145 | void junk2() 146 | { /* void */ } 147 | 148 | int junk3() 149 | { return(*(int *)0); } 150 | 151 | BONG *junk4() 152 | { return(*(BONG **)0); } 153 | 154 | typedef int extern_junk; 155 | 156 | extern_junk *foo() 157 | { return(*(extern_junk **)0); } 158 | 159 | typedef int void_junk; 160 | 161 | void_junk *foo2a() 162 | { return(*(void_junk **)0); } 163 | 164 | void_junk *foo2() 165 | { return(*(void_junk **)0); } 166 | 167 | void_junk *foo_void(void_int) 168 | void_junk void_int; 169 | { return(*(void_junk **)0); } 170 | 171 | static void_junk *foo_void2() 172 | { return(*(void_junk **)0); } 173 | 174 | void (*Sigdisp(sig, func))() 175 | int sig; 176 | void (*func)(); 177 | { return(*(void(*)())0); } 178 | 179 | void (*sigdisp2(sig, func))() 180 | int sig; 181 | void (*func)(); 182 | { return(*(void(*)())0); } 183 | 184 | int (*K_R_INT_ptr(p1, p2))() 185 | long *p1; 186 | int p2; 187 | { return(*(int(*)())0); } 188 | 189 | void (*K_R_VOID_ptr(p1, p2))() 190 | long *p1; 191 | int p2; 192 | { return(*(void(*)())0); } 193 | 194 | int *K_R_int_ptr(p1, p2) 195 | long *p1; 196 | int p2; 197 | { return(*(int **)0); } 198 | 199 | void *K_R_void_ptr(p1, p2) 200 | long *p1; 201 | int p2; 202 | { return(*(void **)0); } 203 | 204 | int K_R_int_val(p1, p2) 205 | long *p1; 206 | int p2; 207 | { return(*(int *)0); } 208 | 209 | int K_R_int_val2(p1, p2) 210 | long *p1; 211 | int p2; 212 | { return(*(int *)0); } 213 | 214 | void K_R_void_val(p1, p2) 215 | long *p1; 216 | int p2; 217 | { /* void */ } 218 | 219 | void K_R_void_val2(p1, p2) 220 | long *p1; 221 | int p2; 222 | { /* void */ } 223 | 224 | long long xxx; 225 | char *xxs; 226 | -------------------------------------------------------------------------------- /testing/case14.ref: -------------------------------------------------------------------------------- 1 | /* LINTLIBRARY */ 2 | 3 | /* case14.c */ 4 | 5 | int x3; 6 | 7 | typedef int x4t; 8 | 9 | char x6; 10 | short x7; 11 | int x8; 12 | long x9; 13 | float x10; 14 | double x11; 15 | signed x12; 16 | unsigned x13; 17 | 18 | struct x14; 19 | 20 | union x15; 21 | 22 | enum x16; 23 | 24 | x4t; 25 | 26 | x4t x17; 27 | const x18 = {0}; 28 | volatile x19; 29 | 30 | typedef struct _first { 31 | int a:5; 32 | struct { 33 | int a,b; 34 | } b_struct; 35 | char b:16, b1:1; 36 | long c:16, c1; 37 | short d:16, d1:8, d2; 38 | unsigned e:16; 39 | float f; 40 | double g; 41 | struct _first *link; 42 | } _FIRST; 43 | 44 | typedef int badStyle; 45 | 46 | void badFunc(badStyle) 47 | int *badStyle; 48 | { /* void */ } 49 | 50 | _FIRST first; 51 | _FIRST last; 52 | _FIRST first_last[]; 53 | struct _second { 54 | enum {true, false} bool; 55 | enum {wrong=1, right=3} values; 56 | } _SECOND; 57 | int i[]; 58 | float f[]; 59 | int array[][10][20]; 60 | 61 | int dots_0(p1) 62 | int p1; 63 | { return(*(int *)0); } 64 | 65 | /* VARARGS1 */ 66 | int dots_1(p1) 67 | int p1; 68 | { return(*(int *)0); } 69 | 70 | /* VARARGS2 */ 71 | int dots_3(p1, p2) 72 | int p1; 73 | char p2; 74 | { return(*(int *)0); } 75 | 76 | int dots_4(p1, p2, p3) 77 | int p1; 78 | char p2; 79 | char *p3; 80 | { return(*(int *)0); } 81 | 82 | /* VARARGS3 */ 83 | char *dots_5(p1, p2, p3) 84 | int p1; 85 | char p2; 86 | char *p3; 87 | { return(*(char **)0); } 88 | 89 | /* VARARGS3 */ 90 | char *(dots_6)(p1, p2, p3) 91 | int p1; 92 | char p2; 93 | char *p3; 94 | { return(*(char **)0); } 95 | 96 | _FIRST *xdots_0(p1) 97 | int p1; 98 | { return(*(_FIRST **)0); } 99 | 100 | /* VARARGS1 */ 101 | char *xdots_1(p1) 102 | int p1; 103 | { return(*(char **)0); } 104 | 105 | /* VARARGS2 */ 106 | int xdots_3(p1, p2) 107 | int p1; 108 | char p2; 109 | { return(*(int *)0); } 110 | 111 | _FIRST *func1() 112 | { return(*(_FIRST **)0); } 113 | 114 | _FIRST *func2(p1, p2, p) 115 | _FIRST *p1; 116 | int p2[]; 117 | float p; 118 | { return(*(_FIRST **)0); } 119 | 120 | int *(func_func)() 121 | { return(*(int **)0); } 122 | 123 | float efunc0(p1, p2, p3) 124 | int p1; 125 | int p2; 126 | int p3; 127 | { return(*(float *)0); } 128 | 129 | _FIRST efunc1(p1, p2, p3) 130 | int p1; 131 | float p2; 132 | long p3; 133 | { return(*(_FIRST *)0); } 134 | 135 | typedef int bool; 136 | 137 | bool a1; 138 | bool a3; 139 | 140 | struct ZIP1 { int x1, y1; }; 141 | 142 | struct zip2 { int x2, y2; } z2; 143 | struct { int x3, y3; } z3; 144 | 145 | struct ZIP4 { int x4, y4; }; 146 | 147 | enum zap1 { a,b,c,d } what; 148 | enum zap2 what2; 149 | enum {a9,b9,c9,d9} what3; 150 | 151 | typedef struct bong { 152 | int (*func)(); 153 | } BONG; 154 | 155 | typedef char *string; 156 | 157 | int junk; 158 | 159 | void main(argc, argv) 160 | int argc; 161 | char **argv; 162 | { /* void */ } 163 | 164 | /* VARARGS */ 165 | int veryfunny(a, b, c) 166 | char *a; 167 | long b; 168 | long c; 169 | { return(*(int *)0); } 170 | 171 | /* VARARGS3 */ 172 | int program(argv, y, zz, z1, z2, z3) 173 | string argv[]; 174 | struct alpha { int x,z; } y; 175 | int zz; 176 | int z1; 177 | int z2; 178 | int z3; 179 | { return(*(int *)0); } 180 | 181 | void junk0() 182 | { /* void */ } 183 | 184 | int junk1() 185 | { return(*(int *)0); } 186 | 187 | void junk2() 188 | { /* void */ } 189 | 190 | int junk3() 191 | { return(*(int *)0); } 192 | 193 | BONG *junk4() 194 | { return(*(BONG **)0); } 195 | 196 | typedef int extern_junk; 197 | 198 | extern_junk *foo() 199 | { return(*(extern_junk **)0); } 200 | 201 | typedef int void_junk; 202 | 203 | void_junk *foo2a() 204 | { return(*(void_junk **)0); } 205 | 206 | void_junk *foo2a() 207 | { return(*(void_junk **)0); } 208 | 209 | void_junk *foo2() 210 | { return(*(void_junk **)0); } 211 | 212 | void_junk *foo_void(void_int) 213 | void_junk void_int; 214 | { return(*(void_junk **)0); } 215 | 216 | void (*sigdisp(sig, func))() 217 | int sig; 218 | void (*func)(); 219 | { return(*(void(*)())0); } 220 | 221 | void (*Sigdisp(sig, func))() 222 | int sig; 223 | void (*func)(); 224 | { return(*(void(*)())0); } 225 | 226 | void (*sigdisp2(sig, func))() 227 | int sig; 228 | void (*func)(); 229 | { return(*(void(*)())0); } 230 | 231 | int (*K_R_INT_ptr(p1, p2))() 232 | long *p1; 233 | int p2; 234 | { return(*(int(*)())0); } 235 | 236 | int (*STD_INT_ptr(p1, p2))() 237 | long *p1; 238 | int p2; 239 | { return(*(int(*)())0); } 240 | 241 | void (*K_R_VOID_ptr(p1, p2))() 242 | long *p1; 243 | int p2; 244 | { return(*(void(*)())0); } 245 | 246 | void (*STD_VOID_ptr(p1, p2))() 247 | long *p1; 248 | int p2; 249 | { return(*(void(*)())0); } 250 | 251 | int *K_R_int_ptr(p1, p2) 252 | long *p1; 253 | int p2; 254 | { return(*(int **)0); } 255 | 256 | int **STD_int2_ptr(p1, p2) 257 | long *p1; 258 | int p2; 259 | { return(*(int ***)0); } 260 | 261 | int *STD_int_ptr(p1, p2) 262 | long *p1; 263 | int p2; 264 | { return(*(int **)0); } 265 | 266 | void *K_R_void_ptr(p1, p2) 267 | long *p1; 268 | int p2; 269 | { return(*(void **)0); } 270 | 271 | void *STD_void_ptr(p1, p2) 272 | long *p1; 273 | int p2; 274 | { return(*(void **)0); } 275 | 276 | int K_R_int_val(p1, p2) 277 | long *p1; 278 | int p2; 279 | { return(*(int *)0); } 280 | 281 | int K_R_int_val2(p1, p2) 282 | long *p1; 283 | int p2; 284 | { return(*(int *)0); } 285 | 286 | int STD_int_val(p1, p2) 287 | long *p1; 288 | int p2; 289 | { return(*(int *)0); } 290 | 291 | void K_R_void_val(p1, p2) 292 | long *p1; 293 | int p2; 294 | { /* void */ } 295 | 296 | void K_R_void_val2(p1, p2) 297 | long *p1; 298 | int p2; 299 | { /* void */ } 300 | 301 | void STD_void_val(p1, p2) 302 | long *p1; 303 | int p2; 304 | { /* void */ } 305 | 306 | int (*XSetAfterFunction(p1, p2))() 307 | long *p1; 308 | int (*p2)(); 309 | { return(*(int(*)())0); } 310 | 311 | int XQueryKeymap(p1, p2) 312 | long *p1; 313 | char p2[32]; 314 | { return(*(int *)0); } 315 | 316 | int Another(p1, p2) 317 | long *p1; 318 | int (*p2)(); 319 | { return(*(int *)0); } 320 | 321 | int GenFunc(p1, p2) 322 | int *p1; 323 | int (*p2()); 324 | { return(*(int *)0); } 325 | 326 | void *(*__glob_opendir_hook)(); 327 | const char *(*__glob_readdir_hook)() = {0}; 328 | void (*__glob_closedir_hook)(); 329 | long long xxx; 330 | char *xxs; 331 | -------------------------------------------------------------------------------- /testing/case16.ref: -------------------------------------------------------------------------------- 1 | /* case16.c */ 2 | void badFunc(int *badStyle); 3 | int dots_0(int p1); 4 | int dots_1(int p1, ...); 5 | int dots_3(int P1, char P2, ...); 6 | _FIRST *func1(void); 7 | _FIRST *func2(_FIRST *P1 , int P2 [], float p); 8 | int *(func_func)(int p1, int p2, int p3); 9 | int main(register argc, char **argv); 10 | int veryfunny(char *a, long b, long c); 11 | int program(string argv[], struct alpha y, int zz, int z1, int z2, int z3); 12 | int junk0(void); 13 | int junk1(void); 14 | int junk2(void); 15 | int junk3(void); 16 | BONG *junk4(void); 17 | extern_junk *foo(void); 18 | void_junk *foo2a(void); 19 | void_junk *foo2(void); 20 | void_junk *foo_void(void_junk void_int); 21 | void (*Sigdisp(int sig, void (*func)(int sig)))(int sig1); 22 | void (*sigdisp2(int sig, void (*func)(int sig)))(int sig2); 23 | int (*K_R_INT_ptr(long *p1, int p2))(void); 24 | void (*K_R_VOID_ptr(long *p1, int p2))(void); 25 | int *K_R_int_ptr(long *p1, int p2); 26 | void *K_R_void_ptr(long *p1, int p2); 27 | int K_R_int_val(long *p1, int p2); 28 | int K_R_int_val2(long *p1, int p2); 29 | void K_R_void_val(long *p1, int p2); 30 | int K_R_void_val2(long *p1, int p2); 31 | ... edited case16.c ... 32 | /* 33 | * Define: 34 | * ERR_YACC to force yacc error reporting 35 | * ERR_LEX to force lex error reporting 36 | * ERR_CHECK to force compiler error reporting 37 | */ 38 | /* use one item from type-specifiers */ 39 | #ifdef ERR_YACC 40 | auto x; 41 | register x1; 42 | #endif /* ERR_YACC */ 43 | static x2; 44 | extern x3; 45 | #ifdef ERR_CC 46 | typedef x4; 47 | #endif 48 | typedef int x4t; 49 | #ifdef ERR_YACC 50 | void x5; 51 | #endif /* ERR_YACC */ 52 | char x6; 53 | short x7; 54 | int x8; 55 | long x9; 56 | float x10; 57 | double x11; 58 | signed x12; 59 | unsigned x13; 60 | struct x14; 61 | #ifdef ERR_CHECK 62 | struct x14a {}; 63 | struct {}; 64 | #endif /* ERR_CHECK */ 65 | union x15; 66 | enum x16; 67 | x4t; 68 | x4t x17; 69 | const x18; 70 | volatile x19; 71 | #ifdef ERR_CHECK 72 | junk x20; 73 | #endif /* ERR_CHECK */ 74 | 75 | extern int *asm (fopen, (__const char *__restrict __filename, __const char *__restrict __modes), fopen64); 76 | extern int __asm__ (mkstemp, (char *__template), mkstemp64); 77 | int __asm__ (mkstemp, (char *__template), mkstemp64); 78 | asm("something"); 79 | asm("something", "else"); 80 | asm("something", (this and that)); 81 | int asm(first, "something"); 82 | static int asm(first, "something"); 83 | extern int asm(first, "something"); 84 | 85 | typedef struct _first { 86 | int a:5; 87 | struct { 88 | int a,b; 89 | } b_struct; 90 | char b:16, b1:1; /* comment with };};}; */ 91 | long c:16, c1; 92 | short d:16, d1:8, d2; 93 | unsigned e:16; 94 | float f; 95 | double g; 96 | #ifdef ERR_CHECK 97 | long float f2; 98 | long double g2; 99 | #endif /* ERR_CHECK */ 100 | struct _first *link; 101 | } _FIRST; 102 | 103 | typedef int badStyle; 104 | void badFunc(int *badStyle) { } 105 | 106 | _FIRST first, last={0}, first_last[] = {{0},{1},{2},{3,{4}}}; 107 | 108 | struct _second { 109 | enum {true, false} bool; 110 | enum {wrong=1, right=3} values; 111 | } _SECOND; 112 | 113 | int i[] = {1, 114 | '\002', 115 | 03, 116 | 0x4, 117 | 0X5, 118 | 0x6a, 119 | 0X7b, 120 | 0x8aBcD, 121 | 9l, 122 | 10l, 123 | 11L}; 124 | float f[] = {5, 125 | #ifdef ERR_CHECK 126 | .5e, 127 | .5e+, 128 | 5e-, 129 | 5e, 130 | .34P1, 131 | 0x1.2.34, /* error */ 132 | #endif 133 | .5, 134 | 5.5, 135 | 5e5, 136 | 5e0, 137 | 5e-1, 138 | 5e+5 139 | #ifdef __STDC_VERSION__ /* ( C9X supports hexadecimal floating point ;-) */ 140 | 0x12.34+1, 141 | 0x12.34P1, 142 | .34e1, 143 | 0.34e1, 144 | 0x.34P1, 145 | #endif 146 | .0e-1 147 | }; 148 | 149 | int array[][10][20]; 150 | 151 | /* 152 | * This grammar can accept some illegal stuff too, in particular it will 153 | * permit some instances of parameter-names to be dropped. 154 | */ 155 | #ifdef ERR_CHECK 156 | #define P1 157 | #define P2 158 | #define P3 159 | #else 160 | #define P1 p1 161 | #define P2 p2 162 | #define P3 p3 163 | #endif 164 | 165 | /* ellipsis is legal, except in K&R style declaration */ 166 | 167 | int 168 | dots_0 (int p1) { return(1); } 169 | 170 | dots_1(int p1, ...) { return(1); } 171 | 172 | #ifdef ERR_CHECK 173 | dots_2(p1, ...) { return(1); } 174 | #endif /* ERR_CHECK */ 175 | 176 | dots_3(int P1,char P2, ...) { return(1); } 177 | 178 | int dots_4(int,char, char *); 179 | char * dots_5(int,char, char *, ...); 180 | char * (dots_6)(int,char, char *, ...); 181 | 182 | extern _FIRST *xdots_0(p1); 183 | 184 | extern char *xdots_1(int p1, ...); 185 | 186 | #ifdef ERR_CHECK 187 | extern xdots_2(p1, ...); 188 | #endif /* ERR_CHECK */ 189 | 190 | extern xdots_3(int P1,char P2, ...); 191 | 192 | _FIRST * 193 | func1 (void) { } 194 | _FIRST *func2(_FIRST *P1,int P2[],float p) { } 195 | 196 | int *( 197 | func_func) (int p1, int p2, int p3) { return(0); } 198 | 199 | extern float efunc0(p1,p2,p3); 200 | extern _FIRST efunc1(int p1, float p2,long P3); 201 | #ifdef ERR_CHECK 202 | extern _FIRST efunc1(int p1, float p2,p3); 203 | #endif /* ERR_CHECK */ 204 | 205 | 206 | typedef int bool; 207 | 208 | bool a1; 209 | static bool a2; 210 | extern bool a3; 211 | 212 | struct ZIP1 { int x1, y1; }; 213 | struct zip2 { int x2, y2; } z2; 214 | struct { int x3, y3; } z3; /* not ANSI, but mostly accepted */ 215 | 216 | static struct ZIP4 { int x4, y4; }; 217 | static struct zip5 { int x5, y5; } z5; 218 | static struct zip6 { int x6, y6; } z6, w6; 219 | static struct { int x7, y7; } z7; 220 | static struct { int x8, y8; } z8, w8; 221 | 222 | enum zap1 { a,b,c,d } what; 223 | enum zap2 what2; 224 | enum {a9,b9,c9,d9} what3; 225 | 226 | static char *zap = "alphabet/\ 227 | first/\ 228 | last"; 229 | typedef struct bong { 230 | int (*func)(); 231 | } BONG; 232 | 233 | typedef char *string; 234 | 235 | #ifdef ERR_LEX 236 | string s = "aaa\0000\ 237 | 238 | bbb"; 239 | #endif /* ERR_LEX */ 240 | 241 | extern int junk; 242 | 243 | int 244 | main (register argc, extern char **argv) 245 | { 246 | } 247 | 248 | /*VARARGS*/ 249 | /* some other comment */ 250 | int 251 | veryfunny (char *a, long b, long c) 252 | { 253 | return 0; 254 | } 255 | 256 | /*VARARGS3*/ 257 | int 258 | program ( 259 | string argv[], /* first argument */ 260 | struct alpha y, /* second argument */ 261 | int zz, 262 | int z1, 263 | int z2, 264 | int z3 265 | ) 266 | { 267 | return(0); 268 | } 269 | 270 | int 271 | junk0 (void) { if(junk != 6) return; else junk++; } 272 | int 273 | junk1 (void) { return (0); } 274 | int 275 | junk2 (void) { } 276 | int 277 | junk3 (void) { return 1; } 278 | 279 | BONG * 280 | junk4 (void) { } 281 | 282 | typedef int extern_junk; 283 | extern_junk * 284 | foo (void) { } 285 | 286 | typedef int void_junk; 287 | extern void_junk * 288 | foo2a (void) { } 289 | extern void_junk *foo2a(); 290 | void_junk * 291 | foo2 (void) { } 292 | void_junk *foo_void(void_junk void_int) { } 293 | static void_junk * 294 | foo_void2 (void) { } 295 | 296 | extern void (*sigdisp(int sig, void (*func)(int sig)))(int sig); 297 | 298 | void (*Sigdisp(int sig, void (*func)(int sig)))(int sig1) 299 | { /* nothing */ } 300 | 301 | void (* 302 | sigdisp2 ( 303 | int sig, /* the signal value */ 304 | void (*func)(int sig) /* the function pointer */ 305 | ))(int sig2) 306 | { /* nothing again! */ } 307 | 308 | int (* 309 | K_R_INT_ptr (long *p1, int p2))(void) { return (*(int(*)())0); } 310 | 311 | int (*STD_INT_ptr(long* , int))(); 312 | 313 | void (* 314 | K_R_VOID_ptr (long *p1, int p2))(void) { return (*(void(*)())0); } 315 | 316 | void (*STD_VOID_ptr(long* , int))(); 317 | 318 | int * 319 | K_R_int_ptr (long *p1, int p2) { return (*(int **)0); } 320 | 321 | int **STD_int2_ptr(long* , int); 322 | 323 | int *STD_int_ptr(long* , int); 324 | 325 | void * 326 | K_R_void_ptr (long *p1, int p2) { return (*(void **)0); } 327 | 328 | void *STD_void_ptr(long* , int); 329 | 330 | int 331 | K_R_int_val (long *p1, int p2) { return (*(int *)0); } 332 | 333 | int 334 | K_R_int_val2 (long *p1, int p2) { return (*(int *)0); } 335 | 336 | int STD_int_val(long*, int); 337 | 338 | void 339 | K_R_void_val (long *p1, int p2) { /*void*/ } 340 | 341 | int 342 | K_R_void_val2 ( 343 | long *p1, 344 | int p2 { /*void*/ 345 | ) } 346 | 347 | void STD_void_val(long* , int); 348 | 349 | extern xdots_3(int P1,char P2, ...); 350 | 351 | extern int (*XSetAfterFunction(long* , int (*) ( long*)))(); 352 | extern XQueryKeymap(long*, char [32]); 353 | extern Another(long*, int (*)()); 354 | 355 | extern GenFunc(int *, int *()); 356 | 357 | /* these are pointers, not actual functions */ 358 | extern void * (*__glob_opendir_hook) (const char *__directory); 359 | extern const char *(*__glob_readdir_hook) (void * __stream); 360 | extern void (*__glob_closedir_hook) (void * __stream); 361 | 362 | /* inline function */ 363 | int inline inline_func(double x) { return(0); } 364 | static int inline local_inline_func(double x) { return(0); } 365 | 366 | /* c99 types */ 367 | long long xxx = 1; 368 | char *xxs = "\x1234\?\u1234"; 369 | -------------------------------------------------------------------------------- /testing/case17.ref: -------------------------------------------------------------------------------- 1 | /* case17.c */ 2 | void badFunc(int *badStyle); 3 | int dots_0(int p1); 4 | int dots_1(int p1, ...); 5 | int dots_3(int P1, char P2, ...); 6 | _FIRST *func1(void); 7 | _FIRST *func2(_FIRST *P1 , int P2 [], float p); 8 | int *(func_func)(int p1, int p2, int p3); 9 | int main(register argc, char **argv); 10 | int veryfunny(char *a, long b, long c); 11 | int program(string argv[], struct alpha y, int zz, int z1, int z2, int z3); 12 | int junk0(void); 13 | int junk1(void); 14 | int junk2(void); 15 | int junk3(void); 16 | BONG *junk4(void); 17 | extern_junk *foo(void); 18 | void_junk *foo2a(void); 19 | void_junk *foo2(void); 20 | void_junk *foo_void(void_junk void_int); 21 | void (*Sigdisp(int sig, void (*func)(int sig)))(int sig1); 22 | void (*sigdisp2(int sig, void (*func)(int sig)))(int sig2); 23 | int (*K_R_INT_ptr(long *p1, int p2))(void); 24 | void (*K_R_VOID_ptr(long *p1, int p2))(void); 25 | int *K_R_int_ptr(long *p1, int p2); 26 | void *K_R_void_ptr(long *p1, int p2); 27 | int K_R_int_val(long *p1, int p2); 28 | int K_R_int_val2(long *p1, int p2); 29 | void K_R_void_val(long *p1, int p2); 30 | int K_R_void_val2(long *p1, int p2); 31 | ... edited case17.c ... 32 | /* 33 | * Define: 34 | * ERR_YACC to force yacc error reporting 35 | * ERR_LEX to force lex error reporting 36 | * ERR_CHECK to force compiler error reporting 37 | */ 38 | /* use one item from type-specifiers */ 39 | #ifdef ERR_YACC 40 | auto x; 41 | register x1; 42 | #endif /* ERR_YACC */ 43 | static x2; 44 | extern x3; 45 | #ifdef ERR_CC 46 | typedef x4; 47 | #endif 48 | typedef int x4t; 49 | #ifdef ERR_YACC 50 | void x5; 51 | #endif /* ERR_YACC */ 52 | char x6; 53 | short x7; 54 | int x8; 55 | long x9; 56 | float x10; 57 | double x11; 58 | signed x12; 59 | unsigned x13; 60 | struct x14; 61 | #ifdef ERR_CHECK 62 | struct x14a {}; 63 | struct {}; 64 | #endif /* ERR_CHECK */ 65 | union x15; 66 | enum x16; 67 | x4t; 68 | x4t x17; 69 | const x18; 70 | volatile x19; 71 | #ifdef ERR_CHECK 72 | junk x20; 73 | #endif /* ERR_CHECK */ 74 | 75 | extern int *asm (fopen, (__const char *__restrict __filename, __const char *__restrict __modes), fopen64); 76 | extern int __asm__ (mkstemp, (char *__template), mkstemp64); 77 | int __asm__ (mkstemp, (char *__template), mkstemp64); 78 | asm("something"); 79 | asm("something", "else"); 80 | asm("something", (this and that)); 81 | int asm(first, "something"); 82 | static int asm(first, "something"); 83 | extern int asm(first, "something"); 84 | 85 | typedef struct _first { 86 | int a:5; 87 | struct { 88 | int a,b; 89 | } b_struct; 90 | char b:16, b1:1; /* comment with };};}; */ 91 | long c:16, c1; 92 | short d:16, d1:8, d2; 93 | unsigned e:16; 94 | float f; 95 | double g; 96 | #ifdef ERR_CHECK 97 | long float f2; 98 | long double g2; 99 | #endif /* ERR_CHECK */ 100 | struct _first *link; 101 | } _FIRST; 102 | 103 | typedef int badStyle; 104 | void 105 | badFunc (badStyle) 106 | int *badStyle; { } 107 | 108 | _FIRST first, last={0}, first_last[] = {{0},{1},{2},{3,{4}}}; 109 | 110 | struct _second { 111 | enum {true, false} bool; 112 | enum {wrong=1, right=3} values; 113 | } _SECOND; 114 | 115 | int i[] = {1, 116 | '\002', 117 | 03, 118 | 0x4, 119 | 0X5, 120 | 0x6a, 121 | 0X7b, 122 | 0x8aBcD, 123 | 9l, 124 | 10l, 125 | 11L}; 126 | float f[] = {5, 127 | #ifdef ERR_CHECK 128 | .5e, 129 | .5e+, 130 | 5e-, 131 | 5e, 132 | .34P1, 133 | 0x1.2.34, /* error */ 134 | #endif 135 | .5, 136 | 5.5, 137 | 5e5, 138 | 5e0, 139 | 5e-1, 140 | 5e+5 141 | #ifdef __STDC_VERSION__ /* ( C9X supports hexadecimal floating point ;-) */ 142 | 0x12.34+1, 143 | 0x12.34P1, 144 | .34e1, 145 | 0.34e1, 146 | 0x.34P1, 147 | #endif 148 | .0e-1 149 | }; 150 | 151 | int array[][10][20]; 152 | 153 | /* 154 | * This grammar can accept some illegal stuff too, in particular it will 155 | * permit some instances of parameter-names to be dropped. 156 | */ 157 | #ifdef ERR_CHECK 158 | #define P1 159 | #define P2 160 | #define P3 161 | #else 162 | #define P1 p1 163 | #define P2 p2 164 | #define P3 p3 165 | #endif 166 | 167 | /* ellipsis is legal, except in K&R style declaration */ 168 | 169 | dots_0(p1) { return(1); } 170 | 171 | int 172 | dots_1 (p1) 173 | int p1; { return(1); } 174 | 175 | #ifdef ERR_CHECK 176 | dots_2(p1, ...) { return(1); } 177 | #endif /* ERR_CHECK */ 178 | 179 | int 180 | dots_3 (, ) 181 | int P1; 182 | char P2; { return(1); } 183 | 184 | int dots_4(); 185 | char *dots_5(); 186 | char *(dots_6)(); 187 | 188 | extern _FIRST *xdots_0(); 189 | 190 | extern char *xdots_1(); 191 | 192 | #ifdef ERR_CHECK 193 | extern xdots_2(p1, ...); 194 | #endif /* ERR_CHECK */ 195 | 196 | extern xdots_3(); 197 | 198 | _FIRST *func1() { } 199 | _FIRST * 200 | func2 (, , p) 201 | _FIRST *P1 ; 202 | int P2 []; 203 | float p; { } 204 | 205 | int *(func_func)( 206 | #ifdef ERR_CHECK 207 | p1,p2,p3 208 | #endif /* ERR_CHECK */ 209 | ) { return(0); } 210 | 211 | extern float efunc0(); 212 | extern _FIRST efunc1(); 213 | #ifdef ERR_CHECK 214 | extern _FIRST efunc1(int p1, float p2,p3); 215 | #endif /* ERR_CHECK */ 216 | 217 | 218 | typedef int bool; 219 | 220 | bool a1; 221 | static bool a2; 222 | extern bool a3; 223 | 224 | struct ZIP1 { int x1, y1; }; 225 | struct zip2 { int x2, y2; } z2; 226 | struct { int x3, y3; } z3; /* not ANSI, but mostly accepted */ 227 | 228 | static struct ZIP4 { int x4, y4; }; 229 | static struct zip5 { int x5, y5; } z5; 230 | static struct zip6 { int x6, y6; } z6, w6; 231 | static struct { int x7, y7; } z7; 232 | static struct { int x8, y8; } z8, w8; 233 | 234 | enum zap1 { a,b,c,d } what; 235 | enum zap2 what2; 236 | enum {a9,b9,c9,d9} what3; 237 | 238 | static char *zap = "alphabet/\ 239 | first/\ 240 | last"; 241 | typedef struct bong { 242 | int (*func)(); 243 | } BONG; 244 | 245 | typedef char *string; 246 | 247 | #ifdef ERR_LEX 248 | string s = "aaa\0000\ 249 | 250 | bbb"; 251 | #endif /* ERR_LEX */ 252 | 253 | extern int junk; 254 | 255 | main(argc, argv) 256 | register argc; 257 | #ifdef ERR_CHECK 258 | extern 259 | #endif /* ERR_CHECK */ 260 | char **argv; 261 | { 262 | } 263 | 264 | /*VARARGS*/ 265 | /* some other comment */ 266 | veryfunny(a,b,c) 267 | char *a; 268 | long b, c; 269 | { 270 | return 0; 271 | } 272 | 273 | /*VARARGS3*/ 274 | program(argv, y, zz, z1, z2, z3) 275 | string argv[]; /* first argument */ 276 | struct alpha { int x,z; } y; /* second argument */ 277 | { 278 | return(0); 279 | } 280 | 281 | junk0() { if(junk != 6) return; else junk++; } 282 | junk1() { return (0); } 283 | junk2() { } 284 | junk3() { return 1; } 285 | 286 | BONG *junk4() { } 287 | 288 | typedef int extern_junk; 289 | extern_junk *foo() { } 290 | 291 | typedef int void_junk; 292 | extern void_junk *foo2a() { } 293 | extern void_junk *foo2a(); 294 | void_junk *foo2() { } 295 | void_junk * 296 | foo_void (void_int) 297 | void_junk void_int; { } 298 | static void_junk *foo_void2() { } 299 | 300 | extern void (*sigdisp())(); 301 | 302 | void (* 303 | Sigdisp (sig, func))() 304 | int sig; 305 | void (*func)(); 306 | { /* nothing */ } 307 | 308 | void (* 309 | sigdisp2 ( 310 | sig, 311 | func 312 | ))() 313 | int sig; /* the signal value */ 314 | void (*func)(); /* the function pointer */ 315 | { /* nothing again! */ } 316 | 317 | int (*K_R_INT_ptr(p1, p2))() long *p1; int p2; { return (*(int(*)())0); } 318 | 319 | int (*STD_INT_ptr())(); 320 | 321 | void (*K_R_VOID_ptr(p1,p2))() long *p1; int p2; { return (*(void(*)())0); } 322 | 323 | void (*STD_VOID_ptr())(); 324 | 325 | int *K_R_int_ptr(p1,p2) long *p1; int p2; { return (*(int **)0); } 326 | 327 | int **STD_int2_ptr(); 328 | 329 | int *STD_int_ptr(); 330 | 331 | void *K_R_void_ptr(p1,p2) long *p1; int p2; { return (*(void **)0); } 332 | 333 | void *STD_void_ptr(); 334 | 335 | int K_R_int_val(p1,p2) long *p1; int p2; { return (*(int *)0); } 336 | 337 | K_R_int_val2(p1,p2) long *p1; int p2; { return (*(int *)0); } 338 | 339 | int STD_int_val(); 340 | 341 | void K_R_void_val(p1,p2) long *p1; int p2; { /*void*/ } 342 | 343 | K_R_void_val2(p1,p2) long *p1; int p2; { /*void*/ } 344 | 345 | void STD_void_val(); 346 | 347 | extern xdots_3(); 348 | 349 | extern int (*XSetAfterFunction())(); 350 | extern XQueryKeymap(); 351 | extern Another(); 352 | 353 | extern GenFunc(); 354 | 355 | /* these are pointers, not actual functions */ 356 | extern void *(*__glob_opendir_hook)(); 357 | extern const char *(*__glob_readdir_hook)(); 358 | extern void (*__glob_closedir_hook)(); 359 | 360 | /* inline function */ 361 | int inline 362 | inline_func (x) 363 | double x; { return(0); } 364 | static int inline 365 | local_inline_func (x) 366 | double x; { return(0); } 367 | 368 | /* c99 types */ 369 | long long xxx = 1; 370 | char *xxs = "\x1234\?\u1234"; 371 | -------------------------------------------------------------------------------- /testing/case18.ref: -------------------------------------------------------------------------------- 1 | /* case18.c */ 2 | void badFunc(); 3 | int dots_0(); 4 | int dots_1(); 5 | int dots_3(); 6 | _FIRST *func1(); 7 | _FIRST *func2(); 8 | int *(func_func)(); 9 | int main(); 10 | int veryfunny(); 11 | int program(); 12 | int junk0(); 13 | int junk1(); 14 | int junk2(); 15 | int junk3(); 16 | BONG *junk4(); 17 | extern_junk *foo(); 18 | void_junk *foo2a(); 19 | void_junk *foo2(); 20 | void_junk *foo_void(); 21 | void (*Sigdisp())(); 22 | void (*sigdisp2())(); 23 | int (*K_R_INT_ptr())(); 24 | void (*K_R_VOID_ptr())(); 25 | int *K_R_int_ptr(); 26 | void *K_R_void_ptr(); 27 | int K_R_int_val(); 28 | int K_R_int_val2(); 29 | void K_R_void_val(); 30 | int K_R_void_val2(); 31 | -------------------------------------------------------------------------------- /testing/case19.ref: -------------------------------------------------------------------------------- 1 | /* case19.c */ 2 | void badFunc(int *); 3 | int dots_0(int); 4 | int dots_1(int, ...); 5 | int dots_3(int, char, ...); 6 | _FIRST *func1(void); 7 | _FIRST *func2(_FIRST *, int [], float); 8 | int *(func_func)(void); 9 | int main(register, char **); 10 | int veryfunny(char *, long, long); 11 | int program(string [], struct alpha, int, int, int, int); 12 | int junk0(void); 13 | int junk1(void); 14 | int junk2(void); 15 | int junk3(void); 16 | BONG *junk4(void); 17 | extern_junk *foo(void); 18 | void_junk *foo2a(void); 19 | void_junk *foo2(void); 20 | void_junk *foo_void(void_junk); 21 | void (*Sigdisp(int, void (*)(int)))(int); 22 | void (*sigdisp2(int, void (*)(int)))(int); 23 | int (*K_R_INT_ptr(long *, int))(void); 24 | void (*K_R_VOID_ptr(long *, int))(void); 25 | int *K_R_int_ptr(long *, int); 26 | void *K_R_void_ptr(long *, int); 27 | int K_R_int_val(long *, int); 28 | int K_R_int_val2(long *, int); 29 | void K_R_void_val(long *, int); 30 | int K_R_void_val2(long *, int); 31 | -------------------------------------------------------------------------------- /testing/case20.ref: -------------------------------------------------------------------------------- 1 | /* case20.c */ 2 | void badFunc(int *badStyle); 3 | int dots_0(int p1); 4 | int dots_1(int p1, ...); 5 | int dots_3(int p1, char p2, ...); 6 | _FIRST *func1(void); 7 | _FIRST *func2(_FIRST *p1, int p2[], float p); 8 | int *(func_func)(void); 9 | int main(register argc, char **argv); 10 | int veryfunny(char *a, long b, long c); 11 | int program(string argv[], struct alpha y, int zz, int z1, int z2, int z3); 12 | int junk0(void); 13 | int junk1(void); 14 | int junk2(void); 15 | int junk3(void); 16 | BONG *junk4(void); 17 | extern_junk *foo(void); 18 | void_junk *foo2a(void); 19 | void_junk *foo2(void); 20 | void_junk *foo_void(void_junk void_int); 21 | void (*Sigdisp(int sig, void (*func)(int sig)))(int sig1); 22 | void (*sigdisp2(int sig, void (*func)(int sig)))(int sig2); 23 | int (*K_R_INT_ptr(long *p1, int p2))(void); 24 | void (*K_R_VOID_ptr(long *p1, int p2))(void); 25 | int *K_R_int_ptr(long *p1, int p2); 26 | void *K_R_void_ptr(long *p1, int p2); 27 | int K_R_int_val(long *p1, int p2); 28 | int K_R_int_val2(long *p1, int p2); 29 | void K_R_void_val(long *p1, int p2); 30 | int K_R_void_val2(long *p1, int p2); 31 | -------------------------------------------------------------------------------- /testing/case21.ref: -------------------------------------------------------------------------------- 1 | /* case21.c */ 2 | char x6; 3 | short x7; 4 | int x8; 5 | long x9; 6 | float x10; 7 | double x11; 8 | signed x12; 9 | unsigned x13; 10 | x4t x17; 11 | const x18; 12 | volatile x19; 13 | void badFunc( 14 | int *badStyle 15 | ); 16 | _FIRST first; 17 | _FIRST last; 18 | _FIRST first_last[]; 19 | struct _second _SECOND; 20 | int i[]; 21 | float f[]; 22 | int array[][10][20]; 23 | int dots_0( 24 | int p1 25 | ); 26 | int dots_1( 27 | int p1, 28 | ... 29 | ); 30 | int dots_3( 31 | int p1, 32 | char p2, 33 | ... 34 | ); 35 | _FIRST *func1(void); 36 | _FIRST *func2( 37 | _FIRST *p1, 38 | int p2[], 39 | float p 40 | ); 41 | int *(func_func)(void); 42 | bool a1; 43 | struct zip2 z2; 44 | struct {} z3; 45 | enum zap1 what; 46 | enum zap2 what2; 47 | enum {} what3; 48 | int main( 49 | register argc, 50 | char **argv 51 | ); 52 | int veryfunny( 53 | char *a, 54 | long b, 55 | long c 56 | ); 57 | int program( 58 | string argv[], 59 | struct alpha y, 60 | int zz, 61 | int z1, 62 | int z2, 63 | int z3 64 | ); 65 | int junk0(void); 66 | int junk1(void); 67 | int junk2(void); 68 | int junk3(void); 69 | BONG *junk4(void); 70 | extern_junk *foo(void); 71 | void_junk *foo2a(void); 72 | void_junk *foo2(void); 73 | void_junk *foo_void( 74 | void_junk void_int 75 | ); 76 | void (*Sigdisp( 77 | int sig, 78 | void (*func)(int sig) 79 | ))(int sig1); 80 | void (*sigdisp2( 81 | int sig, 82 | void (*func)(int sig) 83 | ))(int sig2); 84 | int (*K_R_INT_ptr( 85 | long *p1, 86 | int p2 87 | ))(void); 88 | void (*K_R_VOID_ptr( 89 | long *p1, 90 | int p2 91 | ))(void); 92 | int *K_R_int_ptr( 93 | long *p1, 94 | int p2 95 | ); 96 | void *K_R_void_ptr( 97 | long *p1, 98 | int p2 99 | ); 100 | int K_R_int_val( 101 | long *p1, 102 | int p2 103 | ); 104 | int K_R_int_val2( 105 | long *p1, 106 | int p2 107 | ); 108 | void K_R_void_val( 109 | long *p1, 110 | int p2 111 | ); 112 | int K_R_void_val2( 113 | long *p1, 114 | int p2 115 | ); 116 | long long xxx; 117 | char *xxs; 118 | -------------------------------------------------------------------------------- /testing/case22.ref: -------------------------------------------------------------------------------- 1 | /* LINTLIBRARY */ 2 | 3 | /* case22.c */ 4 | 5 | typedef int x4t; 6 | 7 | #undef x6 8 | char x6; 9 | #undef x7 10 | short x7; 11 | #undef x8 12 | int x8; 13 | #undef x9 14 | long x9; 15 | #undef x10 16 | float x10; 17 | #undef x11 18 | double x11; 19 | #undef x12 20 | signed x12; 21 | #undef x13 22 | unsigned x13; 23 | 24 | struct x14; 25 | 26 | union x15; 27 | 28 | enum x16; 29 | 30 | x4t; 31 | 32 | #undef x17 33 | x4t x17; 34 | #undef x18 35 | const x18 = {0}; 36 | #undef x19 37 | volatile x19; 38 | 39 | typedef struct _first { 40 | int a:5; 41 | struct { 42 | int a,b; 43 | } b_struct; 44 | char b:16, b1:1; 45 | long c:16, c1; 46 | short d:16, d1:8, d2; 47 | unsigned e:16; 48 | float f; 49 | double g; 50 | struct _first *link; 51 | } _FIRST; 52 | 53 | typedef int badStyle; 54 | 55 | #undef badFunc 56 | void badFunc( 57 | int *badStyle) 58 | { /* void */ } 59 | 60 | #undef first 61 | _FIRST first; 62 | #undef last 63 | _FIRST last; 64 | #undef first_last 65 | _FIRST first_last[]; 66 | #undef _SECOND 67 | struct _second { 68 | enum {true, false} bool; 69 | enum {wrong=1, right=3} values; 70 | } _SECOND; 71 | #undef i 72 | int i[]; 73 | #undef f 74 | float f[]; 75 | #undef array 76 | int array[][10][20]; 77 | 78 | #undef dots_0 79 | int dots_0( 80 | int p1) 81 | { return(*(int *)0); } 82 | 83 | #undef dots_1 84 | int dots_1( 85 | int p1, 86 | ...) 87 | { return(*(int *)0); } 88 | 89 | #undef dots_3 90 | int dots_3( 91 | int p1, 92 | char p2, 93 | ...) 94 | { return(*(int *)0); } 95 | 96 | #undef func1 97 | _FIRST *func1(void) 98 | { return(*(_FIRST **)0); } 99 | 100 | #undef func2 101 | _FIRST *func2( 102 | _FIRST *p1, 103 | int p2[], 104 | float p) 105 | { return(*(_FIRST **)0); } 106 | 107 | #undef func_func 108 | int *(func_func)(void) 109 | { return(*(int **)0); } 110 | 111 | typedef int bool; 112 | 113 | #undef a1 114 | bool a1; 115 | 116 | struct ZIP1 { int x1, y1; }; 117 | 118 | #undef z2 119 | struct zip2 { int x2, y2; } z2; 120 | #undef z3 121 | struct { int x3, y3; } z3; 122 | 123 | struct ZIP4 { int x4, y4; }; 124 | 125 | #undef what 126 | enum zap1 { a,b,c,d } what; 127 | #undef what2 128 | enum zap2 what2; 129 | #undef what3 130 | enum {a9,b9,c9,d9} what3; 131 | 132 | typedef struct bong { 133 | int (*func)(); 134 | } BONG; 135 | 136 | typedef char *string; 137 | 138 | #undef main 139 | void main( 140 | int argc, 141 | char **argv) 142 | { /* void */ } 143 | 144 | /* VARARGS */ 145 | #undef veryfunny 146 | int veryfunny( 147 | char *a, 148 | long b, 149 | long c) 150 | { return(*(int *)0); } 151 | 152 | /* VARARGS3 */ 153 | #undef program 154 | int program( 155 | string argv[], 156 | struct alpha { int x,z; } y, 157 | int zz, 158 | int z1, 159 | int z2, 160 | int z3) 161 | { return(*(int *)0); } 162 | 163 | #undef junk0 164 | void junk0(void) 165 | { /* void */ } 166 | 167 | #undef junk1 168 | int junk1(void) 169 | { return(*(int *)0); } 170 | 171 | #undef junk2 172 | void junk2(void) 173 | { /* void */ } 174 | 175 | #undef junk3 176 | int junk3(void) 177 | { return(*(int *)0); } 178 | 179 | #undef junk4 180 | BONG *junk4(void) 181 | { return(*(BONG **)0); } 182 | 183 | typedef int extern_junk; 184 | 185 | #undef foo 186 | extern_junk *foo(void) 187 | { return(*(extern_junk **)0); } 188 | 189 | typedef int void_junk; 190 | 191 | #undef foo2a 192 | void_junk *foo2a(void) 193 | { return(*(void_junk **)0); } 194 | 195 | #undef foo2 196 | void_junk *foo2(void) 197 | { return(*(void_junk **)0); } 198 | 199 | #undef foo_void 200 | void_junk *foo_void( 201 | void_junk void_int) 202 | { return(*(void_junk **)0); } 203 | 204 | #undef Sigdisp 205 | void (*Sigdisp( 206 | int sig, 207 | void (*func)( 208 | int sig)))( 209 | int sig1) 210 | { return(*(void(*)())0); } 211 | 212 | #undef sigdisp2 213 | void (*sigdisp2( 214 | int sig, 215 | void (*func)( 216 | int sig)))( 217 | int sig2) 218 | { return(*(void(*)())0); } 219 | 220 | #undef K_R_INT_ptr 221 | int (*K_R_INT_ptr( 222 | long *p1, 223 | int p2))(void) 224 | { return(*(int(*)())0); } 225 | 226 | #undef K_R_VOID_ptr 227 | void (*K_R_VOID_ptr( 228 | long *p1, 229 | int p2))(void) 230 | { return(*(void(*)())0); } 231 | 232 | #undef K_R_int_ptr 233 | int *K_R_int_ptr( 234 | long *p1, 235 | int p2) 236 | { return(*(int **)0); } 237 | 238 | #undef K_R_void_ptr 239 | void *K_R_void_ptr( 240 | long *p1, 241 | int p2) 242 | { return(*(void **)0); } 243 | 244 | #undef K_R_int_val 245 | int K_R_int_val( 246 | long *p1, 247 | int p2) 248 | { return(*(int *)0); } 249 | 250 | #undef K_R_int_val2 251 | int K_R_int_val2( 252 | long *p1, 253 | int p2) 254 | { return(*(int *)0); } 255 | 256 | #undef K_R_void_val 257 | void K_R_void_val( 258 | long *p1, 259 | int p2) 260 | { /* void */ } 261 | 262 | #undef K_R_void_val2 263 | void K_R_void_val2( 264 | long *p1, 265 | int p2) 266 | { /* void */ } 267 | 268 | #undef xxx 269 | long long xxx; 270 | #undef xxs 271 | char *xxs; 272 | -------------------------------------------------------------------------------- /testing/case23.ref: -------------------------------------------------------------------------------- 1 | /* case23.c */ 2 | void badFunc(int *badStyle); 3 | int dots_0(int p1); 4 | int dots_1(int p1, ...); 5 | int dots_3(int p1, char p2, ...); 6 | _FIRST *func1(void); 7 | _FIRST *func2(_FIRST *p1, int p2[], float p); 8 | int *(func_func)(void); 9 | int main(register argc, char **argv); 10 | int veryfunny(char *a, long b, long c); 11 | int program(string argv[], struct alpha y, int zz, int z1, int z2, int z3); 12 | int junk0(void); 13 | int junk1(void); 14 | int junk2(void); 15 | int junk3(void); 16 | BONG *junk4(void); 17 | extern_junk *foo(void); 18 | void_junk *foo2a(void); 19 | void_junk *foo2(void); 20 | void_junk *foo_void(void_junk void_int); 21 | void (*Sigdisp(int sig, void (*func)(int sig)))(int sig1); 22 | void (*sigdisp2(int sig, void (*func)(int sig)))(int sig2); 23 | int (*K_R_INT_ptr(long *p1, int p2))(void); 24 | void (*K_R_VOID_ptr(long *p1, int p2))(void); 25 | int *K_R_int_ptr(long *p1, int p2); 26 | void *K_R_void_ptr(long *p1, int p2); 27 | int K_R_int_val(long *p1, int p2); 28 | int K_R_int_val2(long *p1, int p2); 29 | void K_R_void_val(long *p1, int p2); 30 | int K_R_void_val2(long *p1, int p2); 31 | int inline inline_func(double x); 32 | -------------------------------------------------------------------------------- /testing/case24.ref: -------------------------------------------------------------------------------- 1 | /* case24.c */ 2 | void badFunc(int *badStyle); 3 | int dots_0(int p1); 4 | int dots_1(int p1, ...); 5 | int dots_3(int p1, char p2, ...); 6 | _FIRST *func1(void); 7 | _FIRST *func2(_FIRST *p1, int p2[], float p); 8 | int *(func_func)(void); 9 | int main(register argc, char **argv); 10 | int veryfunny(char *a, long b, long c); 11 | int program(string argv[], struct alpha y, int zz, int z1, int z2, int z3); 12 | int junk0(void); 13 | int junk1(void); 14 | int junk2(void); 15 | int junk3(void); 16 | BONG *junk4(void); 17 | extern_junk *foo(void); 18 | void_junk *foo2a(void); 19 | void_junk *foo2(void); 20 | void_junk *foo_void(void_junk void_int); 21 | static void_junk *foo_void2(void); 22 | void (*Sigdisp(int sig, void (*func)(int sig)))(int sig1); 23 | void (*sigdisp2(int sig, void (*func)(int sig)))(int sig2); 24 | int (*K_R_INT_ptr(long *p1, int p2))(void); 25 | void (*K_R_VOID_ptr(long *p1, int p2))(void); 26 | int *K_R_int_ptr(long *p1, int p2); 27 | void *K_R_void_ptr(long *p1, int p2); 28 | int K_R_int_val(long *p1, int p2); 29 | int K_R_int_val2(long *p1, int p2); 30 | void K_R_void_val(long *p1, int p2); 31 | int K_R_void_val2(long *p1, int p2); 32 | int inline inline_func(double x); 33 | static int inline local_inline_func(double x); 34 | -------------------------------------------------------------------------------- /testing/descrip.mms: -------------------------------------------------------------------------------- 1 | # $Id: descrip.mms,v 4.1 1998/01/20 00:59:43 cthuang Exp $ 2 | # VMS make-file for CPROTO test directory 3 | # 4 | 5 | ####### (Development) ########################################################## 6 | 7 | ####### (Command-line Options) ################################################# 8 | 9 | ####### (Standard Lists) ####################################################### 10 | 11 | REF_FILES=\ 12 | case1.ref case2.ref case3.ref case4.ref\ 13 | case5.ref case6.ref case7.ref case8.ref\ 14 | case9.ref case10.ref case11.ref case12.ref\ 15 | case13.ref case14.ref case15.ref\ 16 | case17.ref case18.ref case19.ref case20.ref\ 17 | case21.ref 18 | 19 | COM_FILES=\ 20 | case1.dcl case2.dcl case3.dcl case4.dcl\ 21 | case5.dcl case6.dcl case7.dcl case8.dcl\ 22 | case9.dcl case10.dcl case11.dcl case12.dcl\ 23 | case13.dcl case14.dcl case15.dcl\ 24 | case17.dcl case18.dcl case19.dcl case20.dcl\ 25 | case21.dcl 26 | 27 | TESTDATA=\ 28 | syntax.c\ 29 | $(COM_FILES)\ 30 | $(REF_FILES) 31 | 32 | SCRIPTS =\ 33 | run_tests.sh run_tests.com 34 | 35 | SOURCES = makefile descrip.mms $(SCRIPTS) $(TESTDATA) 36 | 37 | ALL = $(SCRIPTS) 38 | 39 | ####### (Standard Productions) ################################################# 40 | all : $(ALL) [-.bin]$(THIS).exe [-.bin]$(THIS)1.exe 41 | @ write sys$output "Type ""mms run_tests"" 42 | 43 | clean : 44 | @- write sys$output "** made $@" 45 | clobber : clean 46 | @- write sys$output "** made $@" 47 | destroy : 48 | @- remove -vf *.*;* 49 | run_tests : $(SCRIPTS) $(TESTDATA) 50 | @run_tests 51 | 52 | ####### (Details of Productions) ############################################### 53 | -------------------------------------------------------------------------------- /testing/linux.c: -------------------------------------------------------------------------------- 1 | /* $Id: linux.c,v 4.2 1998/01/08 00:03:30 cthuang Exp $ */ 2 | /* LINT_EXTERN */ 3 | /* LINT_SHADOWED */ 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | /* #include */ 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | /* #include */ 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | /* #include */ 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | /* #include */ 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | /* #include */ 58 | #include 59 | #include 60 | #include 61 | #include 62 | #include 63 | /* #include */ 64 | #include 65 | #include 66 | #include 67 | #include 68 | #include 69 | #include 70 | #include 71 | #include 72 | #include 73 | #include 74 | #include 75 | #include 76 | #include 77 | #include 78 | #include 79 | #include 80 | #include 81 | #include 82 | #include 83 | #include 84 | #include 85 | #include 86 | #include 87 | #include 88 | -------------------------------------------------------------------------------- /testing/make_bat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # $Id: make_bat.sh,v 4.3 1998/01/24 01:42:13 cthuang Exp $ 3 | # 4 | # This makes a special ".bat" file for testing CPROTO on MSDOS. 5 | # It won't work properly if /bin/echo tries to expand the backslash sequences. 6 | # (This is the case on SunOS 4.1.x). 7 | # 8 | # The MSDOS 'fc' program doesn't return an exit code for differing files. 9 | # We have to examine the output log... 10 | TMP=make$$ 11 | rm -f $TMP 12 | trap "rm -f $TMP" 0 1 2 5 15 13 | if [ -f /bin/echo ] 14 | then 15 | ECHO=/bin/echo 16 | else 17 | ECHO=echo 18 | fi 19 | for i in $* 20 | do 21 | i="`echo $i | sed -e 's/[A-Za-z_.]//g'`" 22 | I="case$i" 23 | if [ -n "$i" -a ! -f $I.bat ] 24 | then 25 | echo '** making '$I.bat 26 | cat >$I.bat <>run_test.out 30 | if exist $I.out erase $I.out 31 | if exist $I.dif erase $I.dif 32 | copy syntax.c $I.c 33 | EOF 34 | grep 'CASE[ ]'$i run_test.txt >$TMP 35 | OPTS=`sed -e 's/^.*=/CPROTO/' $TMP` 36 | TEST=`sed -e 's/^.*=/CPROTO/' -e 's/-[at]//' $TMP` 37 | sed -e 's/^.*=/CPROTO/' $TMP | \ 38 | sed -e 's/^/..\\/' \ 39 | -e s/\$/\ -o$I.out\ -O$I.err\ $I.c/ \ 40 | -e s/\"//g >>$I.bat 41 | if [ ".$OPTS" != ".$TEST" ] 42 | then 43 | cat >>$I.bat <>$I.out 45 | type $I.c >>$I.out 46 | EOF 47 | fi 48 | cat >>$I.bat <>run_test.out 51 | if exist $I.out erase $I.out 52 | if exist $I.err erase $I.err 53 | goto end 54 | :saveit 55 | ren $I.out $I.ref 56 | :end 57 | erase $I.c 58 | EOF 59 | fi 60 | done 61 | -------------------------------------------------------------------------------- /testing/make_dcl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # $Id: make_dcl.sh,v 4.1 1998/01/20 00:59:45 cthuang Exp $ 3 | # 4 | # This makes a special ".dcl" file that can be executed from either UNIX or 5 | # VMS. We auto-generate the script (with this name) to avoid confusion on 6 | # MSDOS, which thinks ".com" files are even more special. 7 | # 8 | for i in $* 9 | do 10 | i="`echo $i | sed -e 's/[A-Za-z_.]//g'`" 11 | I="case$i" 12 | if [ -n "$i" -a ! -f $I.dcl ] 13 | then 14 | echo '** making '$I.dcl 15 | grep "CASE[ ]$i" run_test.txt | \ 16 | sed -e 's/^.*=/$CPROTO /' \ 17 | -e s/\$/\ -o$I.out\ $I.c/ >$I.dcl 18 | chmod 755 $I.dcl 19 | fi 20 | done 21 | -------------------------------------------------------------------------------- /testing/makefile: -------------------------------------------------------------------------------- 1 | # $Id: makefile,v 4.4 2004/03/09 01:31:56 tom Exp $ 2 | # make-file for CPROTO test directory 3 | 4 | THIS = cproto 5 | B = .. 6 | 7 | ####### (Standard Lists) ####################################################### 8 | REF_FILES=\ 9 | case01.ref case02.ref case03.ref case04.ref\ 10 | case05.ref case06.ref case07.ref case08.ref\ 11 | case09.ref case10.ref case11.ref case12.ref\ 12 | case13.ref case14.ref case15.ref case16.ref\ 13 | case17.ref case18.ref case19.ref case20.ref\ 14 | case21.ref 15 | 16 | TESTDATA=\ 17 | run_test.txt\ 18 | syntax.c\ 19 | $(COM_FILES)\ 20 | $(REF_FILES) 21 | 22 | SCRIPTS =\ 23 | make_dcl.sh\ 24 | testunix.sh\ 25 | run_test.sh run_test.com 26 | 27 | SOURCES = makefile descrip.mms $(SCRIPTS) $(TESTDATA) 28 | 29 | ####### (Standard Productions) ################################################# 30 | all: $(SOURCES) $B/$(THIS) 31 | @echo 'Type "make run_test"' 32 | 33 | scripts : $(SOURCES) 34 | make_bat.sh `fgrep dos run_test.txt |sed -e 's/=.*//'` 35 | make_dcl.sh `fgrep unix run_test.txt |sed -e 's/=.*//'` 36 | 37 | clean: 38 | - rm -f *.log *.out *.err *.tmp case*.c *.dcl 39 | 40 | distclean: clean 41 | 42 | realclean: distclean 43 | - rm -f *.dcl case*.bat 44 | 45 | run_test: $(SOURCES) 46 | date >>$@.out 47 | sh -c '(./run_test.sh 2>&1)' |tee -a $@.out 48 | -------------------------------------------------------------------------------- /testing/run_test.com: -------------------------------------------------------------------------------- 1 | $! $Id: run_test.com,v 4.3 1998/01/08 00:03:35 cthuang Exp $ 2 | $! Perform all regression-tests for CPROTO on VAX/VMS 3 | $ 4 | $ verify = F$VERIFY(0) 5 | $ path := 'F$ENVIRONMENT("DEFAULT") 6 | $ path := "''F$EXTRACT(0,F$LENGTH(path)-1,path)'.-]" 7 | $ CPROTO :== "$''path'cproto.exe" 8 | $ CPROTO1 :== "$''path'cproto1.exe" 9 | $ 10 | $ caselist="" 11 | $ open/read input_file run_test.txt 12 | $ read_loop: 13 | $ read/end=read_exit input_file sometext 14 | $ if f$locate("vms",sometext) .ne. f$length(sometext) 15 | $ then 16 | $ sometext = f$edit(sometext,"collapse,lowercase") 17 | $ sometext = f$extract(0, f$locate("=", sometext), sometext) 18 | $ caselist = "''caselist'/''sometext'" 19 | $ endif 20 | $ goto read_loop 21 | $ read_exit: 22 | $ close input_file 23 | $ caselist = "''caselist'/" 24 | $ 25 | $ 26 | $ if "''p1'" .eqs. "" 27 | $ then 28 | $ cases = "*" 29 | $ else 30 | $ cases = "''p1'" 31 | $ endif 32 | $ 33 | $ old_name = "" 34 | $ test_loop: 35 | $ ref_name = F$SEARCH("''cases'.ref;",1) 36 | $ if ref_name .eqs. "" 37 | $ then 38 | $ verify = F$VERIFY(verify) 39 | $ exit 40 | $ endif 41 | $ if "''old_name'" .eqs. "''ref_name'" then exit 42 | $ old_name = ref_name 43 | $ 44 | $ com_name = F$EXTRACT(0, F$LOCATE(".REF;", ref_name), ref_name) 45 | $ casename = F$PARSE(ref_name,,, "NAME", "SYNTAX_ONLY") 46 | $ casename = F$EDIT(casename,"LOWERCASE") 47 | $ case_num = F$EXTRACT(4, F$LENGTH(casename), casename) 48 | $ 49 | $ write sys$output "** ",ref_name 50 | $ if f$locate("/''casename'/", caselist) .eq. f$length(caselist) 51 | $ then 52 | $ write sys$output "...skipped" 53 | $ goto test_loop 54 | $ endif 55 | $ 56 | $ if F$SEARCH("''com_name'.dcl;", 2) .eqs. "" 57 | $ then 58 | $ write sys$output "?? no script for ", ref_name 59 | $ else 60 | $ if F$SEARCH("''com_name'.out") .nes. "" then delete 'com_name.out;* 61 | $ if F$SEARCH("''com_name'.err") .nes. "" then delete 'com_name.err;* 62 | $ if F$SEARCH("''casename'.c") .nes. "" then delete 'casename.c;* 63 | $ copy syntax.c 'casename.c; 64 | $ set noon 65 | $ define/user_mode sys$error 'casename.err 66 | $ @'com_name.dcl 67 | $ set on 68 | $ if F$SEARCH("''com_name'.out") .eqs. "" 69 | $ then 70 | $ write sys$output "?? no output from test" 71 | $ else 72 | $ if f$search("''casename'.c;-1") .nes. "" 73 | $ then 74 | $ diff/out='com_name 'casename.c 75 | $ if $severity .ne. 1 76 | $ then 77 | $ open/append output_file 'com_name.out 78 | $ write output_file "... edited ''casename'.c ..." 79 | $ close output_file 80 | $ append 'casename.c 'com_name.out 81 | $ endif 82 | $ endif 83 | $ diff/out='com_name 'com_name.out 'ref_name 84 | $ if $severity .ne. 1 85 | $ then 86 | $ write sys$output "?? test failed" 87 | $ type 'com_name.dif 88 | $ else 89 | $ delete 'com_name.dif;* 90 | $ if F$SEARCH("''com_name'.err") .nes. "" then delete 'com_name.err;* 91 | $ endif 92 | $ delete 'casename.c;*, 'com_name.out;* 93 | $ endif 94 | $ endif 95 | $ goto test_loop 96 | -------------------------------------------------------------------------------- /testing/run_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # $Id: run_test.sh,v 4.3 1998/01/08 00:03:37 cthuang Exp $ 3 | # 4 | # This test-script assumes that we can reproduce (except for minor whitespace) 5 | # the reference files listed in run_test.txt 6 | # 7 | echo '** '`date` 8 | for i in `grep 'CASE.*unix' run_test.txt | sed -e 's/^[^0-9]*//' -e 's/[ ].*//'` 9 | do 10 | ./testunix.sh $i 11 | done 12 | -------------------------------------------------------------------------------- /testing/run_test.txt: -------------------------------------------------------------------------------- 1 | $Id: run_test.txt,v 4.5 2004/03/09 23:30:11 tom Exp $ 2 | CASE 01 = unix, vms, dos, os2 = 3 | CASE 02 = unix, vms, dos, os2 = -f0 4 | CASE 03 = unix, vms, dos, os2 = -c -f1 5 | CASE 04 = unix, vms, dos, os2 = -c -f2 6 | CASE 05 = unix, vms, dos, os2 = -c -f3 7 | CASE 06 = unix, vms, dos = -c -f3 -v 8 | CASE 07 = unix, vms, dos = -c -f3 -v -e 9 | CASE 08 = unix, vms, dos = -c -f3 -v -e -m 10 | CASE 09 = unix, vms, dos = -c -f3 -v -"Pint\sfunc(\n\ta,\n\tb\n\t)" 11 | CASE 10 = unix = -"T" 12 | CASE 11 = unix = -l 13 | CASE 12 = unix, vms, dos, os2 = -s 14 | CASE 13 = unix = -l -s 15 | CASE 14 = unix = -l -x 16 | CASE 15 = apollo = -D__STDC__ -D__attribute='#attributes' -l apollo.c 17 | CASE 16 = unix, vms, dos = -a 18 | CASE 17 = unix, vms, dos = -t 19 | CASE 18 = unix, vms, dos, os2 = -f1 20 | CASE 19 = unix, vms, dos, os2 = -f2 21 | CASE 20 = unix, vms, dos, os2 = -f3 22 | CASE 21 = unix, vms, dos = -f3 -v -"Pint\sfunc(\n\ta,\n\tb\n\t)" 23 | CASE 22 = unix = -l -a 24 | CASE 23 = unix, vms, dos, os2 = -i 25 | CASE 24 = unix, vms, dos, os2 = -i -s 26 | -------------------------------------------------------------------------------- /testing/solaris.c: -------------------------------------------------------------------------------- 1 | /* $Id: solaris.c,v 4.1 1994/10/12 14:12:48 cthuang Exp $ */ 2 | /*LINTLIBRARY*/ 3 | /*LINT_EXTERN*/ 4 | /*LINT_SHADOWED*/ 5 | #include 6 | #include 7 | /*LINT_PREPRO2 8 | #define MAXDNAME 10 9 | */ 10 | #define MAXDNAME 10 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | /*#include -- true redef */ 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | #include 69 | #include 70 | #include 71 | #include 72 | #include 73 | #include 74 | #include 75 | #include 76 | #include 77 | #include 78 | #include 79 | #include 80 | #include 81 | #include 82 | #include 83 | /*#include */ 84 | #include 85 | #include 86 | #include 87 | #include 88 | #include 89 | #include 90 | #include 91 | #include 92 | #include 93 | /*#include */ 94 | #include 95 | #include 96 | #include 97 | #include 98 | #include 99 | #include 100 | #include 101 | #include 102 | #include 103 | #include 104 | #include 105 | #include 106 | #include 107 | #include 108 | #include 109 | /* #include conflict with search.h */ 110 | #include 111 | /* #include conflict with termcap.h */ 112 | /*LINT_PREPRO2 113 | #undef PC 114 | */ 115 | #undef PC 116 | #include 117 | #include 118 | #include 119 | #include 120 | #include 121 | #include 122 | #include 123 | #include 124 | #include 125 | #include 126 | #include 127 | #include 128 | #include 129 | #include 130 | #include 131 | #include 132 | #include 133 | #include 134 | /* #include - gcc prefers to give its own include-pathname here */ 135 | #include 136 | #include 137 | #include 138 | #include 139 | -------------------------------------------------------------------------------- /testing/syntax.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Define: 3 | * ERR_YACC to force yacc error reporting 4 | * ERR_LEX to force lex error reporting 5 | * ERR_CHECK to force compiler error reporting 6 | */ 7 | /* use one item from type-specifiers */ 8 | #ifdef ERR_YACC 9 | auto x; 10 | register x1; 11 | #endif /* ERR_YACC */ 12 | static x2; 13 | extern x3; 14 | #ifdef ERR_CC 15 | typedef x4; 16 | #endif 17 | typedef int x4t; 18 | #ifdef ERR_YACC 19 | void x5; 20 | #endif /* ERR_YACC */ 21 | char x6; 22 | short x7; 23 | int x8; 24 | long x9; 25 | float x10; 26 | double x11; 27 | signed x12; 28 | unsigned x13; 29 | struct x14; 30 | #ifdef ERR_CHECK 31 | struct x14a {}; 32 | struct {}; 33 | #endif /* ERR_CHECK */ 34 | union x15; 35 | enum x16; 36 | x4t; 37 | x4t x17; 38 | const x18; 39 | volatile x19; 40 | #ifdef ERR_CHECK 41 | junk x20; 42 | #endif /* ERR_CHECK */ 43 | 44 | extern int *asm (fopen, (__const char *__restrict __filename, __const char *__restrict __modes), fopen64); 45 | extern int __asm__ (mkstemp, (char *__template), mkstemp64); 46 | int __asm__ (mkstemp, (char *__template), mkstemp64); 47 | asm("something"); 48 | asm("something", "else"); 49 | asm("something", (this and that)); 50 | int asm(first, "something"); 51 | static int asm(first, "something"); 52 | extern int asm(first, "something"); 53 | 54 | typedef struct _first { 55 | int a:5; 56 | struct { 57 | int a,b; 58 | } b_struct; 59 | char b:16, b1:1; /* comment with };};}; */ 60 | long c:16, c1; 61 | short d:16, d1:8, d2; 62 | unsigned e:16; 63 | float f; 64 | double g; 65 | #ifdef ERR_CHECK 66 | long float f2; 67 | long double g2; 68 | #endif /* ERR_CHECK */ 69 | struct _first *link; 70 | } _FIRST; 71 | 72 | typedef int badStyle; 73 | void badFunc(int *badStyle) { } 74 | 75 | _FIRST first, last={0}, first_last[] = {{0},{1},{2},{3,{4}}}; 76 | 77 | struct _second { 78 | enum {true, false} bool; 79 | enum {wrong=1, right=3} values; 80 | } _SECOND; 81 | 82 | int i[] = {1, 83 | '\002', 84 | 03, 85 | 0x4, 86 | 0X5, 87 | 0x6a, 88 | 0X7b, 89 | 0x8aBcD, 90 | 9l, 91 | 10l, 92 | 11L}; 93 | float f[] = {5, 94 | #ifdef ERR_CHECK 95 | .5e, 96 | .5e+, 97 | 5e-, 98 | 5e, 99 | .34P1, 100 | 0x1.2.34, /* error */ 101 | #endif 102 | .5, 103 | 5.5, 104 | 5e5, 105 | 5e0, 106 | 5e-1, 107 | 5e+5 108 | #ifdef __STDC_VERSION__ /* ( C9X supports hexadecimal floating point ;-) */ 109 | 0x12.34+1, 110 | 0x12.34P1, 111 | .34e1, 112 | 0.34e1, 113 | 0x.34P1, 114 | #endif 115 | .0e-1 116 | }; 117 | 118 | int array[][10][20]; 119 | 120 | /* 121 | * This grammar can accept some illegal stuff too, in particular it will 122 | * permit some instances of parameter-names to be dropped. 123 | */ 124 | #ifdef ERR_CHECK 125 | #define P1 126 | #define P2 127 | #define P3 128 | #else 129 | #define P1 p1 130 | #define P2 p2 131 | #define P3 p3 132 | #endif 133 | 134 | /* ellipsis is legal, except in K&R style declaration */ 135 | 136 | dots_0(p1) { return(1); } 137 | 138 | dots_1(int p1, ...) { return(1); } 139 | 140 | #ifdef ERR_CHECK 141 | dots_2(p1, ...) { return(1); } 142 | #endif /* ERR_CHECK */ 143 | 144 | dots_3(int P1,char P2, ...) { return(1); } 145 | 146 | int dots_4(int,char, char *); 147 | char * dots_5(int,char, char *, ...); 148 | char * (dots_6)(int,char, char *, ...); 149 | 150 | extern _FIRST *xdots_0(p1); 151 | 152 | extern char *xdots_1(int p1, ...); 153 | 154 | #ifdef ERR_CHECK 155 | extern xdots_2(p1, ...); 156 | #endif /* ERR_CHECK */ 157 | 158 | extern xdots_3(int P1,char P2, ...); 159 | 160 | _FIRST *func1() { } 161 | _FIRST *func2(_FIRST *P1,int P2[],float p) { } 162 | 163 | int *(func_func)( 164 | #ifdef ERR_CHECK 165 | p1,p2,p3 166 | #endif /* ERR_CHECK */ 167 | ) { return(0); } 168 | 169 | extern float efunc0(p1,p2,p3); 170 | extern _FIRST efunc1(int p1, float p2,long P3); 171 | #ifdef ERR_CHECK 172 | extern _FIRST efunc1(int p1, float p2,p3); 173 | #endif /* ERR_CHECK */ 174 | 175 | 176 | typedef int bool; 177 | 178 | bool a1; 179 | static bool a2; 180 | extern bool a3; 181 | 182 | struct ZIP1 { int x1, y1; }; 183 | struct zip2 { int x2, y2; } z2; 184 | struct { int x3, y3; } z3; /* not ANSI, but mostly accepted */ 185 | 186 | static struct ZIP4 { int x4, y4; }; 187 | static struct zip5 { int x5, y5; } z5; 188 | static struct zip6 { int x6, y6; } z6, w6; 189 | static struct { int x7, y7; } z7; 190 | static struct { int x8, y8; } z8, w8; 191 | 192 | enum zap1 { a,b,c,d } what; 193 | enum zap2 what2; 194 | enum {a9,b9,c9,d9} what3; 195 | 196 | static char *zap = "alphabet/\ 197 | first/\ 198 | last"; 199 | typedef struct bong { 200 | int (*func)(); 201 | } BONG; 202 | 203 | typedef char *string; 204 | 205 | #ifdef ERR_LEX 206 | string s = "aaa\0000\ 207 | 208 | bbb"; 209 | #endif /* ERR_LEX */ 210 | 211 | extern int junk; 212 | 213 | main(argc, argv) 214 | register argc; 215 | #ifdef ERR_CHECK 216 | extern 217 | #endif /* ERR_CHECK */ 218 | char **argv; 219 | { 220 | } 221 | 222 | /*VARARGS*/ 223 | /* some other comment */ 224 | veryfunny(a,b,c) 225 | char *a; 226 | long b, c; 227 | { 228 | return 0; 229 | } 230 | 231 | /*VARARGS3*/ 232 | program(argv, y, zz, z1, z2, z3) 233 | string argv[]; /* first argument */ 234 | struct alpha { int x,z; } y; /* second argument */ 235 | { 236 | return(0); 237 | } 238 | 239 | junk0() { if(junk != 6) return; else junk++; } 240 | junk1() { return (0); } 241 | junk2() { } 242 | junk3() { return 1; } 243 | 244 | BONG *junk4() { } 245 | 246 | typedef int extern_junk; 247 | extern_junk *foo() { } 248 | 249 | typedef int void_junk; 250 | extern void_junk *foo2a() { } 251 | extern void_junk *foo2a(); 252 | void_junk *foo2() { } 253 | void_junk *foo_void(void_junk void_int) { } 254 | static void_junk *foo_void2() { } 255 | 256 | extern void (*sigdisp(int sig, void (*func)(int sig)))(int sig); 257 | 258 | void (*Sigdisp(int sig, void (*func)(int sig)))(int sig1) 259 | { /* nothing */ } 260 | 261 | void (*sigdisp2(sig, func))(int sig2) 262 | int sig; /* the signal value */ 263 | void (*func)(int sig); /* the function pointer */ 264 | { /* nothing again! */ } 265 | 266 | int (*K_R_INT_ptr(p1, p2))() long *p1; int p2; { return (*(int(*)())0); } 267 | 268 | int (*STD_INT_ptr(long* , int))(); 269 | 270 | void (*K_R_VOID_ptr(p1,p2))() long *p1; int p2; { return (*(void(*)())0); } 271 | 272 | void (*STD_VOID_ptr(long* , int))(); 273 | 274 | int *K_R_int_ptr(p1,p2) long *p1; int p2; { return (*(int **)0); } 275 | 276 | int **STD_int2_ptr(long* , int); 277 | 278 | int *STD_int_ptr(long* , int); 279 | 280 | void *K_R_void_ptr(p1,p2) long *p1; int p2; { return (*(void **)0); } 281 | 282 | void *STD_void_ptr(long* , int); 283 | 284 | int K_R_int_val(p1,p2) long *p1; int p2; { return (*(int *)0); } 285 | 286 | K_R_int_val2(p1,p2) long *p1; int p2; { return (*(int *)0); } 287 | 288 | int STD_int_val(long*, int); 289 | 290 | void K_R_void_val(p1,p2) long *p1; int p2; { /*void*/ } 291 | 292 | K_R_void_val2(p1,p2) long *p1; int p2; { /*void*/ } 293 | 294 | void STD_void_val(long* , int); 295 | 296 | extern xdots_3(int P1,char P2, ...); 297 | 298 | extern int (*XSetAfterFunction(long* , int (*) ( long*)))(); 299 | extern XQueryKeymap(long*, char [32]); 300 | extern Another(long*, int (*)()); 301 | 302 | extern GenFunc(int *, int *()); 303 | 304 | /* these are pointers, not actual functions */ 305 | extern void * (*__glob_opendir_hook) (const char *__directory); 306 | extern const char *(*__glob_readdir_hook) (void * __stream); 307 | extern void (*__glob_closedir_hook) (void * __stream); 308 | 309 | /* inline function */ 310 | int inline inline_func(double x) { return(0); } 311 | static int inline local_inline_func(double x) { return(0); } 312 | 313 | /* c99 types */ 314 | long long xxx = 1; 315 | char *xxs = "\x1234\?\u1234"; 316 | -------------------------------------------------------------------------------- /testing/test_dos.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem $Id: test_dos.bat,v 4.1 1998/01/08 00:19:27 cthuang Exp $ 3 | erase run_test.out 4 | for %%n in ( case*.bat ) do call %%n 5 | -------------------------------------------------------------------------------- /testing/testunix.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # $Id: testunix.sh,v 4.1 1998/01/20 00:59:47 cthuang Exp $ 3 | # 4 | # Test one or more given cases by number, creating the VMS test script 5 | # as a side-effect. 6 | # 7 | CPROTO=../cproto 8 | for i in $* 9 | do 10 | echo '** Case '$i 11 | I="case$i" 12 | ./make_dcl.sh $i 13 | 14 | rm -f $I.c $I.out $I.err $I.tmp 15 | cp syntax.c $I.c 16 | chmod +w $I.c 17 | 18 | . ./$I.dcl 2>$I.err 19 | 20 | if [ -f $I.ref ] 21 | then 22 | # When we select either the -a or -t options, CPROTO will edit 23 | # the input file. It also writes to the standard output the 24 | # prototypes that it is extracting. Since there's only one 25 | # reference for each test, I simply concatenate the edited file 26 | # after the test output, for use as a combined reference. 27 | if ( cmp -s $I.c syntax.c ) 28 | then 29 | rm -f $I.c 30 | else 31 | echo '... edited '$I.c' ...' >>$I.out 32 | cat $I.c >>$I.out 33 | rm -f $I.c 34 | fi 35 | 36 | if [ -f $I.out ] 37 | then 38 | diff -b -c $I.ref $I.out |fgrep -v 'No diff' >$I.tmp 39 | if [ -s $I.tmp ] 40 | then 41 | cat $I.err 42 | cat $I.tmp 43 | else 44 | echo '... ok' 45 | rm -f $I.out $I.tmp $I.err 46 | fi 47 | else 48 | echo '? no output '$I 49 | fi 50 | else 51 | echo '...saving reference for '$i 52 | mv $I.out $I.ref 53 | rm -f $I.err 54 | fi 55 | done 56 | -------------------------------------------------------------------------------- /testing/turboc.c: -------------------------------------------------------------------------------- 1 | /*LINT_EXTERN*/ 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | /* C++ only #include */ 9 | #include 10 | /* C++ only #include */ 11 | #include 12 | /* C++ only #include */ 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | /* C++ only #include */ 22 | /* C++ only #include */ 23 | #include 24 | #include 25 | /* C++ only #include */ 26 | /* C++ only #include */ 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | /* C++ only #include */ 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | /* ? #include */ 42 | #include 43 | #include 44 | /* C++ only #include */ 45 | #include 46 | #include 47 | /* C++ only #include */ 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | /* ? #include */ 54 | -------------------------------------------------------------------------------- /trace.c: -------------------------------------------------------------------------------- 1 | /* $Id: trace.c,v 4.6 2011/01/02 19:28:44 tom Exp $ 2 | * 3 | * Simple malloc debugging (for finding leaks) 4 | * 5 | * This is a cut-down version of a module I wrote originally for 'vile', it 6 | * requires an ANSI compiler. Its main purpose is to allow tracing problems in 7 | * a repeatable test, including malloc/free bugs -- T.Dickey 8 | */ 9 | #include /* interface of this module */ 10 | 11 | #if DOALLOC 12 | #undef malloc 13 | #undef realloc 14 | #undef free 15 | #endif /* DOALLOC */ 16 | 17 | #include 18 | 19 | #if TIME_WITH_SYS_TIME 20 | # include 21 | # include 22 | #else 23 | # if HAVE_SYS_TIME_H 24 | # include 25 | # else 26 | # include 27 | # endif 28 | #endif 29 | 30 | #include 31 | 32 | #define BEFORE 0 /* padding "before" allocated area */ 33 | #define AFTER 0 /* padding "after" allocated area */ 34 | 35 | #define BEFORE_PTR(ptr) (void *)((char *)(ptr) - BEFORE) 36 | 37 | void 38 | Where(char *file, int line) 39 | { 40 | fflush(stderr); 41 | printf("%s @%d\n", file, line); 42 | fflush(stdout); 43 | Trace("%s @%d\n", file, line); 44 | } 45 | 46 | void 47 | Trace(char *format,...) 48 | { 49 | static FILE *fp; 50 | va_list ap; 51 | 52 | if (!fp) 53 | fp = fopen("Trace.out", "w"); 54 | if (!fp) 55 | abort(); 56 | 57 | if (format != 0) { 58 | va_start(ap, format); 59 | vfprintf(fp, format, ap); 60 | va_end(ap); 61 | (void) fflush(fp); 62 | } else { 63 | (void) fclose(fp); 64 | (void) fflush(stdout); 65 | (void) fflush(stderr); 66 | } 67 | } 68 | 69 | #define SECS(tv) (tv.tv_sec + (tv.tv_usec / 1.0e6)) 70 | 71 | void 72 | Elapsed(char *msg) 73 | { 74 | #if HAVE_GETTIMEOFDAY 75 | static struct timeval tv0, tv1; 76 | static struct timezone tz0, tz1; 77 | static int init; 78 | if (!init++) 79 | gettimeofday(&tv0, &tz0); 80 | gettimeofday(&tv1, &tz1); 81 | Trace("%10.6f %s\n", SECS(tv1) - SECS(tv0), msg); 82 | tv0 = tv1; 83 | #endif 84 | } 85 | 86 | #ifdef apollo 87 | static int 88 | contains(char *ref, char *tst) 89 | { 90 | size_t len = strlen(ref); 91 | while (*tst) { 92 | if (!strncmp(ref, tst++, len)) 93 | return TRUE; 94 | } 95 | return FALSE; 96 | } 97 | #endif /* apollo */ 98 | 99 | void 100 | WalkBack(void) 101 | { 102 | #ifdef apollo 103 | static char *first = "\"WalkBack\"", *last = "\"unix_$main\""; 104 | auto FILE *pp; 105 | auto char bfr[BUFSIZ]; 106 | auto int ok = FALSE; 107 | static int count; 108 | 109 | Trace("%s %d\n", first, ++count); 110 | sprintf(bfr, "/com/tb %d", getpid()); 111 | if (!(pp = popen(bfr, "r"))) 112 | perror(bfr); 113 | 114 | while (fgets(bfr, sizeof(bfr), pp)) { 115 | if (ok && contains(last, bfr)) 116 | break; 117 | else if (contains(first, bfr)) 118 | ok = TRUE; 119 | else if (ok) 120 | Trace("%s", bfr); 121 | } 122 | (void) fclose(pp); 123 | #endif /* apollo */ 124 | } 125 | 126 | static long count_alloc, count_freed; 127 | 128 | void 129 | fail_alloc(char *msg, char *ptr) 130 | { 131 | Trace("%s: %p\n", msg, ptr); 132 | Trace("allocs %ld, frees %ld\n", count_alloc, count_freed); 133 | WalkBack(); 134 | #ifdef NO_LEAKS 135 | show_alloc(); 136 | #endif 137 | Trace((char *) 0); 138 | abort(); 139 | } 140 | 141 | #if DOALLOC 142 | #undef malloc 143 | #undef realloc 144 | #undef free 145 | 146 | typedef struct { 147 | long size; /* ...its size */ 148 | char *text; /* the actual segment */ 149 | int note; /* ...last value of 'count_alloc' */ 150 | } AREA; 151 | 152 | static AREA area[DOALLOC]; 153 | 154 | static long maxAllocated, /* maximum # of bytes allocated */ 155 | nowAllocated, /* current # of bytes allocated */ 156 | nowPending, /* current end of 'area[]' table */ 157 | maxPending; /* maximum # of segments allocated */ 158 | 159 | static int 160 | FindArea(char *ptr) 161 | { 162 | register int j; 163 | for (j = 0; j < DOALLOC; j++) 164 | if (area[j].text == ptr) { 165 | if (j >= nowPending) { 166 | nowPending = j + 1; 167 | if (nowPending > maxPending) 168 | maxPending = nowPending; 169 | } 170 | return j; 171 | } 172 | return -1; 173 | } 174 | 175 | static int 176 | record_freed(char *ptr) 177 | { 178 | register int j; 179 | if ((j = FindArea(ptr)) >= 0) { 180 | nowAllocated -= area[j].size; 181 | /*memset(ptr, 0xdf, area[j].size); -* poison */ 182 | area[j].size = 0; 183 | area[j].text = 0; 184 | area[j].note = count_freed; 185 | if ((j + 1) == nowPending) { 186 | register int k; 187 | for (k = j; (k >= 0) && !area[k].size; k--) 188 | nowPending = k; 189 | } 190 | } 191 | return j; 192 | } 193 | 194 | static int 195 | record_alloc(char *newp, char *oldp, unsigned len) 196 | { 197 | register int j; 198 | 199 | if (newp == oldp) { 200 | if ((j = FindArea(oldp)) >= 0) { 201 | nowAllocated -= area[j].size; 202 | area[j].size = len; 203 | area[j].note = count_alloc; 204 | } else 205 | fail_alloc("could not find", oldp); 206 | } else { 207 | if (oldp != 0) 208 | record_freed(oldp); 209 | if ((j = FindArea((char *) 0)) >= 0) { 210 | area[j].text = newp; 211 | area[j].size = len; 212 | area[j].note = count_alloc; 213 | } else 214 | fail_alloc("no room in table", newp); 215 | } 216 | 217 | nowAllocated += len; 218 | if (nowAllocated > maxAllocated) 219 | maxAllocated = nowAllocated; 220 | return len; 221 | } 222 | 223 | #define OK_ALLOC(p,q,n) ((p != 0) && (record_alloc(p,q,n) >= 0)) 224 | #define OK_FREE(p) ((p != 0) && (record_freed(p) >= 0)) 225 | #else 226 | #define OK_ALLOC(p,q,n) (p != 0) 227 | #define OK_FREE(p) (p != 0) 228 | #endif /* DOALLOC */ 229 | 230 | #ifdef DEBUG2 231 | #define LOG_PTR(msg,num) Trace("%s %p\n", msg, num) 232 | #define LOG_LEN(msg,num) Trace("%s %d\n", msg, num) 233 | #else 234 | #define LOG_PTR(msg,num) 235 | #define LOG_LEN(msg,num) 236 | #endif 237 | 238 | /************************************************************************ 239 | * public entrypoints * 240 | ************************************************************************/ 241 | #if DOALLOC 242 | void * 243 | doalloc(void *oldp, unsigned amount) 244 | { 245 | char *newp; 246 | 247 | if (oldp != 0) 248 | oldp = BEFORE_PTR(oldp); 249 | count_alloc += (oldp == 0); 250 | #if 0 251 | if ((count_alloc > 99914 && count_alloc < 99920)) { 252 | Trace("doalloc #%d\n", count_alloc); 253 | WalkBack(); 254 | } 255 | #endif 256 | LOG_LEN("allocate", amount); 257 | LOG_PTR(" old = ", oldp); 258 | amount += (BEFORE + AFTER); /* patch */ 259 | 260 | newp = (oldp != 0) ? realloc(oldp, amount) : malloc(amount); 261 | if (!OK_ALLOC(newp, oldp, amount)) { 262 | perror("doalloc"); 263 | fail_alloc("doalloc", oldp); 264 | /*NOT REACHED */ 265 | } 266 | 267 | LOG_PTR(" new = ", newp); 268 | return (void *) (newp + BEFORE); 269 | } 270 | 271 | /* 272 | * Entrypoint so we can validate pointers 273 | */ 274 | void 275 | dofree(void *oldp) 276 | { 277 | oldp = BEFORE_PTR(oldp); 278 | count_freed++; 279 | LOG_PTR("dealloc ", oldp); 280 | 281 | if (OK_FREE(oldp)) { 282 | free(oldp); 283 | return; 284 | } 285 | 286 | fail_alloc("free (not found)", oldp); 287 | } 288 | #endif 289 | 290 | void 291 | show_alloc(void) 292 | { 293 | #if DOALLOC 294 | static char *format = ".. %-24.24s %10ld\n"; 295 | 296 | Trace("** allocator metrics:\n"); 297 | Trace(format, "allocs:", count_alloc); 298 | Trace(format, "frees:", count_freed); 299 | { 300 | register int j, count = 0; 301 | register long total = 0; 302 | 303 | for (j = 0; j < nowPending; j++) { 304 | if (area[j].text) { 305 | if (count++ < 10) 306 | Trace("...%d) %ld bytes in alloc #%d:%p\n", 307 | j, 308 | area[j].size, 309 | area[j].note, 310 | area[j].text); 311 | total += area[j].size; 312 | } 313 | } 314 | Trace(format, "total bytes allocated:", total); 315 | Trace(format, "current bytes allocated:", nowAllocated); 316 | Trace(format, "maximum bytes allocated:", maxAllocated); 317 | Trace(format, "segment-table length:", nowPending); 318 | Trace(format, "current # of segments:", (long) count); 319 | Trace(format, "maximum # of segments:", maxPending); 320 | } 321 | #endif 322 | } 323 | -------------------------------------------------------------------------------- /trace.h: -------------------------------------------------------------------------------- 1 | /* $Id: trace.h,v 4.4 2011/01/02 18:59:05 tom Exp $ */ 2 | 3 | #ifndef TRACE_H 4 | #define TRACE_H 5 | 6 | #include 7 | 8 | extern void Where(char *f, int n); 9 | extern void Trace(char *f, ...) GCC_PRINTFLIKE(1,2); 10 | extern void show_alloc(void); 11 | extern void Elapsed(char *msg); 12 | extern void WalkBack(void); 13 | extern void fail_alloc(char *msg, char *ptr); 14 | 15 | #ifdef DOALLOC 16 | extern void *doalloc(void *,unsigned); 17 | extern void dofree(void *); 18 | 19 | #define malloc(n) doalloc(0,n) 20 | #define realloc(p,n) doalloc(p,n) 21 | #define free(n) dofree(n) 22 | #endif 23 | 24 | #endif /* TRACE_H */ 25 | -------------------------------------------------------------------------------- /vms/README: -------------------------------------------------------------------------------- 1 | The files in this directory are used to build on VMS. 2 | 3 | descrip.mms makefile for VAX C 4 | -------------------------------------------------------------------------------- /vms/descrip.mms: -------------------------------------------------------------------------------- 1 | # $Id: descrip.mms,v 4.2 2005/12/08 20:34:07 tom Exp $ 2 | # VAX/VMS "mms" script for CPROTO 3 | 4 | THIS = cproto 5 | 6 | #### Start of system configuration section. #### 7 | 8 | LEX = flex 9 | #YACC = bison /fixed_outfiles 10 | YACC = bison 11 | 12 | DEFINES = /Define=(STDC_HEADERS) 13 | CFLAGS = /Include=([]) $(DEFINES) 14 | 15 | #### End of system configuration section. #### 16 | 17 | DOC_FILES = \ 18 | README \ 19 | CHANGES \ 20 | $(THIS).1 21 | 22 | H_FILES = \ 23 | yyerror.c \ 24 | system.h \ 25 | $(THIS).h \ 26 | patchlev.h \ 27 | semantic.h \ 28 | symbol.h 29 | 30 | C_FILES = \ 31 | $(THIS).c \ 32 | lintlibs.c \ 33 | semantic.c \ 34 | strkey.c \ 35 | symbol.c \ 36 | getopt.c 37 | 38 | AUX_FILES = \ 39 | mkdirs.sh \ 40 | lex.l \ 41 | grammar.y 42 | 43 | LEX_YY = lexyy 44 | Y_TAB = y_tab 45 | 46 | JUNK = \ 47 | $(LEX_YY).c \ 48 | $(Y_TAB).c 49 | 50 | OBJECTS = \ 51 | $(THIS).obj, \ 52 | lintlibs.obj, \ 53 | semantic.obj, \ 54 | strkey.obj, \ 55 | symbol.obj, \ 56 | $(Y_TAB).obj, \ 57 | getopt.obj 58 | 59 | SOURCES = $(DOC_FILES) $(H_FILES) $(C_FILES) $(AUX_FILES) 60 | 61 | all : $(THIS).exe 62 | @ write sys$output "** produced $?" 63 | 64 | $(THIS).exe : $(OBJECTS) 65 | $(LINK)/exec=$(THIS) $(OBJECTS),sys$library:vaxcrtl/lib,tools$$library:alloca.obj 66 | 67 | $(Y_TAB).c : grammar.y 68 | $(YACC) grammar.y/fixed_outfiles 69 | 70 | $(LEX_YY).c : lex.l 71 | $(LEX) lex.l 72 | 73 | clean : 74 | - if f$search("*.obj").nes."" then dele/nolog *.obj;* 75 | - if f$search("*.lis").nes."" then dele/nolog *.lis;* 76 | - if f$search("*.log").nes."" then dele/nolog *.log;* 77 | - if f$search("*.map").nes."" then dele/nolog *.map;* 78 | - if f$search("$(Y_TAB).c").nes."" then dele/nolog $(Y_TAB).c;* 79 | - if f$search("$(LEX_YY).c").nes."" then dele/nolog $(LEX_YY).c;* 80 | 81 | clobber : clean 82 | - if f$search("$(THIS).exe").nes."" then dele/nolog $(THIS).exe;* 83 | 84 | cproto.obj : cproto.h system.h patchlev.h 85 | lintlibs.obj : cproto.h system.h semantic.h symbol.h 86 | semantic.obj : cproto.h system.h semantic.h 87 | strkey.obj : cproto.h system.h 88 | symbol.obj : cproto.h system.h symbol.h 89 | $(Y_TAB).obj : cproto.h system.h symbol.h semantic.h $(LEX_YY).c yyerror.c $(Y_TAB).c 90 | $(CC) $(CFLAGS) $(Y_TAB).c 91 | -------------------------------------------------------------------------------- /win32/README: -------------------------------------------------------------------------------- 1 | The files in this directory are used to build on Windows 95 and Windows NT. 2 | 3 | watcom.mak makefile for Watcom C/C++ 4 | -------------------------------------------------------------------------------- /win32/watcom.mak: -------------------------------------------------------------------------------- 1 | # $Id: watcom.mak,v 4.3 1998/01/22 19:49:44 cthuang Exp $ 2 | # 3 | # Watcom makefile for C prototype generator 4 | # To use this file, do 5 | # 6 | # wmake /u /f watcom.mak 7 | 8 | PROGRAM = cproto 9 | DEFINES = 10 | INCLUDES = -I.. -I..\porting 11 | 12 | LEX = lex 13 | YACC = yacc 14 | CC = wcl386 15 | CFLAGS = $(DEFINES) $(INCLUDES) 16 | LIBS = 17 | 18 | .c: .. 19 | 20 | .c.obj: .AUTODEPEND 21 | $(CC) $(CFLAGS) /c $< 22 | 23 | O = .obj 24 | OBJECTS = \ 25 | cproto$(O) \ 26 | getopt$(O) \ 27 | lintlibs$(O) \ 28 | semantic$(O) \ 29 | strkey$(O) \ 30 | symbol$(O) \ 31 | y_tab$(O) 32 | 33 | all: $(PROGRAM).exe 34 | 35 | $(PROGRAM).exe: $(OBJECTS) 36 | $(CC) $(CFLAGS) /fe=$@ $(OBJECTS) $(LIBS) 37 | 38 | getopt$(O): ..\porting\getopt.c 39 | $(CC) $(CFLAGS) /c ..\porting\getopt.c 40 | 41 | cproto.man: cproto.1 42 | cawf -man $*.1 | bsfilt - >$*.man 43 | 44 | clean: 45 | -del $(PROGRAM).exe 46 | -del *$(O) 47 | -del *.err 48 | -del *.log 49 | -del *.out 50 | -del case*.c 51 | -------------------------------------------------------------------------------- /yyerror.c: -------------------------------------------------------------------------------- 1 | /* $Id: yyerror.c,v 4.9 2010/07/14 09:57:46 tom Exp $ 2 | * 3 | * This file is included into grammar.y to provide the 'yyerror()' function. 4 | * If the yacc/bison parser is one that we know how to backtrack, we'll augment 5 | * the "syntax error" message with information that shows what type of token we 6 | * expected. 7 | */ 8 | 9 | #ifndef UCH 10 | #define UCH(c) ((unsigned char)(c)) 11 | #endif 12 | 13 | /* 'yyerror()' has to be a macro, since it must be expanded inline to subvert 14 | * the internal state of 'yyparse()'. 15 | */ 16 | 17 | #if BISON_HAS_YYTNAME /* bison 1.22 */ 18 | #if !defined(YYFLAG) 19 | #define YYFLAG YYPACT_NINF /* yabb (yet-another-bison-bug) */ 20 | #endif 21 | #if YYDEBUG 22 | /* this is better than defining YYERROR_VERBOSE */ 23 | #define yyerror(text) {\ 24 | register int n, c1, count = 0;\ 25 | yaccError(text);\ 26 | if (yypact[yystate] != YYFLAG) { \ 27 | for (c1 = 0; c1 < YYLAST; c1++) {\ 28 | n = yypact[yystate] + c1;\ 29 | if (n >= 0 && n < YYLAST\ 30 | && yycheck[n] == c1 && yytname[c1] != 0)\ 31 | yaccExpected(yytname[c1], count++);\ 32 | }\ 33 | }\ 34 | yaccExpected("", -1);\ 35 | } 36 | #endif 37 | #endif /* BISON_HAS_YYTNAME */ 38 | 39 | #if YACC_HAS_YYTOKS_2 40 | #undef YACC_HAS_YYTOKS 41 | #define YACC_HAS_YYTOKS 1 42 | #define YaccState yy_state 43 | #endif 44 | 45 | #if YACC_HAS_YYTOKS /* Solaris, Gould */ 46 | #if YYDEBUG 47 | #ifndef YaccState 48 | #define YaccState yystate /* sometimes 'yy_state' */ 49 | #endif 50 | #define yyerror(text) {\ 51 | register int n, x, c1, y, count = 0;\ 52 | yaccError(text);\ 53 | if (((n = yypact[YaccState]) > YYFLAG) && (n < YYLAST)) {\ 54 | for (x = ((n > 0) ? n : 0); x < YYLAST; ++x) {\ 55 | c1 = x - n;\ 56 | if ((yychk[yyact[x]] == c1) && (c1 != YYERRCODE)) {\ 57 | if (isascii(UCH(c1))) {\ 58 | static char tmp[] = "'%'";\ 59 | tmp[1] = c1;\ 60 | yaccExpected(tmp, count++);\ 61 | } else {\ 62 | for (y = 0; yytoks[y].t_val >= 0; y++) {\ 63 | if (yytoks[y].t_val == c1) {\ 64 | yaccExpected(yytoks[y].t_name, count++);\ 65 | break;\ 66 | }\ 67 | }\ 68 | }\ 69 | }\ 70 | }\ 71 | }\ 72 | yaccExpected("", -1);\ 73 | } 74 | #endif 75 | #endif /* YACC_HAS_YYTOKS */ 76 | 77 | #if YACC_HAS_YYNAME /* Linux's yacc */ 78 | #if YYDEBUG 79 | #define yyerror(text) {\ 80 | register int n, x, c1, count = 0;\ 81 | yaccError(text);\ 82 | if (((n = yysindex[yystate]) != 0) && (n < YYTABLESIZE)) {\ 83 | for (x = ((n > 0) ? n : 0); x < YYTABLESIZE; ++x) {\ 84 | c1 = x - n;\ 85 | if ((yycheck[x] == c1) && (c1 != YYERRCODE)) {\ 86 | yaccExpected(yyname[c1] ? yyname[c1] : "illegal symbol",\ 87 | count++);\ 88 | }\ 89 | }\ 90 | }\ 91 | yaccExpected("", -1);\ 92 | } 93 | #endif 94 | #endif /* YACC_HAS_YYNAME */ 95 | 96 | /* 97 | * Any way we define it, 'yyerror()' is a real function (that we provide, 98 | * rather than use the one from a library). 99 | */ 100 | static void yaccError(const char *); 101 | 102 | #ifdef yyerror 103 | static int 104 | compar(const void *p1, const void *p2) 105 | { 106 | const char *a = *(const char *const *) p1; 107 | const char *b = *(const char *const *) p2; 108 | return strcmp(a, b); 109 | } 110 | 111 | #define MSGLEN 80 112 | 113 | static void 114 | yaccExpected(const char *s, int count) 115 | { 116 | static struct { 117 | const char *actual, *name; 118 | } tbl[] = { 119 | { 120 | "...", "T_ELLIPSIS" 121 | }, 122 | { 123 | "[]", "T_BRACKETS" 124 | }, 125 | { 126 | "{", "T_LBRACE" 127 | }, 128 | { 129 | "}", "T_MATCHRBRACE" 130 | }, 131 | }; 132 | unsigned j; 133 | int k, x; 134 | unsigned n; 135 | const char *t = s; 136 | char *tt; 137 | const char *tag; 138 | char tmp[MSGLEN]; 139 | 140 | static unsigned have; 141 | static unsigned used; 142 | static char **vec; 143 | 144 | if (count < 0) { 145 | if (used != 0) { 146 | if (used > 1) 147 | qsort((char *) vec, used, sizeof(vec[0]), compar); 148 | /* limit length of error message */ 149 | k = MSGLEN - (int) (strlen(vec[used - 1]) + 2); 150 | for (j = 0; j < used; j++) { 151 | tag = j ? " " : "Expected: "; 152 | s = vec[j]; 153 | if (j != (used - 1)) { 154 | x = (int) (strlen(s) + strlen(tag)); 155 | if (k <= 0) 156 | continue; 157 | else if ((k - x) <= 0) 158 | s = "..."; 159 | k -= x; 160 | } 161 | fprintf(stderr, "%s%s", tag, s); 162 | } 163 | fprintf(stderr, "\n"); 164 | while (used-- != 0) { 165 | free(vec[used]); 166 | vec[used] = 0; 167 | } 168 | } 169 | used = 0; 170 | } else { 171 | int found = FALSE; 172 | 173 | strcpy(tmp, t); 174 | if (!strncmp(t, "T_", 2)) { 175 | for (j = 0; j < sizeof(tbl) / sizeof(tbl[0]); j++) { 176 | if (!strcmp(t, tbl[j].name)) { 177 | t = tbl[j].actual; 178 | found = TRUE; 179 | break; 180 | } 181 | } 182 | if (!found) { 183 | tt = strncpy(tmp, t + 2, sizeof(tmp) - 1); 184 | for (k = 0; tt[k] != '\0'; k++) { 185 | if (tt[k] == '_') 186 | tt[k] = '-'; 187 | else if (isalpha(UCH(tt[k])) && isupper(UCH(tt[k]))) 188 | tt[k] = (char) tolower(UCH(tt[k])); 189 | } 190 | } 191 | } 192 | if ((unsigned) count >= have) { 193 | have = (unsigned) (count + 10); 194 | if (vec == 0) { 195 | vec = (char **) malloc(have * sizeof(*vec)); 196 | } else { 197 | vec = (char **) realloc(vec, have * sizeof(*vec)); 198 | } 199 | for (n = used; n < have; n++) 200 | vec[n] = 0; 201 | } 202 | if (vec[count] != 0) { 203 | free(vec[count]); 204 | } 205 | vec[count] = xstrdup(found ? t : tmp); 206 | used = (unsigned) (count + 1); 207 | } 208 | } 209 | 210 | #else 211 | #define yyerror(s) yaccError(s) 212 | #endif /* yyerror */ 213 | --------------------------------------------------------------------------------