home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume28 / cproto / part01 < prev    next >
Encoding:
Text File  |  1992-03-14  |  51.9 KB  |  2,136 lines

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