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