home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / mm / mm-ccmd-0.91-20031009.tar.gz / mm-ccmd-0.91-20031009.tar / work / ccmd / cmfnc.h4 < prev    next >
Text File  |  1990-12-18  |  10KB  |  296 lines

  1. define(`_',`dnl')_ Use this to prevent extra newlines in the output...
  2. _ ... and for comments!
  3. _
  4. _ Copyright (c) 1986, 1990 by The Trustees of Columbia University in
  5. _ the City of New York.  Permission is granted to any individual or
  6. _ institution to use, copy, or redistribute this software so long as it
  7. _ is not sold for profit, provided this copyright notice is retained.
  8. _
  9. _ Author: Andrew Lowry
  10. _
  11. _ * This M4 source is designed to generate two header files for the
  12. _ * ccmd package, based on information for specific parsing functions.
  13. _ * The actual output stream from M4 contains lines of the form:
  14. _ *     #file xxx
  15. _ * flush to the left margin, signaling the beginning of the text for
  16. _ * file xxx.  This output stream can be passed to the split program
  17. _ * in order to distribute the text to the various files.
  18. _ *
  19. _ * The first output file is called cmfnc.h, and contains symbols and
  20. _ * definitions required by application programs that use the ccmd
  21. _ * package.  The second file, cmfncs.h, contains system symbols and
  22. _ * definitions required primarily by the ccmd package modules.
  23. _ *
  24. _ * The last line in this file is an include statement to read in and
  25. _ * process the file cmconf.h4, which should generally be a series of
  26. _ * fndecl statements for bringing in the files describing the various
  27. _ * functions.  For example, the line:
  28. _ *     fndecl(cfm)
  29. _ * in cmconf.h4 would cause the system to be configured with the cmcfm
  30. _ * parsing function.  The line fndecl(xxx) causes an automatic include
  31. _ * of the file cmxxx.h4.
  32. _ *
  33. _ * The files for the individual parse functions generally include the
  34. _ * following items:
  35. _ *
  36. _ *    fnerror(XXX,`error message')
  37. _ *      Causes a symbol such as CFMxXXX to be defined, and causes the
  38. _ *      given error message to be entered into an error table.  The
  39. _ *      prefix is formed from the upper-cased fndecl argument.
  40. _ *
  41. _ *    fnflag(XXX,x)
  42. _ *      Causes a symbol such as CFM_XXX to be defined, with the value x.
  43. _ *      If x is omitted, the value from the prior fnflag invocation is
  44. _ *      doubled.  If this is the first invocation and x is omitted, 1
  45. _ *      is used.  The prior value is cleared by the fndecl macro.
  46. _ *
  47. _ *    fnconst(XXX,x)
  48. _ *      Causes a symbol such as _CFMXXX to be defined, with the value x.
  49. _ *      If x is omitted, the value from the prior fnconst invocation is
  50. _ *      bumped by 1.  If this is the first invocation and x is omitted, 0
  51. _ *      is used.  The prior value is cleared by the fndecl macro.
  52. _ *
  53. _ *    pvtype(type expression)
  54. _ *      Adds a component to the pval union for returned parse values.
  55. _ *      The component will be named something like _pvxxx, where xxx
  56. _ *      is the parse function name.  The component's type will be
  57. _ *      whatever is specified by the type expression.  Parse functions
  58. _ *      that return integers, strings, characters, or floats need not
  59. _ *      include a pvtype line, as components of these types are preloaded.
  60. _ *
  61. _ *    toapplic(`arbitrary text')
  62. _ *      Causes the given text to be included verbatim in the cmfnc.h file.
  63. _ *      Useful for defining special structures and the like.
  64. _ *
  65. _ *    tosystem(`arbitrary text')
  66. _ *      Causes the given text to be included verbatim in the cmfncs.h file.
  67. _ *
  68. _ *    Anything else
  69. _ *      Goes to the cmfnc.h file.
  70. _ *
  71. _
  72. _ Load initial text for each file before defining any macros that might
  73. _ interfere with their contents
  74. _
  75. divert(1)include(`cmfnc.top')
  76. divert(2)include(`cmfncs.top')
  77. _
  78. _ cat returns its arguments concatenated together
  79. _
  80. define(`cat',$1$2$3$4$5$6$7$8$9)_
  81. _
  82. _ nl - represents a newline
  83. _
  84. define(`nl',``
  85. '')_
  86. _
  87. _ quote - Returns its argument with quotes around it
  88. _
  89. define(`quote',`changequote([,])`$1'changequote(`,')')_
  90. _
  91. _ upper and lower convert letters to upper and lower case, resp.
  92. _
  93. define(`lower',`translit($1,`ABCDEFGHIJKLMNOPQRSTUVWXYZ',
  94.               `abcdefghijklmnopqrstuvwxyz')')_
  95. define(`upper',`translit($1,`abcdefghijklmnopqrstuvwxyz',
  96.               `ABCDEFGHIJKLMNOPQRSTUVWXYZ')')_
  97. _
  98. _ fndecl - set up to configure a named parse function (use the 3-char ending
  99. _   from the function name as the argument)
  100. _
  101. define(`fndecl',cat(``divert(1)'',
  102.            ``fnini($1)'',
  103.            ``fncomment()'',
  104.            ``fncode()'',
  105.            ``fnstub()'',
  106.            ``cat(`include(cm',lname,`.cnf)')'',
  107.            ``outerrs()''))_
  108. _
  109. _ fnini - Set variables for a new function configuration
  110. _
  111. define(`fnini',cat(``define(`lname',lower($1))'',
  112.            ``define(`uname',upper($1))'',
  113.            ``define(`lastval',-1)'',
  114.            ``define(`lastflag',0)'',
  115.            ``define(`lasterr',-1)'',
  116.            ``define(`lastfunc',incr(lastfunc))'',
  117.            ``define(`ftlist',
  118.               cat(quote(ftlist),`ftxxx(',lname,`,',lastfunc,`)'))''))_
  119. _
  120. _ fncomment - Output an appropriate comment to each file
  121. _
  122. define(`fncomment',cat(``cat(nl`/* Configuration information for cm',
  123.                 lname,` */',nl,nl)'',
  124.                ``divert(2)'',
  125.                ``cat(nl,`/* Error table and other configuration data',
  126.                 ` for cm',lname,` */',nl,nl)'',
  127.                ``divert(1)''))_
  128. _
  129. _ fncode - Output the function code symbol definition
  130. _
  131. define(`fncode',`cat(``#define _CM'',uname,` ',lastfunc,nl)')_
  132. _
  133. _ fnstub - Output a macro definition to stub out this parse function
  134. _
  135. define(`fnstub',cat(``cat(nl,`/* Macro to prevent loading of cm',
  136.              lname,` support */',nl,nl)'',
  137.             ``cat(`#define ',uname,`_STUB ftspec ft_',lname,
  138.               ` = { NULL, NULL, NULL, 0, NULL }; \',nl)'',
  139.             ``cat(`    fnerr fe_',lname,` = { 0, NULL };',nl,nl)''))_
  140. _
  141. _ fnerror - Used to declare function-specific error messages
  142. _
  143. define(`fnerror',cat(``define(`lasterr',incr(lasterr))'',
  144.              ``divert(3)'',
  145.          ``ifelse(lasterr,0,`',`,')'',
  146.              ``cat(nl,`        "',$2,")'',
  147.              ``divert(1)'',
  148.              ``cat(`#define ',uname,`x',$1,
  149.                 cat(`    CMERR(',lastfunc,`,',lasterr,`)'))''))_
  150. _
  151. _ outerrs - Output the error table declaration and initializer
  152. _
  153. define(`outerrs',cat(``divert(2)'',
  154.              ``define(`lasterr',incr(lasterr))'',
  155.              ``cat(nl,`#ifdef ',uname,`ERR',nl)'',
  156.              ``ifelse(lasterr,0,`outerr1()',`outerr2()')'',
  157.              ``cat(`#else',nl,`extern fnerr fe_',lname,`;',nl)'',
  158.              ``cat(`#endif',nl)'',
  159.              ``divert(1)'',
  160.                  ``_''))_
  161. define(`outerr1',`cat(nl,`fnerr fe_',lname,` = { 0, NULL };',nl)')_
  162. define(`outerr2',cat(nl,
  163.            ``cat(`static char *(',lname,`err[',lasterr,`]) = {')'',
  164.            ``undivert(3)'',
  165.            ``cat(nl,`};',nl)'',
  166.            ``cat(`fnerr fe_',lname,` = { ',
  167.              lasterr,`, ',lname,`err };',nl)''))_
  168. _
  169. _ fnflag - output a flag symbol definition to the cmfnc.h file
  170. _
  171. define(`fnflag',cat(``cat(``#define '',uname,`_',$1,` ')'',
  172.           ``ifelse($2,,
  173.               ifelse(lastflag,0,
  174.             `define(`lastflag',1)',
  175.             `define(`lastflag',eval(2*lastflag))'),
  176.               `define(`lastflag',$2)')'',
  177.            ``hex(lastflag)''))_
  178. _
  179. _ hex - takes a decimal string and outputs it as a four-digit hex value
  180. _ preceded by "0x"
  181. _
  182. define(`hex',`cat(0x,hexx($1))')_
  183. define(`hexx',`cat(hex1(eval($1/4096)),
  184.            hex1(eval(($1-($1/4096)*4096)/256)),
  185.            hex1(eval(($1-($1/256)*256)/16)),
  186.            hex1(eval($1-($1/16)*16)))')_
  187. define(`hex1',`substr(`0123456789abcdef',$1,1)')_
  188. _
  189. _ fnconst - output a constant symbol definition to the cmfnc.h file
  190. _
  191. define(`fnconst',cat(``cat(``#define _'',uname,$1,` ')'',
  192.            ``ifelse($2,,
  193.                `define(`lastval',incr(lastval))',
  194.                `define(`lastval',$2)')'',
  195.             ``cat(lastval)''))_
  196. _
  197. _ pvtype - adds a component to the pval union declaration.  All additions
  198. _ accumulate in diversion 4.
  199. _
  200. define(`pvtype',cat(``divert(4)'',
  201.             ``cat(`        ',$1,` _pv',lname,`;',nl)'',
  202.             ``divert(1)''))_
  203. _
  204. _ toapplic - Output the argument to the cmfnc.h file
  205. _
  206. define(`toapplic',cat(``divert(1)'',`$1'))_
  207. _
  208. _ tosystem - Output the argument to the cmfncs.h file
  209. _
  210. define(`tosystem',cat(``divert(2)'',`$1 ',``nl()'',``divert(1)''))_
  211. _
  212. _ generic - Outputs the generic error codes and error message table.
  213. _ Mostly just a big kludge to invoke the macros called by fndecl after
  214. _ faking the variables.
  215. _
  216. define(`generic',cat(``define(`uname',`CM')'',
  217.              ``define(`lasterr',-1)'',
  218.              ``divert(1)'',
  219.              ``include(cmgnrc.cnf)'',
  220.              ``define(`uname',`GEN')'',
  221.              ``define(`lname',`gen')'',
  222.              ``tosystem(`/* Generic ccmd error messages */')'',
  223.              ``outerrs()''))_
  224. _
  225. _ outlist - Output the function types in ftlist, each prefixed by the
  226. _ first argument and with the column position initialized to the second
  227. _ argument
  228. _
  229. define(`outlist',cat(``define(`ftprefix',$1)'',
  230.              ``define(`ftcolumn',$2)'',
  231.              ``ftlist()''))_
  232. _
  233. _ Initialize function code counter so first code is 1, and set empty fn list
  234. define(`lastfunc',0)_
  235. define(`ftlist',`')_
  236. _
  237. _ OK, here we go...
  238. _
  239. generic
  240. include(cmconf.h4)_
  241. _
  242. _ Now define the ftxxx macro so ftlist will expand correctly into a list
  243. _ of parse function names, each prefixed by the value of ftprefix. 
  244. _ Newlines are inserted when the column counter exceeds 70, with new
  245. _ lines indented two spaces.
  246. _
  247. define(`ftxxx',cat(``define(`ftxxxx',
  248.                cat(ftprefix,$1,ifelse($2,lastfunc,` ',``| '')))'',
  249.            ``define(`ftcolumn',eval(ftcolumn+len(ftxxxx)))'',
  250.            ``translit(ftxxxx,`|',`,')'',
  251.            ``ifelse(eval(ftcolumn > 70),eval(1 > 0),
  252.                cat(nl,`  ',``define(`ftcolumn',2)''))''))_
  253. divert(0)_
  254. #file cmfnc.h
  255. undivert(1)_
  256.  
  257. /* Union declaration for parse return values */
  258.  
  259. typedef union PVAL {
  260.     int _pvint;
  261.     float _pvflt;
  262.     char _pvchr;
  263.     char *_pvstr;
  264.     char **_pvstrvec;
  265. undivert(4)_
  266. } pval;
  267. #file cmfncs.h
  268. undivert(2)_
  269.  
  270. #ifdef STORAGE
  271.  
  272. /* Function handler table */
  273.  
  274. extern ftspec
  275.   outlist(`ft_',2);
  276.  
  277. ftspec *(cmfntb[lastfunc]) = {
  278.   outlist(`&ft_',2)
  279. };
  280.  
  281. /* Error table table */
  282.  
  283. fnerr *(fnetab[eval(lastfunc+1)]) = {
  284.   &fe_gen, outlist(`&fe_',11)
  285. };
  286.  
  287. /* Number of defined functions */
  288.  
  289. int cmfmax = eval(lastfunc+1);
  290.  
  291. #else
  292. extern ftspec *(cmfntb[]);
  293. extern fnerr *(fnetab[]);
  294. extern int cmfmax;
  295. #endif
  296.