home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / txict100.zip / texicvt1.00 / source / scan.l < prev    next >
Text File  |  1997-03-31  |  34KB  |  1,118 lines

  1. %{
  2. /*
  3. ================================================================================
  4.                         Texinfo converting Tools
  5.                          Release 1.00 28.03.97
  6.                        (c) 1996 by Andreas Kaiser
  7.                     (c) 1997 by Karl Heinz Marbaise
  8. ================================================================================
  9.  
  10. Discription:
  11.     Lexical analyser to convert from Texinfo
  12.     to OS/2-IPF
  13.  
  14. Authors:
  15.    Andreas Kaiser
  16.    Karl Heinz Marbaise
  17.  
  18. e-mail:
  19.    Internet: KHMarbaise@p69.ks.fido.de
  20.    Fido-net: 2:2452/117.69
  21.  
  22. Bugs, question:
  23.    to above e-mail adress.
  24.  
  25. Register:
  26.    Please send a e-mail to above adress to register.
  27.    (include the release you want to register)
  28.    This registration should be done to let me
  29.    know how many people using these tools and
  30.    if it is worth to invest more time in continuing
  31.    development these tools or let the first release
  32.    of them be the last.
  33.    That is the only reason to make a registration.
  34.    I think a e-mail is not to much, isn't it?
  35.  
  36. License:
  37.    The "Texinfo converting tools" are free software;
  38.    you can redistribute it and/or modify it under the terms of
  39.    the GNU General Public License as published by the Free
  40.    Software Foundation; either version 2, or (at your option)
  41.    any later version.
  42.  
  43.    The "Texinfo converting tools" are distributed in the hope that
  44.    they will be useful, but WITHOUT ANY WARRANTY; without even the
  45.    implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  46.    PURPOSE.  See the GNU General Public License for more details.
  47.  
  48.    You should have received a copy of the GNU General Public License
  49.    along with the "Texinfo converting tools" ; see the file COPYING.
  50.    If not, write to the:
  51.    Free Software Foundation,
  52.    59 Temple Place - Suite 330,
  53.    Boston, MA 02111-1307, USA.
  54.  
  55.    See \texicvt1.00\COPYING for details.
  56.  
  57. ================================================================================
  58. */
  59.  
  60. static char *rcsid = "$Id: SCAN.L 1.7 1997/03/30 15:08:22 KHM Exp $";
  61.  
  62. #include "info.h"
  63. #include <ctype.h>
  64. #include <errno.h>
  65. #if defined (__EMX__)
  66. #include <strstrea.h>
  67. #else
  68. #include <strstream.h>
  69. #endif
  70. /*extern "C" char *strupr(char *);*/
  71.  
  72. /*#undef yywrap*/
  73. #define YY_NO_TOP_STATE  /* supress compiler warning
  74.                           * 'yy_top_state' defined but not used
  75.                           */
  76. #define SAVESTATE(x)  yy_push_state(x)
  77. #define RESTORESTATE  yy_pop_state ()
  78.  
  79. String & arg();
  80. String & eol();
  81. String Test;
  82. void unexpected(const char *);
  83. void footnote();
  84. void skip();
  85. void dot();
  86. void include(const char *);
  87. void Defs
  88.      (
  89.          int xVariant,     /* is on of the @def...x */
  90.          int exCategory,   /* =1 means category exists */
  91.          int exClass,      /* =1 class exists */
  92.          int exType,       /* =1 means type exists */
  93.          int exArgs,       /* =1 means arguments exists */
  94.          const char *TypeOfIndex,  /* make index entry in e.g. "fn" */
  95.          const char *CategoryDef   /* some of the @def's are shortages of other @def's */
  96.      );
  97. String &EolPar (void);
  98.  
  99. void ErrorOut (const char *msg, const char *yyt);
  100. void WarningOut (const char *msg, const char *yyt);
  101.  
  102. typedef enum { ifclear, ifset, ifhtml, iftex, ifinfo } tIfType;
  103.  
  104. static const char *cIfType[5] =
  105.     {
  106.         "ifclear",
  107.         "ifset",
  108.         "ifhtml",
  109.         "iftex",
  110.         "ifinfo"
  111.     };
  112.  
  113.  
  114. typedef struct
  115.     {
  116.         tIfType IfType;
  117.         int     Condition;
  118.     } tIfStack;
  119.  
  120. typedef struct
  121.     {
  122.         YY_BUFFER_STATE state;
  123.         char            *fn;   /* File name of include file */
  124.         int             lineno;
  125.     } tIncludeStack;
  126. /* extern "C" int yywrap();*/
  127.  
  128. int iff(String& arg, tIfType IfType);
  129. /*int iff(String&, int); */
  130. /*int endiff();*/
  131. int endiff(tIfType IfType);
  132.  
  133.  
  134. const int    MaxIncl = 10;
  135. /* YY_BUFFER_STATE inclstack[MaxIncl];*/
  136. tIncludeStack   inclstack[MaxIncl];
  137. int        incllevel = 0;
  138.  
  139. const int    MaxIf = 10;
  140. /* int        ifstack[MaxIf];*/
  141. tIfStack        ifstack[MaxIf];
  142. int        iflevel = 0;
  143.  
  144. /* This need to let @raisesection or
  145.  * @lowersection work, but actual it doesn't
  146.  */
  147. int             HeadingLevel = 0;
  148.  
  149. int     DefinedFunction = 0;
  150. %}
  151. %option stack
  152. /*%option noyywrap*/
  153.  
  154. NL      \r?\n
  155. WS      [ \t]*
  156. WSP     [ \t]+
  157.  
  158. %x    TABLE MENU FALSE IGNORE TEX TITLE DIRENTRY MULTITABLE
  159.  
  160. %x      IFTEX IGNORESTUFF IFSET IFCLEAR
  161.  
  162. %%
  163.     
  164. START-INFO-DIR-ENTRY{WS}{NL}  { SAVESTATE (IGNORESTUFF); yylineno++; }
  165. <IGNORESTUFF>.            ;
  166. <IGNORESTUFF>\n           ++yylineno;
  167. <IGNORESTUFF>END-INFO-DIR-ENTRY[ \t]*\n   { ++yylineno; RESTORESTATE;  };
  168.  
  169. @\*            PUTS(endl << ".br"); PUTL();
  170. @\.            PUTS('.');
  171. @\:            ;
  172. @@            PUTS('@');
  173. @\{            PUTS('{');
  174. @\}            PUTS('}');
  175.  
  176. @afourpaper             { WarningOut ( "@afourpaper has to be rounded with @iftex ... @end iftex"
  177.                                      ",look into Texinfo Manual Release 3.9 section 'Printing on A4 Paper'", yytext); }
  178. @appendix        heading(HeadingLevel+1, eol());
  179. @appendixsec        heading(HeadingLevel+2, eol());
  180. @appendixsection    heading(HeadingLevel+2, eol());
  181. @appendixsubsec        heading(HeadingLevel+3, eol());
  182. @appendixsubsubsec    heading(HeadingLevel+4, eol());
  183. @asis            ;
  184. @author            PUTA(":hp5."); PUT(eol()); PUTA(":ehp5.");
  185. @b\{            PUTA(":hp2."); PUT(arg()); PUTA(":ehp2.");
  186. @break            ;
  187. @bullet\{\}        PUTS("&sqbul.");
  188. @bye            return 0;
  189. <INITIAL,MENU,TABLE>@c  skip();
  190. @cartouche        ;
  191. @end\ cartouche        ;
  192. @center            PUTA(":lines align=center."); PUT(eol()); PUTA(":elines.");
  193. @chapheading        heading(HeadingLevel+1, eol());
  194. @chapter        heading(HeadingLevel+1, eol());
  195. @cindex            indexref("cp", eol());
  196. @cite\{            PUTA(":hp1."); PUT(arg()); PUTA(":ehp1.");
  197. @clear            flags.del(eol());
  198. @code\{            font("Courier"); PUT(arg()); font(0);
  199. <INITIAL,MENU,TABLE>@comment  skip();
  200. @contents        ;
  201. @copyright\{\}        PUTS("(C)");
  202. @cropmarks        /*!!*/;
  203. @defcodeindex           skip ();
  204.                         /*
  205.                               +------------------------- x-Version (@def...x)
  206.                               !  +---------------------- has category
  207.                               !  !  +------------------- has class
  208.                               !  !  !  +---------------- has type
  209.                               !  !  !  !  +------------- has arguments
  210.                               !  !  !  !  !    +-------- type of index
  211.                               !  !  !  !  !    !    +--- category name
  212.                               !  !  !  !  !    !    !           */
  213. @defcv{WSP}             Defs (0, 1, 1, 0, 0, "vr", (char *)NULL);
  214. @defcvx{WSP}            Defs (1, 1, 1, 0, 0, "vr", (char *)NULL);
  215. @deffn{WSP}             Defs (0, 1, 0, 0, 1, "fn", (char *)NULL);
  216. @deffnx{WSP}            Defs (1, 1, 0, 0, 1, "fn", (char *)NULL);
  217. @defivar{WSP}           Defs (0, 0, 1, 0, 0, "vr", "Instance Variable");
  218. @defivarx{WSP}          Defs (1, 0, 1, 0, 0, "vr", "Instance Variable");
  219. @defmac{WSP}            Defs (0, 0, 0, 0, 1, "fn", "Macro");
  220. @defmacx{WSP}           Defs (1, 0, 0, 0, 1, "fn", "Macro");
  221. @defmethod{WSP}         Defs (0, 0, 1, 0, 1, "fn", "Method");
  222. @defmethodx{WSP}        Defs (1, 0, 1, 0, 1, "fn", "Method");
  223. @defop{WSP}             Defs (0, 1, 1, 0, 1, "fn", (char *)NULL);
  224. @defopx{WSP}            Defs (1, 1, 1, 0, 1, "fn", (char *)NULL);
  225. @defopt{WSP}            Defs (0, 0, 0, 0, 0, "vr", "User Option");
  226. @defoptx{WSP}           Defs (1, 0, 0, 0, 0, "vr", "User Option");
  227. @defspec{WSP}           Defs (0, 0, 0, 0, 1, "fn", "Special Form");
  228. @defspecx{WSP}          Defs (1, 0, 0, 0, 1, "fn", "Special Form");
  229. @deftp                  Defs (0, 1, 0, 1, 1, "vr", (char *)NULL);
  230. @deftpx{WSP}            Defs (1, 1, 0, 1, 1, "vr", (char *)NULL);
  231. @deftypefn{WSP}         Defs (0, 1, 0, 1, 1, "fn", (char *)NULL);
  232. @deftypefnx{WSP}        Defs (1, 1, 0, 1, 1, "fn", (char *)NULL);
  233. @deftypefun{WSP}        Defs (0, 0, 0, 1, 1, "fn", "Function");
  234. @deftypefunx{WSP}       Defs (1, 0, 0, 1, 1, "fn", "Function");
  235. @deftypevr{WSP}         Defs (0, 1, 0, 1, 0, "vr", (char *)NULL);
  236. @deftypevrx{WSP}        Defs (1, 1, 0, 1, 0, "vr", (char *)NULL);
  237. @deftypevar{WSP}        Defs (0, 0, 0, 1, 0, "vr", "Variable");
  238. @deftypevarx{WSP}       Defs (1, 0, 0, 1, 0, "vr", "Variable");
  239. @defun{WSP}             Defs (0, 0, 0, 0, 1, "fn", "Function");
  240. @defunx{WSP}            Defs (1, 0, 0, 0, 1, "fn", "Function");
  241. @defvar{WSP}            Defs (0, 0, 0, 0, 0, "vr", "Variable");
  242. @defvarx{WSP}           Defs (1, 0, 0, 0, 0, "vr", "Variable");
  243. @defvr{WSP}             Defs (0, 1, 0, 0, 0, "vr", (char *)NULL);
  244. @defvrx{WSP}            Defs (1, 1, 0, 0, 0, "vr", (char *)NULL);
  245. @dircategory            skip ();
  246. @direntry               SAVESTATE (DIRENTRY); skip ();
  247. <DIRENTRY>.             ;
  248. <DIRENTRY>\n            yylineno++;
  249. <DIRENTRY>@end\ direntry skip (); RESTORESTATE;
  250. @end\ def[a-z]+         margin(-10); newpara = 1; DefinedFunction = 0;
  251.  
  252. @dfn\{            PUTA(":hp1."); PUT(arg()); PUTA(":ehp1.");
  253. @display        beg_example("default");
  254. @end\ display        end_example();
  255. @dmn\{            PUTS(' ' << arg());
  256. @dots\{\}        PUTS("&dot.&dot.&dot.");
  257. @email\{                PUTA(":hp1."); PUT(arg()); PUTA(":ehp1.");
  258. @emph\{            PUTA(":hp1."); PUT(arg()); PUTA(":ehp1.");
  259. @enumerate        item_begin(":ol.", 'o',0); skip();
  260. @end\ enumerate        item_end(":eol.");
  261. @equiv\{\}        PUTS("==");
  262. @enddots\{\}            PUTS("&dot.&dot.&dot.&dot.");
  263. @error\{\}        PUTA(":hp8."); PUTS("ERROR: "); PUTA(":ehp8.");
  264. @evenfooting        eol();
  265. @evenheading        eol();
  266. @everyfooting        eol();
  267. @everyheading        eol();
  268. @example        beg_example("Courier");
  269. @end\ example        end_example();
  270. @exdent            { int old=margin(0); PUTS(eol()); margin(old); }
  271. @expansion\{\}        PUTS("==>");
  272. @file\{            font("Courier"); PUTS("&apos." << arg() << "&apos."); font(0);
  273. @finalout        ;
  274. @findex            indexref("fn", eol());
  275. @flushleft        ;
  276. @end\ flushleft        ;
  277. @flushright        PUTA(":lines align=right.");
  278. @end\ flushright    PUTA(":elines.");
  279. @footnote\{        footnote();
  280. @footnotestyle        skip ();
  281. @format            PUTA(":lines align=left.");
  282. @end\ format        PUTA(":elines.");
  283. @ftable            item_begin(":parml break=fit.", 'p',"Function"); SAVESTATE (TABLE);
  284. @end\ ftable        item_end(":eparml.");
  285. <TABLE>@code        istackp->beg = Item("Courier"); istackp->end = Item("default");
  286. <TABLE>@kbd        istackp->beg = 0; istackp->end = 0;
  287. <TABLE>@key        istackp->beg = 0; istackp->end = 0;
  288. <TABLE>@samp        istackp->beg = Item("Courier", 0, "&apos."); istackp->end = Item("default", 0, "&apos.");
  289. <TABLE>@var        istackp->beg = Item(0, 1); istackp->end = Item(0, 1);
  290. <TABLE>@file        istackp->beg = Item("Courier"); istackp->end =Item("default");
  291. <TABLE>@dfn        istackp->beg = Item(0, 1); istackp->end = Item(0, 1);
  292. <TABLE>@cite        istackp->beg = Item(0, 1); istackp->end = Item(0, 1);
  293. <TABLE>@asis        istackp->beg = 0; istackp->end = 0;
  294. <TABLE>@bullet        istackp->beg = Item(0, 100); istackp->end = Item(0, 0);
  295. <TABLE>@b        istackp->beg = Item(0, 2); istackp->end = Item(0, 2);
  296. <TABLE>@strong        istackp->beg = Item(0, 2); istackp->end = Item(0, 2);
  297. <TABLE>@i        istackp->beg = Item(0, 1); istackp->end = Item(0, 1);
  298. <TABLE>@r        istackp->beg = Item("'Tms Rmn'"); istackp->end = Item("default");
  299. <TABLE>@t        istackp->beg = Item("Courier"); istackp->end = Item("default");
  300. <TABLE>@emph        istackp->beg = Item(0, 1); istackp->end = Item(0, 1);
  301. <TABLE>[ \t]        ;
  302. <TABLE>\n        RESTORESTATE; /*BEGIN(0);*/ ++yylineno; /* this might an error */
  303. @group            ;
  304. @end\ group        ;
  305. @heading        heading(HeadingLevel+2, eol());
  306. @headings        eol();
  307. @hyphenation\{          arg ();
  308. @i\{            PUTA(":hp1."); PUT(arg()); PUTA(":ehp1.");
  309. <INITIAL,IFCLEAR,MENU,TABLE>@ifclear{WSP}           if (iff(eol(), ifclear)) SAVESTATE (IFCLEAR);
  310. <IFCLEAR>.              ;
  311. <IFCLEAR>\n             { if (yy_flex_debug) cerr << "IFCLEAR> " << endl; ++yylineno;}
  312. <INITIAL,IFCLEAR,MENU,TABLE>@end\ ifclear {    int s = endiff (ifclear);
  313.                              if (s<0)
  314.                                  ErrorOut ("Unmatched @end ifclear", (char *)NULL);
  315.                              else
  316.                              {
  317.                                  if (s)
  318.                                      RESTORESTATE;
  319.                              }
  320.                              skip ();
  321.                         }
  322. <INITIAL,MENU,TABLE>@ifset{WSP}             if (!iff(eol(), ifset)) SAVESTATE (IFSET);
  323. <IFSET>.                ;
  324. <IFSET>\n               { if (yy_flex_debug)cerr << "IFSET> " << endl; ++yylineno; }
  325. <INITIAL,IFSET,MENU,TABLE>@end\ ifset {   int s = endiff (ifset);
  326.                             if (s<0)
  327.                                 ErrorOut ("Unmatched @end ifset", (char *)NULL);
  328.                             else
  329.                             {
  330.                                 if (!s) RESTORESTATE;
  331.                             }
  332.                         }
  333. @ifinfo            ;
  334. @end\ ifinfo        ;
  335. @iftex            { SAVESTATE (IFTEX); } /* Ignore everything which is used
  336.                                                 * to make a prettier output with TeX
  337.                                                 */
  338. <IFTEX>.               ;
  339. <IFTEX>\n               ++yylineno;
  340. <IFTEX>^@end[ \t]+iftex  { RESTORESTATE; }
  341. @ignore            SAVESTATE (IGNORE); /* BEGIN (IGNORE) */
  342. <IGNORE>^@end\ ignore    { /*BEGIN(0);*/ eol(); RESTORESTATE; }
  343. <IGNORE>\n        ++yylineno;
  344. <IGNORE>.        ; /* Test += yytext[0];*/
  345. @include{WSP}           { include(EolPar ()); /* BEGIN(INITIAL);*/ SAVESTATE (INITIAL); }
  346. @inforef        eol();
  347. ^\\input        { skip (); /* eol(); */ }
  348. @item            istackp->item(eol());
  349. @itemize        item_begin(":ul.", 'u',0); skip();
  350. @end\ itemize        item_end(":eul.");
  351. @itemx            istackp->item(eol());
  352. @kbd\{            PUTS(arg());
  353. @key\{            PUTS(arg());
  354. @kindex            indexref("ky", eol());
  355. @lisp            beg_example("Courier");
  356. @end\ lisp        end_example();
  357. @majorheading        eol();
  358. @medbreak        ;
  359. @menu            eol(); SAVESTATE (MENU); /*BEGIN(MENU);*/ menu.line = ""; PUTS(":parml tsize=30 break=none compact.");
  360. <MENU>@end\ menu    RESTORESTATE; /*BEGIN(0);*/ eol(); menu.flush(); PUTS(":eparml.");
  361. <MENU>\*[ \t]+        menu.flush(); menu.line = eol();
  362. <MENU>[ \t]+        menu.line += ' '; menu.line += eol();
  363. <MENU>\n[ \t]*\n    menu.flush(); PUTL(); ++yylineno;
  364. <MENU>\n        ++yylineno;
  365. <MENU>^\@detailmenu       skip ();
  366. <MENU>^\@end\ detailmenu  skip ();
  367. <MENU>.            menu.flush(); PUTS(yytext[0]); PUTS(eol()); PUTL();
  368. @minus\{\}        PUTS("&emdash.");
  369. @multitable             skip (); SAVESTATE (MULTITABLE);
  370. <MULTITABLE>\n          ++yylineno;
  371. <MULTITABLE>.           ;
  372. <MULTITABLE>^@end\ multitable   skip (); RESTORESTATE;
  373. @need            eol();
  374. @node            words(eol()); node(w[0], w[1], w[2], w[3]);
  375. @nwnode                 words(eol()); node(w[0], w[1], w[2], w[3]);
  376. @noindent        newpara = 0; PUTS(endl << ".br"); PUTL();
  377. @oddfooting        eol();
  378. @oddheading        eol();
  379. @page            ;
  380. @paragraphindent    eol();
  381. @pindex            indexref("pg", eol());
  382. @point\{\}        PUTS('*');
  383. @print\{\}        PUTS("&bxh.&bxri.");
  384. @printindex        printindex(eol());
  385. @pxref\{        words(arg()); xref("see ", w[0], w[1], w[2], w[3], w[4]);
  386. @quotation        margin(+10); PUTA(":rm margin=4.");
  387. @end\ quotation        margin(-10); PUTA(":rm margin=1.");
  388. @r\{            font("'Tms Rmn'"); PUTS(arg()); font(0);
  389. @ref\{            words(arg()); xref(0, w[0], w[1], w[2], w[3], w[4]);
  390. @refill            ;
  391. @result\{\}        PUTS("=>");
  392. @samp\{            font("Courier"); PUTS("&apos." << arg() << "&apos."); font(0);
  393. @sc\{            { const char *cp = upcase(arg()); font("Helv", "8x4"); PUTS(cp); font(0); }
  394. @section        heading(HeadingLevel+2, eol());
  395. @set            setflag(eol());
  396. @setchapternewpage    skip (); /* eol(); */
  397. @setfilename        skip (); /* eol () */
  398. @settitle        PUT(":title." << eol() << endl << ":h1.-Preface-"); PUTL();
  399. @shortcontents        ;
  400. @smallbook        ;
  401. @smallexample        beg_example("Courier");
  402. @end\ smallexample    end_example();
  403. @smalllisp        beg_example("Courier");
  404. @end\ smalllisp        end_example();
  405. @sp            { int n = atoi(eol()); while (n--) { PUTL (); PUT(".br"); PUTL (); lastnl = 1;} }
  406. @strong\{        PUTA(":hp2."); PUTS(arg()); PUTA(":ehp2.");
  407. @subheading        heading(HeadingLevel+3, eol());
  408. @subsection        heading(HeadingLevel+3, eol());
  409. @subsubheading        heading(HeadingLevel+4, eol());
  410. @subsubsection        heading(HeadingLevel+4, eol());
  411. @subtitle        eol();
  412. @summarycontents    ;
  413. @syncodeindex        eol();
  414. @synindex        eol();
  415. @t\{            font("Courier"); PUTS(arg()); font(0);
  416.                         /* I can't find any documentation about this @tt{} */
  417. @tt\{            font("Courier"); PUTS(arg()); font(0);
  418. @table            /* BEGIN(TABLE); */ item_begin(":parml break=fit.", 'p',0); SAVESTATE (TABLE);
  419. @end\ table        item_end(":eparml.");
  420. @ktable            item_begin(":parml break=fit.", 'p',0); SAVESTATE (TABLE); /* BEGIN (TABLE); */
  421. @end\ ktable        item_end(":eparml.");
  422. @TeX\{\}        PUTS("TeX");
  423. @tex            SAVESTATE (TEX); /* BEGIN(TEX);*/
  424. <TEX>^@end\ tex        RESTORESTATE; /*BEGIN(0);*/ eol();
  425. <TEX>\n            ++yylineno;
  426. <TEX>.            ;
  427. @thischapter        ;
  428. @thischaptername    ;
  429. @thisfile        ;
  430. @thispage        ;
  431. @thistitle        ;
  432. @tindex            indexref("tp", eol());
  433. @title            skip (); /* might be changed to get the title */
  434. @titlefont\{        arg();
  435. @shorttitlepage        eol();
  436. @titlepage        SAVESTATE (TITLE); /*BEGIN(TITLE);*/
  437. <TITLE>^@end\ titlepage    RESTORESTATE; /* BEGIN(0);*/ eol();
  438. <TITLE>\n        ++yylineno;
  439. <TITLE>.        ;
  440. @today\{\}              ;
  441. @top            table["Top"] = Name(++hdid, 1, 0); heading(1, eol());
  442. @unnumbered        heading(HeadingLevel+1, eol());
  443. @unnumberedsec        heading(HeadingLevel+2, eol());
  444. @unnumberedsubsec    heading(HeadingLevel+3, eol());
  445. @unnumberedsubsubsec    heading(HeadingLevel+4, eol());
  446. @url\{                  PUT(":hp1."); PUTS(arg()); PUT(":ehp1.");
  447. @value\{        { String& s = arg(); if (flags.contains(s)) PUT(flags[s]); }
  448. @var\{            PUT(":hp1."); PUTS(arg()); PUT(":ehp1.");
  449. @vindex            indexref("vr", eol());
  450. @vskip            eol();
  451. @vtable            SAVESTATE(TABLE); item_begin(":parml break=fit.", 'p',"Variable"); /* BEGIN(TABLE); */
  452. @end\ vtable        item_end(":eparml.");
  453. @w\{            PUT (arg ());/*single_word(arg());*/
  454. @xref\{            words(arg()); xref("See ", w[0], w[1], w[2], w[3], w[4]);
  455.  
  456. @end[ ]+[.]+            ErrorOut ("Unknown control", yytext);
  457.  
  458.                         /* Those things inserted here are handled but
  459.                            not correct.
  460.                            I have to check if they are makeable in IPF
  461.                            */
  462. @AA\{\}                 PUTS("A");
  463. @aa\{\}                 PUTS("a");
  464. @AE\{\}                 PUTS("&Aelig.");
  465. @ae\{\}                 PUTS("æ.");
  466. @dotless\{              PUTS(arg()); /* has to print without dots.
  467.                                         I don't know if this is possible
  468.                                         under IPF */
  469. @H\{                    { arg (); } /* Ignore the parameters */
  470. @l\{\}                  PUTS("l");
  471. @L\{\}                  PUTS("L");
  472. @o\{\}                  PUTS("o");
  473. @O\{\}                  PUTS("O");
  474. @OE\{\}                 PUTS("&Oelig.");
  475. @oe\{\}                 PUTS("&oelig.");
  476.  
  477. @\"a                    *out << "&ae.";
  478. @\"o                    *out << "&oe.";
  479. @\"u                    *out << "&ue.";
  480. @\"A                    *out << "&Ae.";
  481. @\"O                    *out << "&Oe.";
  482. @\"U                    *out << "&Ue.";
  483.  
  484. @ss\{\}                 PUTS("SS"); /* not correct */
  485. @questiondown\{\}       PUTS("&invq."); /* not correct */
  486. @exclamdown\{\}         PUTS("&inve."); /* not correct */
  487. @pounds\{\}             PUTS("£"); /* not correct */
  488. @dotaccent\{            PUTS(arg ());
  489. @ringaccent\{           PUTS(arg ());
  490. @tieaccent\{            PUTS(arg ());
  491. @ubaraccent\{           PUTS(arg ());
  492. @udotaccent\{           PUTS(arg ());
  493. @u\{                    PUTS(arg ());
  494. @v\{                    PUTS(arg ());
  495.  
  496.  
  497. @raisesections          skip (); /*HeadingLevel--; */
  498. @lowersections          skip (); /*HeadingLevel++; */
  499. \&            PUTS("&.");
  500. \n            ++yylineno; return '\n';
  501. \r            ;
  502. " "                     return 0x20;
  503. \:            PUTS("&colon.");
  504. \.            dot();
  505. \{            return '{'; /* PUTS(arg());*/
  506. \}            return '}';
  507. .            PUTS(yytext[0]);
  508. <<EOF>>            {
  509.                           if (yy_flex_debug) cerr << "<<EOF>> done." << endl;
  510.                           if (--incllevel < 0)
  511.                 yyterminate();
  512.               else {
  513.                 yy_delete_buffer(YY_CURRENT_BUFFER);
  514.                                 if (inclstack[incllevel].fn)
  515.                                     free (inclstack[incllevel].fn);
  516.                 yy_switch_to_buffer(inclstack[incllevel].state);
  517.                                 yylineno = inclstack[incllevel].lineno;
  518.                                 /*yyrestart (yyin);*/
  519.               }
  520.             }
  521.  
  522.  
  523. @end\ [-a-zA-Z0-9_$]+   ErrorOut ("Unknown @end control-sequence", yytext); yylineno++;
  524. @[-a-zA-Z0-9_$]+        ErrorOut ("Unknown control", yytext);
  525.  
  526. %%
  527.  
  528. // @[$0-9A-Z_a-z]+         ErrorOut ("Unknown control", yytext);
  529. //@defcv[ \t]+        define(eol(), 0, "vr", 1, 0, null);
  530. //                       { SAVESTATE (DEF); }
  531. //<DEF>  /* in paramter or arguments it is allowed to put @var or @values
  532. //        * (seen in texinfo manual chapter 16 def-commands)
  533. //        */
  534. //<DEF>@var\{             { PUT(":hp1."); PUTS(arg()); PUT(":ehp1."); }
  535. //<DEF>@value\{        { String& s = arg(); if (flags.contains(s)) PUT(flags[s]); }
  536.  
  537. //<DEF>\n                 { RESTORESTATE; }
  538.  
  539. /***********************
  540. <INITIAL,TABLE,FALSE,MENU,TITLE>@ifclear    if (!iff(eol(), 0)) SAVESTATE (FALSE);
  541. <INITIAL,TABLE,FALSE,MENU,TITLE>@ifset        if (!iff(eol(), 1)) SAVESTATE (FALSE);
  542. <INITIAL,TABLE,MENU,TITLE>^@end\ ifclear    RESTORESTATE;
  543. <INITIAL,TABLE,MENU,TITLE>^@end\ ifset        RESTORESTATE;
  544. <FALSE>^@end\ if[a-z]+                yy_start = endiff(); eol(); RESTORESTATE;
  545. <FALSE>\n        ++yylineno;
  546. <FALSE>.        ;
  547. **********************************************************/
  548.  
  549.  
  550.  
  551. static String    buffer;
  552.  
  553. String &
  554. arg()
  555. {
  556.     ostrstream ostr;
  557.     ostream *old = out;
  558.     out = &ostr;
  559.         int Argument = 1;
  560.  
  561.     if (plevel == 9)
  562.         unexpected(0);
  563.     plines[++plevel] = yylineno;
  564.     if (yy_flex_debug)
  565.     {
  566.         fprintf(stderr, "++push to %d\n", plevel);
  567.         cerr << "Saving state." << endl;
  568.     }
  569.         SAVESTATE (INITIAL);
  570.     int old_np = newpara;
  571.     int old_nl = lastnl;
  572.     /* BEGIN(0);*/
  573.     newpara = 0;
  574.     for (;;) {
  575.         switch (yylex()) {
  576.         case 0:
  577.             unexpected("EOF");
  578.                 case '{':
  579.                      continue;
  580.  
  581.                 case '}':
  582.                     if (!Argument)
  583.                         continue;
  584.                     else
  585.                         Argument = 0;
  586.                     break;
  587.  
  588.                 case 0x20:
  589.                     *out << " ";
  590.                     continue;
  591.  
  592.  
  593.         case '\n':
  594.             if (ostr.pcount() > 100) {
  595.                 PUTL();
  596.             } else
  597.                 PUT(' ');
  598.             /*++yylineno; */ /* already done by yylex () */
  599.             continue;
  600.         default:
  601.             continue;
  602.         }
  603.         break;
  604.     }
  605.  
  606.     if (yy_flex_debug)
  607.         cerr << "Restoring state." << endl;
  608.         
  609.         RESTORESTATE;
  610.  
  611.     newpara = old_np;
  612.     lastnl = old_nl;
  613.  
  614.     if (yy_flex_debug)
  615.         fprintf(stderr, "++pop from %d\n", plevel);
  616.     --plevel;
  617.  
  618.     buffer = String(ostr.str(), ostr.pcount());
  619.     /* while (buffer.length() && isspace(buffer[0]))
  620.         buffer.del(0, 1);
  621.                 */
  622.  
  623.     if (yy_flex_debug)
  624.         cerr << "arg(): \"" << buffer << "\"" << endl;
  625.  
  626.     out = old;
  627.     return buffer;
  628. }
  629.  
  630. String &
  631. eol()
  632. {
  633.     ostrstream ostr;
  634.     ostream *old = out;
  635.     out = &ostr;
  636.     
  637.     if (plevel == 9)
  638.         unexpected(0);
  639.     plines[++plevel] = yylineno;
  640.     if (yy_flex_debug)
  641.         fprintf(stderr, "++push to %d\n", plevel);
  642.  
  643.     int old_start = yy_start;
  644.     int old_np = newpara;
  645.     int old_nl = lastnl;
  646.         int Argument = 0;
  647.  
  648.     BEGIN(INITIAL); /* this might be wrong */
  649.     newpara = 0;
  650.     for (;;) {
  651.         switch (yylex()) {
  652.         case 0:
  653.             unexpected("EOF");
  654.                 case '{':
  655.                     Argument = 1;
  656.                     PUTS(arg());
  657.                     continue;
  658.         case '}':
  659.                     if (!Argument)
  660.                         unput('}');
  661.                     else
  662.                         Argument = 0;
  663.             break;
  664.         case '\n':
  665.             /*unput('\n');*/
  666.             break;
  667.                 case 0x20:
  668.                     *out << " ";
  669.                     continue;
  670.         default:
  671.             continue;
  672.         }
  673.         break;
  674.     }
  675.     yy_start = old_start;
  676.     newpara = old_np;
  677.     lastnl = old_nl;
  678.  
  679.     if (yy_flex_debug)
  680.         fprintf(stderr, "++pop from %d\n", plevel);
  681.     --plevel;
  682.  
  683.     buffer = String(ostr.str(), ostr.pcount());
  684.     while (buffer.length() && isspace(buffer[0]))
  685.         buffer.del(0, 1);
  686.     out = old;
  687.     return buffer;
  688. }
  689.  
  690. void
  691. unexpected(const char *msg)
  692. {
  693.     if (msg)
  694.             ErrorOut ("Unexpected EOF",(char *)NULL);
  695.     else
  696.         {
  697.                 if (incllevel > 0)
  698.                     cerr << inclstack[incllevel-1].fn << ": Nesting overflow in line " << yylineno << endl;
  699.                 else
  700.                     cerr << "Nesting overflow in line " << yylineno << endl;
  701.         }
  702.     for (; plevel; --plevel)
  703.         {
  704.         cerr << "\tunterminated argument starting in line "
  705.              << plines[plevel] << endl;
  706.         }
  707.     cerr.flush();
  708.     exit(1);
  709. }
  710.  
  711. void
  712. footnote()
  713. {
  714.     ++fnid;
  715.     PUTS(":fn id=fn" << fnid << '.' << arg() << ":efn. "
  716.       << ":link reftype=fn refid=fn" << fnid << ".(" << fnid << "):elink.");
  717. }
  718.  
  719. void
  720. newline()
  721. {
  722.     if (!lastnl) {
  723.         lastnl = 1;
  724.         *out << endl;
  725.     }
  726.     if (!nofill) {
  727.         int c = yyinput();
  728.         if (c == '\n') {
  729.             newpara = 1;
  730.             do ++yylineno; while ((c = yyinput()) == '\n');
  731.         }
  732.         unput(c);
  733.     }
  734. }    
  735.  
  736. void
  737. skip()
  738. {
  739.     int c;
  740.     for (; (c = yyinput()) != '\n'; )
  741.         ;
  742.     ++yylineno;
  743. }
  744.  
  745. String &EolPar (void)
  746. {
  747.     static String Buffer;
  748.     int c;
  749.     Buffer = "";
  750.     for (; (c = yyinput()) != '\n'; )
  751.         Buffer += (char)c;
  752.     /* ++yylineno; ???*/
  753.     return Buffer;
  754. }
  755.  
  756. void
  757. dot()
  758. {
  759.     int c = yyinput();
  760.     if (c == '.') {
  761.         PUTS("&dot.");
  762.         do { PUT("&dot."); } while ((c = yyinput()) == '.');
  763.     } else if (lastnl) {
  764.         PUTS("&dot.");
  765.     } else
  766.         PUTS('.');
  767.     unput(c);
  768. }
  769.  
  770. void include(const char *fname)
  771. {
  772.     if (incllevel >= MaxIncl)
  773.         {
  774.         cerr << "Includes nested too deeply" << endl;
  775.         exit(1);
  776.     }
  777.         inclstack[incllevel].fn = strdup (fname);
  778.         if (!(inclstack[incllevel].fn))
  779.         {
  780.             cerr << "Not enough memory" << endl;
  781.             exit (2);
  782.         }
  783.  
  784.     inclstack[incllevel].state = YY_CURRENT_BUFFER;
  785.     inclstack[incllevel++].lineno = yylineno;
  786.         cerr << " [" << fname;
  787.     char name[FILENAME_MAX+1];
  788.     strcpy(name, fname);
  789.     char *namep = strtok(name, " \t");    // strip any blanks
  790.     yyin = fopen(namep, "r");
  791.     if (!yyin) {
  792.         char *dotp = strrchr(namep, '.');
  793.         if (dotp && !strpbrk(dotp, ":\\/") && strlen(dotp) > 4)
  794.             dotp[4] = 0;        // truncate .texi to .tex
  795.         yyin = fopen(namep, "r");
  796.     }
  797.     if (!yyin)
  798.         {
  799.         cerr << "Cannot open include file '" << namep << "': "
  800.              << strerror(errno) << endl;
  801.         exit(1);
  802.     }
  803.  
  804.         IncludeFile = 1;
  805.         /* next include file we start counting from one */
  806.         yylineno = 1;
  807.     yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
  808.         yyrestart (yyin);
  809. }
  810.  
  811. int
  812. yywrap()
  813. {
  814.     static int Nr = 0;
  815.     fclose (yyin);
  816.     if (incllevel >0 )
  817.     {
  818.         cerr << "] ";
  819.         Nr ++;
  820.         if (Nr > 3)
  821.         {
  822.             cerr << endl;
  823.             Nr = 0;
  824.         }
  825.     }
  826.     else
  827.         cerr << "] " << endl;
  828.  
  829.     if (--incllevel < 0)
  830.     {
  831.           yyterminate();
  832.           return 1;
  833.     }
  834.     else
  835.     {
  836.           yy_delete_buffer(YY_CURRENT_BUFFER);
  837.           if (inclstack[incllevel].fn)
  838.               free (inclstack[incllevel].fn);
  839.           yylineno = inclstack[incllevel].lineno;
  840.           yy_switch_to_buffer(inclstack[incllevel].state);
  841.           return 0;
  842.     }
  843. }
  844.  
  845.  
  846.  
  847.  
  848. int iff(String& arg, tIfType IfType)
  849. {
  850.  
  851.     if (yy_flex_debug)
  852.         cerr << "Contains(" << arg << ")=" << flags.contains (arg) << endl;
  853.  
  854.     if (iflevel >= MaxIf)
  855.     {
  856.         cerr << "Conditions nested too deeply" << endl;
  857.         exit (3);
  858.     }
  859.  
  860.     ifstack[iflevel].IfType = IfType;
  861.     ifstack[iflevel++].Condition = flags.contains(arg);
  862.     if (flags.contains(arg))
  863.         return 1;
  864.     else
  865.         return 0;
  866. }
  867.  
  868. int endiff(tIfType IfType)
  869. {
  870.     String s;
  871.  
  872.     if (iflevel < 1)
  873.         return -1; /* Error, unmatched @end */
  874.  
  875.     --iflevel;
  876.     if (ifstack[iflevel].IfType != IfType)
  877.     {
  878.         s = "Expected @end ";
  879.         s += cIfType[ifstack[iflevel].IfType];
  880.         s += " but read another.";
  881.         ErrorOut (s, (char *)NULL);
  882.     }
  883.     return ifstack[iflevel].Condition;
  884. }
  885.  
  886.  
  887. /*
  888.  */
  889. String &DefPar ()
  890. {
  891.     static String buffer;
  892.     ostrstream ostr;
  893.     ostream *old = out;
  894.     out = &ostr;
  895.     int old_start = yy_start;
  896.     int old_np = newpara;
  897.     int old_nl = lastnl;
  898.     int c;
  899.     int Paras = 0;
  900.  
  901.     if (plevel == 9)
  902.         unexpected(0);
  903.     plines[++plevel] = yylineno;
  904.     if (yy_flex_debug)
  905.         fprintf(stderr, "++ DefPar:: push to %d\n", plevel);
  906.  
  907.     BEGIN(0);
  908.     newpara = 0;
  909.     for (;;)
  910.     {
  911.         c = yylex ();
  912.         if (yy_flex_debug)
  913.         fprintf(stderr, "  DefPar:: c=%d c=\"%c\"\n", c, (char)c);
  914.         switch (c)
  915.         {
  916.             case 0:
  917.                 unexpected("EOF");
  918.  
  919.             case '{':
  920.                 if (yy_flex_debug)
  921.                 fprintf(stderr, "DefPar:: { erkannt\n");
  922.                 Paras = 1;
  923.                 /*yylex ();*/
  924.                 /**out << arg();*/
  925.                 continue;
  926.  
  927.             case '}':
  928.                 if (!Paras)
  929.                 {
  930.                     yyinput ();
  931.                     continue;
  932.                 }
  933.  
  934.                 if (yy_flex_debug)
  935.                 fprintf(stderr, "DefPar:: } erkannt\n");
  936.                 Paras = 0;
  937.                 /*c = yylex ();*/
  938.                 yyinput ();
  939.                 /*IgnoreSpace ();*/
  940.                 break;
  941.  
  942.             case 0x20:
  943.                 if (Paras)
  944.                 {
  945.                     *out << " ";
  946.                     continue;
  947.                 }
  948.                 else
  949.                 {
  950.                 /*c = yylex ();*/
  951.                 /*IgnoreSpace ();*/
  952.                 break;
  953.                 }
  954.  
  955.             case '\n':
  956.                 /* *out << endl; ??? */
  957.                 /*unexpected ("LF");*/
  958.                 break;
  959.  
  960.             default:
  961.                 continue;
  962.  
  963.         } /* switch (yylex())... */
  964.         break;
  965.     } /* for (;;)... */
  966.  
  967.     yy_start = old_start;
  968.     newpara = old_np;
  969.     lastnl = old_nl;
  970.  
  971.     if (yy_flex_debug)
  972.         fprintf(stderr, "++ DefPar:: pop from %d\n", plevel);
  973.  
  974.     --plevel;
  975.  
  976.     while ( (c = yyinput ()) == ' ');
  977.     unput (c);
  978.  
  979.     buffer = String(ostr.str(), ostr.pcount());
  980.     while (buffer.length() && isspace(buffer[0]))
  981.         buffer.del(0, 1);
  982.     out = old;
  983.     return buffer;
  984. }
  985.  
  986.  
  987. void Defs
  988.      (
  989.          int xVariant,     /* is on of the @def...x */
  990.          int exCategory,   /* =1 means category exists */
  991.          int exClass,      /* =1 class exists */
  992.          int exType,       /* =1 means type exists */
  993.          int exArgs,       /* =1 means arguments exists */
  994.          const char *TypeOfIndex,  /* make index entry in e.g. "fn" */
  995.          const char *CategoryDef   /* some of the @def's are shortages of other @def's */
  996.      )
  997. {
  998.     String Category = CategoryDef;
  999.     String Class;
  1000.     String Type;
  1001.     String Name;
  1002.     String Args;
  1003.  
  1004.     if (yy_flex_debug)
  1005.     {
  1006.         cerr << "Defs" << endl;
  1007.         cerr << "Defs::Category:" << endl;
  1008.     }
  1009.  
  1010.     if (exCategory)
  1011.     {
  1012.         Category = DefPar ();
  1013.         if (yy_flex_debug)
  1014.             cerr << "CAT: " << Category << endl;
  1015.     }
  1016.  
  1017.     if (yy_flex_debug)
  1018.         cerr << "Defs::Class:" << endl;
  1019.  
  1020.     if (exClass)
  1021.     {
  1022.         Class = DefPar ();
  1023.         if (yy_flex_debug)
  1024.             cerr << "CLASS: " << Class << endl;
  1025.     }
  1026.  
  1027.     if (yy_flex_debug) cerr << "Defs::Type:" << endl;
  1028.  
  1029.     if (exType)
  1030.     {
  1031.         Type = DefPar ();
  1032.         if (yy_flex_debug)
  1033.             cerr << "TYP: " << Type << endl;
  1034.     }
  1035.  
  1036.     /* should always exist */
  1037.     if (yy_flex_debug)
  1038.         cerr << "Defs::Name:" << endl;
  1039.     Name = DefPar ();
  1040.  
  1041.     if (yy_flex_debug)
  1042.         cerr << "Defs::Args:" << endl;
  1043.     if (exArgs)
  1044.     {
  1045.         Args = eol ();
  1046.         if (yy_flex_debug)
  1047.             cerr << "ARGS: " << Args << endl;
  1048.     }
  1049.  
  1050.     newpara = 1;
  1051.     if (xVariant)
  1052.     {
  1053.     margin (-10);
  1054.     PUTL ();
  1055.     PUT (".br");
  1056.     PUTL ();
  1057.     }
  1058.     else if (newpara)
  1059.         para ();
  1060.  
  1061.     font ("Courier", FontSize);
  1062.  
  1063.     if (exType)
  1064.         PUT (Type << " "); /* *out << Type << " "; */
  1065.  
  1066.     PUT (":hp2." << Name << ":ehp2. "); /* *out << ":hp2." << Name << ":ehp2. "; */
  1067.  
  1068.     if (exArgs)
  1069.         PUT (":hp1. " << Args << ":ehp1."); /*    *out << ":hp1. " << Args << ":ehp1."; */
  1070.  
  1071.     font (0, 0);
  1072.     PUT ("    :hp9.(" << Category << "):ehp9."); /*  *out << "    :hp9.(" << Category << "):ehp9."; */
  1073.     PUTL (); /* *out << "\n.br\n"; */
  1074.     //PUTL (); /* *out << "\n.br\n"; */
  1075.  
  1076.     lastnl = 1;
  1077.  
  1078.     if (!xVariant)
  1079.     {
  1080.         newpara = 1;
  1081.     para ();
  1082.     }
  1083.  
  1084.     margin (10);
  1085.     
  1086.     indexref (TypeOfIndex, Name);
  1087.  
  1088.     DefinedFunction = 1;
  1089.     
  1090. }
  1091.  
  1092.  
  1093. void ErrorOut (const char *msg, const char *yyt)
  1094. {
  1095.     if (incllevel > 0)
  1096.         cerr << endl << inclstack[incllevel-1].fn << ":"
  1097.              << yylineno << ": " << msg << "(" << yyt << ")"
  1098.              << endl;
  1099.     else
  1100.         cerr << msg << "(" << yyt << ") in line " << yylineno << endl;
  1101. }
  1102.  
  1103. void WarningOut (const char *msg, const char *yyt)
  1104. {
  1105.     if (incllevel > 0)
  1106.         cerr << endl << "warning: " << inclstack[incllevel-1].fn << ":"
  1107.              << yylineno << ": " << msg << "(" << yyt << ")"
  1108.              << endl;
  1109.     else
  1110.         cerr << "warning: " << msg << "(" << yyt << ") in line " << yylineno << endl;
  1111. }
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.