home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume29 / cproto / part01 < prev    next >
Encoding:
Text File  |  1992-04-05  |  54.4 KB  |  2,204 lines

  1. Newsgroups: comp.sources.misc
  2. From: cthuang@zerosan.uucp (Chin Huang)
  3. Subject:  v29i061:  cproto - generate C function prototypes v3PL2, Part01/02
  4. Message-ID: <csm-v29i061=cproto.222242@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: e2d15fb427d42fb9eae3f06fa96f6199
  6. Date: Sun, 5 Apr 1992 04:23:48 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: cthuang@zerosan.uucp (Chin Huang)
  10. Posting-number: Volume 29, Issue 61
  11. Archive-name: cproto/part01
  12. Environment: UNIX, MS-DOS, getopt, lex, yacc
  13. Supersedes: cproto: Volume 28, Issue 100-101
  14.  
  15. This is version 3 patchlevel 2 of cproto, a program that generates
  16. function prototypes and converts function definitions between the old
  17. style and the ANSI C style.  The conversion overwrites the original
  18. files, so make a backup copy of your files in case something goes wrong.
  19.  
  20. This release includes the following changes:
  21.  
  22. - Fix: The function definition conversion may produce a mangled function
  23.   definition if an #include directive appears before the function and
  24.   no comments appear between the directive and the function.
  25. - Fix: The size of the buffer allocated for the C preprocessor command
  26.   string did not include enough space for options set in the environment
  27.   variable CPROTO.
  28. - Replaced the -n option with -c which disables all comments in the
  29.   generated prototypes.
  30. - Replaced the enum's with #define constants to accommodate C compilers
  31.   that don't like enumerators in constant expressions.
  32.  
  33. Thanks to the following people for their suggestions and bug reports:
  34.  
  35. sweet@horizon.com (Kevin Sweet)
  36. kurt@grogatch.celestial.com (Kurt Cockrum)
  37. jamesho@gagme.chi.il.us (James Ho)
  38. reger@magellan.physik.uni-mainz.de (Joseph D. Reger)
  39.  
  40. #! /bin/sh
  41. # This is a shell archive.  Remove anything before this line, then unpack
  42. # it by saving it into a file and typing "sh file".  To overwrite existing
  43. # files, type "sh file -c".  You can also feed this as standard input via
  44. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  45. # will see the following message at the end:
  46. #        "End of shell archive."
  47. # Contents:  README CHANGES cproto.man cproto.1 Makefile.bc
  48. #   Makefile.msc Makefile.uni lex.l grammar.y
  49. # Wrapped by cthuang@zerosan.UUCP on Sat Apr 04 14:07:35 1992
  50. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  51. if test -f README -a "${1}" != "-c" ; then 
  52.   echo shar: Will not over-write existing file \"README\"
  53. else
  54. echo shar: Extracting \"README\" \(689 characters\)
  55. sed "s/^X//" >README <<'END_OF_README'
  56. XCproto is a program that generates function prototypes and variable
  57. Xdeclarations from C source code.  It can also convert function
  58. Xdefinitions between the old style and the ANSI C style.  This conversion
  59. Xoverwrites the original files, so make a backup copy of your files in
  60. Xcase something goes wrong.
  61. X
  62. XThe program isn't confused by complex function definitions as much as
  63. Xother prototype generators because it uses a yacc generated parser.  By
  64. Xignoring all the input between braces, I avoided implementing the entire
  65. XC language grammar.
  66. X
  67. XCproto is in the public domain.  If you have any comments or find any
  68. Xbugs, please let me know.
  69. X
  70. XChin Huang
  71. Xcthuang@zerosan.UUCP
  72. Xchin.huang@canrem.com
  73. END_OF_README
  74. if test 689 -ne `wc -c <README`; then
  75.     echo shar: \"README\" unpacked with wrong size!
  76. fi
  77. # end of overwriting check
  78. fi
  79. if test -f CHANGES -a "${1}" != "-c" ; then 
  80.   echo shar: Will not over-write existing file \"CHANGES\"
  81. else
  82. echo shar: Extracting \"CHANGES\" \(4252 characters\)
  83. sed "s/^X//" >CHANGES <<'END_OF_CHANGES'
  84. XVersion 3
  85. X
  86. XPatchlevel 2
  87. X
  88. X- Fix: The function definition conversion may produce a mangled function
  89. X  definition if an #include directive appears before the function and
  90. X  no comments appear between the directive and the function.
  91. X- Fix: The size of the buffer allocated for the C preprocessor command
  92. X  string did not include enough space for options set in the environment
  93. X  variable CPROTO.
  94. X- Replaced the -n option with -c which disables all comments in the
  95. X  generated prototypes.
  96. X- Replaced the enum's with #define constants to accommodate C compilers
  97. X  that don't like enumerators in constant expressions.
  98. X
  99. XPatchlevel 1
  100. X
  101. X- Fix: The program was calling ftell() on an invalid FILE pointer.
  102. X
  103. XPatchlevel 0
  104. X
  105. X- Added options to convert function definitions between the old style
  106. X  and ANSI C style.
  107. X- Options can be specified from the environment variable CPROTO.
  108. X- The MS-DOS version recognizes more Microsoft C and Borland C++ type
  109. X  modifiers (such as _cdecl, _far, _near).
  110. X- Fix: Formal parameters specified with typedef names were not promoted.
  111. X  For example, for the definition
  112. X
  113. X      typedef unsigned short ushort;
  114. X
  115. X    void test (x)
  116. X    ushort x;
  117. X    {
  118. X    }
  119. X
  120. X  cproto generated the incorrect prototype
  121. X
  122. X      void test(ushort x);
  123. X
  124. X  while the correct one is
  125. X
  126. X      void test(int x);
  127. X
  128. X- Fix: Incorrect prototypes were generated for functions that returned
  129. X  function pointers.  For example, cproto generated an incorrect
  130. X  prototype for the function definition
  131. X
  132. X    void (*signal(int x, void (*func)(int y)))(int z)
  133. X    {
  134. X    }
  135. X
  136. X- Fix: Changed calls to memory allocation functions to abort the program
  137. X  if they fail.
  138. X
  139. XVersion 2
  140. X
  141. XPatchlevel 3
  142. X
  143. X- Made cproto compatible with GNU flex.
  144. X- After compiling with the preprocessor symbol TURBO_CPP defined, on
  145. X  MS-DOS systems, cproto will pipe its input through the Turbo C
  146. X  preprocessor.
  147. X- Fix: Typedef names may now be omitted from typedef declarations.
  148. X  For example, every C compiler I tried accepts
  149. X
  150. X    typedef int;
  151. X
  152. X  and some even give warnings when encountering this statement.
  153. X
  154. XPatchlevel 2
  155. X
  156. X- Cproto is now able to generate prototypes for functions defined in lex
  157. X  and yacc source files named on the command line.  Lex and yacc source
  158. X  files are recognized by the .l or .y extension.
  159. X- Fix: The memory allocated to the typedef symbol table was not being
  160. X  freed after scanning each source file.
  161. X- Fix: Failure to reset a variable during error recovery caused
  162. X  segmentation faults.
  163. X
  164. XPatchlevel 1
  165. X
  166. X- Fix: Cproto incorrectly generated the parameter "int ..." in
  167. X  prototypes of functions taking variable parameters.
  168. X- Fix: Function definitions can now be followed by an optional
  169. X  semicolon.  I found this feature in every C compiler I tried.
  170. X
  171. XPatchlevel 0
  172. X
  173. X- Added formal parameter promotion.
  174. X- Added prototype style that surrounds prototypes with a guard macro.
  175. X- Handles C++ style comment //.
  176. X- Nifty new way to set prototype output format.
  177. X- Got rid of the shell wrapper used to pipe the input through the C
  178. X  preprocessor (cpp).
  179. X- For the port to MS-DOS, I modified cproto to run without cpp, but
  180. X  since I didn't want to reimplement cpp, the program processes only the
  181. X  #include and #define directives and ignores all others.  Macro names
  182. X  defined by the #define directive are treated like typedef names if
  183. X  they appear in declaration specifiers.
  184. X
  185. XVersion 1
  186. X
  187. XPatchlevel 3
  188. X
  189. X- Fix: identical typedef names and struct tags should be allowed.
  190. X  For example:
  191. X
  192. X    typedef struct egg_salad egg_salad;
  193. X
  194. X    struct egg_salad {
  195. X        int mayo;
  196. X    };
  197. X
  198. X    void dine(egg_salad l)
  199. X    {
  200. X    }
  201. X
  202. XPatchlevel 2
  203. X
  204. X- Fix: A typedef statement should allow a list of typedefs to be declared.
  205. X  Example:
  206. X
  207. X    typedef int a, *b;
  208. X
  209. X- Fix: When run with the -v option on this input, cproto did not output
  210. X  a declaration for variable "b":
  211. X
  212. X    char *a="one"; char *b="two";
  213. X
  214. X- The options were renamed.  Added new options that change the output
  215. X  format of the prototypes.
  216. X
  217. XPatchlevel 1
  218. X
  219. X- Fix: Incorrect prototypes were produced for functions that take
  220. X  function pointer parameters or return a function pointer.  For example,
  221. X  cproto produced an erroneous prototype for this function definition:
  222. X
  223. X    void
  224. X    (*signal (sig, func))()
  225. X    int sig;
  226. X    void (*func)();
  227. X    {
  228. X        /* stuff */
  229. X    }
  230. X
  231. X- The lexical analyser now uses LEX.  It should still be compatible with
  232. X  FLEX.
  233. END_OF_CHANGES
  234. if test 4252 -ne `wc -c <CHANGES`; then
  235.     echo shar: \"CHANGES\" unpacked with wrong size!
  236. fi
  237. # end of overwriting check
  238. fi
  239. if test -f cproto.man -a "${1}" != "-c" ; then 
  240.   echo shar: Will not over-write existing file \"cproto.man\"
  241. else
  242. echo shar: Extracting \"cproto.man\" \(7521 characters\)
  243. sed "s/^X//" >cproto.man <<'END_OF_cproto.man'
  244. X
  245. X
  246. XCPROTO(1)                  Unix Programmer's Manual                  CPROTO(1)
  247. X
  248. X
  249. XNAME
  250. X     cproto - generate C function prototypes and convert function definitions
  251. X
  252. XSYNOPSIS
  253. X     cproto [ option ... ] [ file ... ]
  254. X
  255. XDESCRIPTION
  256. X     Cproto  generates  function  prototypes  for  functions  defined  in  the
  257. X     specified   C   source  files  to  the  standard  output.   The  function
  258. X     definitions may be in the old style or ANSI C style.  Optionally,  cproto
  259. X     also  outputs  declarations for any variables defined in the file.  If no
  260. X     file argument is given, cproto reads its input from the standard input.
  261. X
  262. X     By giving a command  line  option,  cproto  will  also  convert  function
  263. X     definitions  in  the  specified  files  from  the old style to the ANSI C
  264. X     style.  The original source files along with files specified by
  265. X
  266. X          #include "file"
  267. X
  268. X     directives appearing in the source code  will  be  overwritten  with  the
  269. X     converted code.  If no file names are given on the command line, then the
  270. X     program reads the source code from the standard  input  and  outputs  the
  271. X     converted source to the standard output.
  272. X
  273. X     If any comments appear in  the  parameter  declarations  for  a  function
  274. X     definition, such as in the example,
  275. X
  276. X          main (argc, argv)
  277. X          int argc; /* number of arguments */
  278. X          char *argv[]; /* arguments */
  279. X          {
  280. X           ...
  281. X          }
  282. X
  283. X     then the converted function definition will have the form
  284. X
  285. X          int
  286. X          main (
  287. X              int argc;    /* number of arguments */
  288. X              char *argv[];   /* arguments */
  289. X          )
  290. X          {
  291. X           ...
  292. X          }
  293. X
  294. X     Otherwise, the converted function definition will look like
  295. X
  296. X          int
  297. X          main (int argc, char *argv[])
  298. X          {
  299. X           ...
  300. X          }
  301. X
  302. X
  303. X
  304. X
  305. X
  306. X
  307. X                                April 3, 1992                                1
  308. X
  309. X
  310. X
  311. X
  312. XCPROTO(1)                  Unix Programmer's Manual                  CPROTO(1)
  313. X
  314. X
  315. X     Cproto can optionally convert function definitions from the ANSI style to
  316. X     the  old  style.   In  this  mode,  the  program  also  converts function
  317. X     declarators and prototypes that appear outside function bodies.  This  is
  318. X     not  a  complete ANSI C to old C conversion.  The program does not change
  319. X     anything within function bodies.
  320. X
  321. XOPTIONS
  322. X
  323. X     -a   Convert function definitions from the old style to the ANSI C style.
  324. X
  325. X     -e   Output the keyword extern  in  front  of  every  declaration  having
  326. X          global scope.
  327. X
  328. X     -fn  Set the style of generated function prototypes where n is  a  number
  329. X          from 0 to 4.  For example, consider the function definition
  330. X
  331. X               main (argc, argv)
  332. X               int argc;
  333. X               char *argv[];
  334. X               {
  335. X                ...
  336. X               }
  337. X
  338. X          If the value is 0, then no prototypes are generated.  When set to 1,
  339. X          the output is:
  340. X
  341. X               int main(/*int argc, char *argv[]*/);
  342. X
  343. X          For a value of 2, the output has the form:
  344. X
  345. X               int main(int /*argc*/, char */*argv*/[]);
  346. X
  347. X          The default value is 3.  It produces the full function prototype:
  348. X
  349. X               int main(int argc, char *argv[]);
  350. X
  351. X          A value of 4 produces prototypes guarded by a macro:
  352. X
  353. X               int main P_((int argc, char *argv[]));
  354. X
  355. X
  356. X     -c   Omit the parameter comments in the prototypes generated by  the  -f1
  357. X          and  -f2  options.   This  option also omits the comments naming the
  358. X          source files from which the prototypes were generated.
  359. X
  360. X     -mname
  361. X          Set the name of the macro used to guard prototypes when  option  -f4
  362. X          is selected.  The default is "P_".
  363. X
  364. X     -d   Omit the definition of the prototype macro named by the -m option.
  365. X
  366. X     -p   Disable  promotion  of  formal  parameters  in  old  style  function
  367. X          definitions.   By  default,  parameters of type char or short in old
  368. X          style function definitions are promoted to type int in the  function
  369. X          prototype  or  converted  ANSI C function definition.  Parameters of
  370. X          type float get promoted to double as well.
  371. X
  372. X
  373. X                                April 3, 1992                                2
  374. X
  375. X
  376. X
  377. X
  378. XCPROTO(1)                  Unix Programmer's Manual                  CPROTO(1)
  379. X
  380. X
  381. X     -s   By default, cproto only generates  declarations  for  functions  and
  382. X          variables  having  global  scope.   This  option  will output static
  383. X          declarations as well.
  384. X
  385. X     -t   Convert  function  definitions  from  the  ANSI  C  style   to   the
  386. X          traditional style.
  387. X
  388. X     -v   Also output declarations for variables defined in the source.
  389. X
  390. X     -Ptemplate
  391. X     -Ftemplate
  392. X     -Ctemplate
  393. X          Set  the  output   format   for   generated   prototypes,   function
  394. X          definitions,   and  function  definitions  with  parameter  comments
  395. X          respectively.  The format is specified by a template in the form
  396. X
  397. X               " int main ( a, b )"
  398. X
  399. X          but you may replace each space in this string  with  any  number  of
  400. X          whitespace characters.  For example, the option
  401. X
  402. X               -F"int main(\n\ta,\n\tb\n\t)"
  403. X
  404. X          will produce
  405. X
  406. X               int main(
  407. X                    int argc,
  408. X                    char *argv[]
  409. X                    )
  410. X
  411. X
  412. X     -Dname\[=value\]
  413. X          This option is passed through to the preprocessor  and  is  used  to
  414. X          define symbols for use with conditionals such as #ifdef.
  415. X
  416. X     -Uname
  417. X          This option is passed through to the preprocessor  and  is  used  to
  418. X          remove any definitions of this symbol.
  419. X
  420. X     -Idirectory
  421. X          This option is passed through to the preprocessor  and  is  used  to
  422. X          specify  a  directory  to  search for files that are referenced with
  423. X          #include.
  424. X
  425. X     -V   Print version information.
  426. X
  427. XENVIRONMENT
  428. X     The environment variable CPROTO is scanned for a list of options  in  the
  429. X     same format as the command line options.
  430. X
  431. XBUGS
  432. X     If an untagged struct, union or enum declaration appears in  a  generated
  433. X     function  prototype  or converted function definition, the content of the
  434. X     declaration between the braces is empty.
  435. X
  436. X
  437. X
  438. X
  439. X                                April 3, 1992                                3
  440. X
  441. X
  442. X
  443. X
  444. XCPROTO(1)                  Unix Programmer's Manual                  CPROTO(1)
  445. X
  446. X
  447. X     The program does not pipe the source files  through  the  C  preprocessor
  448. X     when  it is converting function definitions.  Instead, it tries to handle
  449. X     preprocessor directives and macros itself and can be confused  by  tricky
  450. X     macro  expansions.   The  conversion  also  discards some comments in the
  451. X     function definition head.
  452. X
  453. X     The -v option does not generate declarations for variables  defined  with
  454. X     the  extern  specifier.   This doesn't strictly conform to the C language
  455. X     standard but this rule was implemented  because  include  files  commonly
  456. X     declare variables this way.
  457. X
  458. X     When the program encounters an error, it usually  outputs  the  not  very
  459. X     descriptive message "syntax error".
  460. X
  461. X     Options that take string arguments only interpret the following character
  462. X     escape sequences:
  463. X
  464. X          \n   newline
  465. X          \t   tab
  466. X
  467. X
  468. XAUTHOR
  469. X     Chin Huang
  470. X     cthuang@zerosan.UUCP
  471. X     chin.huang@canrem.com
  472. X
  473. XSEE ALSO
  474. X     cc(1), cpp(1)
  475. X
  476. X
  477. X
  478. X
  479. X
  480. X
  481. X
  482. X
  483. X
  484. X
  485. X
  486. X
  487. X
  488. X
  489. X
  490. X
  491. X
  492. X
  493. X
  494. X
  495. X
  496. X
  497. X
  498. X
  499. X
  500. X
  501. X
  502. X
  503. X
  504. X
  505. X                                April 3, 1992                                4
  506. X
  507. X
  508. END_OF_cproto.man
  509. if test 7521 -ne `wc -c <cproto.man`; then
  510.     echo shar: \"cproto.man\" unpacked with wrong size!
  511. fi
  512. # end of overwriting check
  513. fi
  514. if test -f cproto.1 -a "${1}" != "-c" ; then 
  515.   echo shar: Will not over-write existing file \"cproto.1\"
  516. else
  517. echo shar: Extracting \"cproto.1\" \(6091 characters\)
  518. sed "s/^X//" >cproto.1 <<'END_OF_cproto.1'
  519. X.\" $Id: cproto.1 3.4 92/04/04 14:01:52 cthuang Exp $
  520. X.\"
  521. X.de EX        \"Begin example
  522. X.ne 5
  523. X.if n .sp 1
  524. X.if t .sp .5
  525. X.nf
  526. X.in +5n
  527. X..
  528. X.de EE        \"End example
  529. X.fi
  530. X.in -5n
  531. X.if n .sp 1
  532. X.if t .sp .5
  533. X..
  534. X.TH CPROTO 1 "April 3, 1992"
  535. X.SH NAME
  536. Xcproto \- generate C function prototypes and convert function definitions
  537. X.SH SYNOPSIS
  538. X.B cproto
  539. X[ 
  540. X.I option \fP...\fI
  541. X] [
  542. X.I file \fP...\fI
  543. X]
  544. X.SH DESCRIPTION
  545. X.B Cproto
  546. Xgenerates function prototypes for
  547. Xfunctions defined in the specified C source files to the standard output.
  548. XThe function definitions may be in the old style or ANSI C style.
  549. XOptionally,
  550. X.B cproto
  551. Xalso outputs declarations for any variables defined in the file.
  552. XIf no
  553. X.I file
  554. Xargument is given,
  555. X.B cproto
  556. Xreads its input from the standard input.
  557. X.LP
  558. XBy giving a command line option,
  559. X.B cproto
  560. Xwill also convert function definitions in the specified files from the
  561. Xold style to the ANSI C style.
  562. XThe original source files along with files specified by
  563. X.EX
  564. X#include "file"
  565. X.EE
  566. Xdirectives appearing in the source code will be overwritten
  567. Xwith the converted code.
  568. XIf no file names are given on the command line, then the program reads
  569. Xthe source code from the standard input and outputs the converted source
  570. Xto the standard output.
  571. X.LP
  572. XIf any comments appear in the parameter declarations for a function definition,
  573. Xsuch as in the example,
  574. X.EX
  575. Xmain (argc, argv)
  576. Xint argc;    /* number of arguments */
  577. Xchar *argv[];    /* arguments */
  578. X{
  579. X ...
  580. X}
  581. X.EE
  582. Xthen the converted function definition will have the form
  583. X.EX
  584. Xint
  585. Xmain (
  586. X    int argc;        /* number of arguments */
  587. X    char *argv[];   /* arguments */
  588. X)
  589. X{
  590. X ...
  591. X}
  592. X.EE
  593. XOtherwise, the converted function definition will look like
  594. X.EX
  595. Xint
  596. Xmain (int argc, char *argv[])
  597. X{
  598. X ...
  599. X}
  600. X.EE
  601. X.LP
  602. X.B Cproto
  603. Xcan optionally convert function definitions from the ANSI style to the old
  604. Xstyle.
  605. XIn this mode, the program also converts function declarators and prototypes
  606. Xthat appear outside function bodies.
  607. XThis is not a complete ANSI C to old C conversion.
  608. XThe program does not change anything within function bodies.
  609. X.SH OPTIONS
  610. X.TP
  611. X.B \-a
  612. XConvert function definitions from the old style to the ANSI C style.
  613. X.TP
  614. X.B \-e
  615. XOutput the keyword
  616. X.B extern
  617. Xin front of every declaration having global scope.
  618. X.TP
  619. X.BI \-f n
  620. XSet the style of generated function prototypes where
  621. X.I n
  622. Xis a number from 0 to 4.
  623. XFor example, consider the function definition
  624. X.EX
  625. Xmain (argc, argv)
  626. Xint argc;
  627. Xchar *argv[];
  628. X{
  629. X ...
  630. X}
  631. X.EE
  632. XIf the value is 0, then no prototypes are generated.
  633. XWhen set to 1, the output is:
  634. X.EX
  635. Xint main(/*int argc, char *argv[]*/);
  636. X.EE
  637. XFor a value of 2, the output has the form:
  638. X.EX
  639. Xint main(int /*argc*/, char */*argv*/[]);
  640. X.EE
  641. XThe default value is 3.
  642. XIt produces the full function prototype:
  643. X.EX
  644. Xint main(int argc, char *argv[]);
  645. X.EE
  646. XA value of 4 produces prototypes guarded by a macro:
  647. X.EX
  648. Xint main P_((int argc, char *argv[]));
  649. X.EE
  650. X.TP
  651. X.B \-c
  652. XOmit the parameter comments in the prototypes generated by
  653. Xthe -f1 and -f2 options.
  654. XThis option also omits the comments naming the source files from which
  655. Xthe prototypes were generated.
  656. X.TP
  657. X.BI \-m name
  658. XSet the name of the macro used to guard prototypes when option -f4 is selected.
  659. XThe default is "P_".
  660. X.TP
  661. X.B \-d
  662. XOmit the definition of the prototype macro named by the -m option.
  663. X.TP
  664. X.B \-p
  665. XDisable promotion of formal parameters in old style function definitions.
  666. XBy default, parameters of type
  667. X.B char
  668. Xor
  669. X.B short
  670. Xin old style function definitions are promoted to type
  671. X.B int
  672. Xin the function prototype or converted ANSI C function definition.
  673. XParameters of type
  674. X.B float
  675. Xget promoted to 
  676. X.B double
  677. Xas well.
  678. X.TP
  679. X.B \-s
  680. XBy default,
  681. X.B cproto
  682. Xonly generates declarations for functions and variables having global scope.
  683. XThis option will output
  684. X.B static
  685. Xdeclarations as well.
  686. X.TP
  687. X.B \-t
  688. XConvert function definitions from the ANSI C style to the traditional style.
  689. X.TP
  690. X.B \-v
  691. XAlso output declarations for variables defined in the source.
  692. X.LP
  693. X.nf
  694. X.BI \-P template
  695. X.BI \-F template
  696. X.BI \-C template
  697. X.fi
  698. X.in +5n
  699. XSet the output format for generated prototypes, function definitions,
  700. Xand function definitions with parameter comments respectively.
  701. XThe format is specified by a template in the form
  702. X.EX
  703. X" int main ( a, b )"
  704. X.EE
  705. Xbut you may replace each space in this string with any number of
  706. Xwhitespace characters.
  707. XFor example, the option
  708. X.EX
  709. X-F"int main(\\n\\ta,\\n\\tb\\n\\t)"
  710. X.EE
  711. Xwill produce
  712. X.EX
  713. Xint main(
  714. X    int argc,
  715. X    char *argv[]
  716. X    )
  717. X.EE
  718. X.TP
  719. X.BI \-D name\[=value\]
  720. XThis option is passed through to the preprocessor and is used to define 
  721. Xsymbols for use with conditionals such as
  722. X.I #ifdef.
  723. X.TP
  724. X.BI \-U name
  725. XThis option is passed through to the preprocessor and is used to remove
  726. Xany definitions of this symbol.
  727. X.TP
  728. X.BI \-I directory
  729. XThis option is passed through to the preprocessor and is used to specify
  730. Xa directory to search for files that are referenced with 
  731. X.I #include.
  732. X.TP
  733. X.B \-V
  734. XPrint version information.
  735. X.SH ENVIRONMENT
  736. XThe environment variable CPROTO is scanned for
  737. Xa list of options in the same format as the command line options.
  738. X.SH BUGS
  739. XIf an untagged struct, union or enum declaration appears in
  740. Xa generated function prototype or converted function definition,
  741. Xthe content of the declaration between the braces is empty.
  742. X.LP
  743. XThe program does not pipe the source files through the C preprocessor when
  744. Xit is converting function definitions.
  745. XInstead, it tries to handle preprocessor directives and macros itself
  746. Xand can be confused by tricky macro expansions.
  747. XThe conversion also discards some comments in the function definition
  748. Xhead.
  749. X.LP
  750. XThe -v option does not generate declarations for variables defined with the
  751. X.B extern
  752. Xspecifier.
  753. XThis doesn't strictly conform to the C language standard but this rule
  754. Xwas implemented because include files commonly declare variables this way.
  755. X.LP
  756. XWhen the program encounters an error, it usually outputs the not very
  757. Xdescriptive message "syntax error".
  758. X.LP
  759. XOptions that take string arguments only interpret the following
  760. Xcharacter escape sequences:
  761. X.EX
  762. X\\n    newline
  763. X\\t    tab
  764. X.EE
  765. X.SH AUTHOR
  766. X.nf
  767. XChin Huang
  768. Xcthuang@zerosan.UUCP
  769. Xchin.huang@canrem.com
  770. X.fi
  771. X.SH "SEE ALSO"
  772. Xcc(1),
  773. Xcpp(1)
  774. END_OF_cproto.1
  775. if test 6091 -ne `wc -c <cproto.1`; then
  776.     echo shar: \"cproto.1\" unpacked with wrong size!
  777. fi
  778. # end of overwriting check
  779. fi
  780. if test -f Makefile.bc -a "${1}" != "-c" ; then 
  781.   echo shar: Will not over-write existing file \"Makefile.bc\"
  782. else
  783. echo shar: Extracting \"Makefile.bc\" \(1499 characters\)
  784. sed "s/^X//" >Makefile.bc <<'END_OF_Makefile.bc'
  785. X# $Id: makefile.bc 3.1 92/03/03 10:45:53 cthuang Exp $
  786. X#
  787. X# Borland C++ makefile for C prototype generator
  788. X
  789. X# Define MSDOS for MS-DOS compatibility.
  790. X# Define TURBO_CPP to pipe the input through the Turbo C preprocessor.
  791. XDEFINES = -DMSDOS -DTURBO_CPP
  792. X
  793. XLEX = lex
  794. XYACC = yacc
  795. XCC = bcc
  796. XCFLAGS = -mc $(DEFINES)
  797. XLIBS = \bc\lib\wildargs.obj
  798. X
  799. XDIST1 = README CHANGES cproto.man
  800. XDIST2 = cproto.1 Makefile.bc Makefile.msc Makefile.uni lex.l grammar.y
  801. XDIST3 = config.h cproto.h patchlev.h semantic.h symbol.h
  802. XDIST4 = cproto.c popen.c semantic.c strstr.c symbol.c
  803. X
  804. XOBJECTS = cproto.obj getopt.obj popen.obj semantic.obj symbol.obj y_tab.obj
  805. X
  806. Xall: cproto.exe
  807. X
  808. Xcproto.exe: $(OBJECTS)
  809. X    $(CC) $(CFLAGS) -e$*.exe $(OBJECTS) $(LIBS)
  810. X
  811. Xy_tab.obj: y_tab.c lex_yy.c config.h cproto.h symbol.h semantic.h
  812. X    $(CC) $(CFLAGS) -c $*.c
  813. X
  814. Xy_tab.c: grammar.y
  815. X    $(YACC) grammar.y
  816. X
  817. Xlex_yy.c: lex.l
  818. X    $(LEX) lex.l
  819. X
  820. Xcproto.man: cproto.1
  821. X    cawf -man $*.1 | bsfilt - >$*.man
  822. X
  823. Xclean:
  824. X    erase *.obj
  825. X    erase *.bak
  826. X    erase *.log
  827. X    erase lex_yy.c
  828. X    erase y_tab.c
  829. X    erase cproto.exe
  830. X
  831. Xci:
  832. X    ci -u3 $(DIST2) $(DIST3)
  833. X    ci -u3 $(DIST4)
  834. X
  835. Xshar:
  836. X    rmcr $(DIST1) $(DIST2)
  837. X    rmcr $(DIST3) $(DIST4)
  838. X    shar $(DIST1) $(DIST2) >cproto.sh1
  839. X    shar $(DIST3) $(DIST4) >cproto.sh2
  840. X
  841. Xinscr:
  842. X    inscr $(DIST1) $(DIST2)
  843. X    inscr $(DIST3) $(DIST4)
  844. X
  845. X# DO NOT DELETE THIS LINE -- make depend depends on it.
  846. X
  847. Xcproto.obj: config.h cproto.h symbol.h
  848. Xpopen.obj: config.h cproto.h
  849. Xsemantic.obj: config.h cproto.h symbol.h semantic.h
  850. Xstrstr.obj: config.h
  851. Xsymbol.obj: config.h cproto.h symbol.h
  852. END_OF_Makefile.bc
  853. if test 1499 -ne `wc -c <Makefile.bc`; then
  854.     echo shar: \"Makefile.bc\" unpacked with wrong size!
  855. fi
  856. # end of overwriting check
  857. fi
  858. if test -f Makefile.msc -a "${1}" != "-c" ; then 
  859.   echo shar: Will not over-write existing file \"Makefile.msc\"
  860. else
  861. echo shar: Extracting \"Makefile.msc\" \(1521 characters\)
  862. sed "s/^X//" >Makefile.msc <<'END_OF_Makefile.msc'
  863. X# $Id: makefile.msc 3.2 92/03/14 11:56:40 cthuang Exp $
  864. X#
  865. X# Microsoft C makefile for C prototype generator
  866. X
  867. X# Define MSDOS for MS-DOS compatibility.
  868. X# Define TURBO_CPP to pipe the input through the Turbo C preprocessor.
  869. XDEFINES = -DMSDOS
  870. X
  871. XLEX = lex
  872. XYACC = yacc
  873. XCC = cl
  874. XCFLAGS = -AC $(DEFINES)
  875. XLIBS = \c6\lib\setargv.obj
  876. XLDFLAGS = /link /noe /stack:4096
  877. X
  878. XDIST1 = README CHANGES cproto.man
  879. XDIST2 = cproto.1 Makefile.bc Makefile.msc Makefile.uni lex.l grammar.y
  880. XDIST3 = config.h cproto.h patchlev.h semantic.h symbol.h
  881. XDIST4 = cproto.c popen.c semantic.c strstr.c symbol.c
  882. X
  883. XOBJECTS = cproto.obj getopt.obj semantic.obj symbol.obj y_tab.obj
  884. X
  885. Xall: cproto.exe
  886. X
  887. Xcproto.exe: $(OBJECTS)
  888. X    $(CC) $(CFLAGS) -Fe$*.exe $(OBJECTS) $(LIBS) $(LDFLAGS)
  889. X
  890. Xy_tab.obj: y_tab.c lex_yy.c config.h cproto.h symbol.h semantic.h
  891. X    $(CC) $(CFLAGS) -c $*.c
  892. X
  893. Xy_tab.c: grammar.y
  894. X    $(YACC) grammar.y
  895. X
  896. Xlex_yy.c: lex.l
  897. X    $(LEX) lex.l
  898. X
  899. Xcproto.man: cproto.1
  900. X    cawf -man $*.1 | bsfilt - >$*.man
  901. X
  902. Xclean:
  903. X    erase *.obj
  904. X    erase *.bak
  905. X    erase *.log
  906. X    erase lex_yy.c
  907. X    erase y_tab.c
  908. X    erase cproto.exe
  909. X
  910. Xci:
  911. X    ci -u3 $(DIST2) $(DIST3)
  912. X    ci -u3 $(DIST4)
  913. X
  914. Xshar:
  915. X    rmcr $(DIST1) $(DIST2)
  916. X    rmcr $(DIST3) $(DIST4)
  917. X    shar $(DIST1) $(DIST2) >cproto.sh1
  918. X    shar $(DIST3) $(DIST4) >cproto.sh2
  919. X
  920. Xinscr:
  921. X    inscr $(DIST1) $(DIST2)
  922. X    inscr $(DIST3) $(DIST4)
  923. X
  924. X# DO NOT DELETE THIS LINE -- make depend depends on it.
  925. X
  926. Xcproto.obj: config.h cproto.h symbol.h
  927. Xpopen.obj: config.h cproto.h
  928. Xsemantic.obj: config.h cproto.h symbol.h semantic.h
  929. Xstrstr.obj: config.h
  930. Xsymbol.obj: config.h cproto.h symbol.h
  931. END_OF_Makefile.msc
  932. if test 1521 -ne `wc -c <Makefile.msc`; then
  933.     echo shar: \"Makefile.msc\" unpacked with wrong size!
  934. fi
  935. # end of overwriting check
  936. fi
  937. if test -f Makefile.uni -a "${1}" != "-c" ; then 
  938.   echo shar: Will not over-write existing file \"Makefile.uni\"
  939. else
  940. echo shar: Extracting \"Makefile.uni\" \(1132 characters\)
  941. sed "s/^X//" >Makefile.uni <<'END_OF_Makefile.uni'
  942. X# $Id: makefile.uni 3.3 92/04/04 13:58:48 cthuang Exp $
  943. X#
  944. X# UNIX makefile for C prototype generator
  945. X
  946. X# Define BSD for BSD, otherwise System V is assumed.
  947. X#DEFINES = -DBSD
  948. X
  949. XLEX = lex
  950. XYACC = yacc
  951. XCFLAGS = $(DEFINES)
  952. X
  953. XDIST1 = README CHANGES cproto.man
  954. XDIST2 = cproto.1 Makefile.bc Makefile.msc Makefile.uni lex.l grammar.y
  955. XDIST3 = config.h cproto.h patchlev.h semantic.h symbol.h
  956. XDIST4 = cproto.c popen.c semantic.c strstr.c symbol.c
  957. X
  958. XOBJECTS = cproto.o semantic.o strstr.o symbol.o y.tab.o
  959. X
  960. Xall: cproto cproto.man
  961. X
  962. Xcproto: $(OBJECTS)
  963. X    $(CC) $(CFLAGS) -o $@ $(OBJECTS)
  964. X
  965. Xy.tab.c: grammar.y
  966. X    $(YACC) grammar.y
  967. X
  968. Xlex.yy.c: lex.l
  969. X    $(LEX) lex.l
  970. X
  971. Xcproto.man: cproto.1
  972. X    nroff -man cproto.1 >$@
  973. X
  974. Xclean:
  975. X    rm *.o *.bak *.log cproto
  976. X
  977. Xci:
  978. X    ci -u3 $(DIST2) $(DIST3) $(DIST4)
  979. X
  980. Xshar:
  981. X    shar $(DIST1) $(DIST2) >cproto.sh1
  982. X    shar $(DIST3) $(DIST4) >cproto.sh2
  983. X
  984. Xdepend:
  985. X    makedepend $(DIST4) y.tab.c
  986. X
  987. X# DO NOT DELETE THIS LINE -- make depend depends on it.
  988. X
  989. Xcproto.o: config.h cproto.h symbol.h
  990. Xsemantic.o: config.h cproto.h symbol.h semantic.h
  991. Xstrstr.o: config.h
  992. Xsymbol.o: config.h cproto.h symbol.h
  993. Xy.tab.o: config.h cproto.h symbol.h semantic.h lex.yy.c
  994. END_OF_Makefile.uni
  995. if test 1132 -ne `wc -c <Makefile.uni`; then
  996.     echo shar: \"Makefile.uni\" unpacked with wrong size!
  997. fi
  998. # end of overwriting check
  999. fi
  1000. if test -f lex.l -a "${1}" != "-c" ; then 
  1001.   echo shar: Will not over-write existing file \"lex.l\"
  1002. else
  1003. echo shar: Extracting \"lex.l\" \(11306 characters\)
  1004. sed "s/^X//" >lex.l <<'END_OF_lex.l'
  1005. X%{
  1006. X/* $Id: lex.l 3.5 92/04/04 13:58:53 cthuang Exp $
  1007. X *
  1008. X * Lexical analyzer for C function prototype generator
  1009. X */
  1010. X
  1011. Xstatic int curly;    /* number of curly brace nesting levels */
  1012. Xstatic int ly_count;    /* number of occurances of %% */
  1013. X
  1014. X/* information about the current input file */
  1015. Xtypedef struct {
  1016. X    char *file_name;        /* input file name */
  1017. X    FILE *file;         /* input file */
  1018. X    unsigned line_num;        /* current line number in input file */
  1019. X    FILE *tmp_file;        /* temporary file */
  1020. X    long begin_comment;     /* tmp file offset after last written ) or ; */
  1021. X    long end_comment;        /* tmp file offset after last comment */
  1022. X    boolean convert;        /* if TRUE, convert function definitions */
  1023. X    boolean changed;        /* TRUE if conversion done in this file */
  1024. X#ifdef FLEX_SCANNER
  1025. X    YY_BUFFER_STATE buffer;    /* flex scanner state */
  1026. X#endif
  1027. X} IncludeStack;
  1028. X
  1029. Xstatic int inc_depth;                /* include nesting level */
  1030. Xstatic IncludeStack inc_stack[MAX_INC_DEPTH];    /* stack of included files */
  1031. Xstatic IncludeStack *cur_file;            /* current file */
  1032. Xstatic SymbolTable *included_files;        /* files already included */
  1033. X
  1034. Xstatic void save_text();
  1035. Xstatic void save_text_offset();
  1036. Xstatic void get_comment();
  1037. Xstatic void get_cpp_directive();
  1038. Xstatic void do_include();
  1039. X
  1040. X#ifdef yywrap
  1041. X#undef yywrap
  1042. X#endif
  1043. Xstatic int yywrap();
  1044. X%}
  1045. X
  1046. XWS        [ \t]
  1047. XLETTER        [A-Za-z_]
  1048. XDIGIT        [0-9]
  1049. XID        {LETTER}({LETTER}|{DIGIT})*
  1050. XSTRING        \"(\\\"|[^"\n])*\"
  1051. XQUOTED        ({STRING}|\'(\\\'|[^'\n])*\'|\\.)
  1052. X
  1053. X%s CPP1 INIT1 INIT2 CURLY LEXYACC ASM
  1054. X%%
  1055. X
  1056. X\n            { save_text(); cur_file->line_num++;
  1057. X                cur_declarator = NULL; }
  1058. X
  1059. X"/*"            { save_text(); get_comment(); }
  1060. X"//".*$         save_text();
  1061. X
  1062. X<LEXYACC>^"%%"        { save_text(); if (++ly_count >= 2) BEGIN INITIAL; }
  1063. X<LEXYACC>^"%{"        { save_text(); BEGIN INITIAL; }
  1064. X<LEXYACC>{QUOTED}|.    save_text();
  1065. X<INITIAL>^"%}"        { save_text(); BEGIN LEXYACC; }
  1066. X
  1067. X<INITIAL>#{WS}*     { save_text(); BEGIN CPP1; }
  1068. X
  1069. X<CPP1>define{WS}+{ID}    {
  1070. X                save_text();
  1071. X                sscanf(yytext, "define %s", buf);
  1072. X                get_cpp_directive();
  1073. X                new_symbol(typedef_names, buf, DS_EXTERN);
  1074. X            }
  1075. X
  1076. X<CPP1>include{WS}*\"[^"]+\"     {
  1077. X                save_text();
  1078. X                sscanf(yytext, "include \"%[^\"]\"", buf);
  1079. X                get_cpp_directive();
  1080. X                do_include(buf, FALSE);
  1081. X            }
  1082. X<CPP1>include{WS}*\<[^>]+\>    {
  1083. X                save_text();
  1084. X                sscanf(yytext, "include <%[^>]>", buf);
  1085. X                get_cpp_directive();
  1086. X                do_include(buf, TRUE);
  1087. X            }
  1088. X
  1089. X<CPP1>[0-9]+{WS}+\".*$  {
  1090. X                save_text();
  1091. X                sscanf(yytext, "%d \"%[^\"]\"", &cur_file->line_num,
  1092. X                cur_file->file_name);
  1093. X                cur_file->line_num--;
  1094. X                BEGIN INITIAL;
  1095. X            }
  1096. X<CPP1>[0-9]+.*$     {
  1097. X                save_text();
  1098. X                sscanf(yytext, "%d ", &cur_file->line_num);
  1099. X                cur_file->line_num--;
  1100. X                BEGIN INITIAL;
  1101. X            }
  1102. X
  1103. X<CPP1>.         { save_text(); get_cpp_directive(); }
  1104. X
  1105. X<INITIAL>"("        { save_text_offset(); return '('; }
  1106. X<INITIAL>")"        {
  1107. X                save_text();
  1108. X                if (cur_file->convert)
  1109. X                cur_file->begin_comment =
  1110. X                 ftell(cur_file->tmp_file);
  1111. X                return ')';
  1112. X            }
  1113. X<INITIAL>"*"        { save_text_offset(); return '*'; }
  1114. X<INITIAL>","        { save_text(); return ','; }
  1115. X<INITIAL>";"        {
  1116. X                save_text();
  1117. X                if (cur_file->convert)
  1118. X                cur_file->begin_comment =
  1119. X                 ftell(cur_file->tmp_file);
  1120. X                return ';';
  1121. X            }
  1122. X<INITIAL>"..."        { save_text(); return T_ELLIPSIS; }
  1123. X<INITIAL>{STRING}    { save_text(); return T_STRING_LITERAL; }
  1124. X
  1125. X<INITIAL>asm        { save_text(); BEGIN ASM; return T_ASM; }
  1126. X<ASM>"("        save_text();
  1127. X<ASM>")"        { save_text(); BEGIN INITIAL; return T_ASMARG; }
  1128. X<ASM>{QUOTED}|.     save_text();
  1129. X
  1130. X<INITIAL>auto        { save_text_offset(); return T_AUTO; }
  1131. X<INITIAL>extern     { save_text_offset(); return T_EXTERN; }
  1132. X<INITIAL>register    { save_text_offset(); return T_REGISTER; }
  1133. X<INITIAL>static     { save_text_offset(); return T_STATIC; }
  1134. X<INITIAL>typedef    { save_text_offset(); return T_TYPEDEF; }
  1135. X<INITIAL>inline     { save_text_offset(); return T_INLINE; }
  1136. X<INITIAL>char        { save_text_offset(); return T_CHAR; }
  1137. X<INITIAL>double     { save_text_offset(); return T_DOUBLE; }
  1138. X<INITIAL>float        { save_text_offset(); return T_FLOAT; }
  1139. X<INITIAL>int        { save_text_offset(); return T_INT; }
  1140. X<INITIAL>void        { save_text_offset(); return T_VOID; }
  1141. X<INITIAL>long        { save_text_offset(); return T_LONG; }
  1142. X<INITIAL>short        { save_text_offset(); return T_SHORT; }
  1143. X<INITIAL>signed     { save_text_offset(); return T_SIGNED; }
  1144. X<INITIAL>unsigned    { save_text_offset(); return T_UNSIGNED; }
  1145. X<INITIAL>enum        { save_text_offset(); return T_ENUM; }
  1146. X<INITIAL>struct     { save_text_offset(); return T_STRUCT; }
  1147. X<INITIAL>union        { save_text_offset(); return T_UNION; }
  1148. X
  1149. X<INITIAL>{ID}        {
  1150. X                save_text_offset();
  1151. X                if (find_symbol(type_qualifiers, yytext) != NULL)
  1152. X                return T_TYPE_QUALIFIER;
  1153. X                else if (find_symbol(typedef_names, yytext) != NULL)
  1154. X                return T_TYPEDEF_NAME;
  1155. X                else
  1156. X                return T_IDENTIFIER;
  1157. X            }
  1158. X
  1159. X<INITIAL>\[[^\]]*\]    {
  1160. X                /* This can't handle the case where a comment
  1161. X                 * containing a ] appears between the brackets.
  1162. X                 */
  1163. X                int i;
  1164. X
  1165. X                save_text_offset();
  1166. X                for (i = 0; i < yyleng; ++i) {
  1167. X                if (yytext[i] == '\n')
  1168. X                    cur_file->line_num++;
  1169. X                }
  1170. X                return T_BRACKETS;
  1171. X            }
  1172. X
  1173. X<INITIAL>"="        { save_text(); BEGIN INIT1; return '='; }
  1174. X<INIT1>"{"        { save_text(); curly = 1; BEGIN INIT2; }
  1175. X<INIT1>[,;]        {
  1176. X                unput(yytext[yyleng-1]);
  1177. X                BEGIN INITIAL;
  1178. X                return T_INITIALIZER;
  1179. X            }
  1180. X<INIT1>{QUOTED}|.    save_text();
  1181. X
  1182. X<INIT2>"{"        { save_text(); ++curly; }
  1183. X<INIT2>"}"        {
  1184. X                save_text();
  1185. X                if (--curly == 0) {
  1186. X                BEGIN INITIAL;
  1187. X                return T_INITIALIZER;
  1188. X                }
  1189. X            }
  1190. X<INIT2>{QUOTED}|.    save_text();
  1191. X
  1192. X<INITIAL>"{"        {
  1193. X                save_text();
  1194. X                curly = 1;
  1195. X                BEGIN CURLY;
  1196. X                return T_LBRACE;
  1197. X            }
  1198. X<CURLY>"{"        { save_text(); ++curly; }
  1199. X<CURLY>"}"        {
  1200. X                save_text();
  1201. X                if (--curly == 0) {
  1202. X                BEGIN INITIAL;
  1203. X                return T_MATCHRBRACE;
  1204. X                }
  1205. X            }
  1206. X<CURLY>{QUOTED}|.    save_text();
  1207. X
  1208. X[ \t\f]+        save_text();
  1209. X.            {
  1210. X                save_text();
  1211. X                put_error();
  1212. X                fprintf(stderr, "bad character '%c'\n", yytext[0]);
  1213. X            }
  1214. X%%
  1215. X
  1216. X/* Save the matched text in the temporary file.
  1217. X */
  1218. Xstatic void
  1219. Xsave_text ()
  1220. X{
  1221. X    if (cur_file->convert) {
  1222. X    fputs(yytext, cur_file->tmp_file);
  1223. X    }
  1224. X}
  1225. X
  1226. X/* Record the current position in the temporary file and write the matched text
  1227. X * to the file.
  1228. X */
  1229. Xstatic void
  1230. Xsave_text_offset ()
  1231. X{
  1232. X    strcpy(yylval.text.text, yytext);
  1233. X    if (cur_file->convert) {
  1234. X    yylval.text.begin = ftell(cur_file->tmp_file);
  1235. X    fputs(yytext, cur_file->tmp_file);
  1236. X    }
  1237. X}
  1238. X
  1239. X/* Scan to end of comment.
  1240. X */
  1241. Xstatic void
  1242. Xget_comment ()
  1243. X{
  1244. X    int c, lastc = '\0';
  1245. X
  1246. X    while ((c = input()) != 0) {
  1247. X    if (cur_file->convert)
  1248. X        fputc(c, cur_file->tmp_file);
  1249. X    switch (c) {
  1250. X    case '\n':
  1251. X        cur_file->line_num++;
  1252. X        break;
  1253. X    case '/':
  1254. X        if (lastc == '*') {
  1255. X        if (cur_file->convert) {
  1256. X            if (func_params && cur_declarator) {
  1257. X            cur_declarator->begin_comment = cur_file->begin_comment;
  1258. X            cur_file->begin_comment = ftell(cur_file->tmp_file);
  1259. X            cur_declarator->end_comment = cur_file->begin_comment;
  1260. X            cur_declarator = NULL;
  1261. X            } else {
  1262. X            cur_file->end_comment = ftell(cur_file->tmp_file);
  1263. X            }
  1264. X        }
  1265. X        return;
  1266. X        }
  1267. X        break;
  1268. X    }
  1269. X    lastc = c;
  1270. X    }
  1271. X}
  1272. X
  1273. X/* Scan rest of preprocessor statement.
  1274. X */
  1275. Xstatic void
  1276. Xget_cpp_directive ()
  1277. X{
  1278. X    int c, lastc = '\0';
  1279. X
  1280. X    while ((c = input()) != 0) {
  1281. X    if (cur_file->convert)
  1282. X        fputc(c, cur_file->tmp_file);
  1283. X    switch (c) {
  1284. X    case '\n':
  1285. X        cur_file->line_num++;
  1286. X        if (lastc != '\\') {
  1287. X        BEGIN INITIAL;
  1288. X        return;
  1289. X        }
  1290. X        break;
  1291. X    case '*':
  1292. X        if (lastc == '/')
  1293. X        get_comment();
  1294. X        break;
  1295. X    }
  1296. X    lastc = c;
  1297. X    }
  1298. X}
  1299. X
  1300. X/* Return a pointer to the current file name.
  1301. X */
  1302. Xchar *
  1303. Xcur_file_name ()
  1304. X{
  1305. X    return cur_file->file_name;
  1306. X}
  1307. X
  1308. X/* Return the current line number.
  1309. X */
  1310. Xunsigned
  1311. Xcur_line_num ()
  1312. X{
  1313. X    return cur_file->line_num;
  1314. X}
  1315. X
  1316. X/* Return the current temporary output file.
  1317. X */
  1318. XFILE *
  1319. Xcur_tmp_file ()
  1320. X{
  1321. X    return cur_file->tmp_file;
  1322. X}
  1323. X
  1324. X/* Set the modify flag for the current file.
  1325. X */
  1326. Xvoid
  1327. Xcur_file_changed ()
  1328. X{
  1329. X    cur_file->changed = TRUE;
  1330. X}
  1331. X
  1332. X/* Return the temporary file offset of beginning of the current comment.
  1333. X */
  1334. Xlong
  1335. Xcur_begin_comment ()
  1336. X{
  1337. X    return cur_file->begin_comment;
  1338. X}
  1339. X
  1340. X/* Push a file onto the include stack.    The stream yyin must already
  1341. X * point to the file.
  1342. X */
  1343. Xstatic void
  1344. Xinclude_file (name, convert)
  1345. Xchar *name;        /* file name */
  1346. Xboolean convert;    /* if TRUE, convert function definitions */
  1347. X{
  1348. X    ++inc_depth;
  1349. X    cur_file = inc_stack + inc_depth;
  1350. X    cur_file->file = yyin;
  1351. X    cur_file->file_name = strcpy(xmalloc(MAX_TEXT_SIZE), name);
  1352. X    cur_file->line_num = 1;
  1353. X    cur_file->convert = convert;
  1354. X    cur_file->changed = FALSE;
  1355. X
  1356. X#ifdef FLEX_SCANNER
  1357. X    cur_file->buffer = yy_create_buffer(yyin, YY_BUF_SIZE);
  1358. X    yy_switch_to_buffer(cur_file->buffer);
  1359. X#endif
  1360. X
  1361. X    if (convert) {
  1362. X    cur_file->begin_comment = cur_file->end_comment = 0;
  1363. X    cur_file->tmp_file = tmpfile();
  1364. X    if (cur_file->tmp_file == NULL) {
  1365. X        fprintf(stderr, "%s: cannot create temporary file %s\n", progname);
  1366. X        cur_file->convert = FALSE;
  1367. X    }
  1368. X    }
  1369. X}
  1370. X
  1371. X#define BLOCK_SIZE 2048
  1372. X
  1373. X/* Copy converted C source from the temporary file to the output stream.
  1374. X */
  1375. Xstatic void
  1376. Xput_file (outf)
  1377. XFILE *outf;
  1378. X{
  1379. X    char block[BLOCK_SIZE];
  1380. X    long filesize;
  1381. X    unsigned nread, count;
  1382. X
  1383. X    filesize = ftell(cur_file->tmp_file);
  1384. X    fseek(cur_file->tmp_file, 0L, 0);
  1385. X    while (filesize > 0) {
  1386. X    count = (filesize < BLOCK_SIZE) ? (unsigned)filesize : BLOCK_SIZE;
  1387. X    nread = fread(block, sizeof(char), count, cur_file->tmp_file);
  1388. X    if (nread == 0)
  1389. X        break;
  1390. X    fwrite(block, sizeof(char), nread, outf);
  1391. X    filesize -= nread;
  1392. X    }
  1393. X}
  1394. X
  1395. X/* Remove the top of the include stack.
  1396. X */
  1397. Xvoid
  1398. Xpop_file ()
  1399. X{
  1400. X    FILE *outf;
  1401. X
  1402. X    if (yyin != stdin)
  1403. X    fclose(yyin);
  1404. X
  1405. X    if (cur_file->convert) {
  1406. X    if (cur_file->changed) {
  1407. X        if (yyin == stdin) {
  1408. X        put_file(stdout);
  1409. X        } else if ((outf = fopen(cur_file->file_name, "w")) != NULL) {
  1410. X        put_file(outf);
  1411. X        fclose(outf);
  1412. X        } else {
  1413. X        fprintf(stderr, "%s: cannot create file %s\n", progname,
  1414. X            cur_file->file_name);
  1415. X        }
  1416. X    }
  1417. X
  1418. X    fclose(cur_file->tmp_file);
  1419. X    }
  1420. X    free(cur_file->file_name);
  1421. X
  1422. X#ifdef FLEX_SCANNER
  1423. X    yy_delete_buffer(YY_CURRENT_BUFFER);
  1424. X#endif
  1425. X
  1426. X    if (--inc_depth >= 0) {
  1427. X    cur_file = inc_stack + inc_depth;
  1428. X    yyin = cur_file->file;
  1429. X
  1430. X#ifdef FLEX_SCANNER
  1431. X    yy_switch_to_buffer(cur_file->buffer);
  1432. X#endif
  1433. X    }
  1434. X}
  1435. X
  1436. X/* Process include directive.
  1437. X */
  1438. Xstatic void
  1439. Xdo_include (filename, stdinc)
  1440. Xchar *filename;     /* file to include */
  1441. Xboolean stdinc;     /* TRUE if file name specified with angle brackets */
  1442. X{
  1443. X    char path[MAX_TEXT_SIZE];
  1444. X    int i;
  1445. X    FILE *fp;
  1446. X
  1447. X    if (inc_depth >= MAX_INC_DEPTH-1) {
  1448. X    put_error();
  1449. X    fprintf(stderr, "includes too deeply nested\n");
  1450. X    return;
  1451. X    }
  1452. X
  1453. X    sprintf(path, stdinc ? "<%s>" : "\"%s\"", filename);
  1454. X    if (find_symbol(included_files, path) != NULL)
  1455. X    return;
  1456. X    new_symbol(included_files, path, 0);
  1457. X
  1458. X    for (i = stdinc != 0; i < num_inc_dir; ++i) {
  1459. X    if (strlen(inc_dir[i]) == 0) {
  1460. X        strcpy(path, filename);
  1461. X    } else {
  1462. X        sprintf(path, "%s/%s", inc_dir[i], filename);
  1463. X    }
  1464. X    if ((fp = fopen(path, "r")) != NULL) {
  1465. X        yyin = fp;
  1466. X        include_file(path, func_style != FUNC_NONE && !stdinc);
  1467. X        return;
  1468. X    }
  1469. X    }
  1470. X
  1471. X    put_error();
  1472. X    fprintf(stderr, "cannot read file %s\n", filename);
  1473. X}
  1474. X
  1475. X/* When the end of the current input file is reached, pop a
  1476. X * nested include file.
  1477. X */
  1478. Xstatic int
  1479. Xyywrap ()
  1480. X{
  1481. X    if (inc_depth > 0) {
  1482. X    pop_file();
  1483. X    return 0;
  1484. X    } else {
  1485. X    return 1;
  1486. X    }
  1487. X}
  1488. END_OF_lex.l
  1489. if test 11306 -ne `wc -c <lex.l`; then
  1490.     echo shar: \"lex.l\" unpacked with wrong size!
  1491. fi
  1492. # end of overwriting check
  1493. fi
  1494. if test -f grammar.y -a "${1}" != "-c" ; then 
  1495.   echo shar: Will not over-write existing file \"grammar.y\"
  1496. else
  1497. echo shar: Extracting \"grammar.y\" \(14093 characters\)
  1498. sed "s/^X//" >grammar.y <<'END_OF_grammar.y'
  1499. X/* $Id: grammar.y 3.4 92/04/04 13:58:58 cthuang Exp $
  1500. X *
  1501. X * yacc grammar for C function prototype generator
  1502. X * This was derived from the grammar in Appendix A of
  1503. X * "The C Programming Language" by Kernighan and Ritchie.
  1504. X */
  1505. X
  1506. X%token
  1507. X    /* identifiers that are not reserved words */
  1508. X    T_IDENTIFIER T_TYPEDEF_NAME
  1509. X
  1510. X    /* storage class */
  1511. X    T_AUTO T_EXTERN T_REGISTER T_STATIC T_TYPEDEF
  1512. X    /* This keyword included for compatibility with C++. */
  1513. X    T_INLINE
  1514. X
  1515. X    /* type specifiers */
  1516. X    T_CHAR T_DOUBLE T_FLOAT T_INT T_VOID
  1517. X    T_LONG T_SHORT T_SIGNED T_UNSIGNED
  1518. X    T_ENUM T_STRUCT T_UNION
  1519. X
  1520. X    /* type qualifiers */
  1521. X    T_TYPE_QUALIFIER
  1522. X
  1523. X    /* left brace */
  1524. X    T_LBRACE
  1525. X    /* all input to the matching right brace */
  1526. X    T_MATCHRBRACE
  1527. X
  1528. X    /* paired square brackets and everything between them: [ ... ] */
  1529. X    T_BRACKETS
  1530. X
  1531. X    /* three periods */
  1532. X    T_ELLIPSIS
  1533. X
  1534. X    /* constant expression or paired braces following an equal sign */
  1535. X    T_INITIALIZER
  1536. X
  1537. X    /* string literal */
  1538. X    T_STRING_LITERAL
  1539. X
  1540. X    /* asm */
  1541. X    T_ASM
  1542. X    /* ( "string literal" ) following asm keyword */
  1543. X    T_ASMARG
  1544. X
  1545. X%type <decl_spec> decl_specifiers decl_specifier
  1546. X%type <decl_spec> storage_class type_specifier type_qualifier
  1547. X%type <decl_spec> struct_or_union_specifier enum_specifier
  1548. X%type <decl_list> init_declarator_list
  1549. X%type <declarator> init_declarator declarator direct_declarator
  1550. X%type <declarator> abs_declarator direct_abs_declarator
  1551. X%type <param_list> parameter_type_list parameter_list
  1552. X%type <parameter> parameter_declaration
  1553. X%type <param_list> opt_identifier_list identifier_list
  1554. X%type <text>
  1555. X    struct_or_union pointer opt_type_qualifiers type_qualifier_list any_id
  1556. X    T_BRACKETS
  1557. X    T_IDENTIFIER T_TYPEDEF_NAME
  1558. X    T_AUTO T_EXTERN T_REGISTER T_STATIC T_TYPEDEF T_INLINE
  1559. X    T_CHAR T_DOUBLE T_FLOAT T_INT T_VOID T_LONG T_SHORT T_SIGNED T_UNSIGNED
  1560. X    T_ENUM T_STRUCT T_UNION
  1561. X    T_TYPE_QUALIFIER
  1562. X    '(' '*'
  1563. X
  1564. X%{
  1565. X#include <stdio.h>
  1566. X#include "cproto.h"
  1567. X#include "symbol.h"
  1568. X#include "semantic.h"
  1569. X
  1570. X#define YYMAXDEPTH 150
  1571. X
  1572. X/* Declaration specifier attributes for the typedef statement currently being
  1573. X * scanned.
  1574. X */
  1575. Xstatic int cur_decl_spec_flags;
  1576. X
  1577. X/* Pointer to parameter list for the current function definition. */
  1578. Xstatic ParameterList *func_params;
  1579. X
  1580. X/* Pointer to current declarator in function parameter declaration. */
  1581. Xstatic Declarator *cur_declarator;
  1582. X
  1583. X/* temporary string buffer */
  1584. Xstatic char buf[MAX_TEXT_SIZE];
  1585. X
  1586. X/* Table of typedef names */
  1587. Xstatic SymbolTable *typedef_names;
  1588. X
  1589. X/* Table of type qualifiers */
  1590. Xstatic SymbolTable *type_qualifiers;
  1591. X%}
  1592. X%%
  1593. X
  1594. Xprogram
  1595. X    : /* empty */
  1596. X    | translation_unit
  1597. X    ;
  1598. X
  1599. Xtranslation_unit
  1600. X    : external_declaration
  1601. X    | translation_unit external_declaration
  1602. X    ;
  1603. X
  1604. Xexternal_declaration
  1605. X    : declaration
  1606. X    | function_definition
  1607. X    | function_definition ';'
  1608. X    | linkage_specification
  1609. X    | T_ASM T_ASMARG ';'
  1610. X    | error ';'
  1611. X    | error braces
  1612. X    ;
  1613. X
  1614. Xbraces
  1615. X    : T_LBRACE T_MATCHRBRACE
  1616. X    ;
  1617. X
  1618. Xlinkage_specification
  1619. X    : T_EXTERN T_STRING_LITERAL braces
  1620. X    | T_EXTERN T_STRING_LITERAL declaration
  1621. X    ;
  1622. X
  1623. Xdeclaration
  1624. X    : decl_specifiers ';'
  1625. X    {
  1626. X        free_decl_spec(&$1);
  1627. X    }
  1628. X    | decl_specifiers init_declarator_list ';'
  1629. X    {
  1630. X        check_untagged(&$1);
  1631. X        if (func_params != NULL) {
  1632. X        set_param_types(func_params, &$1, &$2);
  1633. X        } else {
  1634. X        gen_declarations(&$1, &$2);
  1635. X        free_decl_list(&$2);
  1636. X        }
  1637. X        free_decl_spec(&$1);
  1638. X    }
  1639. X    | T_TYPEDEF decl_specifiers
  1640. X    {
  1641. X        cur_decl_spec_flags = $2.flags;
  1642. X        free_decl_spec(&$2);
  1643. X    }
  1644. X      opt_declarator_list ';'
  1645. X    ;
  1646. X
  1647. Xopt_declarator_list
  1648. X    : /* empty */
  1649. X    | declarator_list
  1650. X    ;
  1651. X
  1652. Xdeclarator_list
  1653. X    : declarator
  1654. X    {
  1655. X        new_symbol(typedef_names, $1->name, cur_decl_spec_flags);
  1656. X        free_declarator($1);
  1657. X    }
  1658. X    | declarator_list ',' declarator
  1659. X    {
  1660. X        new_symbol(typedef_names, $3->name, cur_decl_spec_flags);
  1661. X        free_declarator($3);
  1662. X    }
  1663. X    ;
  1664. X
  1665. Xfunction_definition
  1666. X    : decl_specifiers declarator
  1667. X    {
  1668. X        check_untagged(&$1);
  1669. X        if ($2->func_def == FUNC_NONE) {
  1670. X        yyerror("syntax error");
  1671. X        YYERROR;
  1672. X        }
  1673. X        func_params = &($2->head->params);
  1674. X        func_params->begin_comment = cur_file->begin_comment;
  1675. X        func_params->end_comment = cur_file->end_comment;
  1676. X    }
  1677. X      opt_declaration_list T_LBRACE
  1678. X    {
  1679. X        func_params = NULL;
  1680. X
  1681. X        if (cur_file->convert)
  1682. X        gen_func_definition(&$1, $2);
  1683. X        gen_prototype(&$1, $2);
  1684. X        free_decl_spec(&$1);
  1685. X        free_declarator($2);
  1686. X    }
  1687. X      T_MATCHRBRACE
  1688. X    | declarator
  1689. X    {
  1690. X        if ($1->func_def == FUNC_NONE) {
  1691. X        yyerror("syntax error");
  1692. X        YYERROR;
  1693. X        }
  1694. X        func_params = &($1->head->params);
  1695. X        func_params->begin_comment = cur_file->begin_comment;
  1696. X        func_params->end_comment = cur_file->end_comment;
  1697. X    }
  1698. X      opt_declaration_list T_LBRACE
  1699. X    {
  1700. X        DeclSpec decl_spec;
  1701. X
  1702. X        func_params = NULL;
  1703. X
  1704. X        new_decl_spec(&decl_spec, "int", $1->begin, DS_EXTERN);
  1705. X        if (cur_file->convert)
  1706. X        gen_func_definition(&decl_spec, $1);
  1707. X        gen_prototype(&decl_spec, $1);
  1708. X        free_decl_spec(&decl_spec);
  1709. X        free_declarator($1);
  1710. X    }
  1711. X      T_MATCHRBRACE
  1712. X    ;
  1713. X
  1714. Xopt_declaration_list
  1715. X    : /* empty */
  1716. X    | declaration_list
  1717. X    ;
  1718. X
  1719. Xdeclaration_list
  1720. X    : declaration
  1721. X    | declaration_list declaration
  1722. X    ;
  1723. X
  1724. Xdecl_specifiers
  1725. X    : decl_specifier
  1726. X    | decl_specifiers decl_specifier
  1727. X    {
  1728. X        join_decl_specs(&$$, &$1, &$2);
  1729. X        free($1.text);
  1730. X        free($2.text);
  1731. X    }
  1732. X    ;
  1733. X
  1734. Xdecl_specifier
  1735. X    : storage_class
  1736. X    | type_specifier
  1737. X    | type_qualifier
  1738. X    ;
  1739. X
  1740. Xstorage_class
  1741. X    : T_AUTO
  1742. X    {
  1743. X        new_decl_spec(&$$, $1.text, $1.begin, DS_EXTERN);
  1744. X    }
  1745. X    | T_EXTERN
  1746. X    {
  1747. X        new_decl_spec(&$$, $1.text, $1.begin, DS_JUNK);
  1748. X    }
  1749. X    | T_REGISTER
  1750. X    {
  1751. X        new_decl_spec(&$$, $1.text, $1.begin, DS_EXTERN);
  1752. X    }
  1753. X    | T_STATIC
  1754. X    {
  1755. X        new_decl_spec(&$$, $1.text, $1.begin, DS_STATIC);
  1756. X    }
  1757. X    | T_INLINE
  1758. X    {
  1759. X        new_decl_spec(&$$, $1.text, $1.begin, DS_JUNK);
  1760. X    }
  1761. X    ;
  1762. X
  1763. Xtype_specifier
  1764. X    : T_CHAR
  1765. X    {
  1766. X        new_decl_spec(&$$, $1.text, $1.begin, DS_EXTERN | DS_CHAR);
  1767. X    }
  1768. X    | T_DOUBLE
  1769. X    {
  1770. X        new_decl_spec(&$$, $1.text, $1.begin, DS_EXTERN);
  1771. X    }
  1772. X    | T_FLOAT
  1773. X    {
  1774. X        new_decl_spec(&$$, $1.text, $1.begin, DS_EXTERN | DS_FLOAT);
  1775. X    }
  1776. X    | T_INT
  1777. X    {
  1778. X        new_decl_spec(&$$, $1.text, $1.begin, DS_EXTERN);
  1779. X    }
  1780. X    | T_LONG
  1781. X    {
  1782. X        new_decl_spec(&$$, $1.text, $1.begin, DS_EXTERN);
  1783. X    }
  1784. X    | T_SHORT
  1785. X    {
  1786. X        new_decl_spec(&$$, $1.text, $1.begin, DS_EXTERN | DS_SHORT);
  1787. X    }
  1788. X    | T_SIGNED
  1789. X    {
  1790. X        new_decl_spec(&$$, $1.text, $1.begin, DS_EXTERN);
  1791. X    }
  1792. X    | T_UNSIGNED
  1793. X    {
  1794. X        new_decl_spec(&$$, $1.text, $1.begin, DS_EXTERN);
  1795. X    }
  1796. X    | T_VOID
  1797. X    {
  1798. X        new_decl_spec(&$$, $1.text, $1.begin, DS_EXTERN);
  1799. X    }
  1800. X    | struct_or_union_specifier
  1801. X    | enum_specifier
  1802. X    ;
  1803. X
  1804. Xtype_qualifier
  1805. X    : T_TYPE_QUALIFIER
  1806. X    {
  1807. X        new_decl_spec(&$$, $1.text, $1.begin, DS_EXTERN);
  1808. X    }
  1809. X    | T_TYPEDEF_NAME
  1810. X    {
  1811. X        /* A typedef name is actually a type specifier, but since the
  1812. X         * typedef symbol table also stores #define names, this production
  1813. X         * is here so the <pointer> nonterminal will scan #define names.
  1814. X         */
  1815. X        Symbol *s;
  1816. X        s = find_symbol(typedef_names, $1.text);
  1817. X        new_decl_spec(&$$, $1.text, $1.begin, s->flags);
  1818. X    }
  1819. X    ;
  1820. X
  1821. Xstruct_or_union_specifier
  1822. X    : struct_or_union any_id braces
  1823. X    {
  1824. X        sprintf(buf, "%s %s", $1.text, $2.text);
  1825. X        new_decl_spec(&$$, buf, $1.begin, DS_EXTERN);
  1826. X    }
  1827. X    | struct_or_union braces
  1828. X    {
  1829. X        sprintf(buf, "%s {}", $1.text);
  1830. X        new_decl_spec(&$$, buf, $1.begin, DS_EXTERN);
  1831. X    }
  1832. X    | struct_or_union any_id
  1833. X    {
  1834. X        sprintf(buf, "%s %s", $1.text, $2.text);
  1835. X        new_decl_spec(&$$, buf, $1.begin, DS_EXTERN);
  1836. X    }
  1837. X    ;
  1838. X
  1839. Xstruct_or_union
  1840. X    : T_STRUCT
  1841. X    | T_UNION
  1842. X    ;
  1843. X
  1844. Xinit_declarator_list
  1845. X    : init_declarator
  1846. X    {
  1847. X        new_decl_list(&$$, $1);
  1848. X    }
  1849. X    | init_declarator_list ',' init_declarator
  1850. X    {
  1851. X        add_decl_list(&$$, &$1, $3);
  1852. X    }
  1853. X    ;
  1854. X
  1855. Xinit_declarator
  1856. X    : declarator
  1857. X    {
  1858. X        if ($1->func_def != FUNC_NONE && func_params == NULL &&
  1859. X        func_style == FUNC_TRADITIONAL && cur_file->convert) {
  1860. X        gen_func_declarator($1);
  1861. X        fputs(yytext, cur_file->tmp_file);
  1862. X        }
  1863. X        cur_declarator = $$;
  1864. X    }
  1865. X    | declarator '='
  1866. X    {
  1867. X        if ($1->func_def != FUNC_NONE && func_params == NULL &&
  1868. X        func_style == FUNC_TRADITIONAL && cur_file->convert) {
  1869. X        gen_func_declarator($1);
  1870. X        fputs(" =", cur_file->tmp_file);
  1871. X        }
  1872. X    }
  1873. X      T_INITIALIZER
  1874. X    ;
  1875. X
  1876. Xenum_specifier
  1877. X    : T_ENUM any_id braces
  1878. X    {
  1879. X        sprintf(buf, "enum %s", $2.text);
  1880. X        new_decl_spec(&$$, buf, $1.begin, DS_EXTERN);
  1881. X    }
  1882. X    | T_ENUM braces
  1883. X    {
  1884. X        new_decl_spec(&$$, "enum {}", $1.begin, DS_EXTERN);
  1885. X    }
  1886. X    | T_ENUM any_id
  1887. X    {
  1888. X        sprintf(buf, "enum %s", $2.text);
  1889. X        new_decl_spec(&$$, buf, $1.begin, DS_EXTERN);
  1890. X    }
  1891. X    ;
  1892. X
  1893. Xany_id
  1894. X    : T_IDENTIFIER
  1895. X    | T_TYPEDEF_NAME
  1896. X    ;
  1897. X
  1898. Xdeclarator
  1899. X    : pointer direct_declarator
  1900. X    {
  1901. X        $$ = $2;
  1902. X        sprintf(buf, "%s%s", $1.text, $$->text);
  1903. X        free($$->text);
  1904. X        $$->text = xstrdup(buf);
  1905. X        $$->begin = $1.begin;
  1906. X    }
  1907. X    | direct_declarator
  1908. X    ;
  1909. X
  1910. Xdirect_declarator
  1911. X    : T_IDENTIFIER
  1912. X    {
  1913. X        $$ = new_declarator($1.text, $1.text, $1.begin);
  1914. X    }
  1915. X    | '(' declarator ')'
  1916. X    {
  1917. X        $$ = $2;
  1918. X        sprintf(buf, "(%s)", $$->text);
  1919. X        free($$->text);
  1920. X        $$->text = xstrdup(buf);
  1921. X        $$->begin = $1.begin;
  1922. X    }
  1923. X    | direct_declarator T_BRACKETS
  1924. X    {
  1925. X        $$ = $1;
  1926. X        sprintf(buf, "%s%s", $$->text, $2.text);
  1927. X        free($$->text);
  1928. X        $$->text = xstrdup(buf);
  1929. X    }
  1930. X    | direct_declarator '(' parameter_type_list ')'
  1931. X    {
  1932. X        $$ = new_declarator("%s()", $1->name, $1->begin);
  1933. X        $$->params = $3;
  1934. X        $$->func_stack = $1;
  1935. X        $$->head = ($1->func_stack == NULL) ? $$ : $1->head;
  1936. X        $$->func_def = FUNC_ANSI;
  1937. X    }
  1938. X    | direct_declarator '(' opt_identifier_list ')'
  1939. X    {
  1940. X        $$ = new_declarator("%s()", $1->name, $1->begin);
  1941. X        $$->params = $3;
  1942. X        $$->func_stack = $1;
  1943. X        $$->head = ($1->func_stack == NULL) ? $$ : $1->head;
  1944. X        $$->func_def = FUNC_TRADITIONAL;
  1945. X    }
  1946. X    ;
  1947. X
  1948. Xpointer
  1949. X    : '*' opt_type_qualifiers
  1950. X    {
  1951. X        sprintf($$.text, "*%s", $2.text);
  1952. X        $$.begin = $1.begin;
  1953. X    }
  1954. X    | '*' opt_type_qualifiers pointer
  1955. X    {
  1956. X        sprintf($$.text, "*%s%s", $2.text, $3.text);
  1957. X        $$.begin = $1.begin;
  1958. X    }
  1959. X    ;
  1960. X
  1961. Xopt_type_qualifiers
  1962. X    : /* empty */
  1963. X    {
  1964. X        strcpy($$.text, "");
  1965. X        $$.begin = 0L;
  1966. X    }
  1967. X    | type_qualifier_list
  1968. X    ;
  1969. X
  1970. Xtype_qualifier_list
  1971. X    : type_qualifier
  1972. X    {
  1973. X        strcpy($$.text, $1.text);
  1974. X        $$.begin = $1.begin;
  1975. X        free($1.text);
  1976. X    }
  1977. X    | type_qualifier_list type_qualifier
  1978. X    {
  1979. X        sprintf($$.text, "%s %s ", $1.text, $2.text);
  1980. X        $$.begin = $1.begin;
  1981. X        free($2.text);
  1982. X    }
  1983. X    ;
  1984. X
  1985. Xparameter_type_list
  1986. X    : parameter_list
  1987. X    | parameter_list ',' T_ELLIPSIS
  1988. X    {
  1989. X        add_ident_list(&$$, &$1, "...");
  1990. X    }
  1991. X    ;
  1992. X
  1993. Xparameter_list
  1994. X    : parameter_declaration
  1995. X    {
  1996. X        new_param_list(&$$, &$1);
  1997. X    }
  1998. X    | parameter_list ',' parameter_declaration
  1999. X    {
  2000. X        add_param_list(&$$, &$1, &$3);
  2001. X    }
  2002. X    ;
  2003. X
  2004. Xparameter_declaration
  2005. X    : decl_specifiers declarator
  2006. X    {
  2007. X        check_untagged(&$1);
  2008. X        new_parameter(&$$, &$1, $2);
  2009. X    }
  2010. X    | decl_specifiers abs_declarator
  2011. X    {
  2012. X        check_untagged(&$1);
  2013. X        new_parameter(&$$, &$1, $2);
  2014. X    }
  2015. X    | decl_specifiers
  2016. X    {
  2017. X        check_untagged(&$1);
  2018. X        new_parameter(&$$, &$1, NULL);
  2019. X    }
  2020. X    ;
  2021. X
  2022. Xopt_identifier_list
  2023. X    : /* empty */
  2024. X    {
  2025. X        new_ident_list(&$$);
  2026. X    }
  2027. X    | identifier_list
  2028. X    ;
  2029. X
  2030. Xidentifier_list
  2031. X    : T_IDENTIFIER
  2032. X    {
  2033. X        new_ident_list(&$$);
  2034. X        add_ident_list(&$$, &$$, $1.text);
  2035. X    }
  2036. X    | identifier_list ',' T_IDENTIFIER
  2037. X    {
  2038. X        add_ident_list(&$$, &$1, $3.text);
  2039. X    }
  2040. X    ;
  2041. X
  2042. Xabs_declarator
  2043. X    : pointer
  2044. X    {
  2045. X        $$ = new_declarator($1.text, "", $1.begin);
  2046. X    }
  2047. X    | pointer direct_abs_declarator
  2048. X    {
  2049. X        $$ = $2;
  2050. X        sprintf(buf, "%s%s", $1.text, $$->text);
  2051. X        free($$->text);
  2052. X        $$->text = xstrdup(buf);
  2053. X        $$->begin = $1.begin;
  2054. X    }
  2055. X    | direct_abs_declarator
  2056. X    ;
  2057. X
  2058. Xdirect_abs_declarator
  2059. X    : '(' abs_declarator ')'
  2060. X    {
  2061. X        $$ = $2;
  2062. X        sprintf(buf, "(%s)", $$->text);
  2063. X        free($$->text);
  2064. X        $$->text = xstrdup(buf);
  2065. X        $$->begin = $1.begin;
  2066. X    }
  2067. X    | direct_abs_declarator T_BRACKETS
  2068. X    {
  2069. X        $$ = $1;
  2070. X        sprintf(buf, "%s%s", $$->text, $2.text);
  2071. X        free($$->text);
  2072. X        $$->text = xstrdup(buf);
  2073. X    }
  2074. X    | T_BRACKETS
  2075. X    {
  2076. X        $$ = new_declarator($1.text, "", $1.begin);
  2077. X    }
  2078. X    | direct_abs_declarator '(' parameter_type_list ')'
  2079. X    {
  2080. X        $$ = new_declarator("%s()", "", $1->begin);
  2081. X        $$->params = $3;
  2082. X        $$->func_stack = $1;
  2083. X        $$->head = ($1->func_stack == NULL) ? $$ : $1->head;
  2084. X        $$->func_def = FUNC_ANSI;
  2085. X    }
  2086. X    | direct_abs_declarator '(' ')'
  2087. X    {
  2088. X        $$ = new_declarator("%s()", "", $1->begin);
  2089. X        $$->func_stack = $1;
  2090. X        $$->head = ($1->func_stack == NULL) ? $$ : $1->head;
  2091. X        $$->func_def = FUNC_ANSI;
  2092. X    }
  2093. X    | '(' parameter_type_list ')'
  2094. X    {
  2095. X        Declarator *d;
  2096. X        
  2097. X        d = new_declarator("", "", $1.begin);
  2098. X        $$ = new_declarator("%s()", "", $1.begin);
  2099. X        $$->params = $2;
  2100. X        $$->func_stack = d;
  2101. X        $$->head = $$;
  2102. X        $$->func_def = FUNC_ANSI;
  2103. X    }
  2104. X    | '(' ')'
  2105. X    {
  2106. X        Declarator *d;
  2107. X        
  2108. X        d = new_declarator("", "", $1.begin);
  2109. X        $$ = new_declarator("%s()", "", $1.begin);
  2110. X        $$->func_stack = d;
  2111. X        $$->head = $$;
  2112. X        $$->func_def = FUNC_ANSI;
  2113. X    }
  2114. X    ;
  2115. X
  2116. X%%
  2117. X#ifdef MSDOS
  2118. X#include "lex_yy.c"
  2119. X#else
  2120. X#include "lex.yy.c"
  2121. X#endif
  2122. X
  2123. Xvoid
  2124. Xyyerror (msg)
  2125. Xchar *msg;
  2126. X{
  2127. X    func_params = NULL;
  2128. X    put_error();
  2129. X    fprintf(stderr, "%s\n", msg);
  2130. X}
  2131. X
  2132. X/* Initialize the table of type qualifier keywords recognized by the lexical
  2133. X * analyzer.
  2134. X */
  2135. Xvoid
  2136. Xinit_parser ()
  2137. X{
  2138. X    static char *keywords[] = {
  2139. X    "const", "volatile",
  2140. X#ifdef MSDOS
  2141. X    "_cdecl", "_export", "_far", "_fastcall", "_fortran", "_huge",
  2142. X    "_interrupt", "_loadds", "_near", "_pascal", "_saveregs", "_segment",
  2143. X    "_cs", "_ds", "_es", "_ss", "_seg",
  2144. X    "cdecl", "far", "huge", "interrupt", "near", "pascal",
  2145. X#endif
  2146. X    };
  2147. X    int i;
  2148. X
  2149. X    /* Initialize type qualifier table. */
  2150. X    type_qualifiers = new_symbol_table();
  2151. X    for (i = 0; i < sizeof(keywords)/sizeof(keywords[0]); ++i) {
  2152. X    new_symbol(type_qualifiers, keywords[i], DS_EXTERN);
  2153. X    }
  2154. X}
  2155. X
  2156. X/* Process the C source file.  Write function prototypes to the standard
  2157. X * output.  Convert function definitions and write the converted source
  2158. X * code to a temporary file.
  2159. X */
  2160. Xvoid
  2161. Xprocess_file (infile, name)
  2162. XFILE *infile;
  2163. Xchar *name;
  2164. X{
  2165. X    char *s;
  2166. X
  2167. X    if (strlen(name) > 2) {
  2168. X    s = name + strlen(name) - 2;
  2169. X    if (*s == '.') {
  2170. X        ++s;
  2171. X        if (*s == 'l' || *s == 'y')
  2172. X        BEGIN LEXYACC;
  2173. X#ifdef MSDOS
  2174. X        if (*s == 'L' || *s == 'Y')
  2175. X        BEGIN LEXYACC;
  2176. X#endif
  2177. X    }
  2178. X    }
  2179. X
  2180. X    included_files = new_symbol_table();
  2181. X    typedef_names = new_symbol_table();
  2182. X    inc_depth = -1;
  2183. X    curly = 0;
  2184. X    ly_count = 0;
  2185. X    func_params = NULL;
  2186. X    yyin = infile;
  2187. X    include_file(name, func_style != FUNC_NONE);
  2188. X    if (proto_comments)
  2189. X    printf("/* %s */\n", cur_file_name());
  2190. X    yyparse();
  2191. X    free_symbol_table(typedef_names);
  2192. X    free_symbol_table(included_files);
  2193. X}
  2194. END_OF_grammar.y
  2195. if test 14093 -ne `wc -c <grammar.y`; then
  2196.     echo shar: \"grammar.y\" unpacked with wrong size!
  2197. fi
  2198. # end of overwriting check
  2199. fi
  2200. echo shar: End of shell archive.
  2201. exit 0
  2202.  
  2203. exit 0 # Just in case...
  2204.