home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume38 / unproto / patch02 < prev    next >
Encoding:
Text File  |  1993-06-19  |  13.4 KB  |  424 lines

  1. Newsgroups: comp.sources.misc
  2. From: wietse@wzv.win.tue.nl (Wietse Venema)
  3. Subject: v38i013: unproto - ANSI C with old-style C compiler, Patch02
  4. Message-ID: <1993Jun20.230147.9326@sparky.imd.sterling.com>
  5. X-Md4-Signature: 3481182d4ce7b771221fb35f96d59f11
  6. Sender: kent@sparky.imd.sterling.com (Kent Landfield)
  7. Organization: Eindhoven University of Technology, The Netherlands
  8. Date: Sun, 20 Jun 1993 23:01:47 GMT
  9. Approved: kent@sparky.imd.sterling.com
  10.  
  11. Submitted-by: wietse@wzv.win.tue.nl (Wietse Venema)
  12. Posting-number: Volume 38, Issue 13
  13. Archive-name: unproto/patch02
  14. Environment: UNIX, PCC
  15. Patch-To: unproto: Volume 27, Issue 85-86
  16.  
  17. This is the second patch to the unproto release that appeared in this
  18. news group (volume 27, issues 85 and 86). The first patch appeared in
  19. volume 28, issue 69.  A fully patched version of the unproto source can
  20. be obtained from ftp.win.tue.nl, file /pub/unix/unproto5.shar.Z
  21.  
  22. This patch fixes one bug and adds more support for weird compilers.
  23.  
  24. - Incorrect code could be generated for functions with anonymous struct
  25. declarations within argument lists. For example, foo(struct {...} blah)
  26. instead of properly-used typedefs. The result would be rejected by the
  27. compiler, so no harm was done.
  28.  
  29. - Support for systems with a non-empty "va_dcl" definition in their
  30. varargs.h system include file. For example, the M88k Greenhills C
  31. compiler.
  32.  
  33. In addition, the unprototyper now comes with an `acc' shell script that
  34. emulates most of an ANSI C compiler with SunOS 4.x, Ultrix 4.x, System
  35. V.2 and other UNIX versions, and that hides the gory details of how to
  36. run alternate C preprocessors.
  37.  
  38.         Wietse Venema
  39.         wietse@wzv.win.tue.nl
  40.         Mathematics and Computing Science
  41.         Eindhoven University of Technology
  42.         The Netherlands
  43.  
  44. *** ./example.c-    Sat Feb 15 17:17:00 1992
  45. --- ./example.c    Fri Jun 18 22:29:47 1993
  46. ***************
  47. *** 1,5 ****
  48.    /*
  49. !   * @(#) example.c 1.4 92/02/15 17:17:05
  50.     * 
  51.     * Examples of things that can be done with the unproto package
  52.     */
  53. --- 1,5 ----
  54.    /*
  55. !   * @(#) example.c 1.5 93/06/18 22:29:46
  56.     * 
  57.     * Examples of things that can be done with the unproto package
  58.     */
  59. ***************
  60. *** 214,216 ****
  61. --- 214,222 ----
  62.   int (*(*test26(foo))())()
  63.   long foo;
  64.   { /* body */ }
  65. + #define ARGSTR()   struct {int l; char c[1];}
  66. + void functie(ARGSTR() *cmdlin, ARGSTR() *c1)
  67. + {
  68. + }
  69. *** ./unproto.c-    Sat Feb 15 17:17:12 1992
  70. --- ./unproto.c    Fri Jun 18 22:29:39 1993
  71. ***************
  72. *** 125,136 ****
  73.   /*    Department of Mathematics and Computer Science
  74.   /*    Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  75.   /* LAST MODIFICATION
  76. ! /*    92/02/15 17:17:09
  77.   /* VERSION/RELEASE
  78. ! /*    1.5
  79.   /*--*/
  80.   
  81. ! static char unproto_sccsid[] = "@(#) unproto.c 1.5 92/02/15 17:17:09";
  82.   
  83.   /* C library */
  84.   
  85. --- 125,136 ----
  86.   /*    Department of Mathematics and Computer Science
  87.   /*    Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  88.   /* LAST MODIFICATION
  89. ! /*    93/06/18 22:29:37
  90.   /* VERSION/RELEASE
  91. ! /*    1.6
  92.   /*--*/
  93.   
  94. ! static char unproto_sccsid[] = "@(#) unproto.c 1.6 93/06/18 22:29:37";
  95.   
  96.   /* C library */
  97.   
  98. ***************
  99. *** 370,376 ****
  100.   
  101.       if (!LAST_ARG_AND_EQUAL(t->head, VOID_ARG)) {
  102.       for (s = t->head; s; s = s->next) {    /* foreach argument... */
  103. !         if (!LAST_ARG_AND_EQUAL(s, "...")) {
  104.           if (s->head != s->tail) {    /* really new-style argument? */
  105.               show_type(s);        /* rewrite type info */
  106.               put_ch(';');
  107. --- 370,381 ----
  108.   
  109.       if (!LAST_ARG_AND_EQUAL(t->head, VOID_ARG)) {
  110.       for (s = t->head; s; s = s->next) {    /* foreach argument... */
  111. !         if (LAST_ARG_AND_EQUAL(s, "...")) {
  112. ! #ifdef _VA_DCL_                    /* see ./stdarg.h */
  113. !         put_str(_VA_DCL_);        /* varargs magic */
  114. !         put_nl();            /* make output look nicer */
  115. ! #endif
  116. !         } else {
  117.           if (s->head != s->tail) {    /* really new-style argument? */
  118.               show_type(s);        /* rewrite type info */
  119.               put_ch(';');
  120. ***************
  121. *** 463,468 ****
  122. --- 468,494 ----
  123.       fpf_header_types(l1);            /* show argument types */
  124.   }
  125.   
  126. + /* skip_enclosed - skip over enclosed tokens */
  127. + static struct token *skip_enclosed(p, stop)
  128. + register struct token *p;
  129. + register int stop;
  130. + {
  131. +     register int start = p->tokno;
  132. +     /* Always return a pointer to the last processed token, never NULL. */
  133. +     while (p->next) {
  134. +     p = p->next;
  135. +     if (p->tokno == start) {
  136. +         p = skip_enclosed(p, stop);        /* recurse */
  137. +     } else if (p->tokno == stop) {
  138. +         break;                /* done */
  139. +     }
  140. +     }
  141. +     return (p);
  142. + }
  143.   /* show_arg_name - extract argument name from argument type info */
  144.   
  145.   static void show_arg_name(s)
  146. ***************
  147. *** 477,482 ****
  148. --- 503,510 ----
  149.       for (p = s->head; p; p = p->next) {
  150.           if (p->tokno == TOK_WORD) {
  151.           t = p;                /* remember last word */
  152. +         } else if (p->tokno == '{') {
  153. +         p = skip_enclosed(p, '}');    /* skip structured stuff */
  154.           } else if (p->tokno == '[') {
  155.           break;                /* dimension may be a macro */
  156.           } else if (IS_FUNC_PTR_TYPE(p)) {
  157. *** ./acc.sh-    Fri Jun 18 22:06:05 1993
  158. --- ./acc.sh    Fri Jun 18 22:29:43 1993
  159. ***************
  160. *** 0 ****
  161. --- 1,35 ----
  162. + #!/bin/sh
  163. + # @(#) acc.sh 1.1 93/06/18 22:29:42
  164. + #
  165. + # Script to emulate most of an ANSI C compiler with a traditional UNIX
  166. + # C compiler.
  167. + # INCDIR should be the directory with auxiliary include files from the
  168. + # unproto source distribution (stdarg.h, stdlib.h, stddef.h, and other
  169. + # stuff that is missing from your compilation environment). With Ultrix
  170. + # 4.[0-2] you need unproto's stdarg.h even though the system provides
  171. + # one.
  172. + #
  173. + INCDIR=.
  174. + # CPPDIR should be the directory with the unprototypeing cpp filter
  175. + # (preferably the version with the PIPE_THROUGH_CPP feature).
  176. + #
  177. + CPPDIR=.
  178. + # DEFINES: you will want to define volatile and const, and maybe even
  179. + # __STDC__.
  180. + #
  181. + DEFINES="-Dvolatile= -Dconst= -D__STDC__"
  182. + # Possible problem: INCDIR should be listed after the user-specified -I
  183. + # command-line options, not before them as we do here. This is a problem
  184. + # only if you attempt to redefine system libraries.
  185. + #
  186. + # Choose one of the commands below that is appropriate for your system.
  187. + #
  188. + exec cc -Qpath ${CPPDIR} -I${INCDIR} ${DEFINES} "$@"    # SunOS 4.x
  189. + exec cc -tp -h${CPPDIR} -B -I${INCDIR} ${DEFINES} "$@"    # Ultrix 4.2
  190. + exec cc -Yp,${CPPDIR} -I${INCDIR} ${DEFINES} "$@"    # M88 SysV.3
  191. + exec cc -B${CPPDIR}/ -tp -I${INCDIR} ${DEFINES} "$@"    # System V.2
  192. *** ./stdarg.h-    Wed Jan 15 21:53:25 1992
  193. --- ./stdarg.h    Fri Jun 18 22:29:45 1993
  194. ***************
  195. *** 1,5 ****
  196.    /*
  197. !   * @(#) stdarg.h 1.3 92/01/15 21:53:24
  198.     * 
  199.     * Sample stdarg.h file for use with the unproto filter.
  200.     * 
  201. --- 1,5 ----
  202.    /*
  203. !   * @(#) stdarg.h 1.4 93/06/18 22:29:44
  204.     * 
  205.     * Sample stdarg.h file for use with the unproto filter.
  206.     * 
  207. ***************
  208. *** 7,16 ****
  209. --- 7,22 ----
  210.     * 
  211.     * 1 - On systems that do not have a /usr/include/stdarg.h file, it should be
  212.     * included by C source files that implement ANSI-style variadic functions.
  213. +   * Ultrix 4.[0-2] comes with stdarg.h but still needs the one that is
  214. +   * provided with the unproto filter.
  215.     * 
  216.     * 2 - To configure the unprototyper itself. If the _VA_ALIST_ macro is
  217.     * defined, its value will appear in the place of the "..." at the end of
  218.     * argument lists of variadic function *definitions* (not declarations).
  219. +   * Some compilers (such as Greenhills m88k) have a non-empty va_dcl
  220. +   * definition in the system header file varargs.h. If that is the case,
  221. +   * define "_VA_DCL_" with the same value as va_dcl. If _VA_DCL_ is defined,
  222. +   * the unprototyper will emit its value just before the opening "{".
  223.     * 
  224.     * Compilers that always pass arguments via the stack can use the default code
  225.     * at the end of this file (this usually applies for the vax, mc68k and
  226. ***************
  227. *** 34,44 ****
  228.   #define va_arg(ap, type)    ((type *) __builtin_va_arg_incr((type *) ap))[0]
  229.   #define va_end(ap)
  230.   
  231. ! #elif defined(mips) /* tested with Ultrix 4.0 and 4.2 */
  232.   
  233.   #define _VA_ALIST_        "va_alist"
  234. ! #include <stdarg.h>        /* huh? */
  235.   
  236.   #else /* vax, mc68k, 80*86 */
  237.   
  238.   typedef char *va_list;
  239. --- 40,78 ----
  240.   #define va_arg(ap, type)    ((type *) __builtin_va_arg_incr((type *) ap))[0]
  241.   #define va_end(ap)
  242.   
  243. ! #else
  244. ! #ifdef mips /* tested with Ultrix 4.0 and 4.2 */
  245.   
  246.   #define _VA_ALIST_        "va_alist"
  247. ! #include "/usr/include/stdarg.h"
  248.   
  249. + #else
  250. + #ifdef m88k /* Motorola SYSTEM V/88 R32V3 */
  251. + #define _VA_ALIST_        "va_alist"
  252. + #define _VA_DCL_        "va_type va_alist;"
  253. + typedef struct _va_struct {
  254. +     int va_narg;
  255. +     int *va_stkaddr;
  256. +     int *va_iregs;
  257. + } va_list;
  258. + #define va_start(ap, p) \
  259. + ((ap).va_narg=(int *)&va_alist-va_stkarg, \
  260. +  (ap).va_stkaddr=va_stkarg, \
  261. +  (ap).va_iregs=(int *)va_intreg)
  262. + #define va_end(p)
  263. + #if defined(LittleEndian)
  264. + #define va_arg(p,mode) \
  265. +     (*(mode *)_gh_va_arg(&p, va_align(mode), va_regtyp(mode), sizeof(mode)))
  266. + #else /* defined(LittleEndian) */
  267. + #define va_arg(p,mode) ( \
  268. +     (p).va_narg += ((p).va_narg & (va_align(mode) == 8)) + \
  269. +                       (sizeof(mode)+3)/4, \
  270. +     ((mode *)((va_regtyp(mode) && (p).va_narg <= 8 ? \
  271. +              (p).va_iregs: \
  272. +              (p).va_stkaddr) + (p).va_narg))[-1])
  273. + #endif /* defined(LittleEndian) */
  274.   #else /* vax, mc68k, 80*86 */
  275.   
  276.   typedef char *va_list;
  277. ***************
  278. *** 46,49 ****
  279.   #define va_arg(ap, type)    ((type *) (ap += sizeof(type)))[-1]
  280.   #define va_end(ap)
  281.   
  282. ! #endif
  283. --- 80,85 ----
  284.   #define va_arg(ap, type)    ((type *) (ap += sizeof(type)))[-1]
  285.   #define va_end(ap)
  286.   
  287. ! #endif /* m88k */
  288. ! #endif /* mips */
  289. ! #endif /* sparc */
  290. *** ./README-    Sat Feb 15 17:17:02 1992
  291. --- ./README    Fri Jun 18 22:29:36 1993
  292. ***************
  293. *** 1,4 ****
  294. ! @(#) README 1.5 92/02/15 17:17:00
  295.   
  296.   unproto - Compile ANSI C with traditional UNIX C compiler
  297.   
  298. --- 1,4 ----
  299. ! @(#) README 1.6 93/06/18 22:29:34
  300.   
  301.   unproto - Compile ANSI C with traditional UNIX C compiler
  302.   
  303. ***************
  304. *** 61,67 ****
  305.   
  306.       System V.2: cc -Bdirectory_with_alternate_cpp/ -tp ...
  307.   
  308. ! Your C compiler manual page should provide the necessary information.
  309.   
  310.   A more portable, but less efficient, approach relies on the observation
  311.   that almost every UNIX C compiler supports the -E (write preprocessor
  312. --- 61,69 ----
  313.   
  314.       System V.2: cc -Bdirectory_with_alternate_cpp/ -tp ...
  315.   
  316. ! Examples of these, and others, can be found in the acc.sh shell script
  317. ! that emulates an ANSI C compiler.  Your C compiler manual page should
  318. ! provide the necessary information.
  319.   
  320.   A more portable, but less efficient, approach relies on the observation
  321.   that almost every UNIX C compiler supports the -E (write preprocessor
  322. ***************
  323. *** 136,151 ****
  324.   available from ftp.uu.net as comp.sources.misc/volume10/config42.Z).
  325.   
  326.   If you run the unprototyper with "cc -E" just install the `unproto'
  327. ! binary; the `cpp' shell script will not be needed.
  328.   
  329.   If you use the `cpp' shell script to pipe the preprocessor output
  330.   through the unprototyper program, install the `unproto' binary in a
  331.   place where the `cpp' shell script can find it, and install the `cpp'
  332. ! shell script in a suitable place.
  333.   
  334.   If the unprototyper itself opens the pipe to the C preprocessor (i.e.
  335.   the unprototyper was built with the `PIPE_THROUGH_CPP' macro defined),
  336. ! install the `cpp' unprototyper binary in a suitable place.
  337.   
  338.       Wietse Venema
  339.       wietse@wzv.win.tue.nl
  340. --- 138,157 ----
  341.   available from ftp.uu.net as comp.sources.misc/volume10/config42.Z).
  342.   
  343.   If you run the unprototyper with "cc -E" just install the `unproto'
  344. ! binary; the `cpp' and `acc' shell scripts will not be needed.
  345.   
  346.   If you use the `cpp' shell script to pipe the preprocessor output
  347.   through the unprototyper program, install the `unproto' binary in a
  348.   place where the `cpp' shell script can find it, and install the `cpp'
  349. ! shell script in a suitable place. Edit the `acc' shell script and
  350. ! install it in a suitable place. From now on, type `acc' instead of
  351. ! `cc'.
  352.   
  353.   If the unprototyper itself opens the pipe to the C preprocessor (i.e.
  354.   the unprototyper was built with the `PIPE_THROUGH_CPP' macro defined),
  355. ! install the `cpp' unprototyper binary in a suitable place. Edit the
  356. ! `acc' shell script and install it in a suitable place. From now on,
  357. ! type `acc' instead of `cc'.
  358.   
  359.       Wietse Venema
  360.       wietse@wzv.win.tue.nl
  361. *** ./example.out-    Sat Feb 15 17:17:09 1992
  362. --- ./example.out    Fri Jun 18 22:30:54 1993
  363. ***************
  364. *** 259,261 ****
  365. --- 259,271 ----
  366.   int (*(*test26(foo))())()
  367.   long foo;
  368.   {/*1*/  }/*1*/
  369. + void functie(cmdlin,c1)
  370. + # 220 "example.c"
  371. + struct {int l; char c[1];} *cmdlin;
  372. + # 220 "example.c"
  373. + struct {int l; char c[1];} *c1;
  374. + {/*1*/
  375. + }/*1*/
  376. *** ./Makefile-    Sat Feb 15 17:17:04 1992
  377. --- ./Makefile    Fri Jun 18 22:29:42 1993
  378. ***************
  379. *** 1,4 ****
  380. ! # @(#) Makefile 1.5 92/02/15 17:17:03
  381.   
  382.   ## BEGIN CONFIGURATION STUFF
  383.   
  384. --- 1,4 ----
  385. ! # @(#) Makefile 1.6 93/06/18 22:29:40
  386.   
  387.   ## BEGIN CONFIGURATION STUFF
  388.   
  389. ***************
  390. *** 74,80 ****
  391.   CFILES    = unproto.c tok_io.c tok_class.c tok_pool.c vstring.c symbol.c error.c \
  392.       hash.c strsave.c
  393.   HFILES    = error.h token.h vstring.h symbol.h
  394. ! SCRIPTS    = cpp.sh
  395.   SAMPLES    = stdarg.h stddef.h stdlib.h varargs.c example.c example.out
  396.   SOURCES    = README $(CFILES) $(HFILES) Makefile $(SCRIPTS) $(SAMPLES)
  397.   FILES    = $(SOURCES) unproto.1
  398. --- 74,80 ----
  399.   CFILES    = unproto.c tok_io.c tok_class.c tok_pool.c vstring.c symbol.c error.c \
  400.       hash.c strsave.c
  401.   HFILES    = error.h token.h vstring.h symbol.h
  402. ! SCRIPTS    = cpp.sh acc.sh
  403.   SAMPLES    = stdarg.h stddef.h stdlib.h varargs.c example.c example.out
  404.   SOURCES    = README $(CFILES) $(HFILES) Makefile $(SCRIPTS) $(SAMPLES)
  405.   FILES    = $(SOURCES) unproto.1
  406.  
  407. exit 0 # Just in case...
  408.