home *** CD-ROM | disk | FTP | other *** search
/ Dream 45 / Amiga_Dream_45.iso / Amiga / Magazine / Dossier-LaTeX / rtf2latex.lha / latex2rtf / funct1.c < prev    next >
C/C++ Source or Header  |  1997-02-28  |  41KB  |  1,399 lines

  1. /*
  2.  * $Id: funct1.c,v 1.2 1994/06/21 08:14:11 ralf Exp $
  3.  * History:
  4.  * $Log: funct1.c,v $
  5.  * Revision 1.2  1994/06/21  08:14:11  ralf
  6.  * Corrected Bug in keyword search
  7.  *
  8.  * Revision 1.1  1994/06/17  11:26:29  ralf
  9.  * Initial revision
  10.  *
  11.  */
  12. /***************************************************************************
  13.    name : funct1.c
  14.  author : DORNER Fernando, GRANZER Andreas
  15. purpose : includes besides funct2.c all functions which are called from the programm commands.c;
  16.  ****************************************************************************/
  17.  
  18. /********************************* includes *********************************/
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <ctype.h>
  23. #include "main.h"
  24. #include "funct1.h"
  25. #include "funct2.h"
  26. #include "commands.h"
  27. #include "stack.h"
  28. #include "fonts.h"
  29. /*****************************************************************************/
  30.  
  31. /**************************** extern variables ******************************/
  32. extern FILE *fRtf;                       /* Rtf-File-Pointer */
  33. extern FILE *fTex;                       /* LaTex-File-Pointer */
  34. extern int bPard;                        /* true if \pard-command is necessary */
  35. extern BOOL bInDocument;                 /* true if File-Pointer is in the document */
  36. extern int BracketLevel;                 /* counts open braces */
  37. extern int RecursLevel;                  /* counts returns occured by closing braces */
  38. extern BOOL MathMode;                    /* true at a formula-convertion */
  39. extern int fontsize;                     /* includes the actual fontsize in points */
  40. extern BOOL twocolumn;                   /* true if twocolumn-mode is enabled */
  41. extern BOOL titlepage;                   /* true if titlepage-mode is set */
  42. extern BOOL article;                     /* true if article-mode is set */
  43. extern int indent;                       /* includes the left margin e.g. for itemize-commands */
  44. extern int NoNewLine;
  45. extern BOOL bNewPar;
  46. extern BOOL TABBING_ON;
  47. extern BOOL TITLE_AUTHOR_ON;
  48. extern char *progname;
  49. extern char *latexname;
  50. extern char alignment;
  51. extern BOOL GermanMode;
  52. extern BOOL mbox;
  53. extern long linenumber;
  54. /***************************************************************************/
  55.  
  56. /***************************  prototypes     ********************************/
  57. void ConvertFormula();
  58. /****************************************************************************/
  59.  
  60. /****************************************************************************/
  61. void CmdCharFormat(int code)
  62. /****************************************************************************
  63.      purpose : sets the characterformat to bold, italic, underlined...
  64.    parameter : code includes the character-format-style
  65.  ****************************************************************************/
  66. {
  67.   if (TABBING_ON == FALSE)
  68.     {
  69.      switch(code)
  70.      {
  71.        case CMD_BOLD: fprintf(fRtf,"{\\b ");
  72.               break;
  73.        case CMD_ITALIC: fprintf(fRtf,"{\\i ");
  74.             break;
  75.        case CMD_UNDERLINE: fprintf(fRtf,"{\\ul ");
  76.                break;
  77.        case CMD_CAPS: fprintf(fRtf,"{\\scaps ");
  78.               break;
  79.      }
  80.      Convert();
  81.      fprintf(fRtf,"}");
  82.    }
  83. }
  84.  
  85. /******************       helping function for CmdBegin               ***/
  86. /**************************************************************************/
  87. void GetParam(char *string, int size)
  88. /**************************************************************************
  89.      purpose: returns the parameter after the \begin-command
  90.           for instance: \begin{environment}
  91.             return: -> string = "environment"
  92.    parameter: string: look at purpose
  93.          int: maximal number of characters from string
  94.      returns: success: string
  95.           miss : string = ""
  96.  **************************************************************************/
  97. {
  98.   char cThis;
  99.   int i,PopLevel,PopBrack;
  100.   int bracket=0;
  101.  
  102.   if ( (fread(&cThis,1,1,fTex) < 1))
  103.     numerror(ERR_EOF_INPUT);
  104.   if ( cThis != '{' )
  105.   {
  106.     string[0] = cThis;
  107.     string[1] = '\0';
  108.     return;
  109.   }
  110.   else
  111.   {
  112.     bracket++;
  113.     ++BracketLevel;
  114.     Push(RecursLevel,BracketLevel);
  115.   }
  116.   /* Varibale Bracket is 1 here */
  117.   for (i = 0; ;i++)   /* get param from input stream */
  118.   {
  119.     if (fread(&cThis,1,1,fTex) < 1)
  120.        numerror(ERR_EOF_INPUT);
  121.     if (cThis == '}')
  122.     {
  123.       bracket--;
  124.       if (bracket == 0)
  125.       {
  126.     --BracketLevel;
  127.     Pop(&PopLevel,&PopBrack);
  128.        break;
  129.       }
  130.     }
  131.     if (cThis == '{')
  132.     {
  133.       bracket++;
  134.     }
  135.  
  136.     /* \and-command handling routine
  137.     if (cThis == '\\')
  138.        {
  139.        /* command is overread !
  140.     for(;;)
  141.     {
  142.     if (fread(&cThis,1,1,fTex) < 1)
  143.        numerror(ERR_EOF_INPUT);
  144.     if (!isalpha(cThis))
  145.         break;
  146.     }
  147.        fseek(fTex,-1L,SEEK_CUR); /* reread last character
  148.        continue;
  149.        }
  150.      */
  151.     if (cThis == '%')
  152.     {
  153.     IgnoreTo('\n');
  154.     i--;
  155.     continue;
  156.     }
  157.  
  158.     if (size-- > 0)
  159.       string[i] = cThis;
  160.   }
  161.   string[i] = '\0';
  162. }
  163.  
  164. /***************************************************************************/
  165. void CmdBeginEnd(int code)
  166. /***************************************************************************
  167.    purpose: reads the parameter after the \begin or \end-command; ( see also GetParam )
  168.         after reading the parameter the CallParamFunc-function calls the
  169.         handling-routine for that special environment
  170.  parameter: code: CMD_BEGIN: start of environment
  171.           CMD_END:   end of environment
  172.  ***************************************************************************/
  173. {
  174.   char cParam[50];
  175.   switch(code)
  176.   {
  177.     case CMD_BEGIN:
  178.             GetParam(cParam,49);
  179.             CallParamFunc(cParam,ON);
  180.             break;
  181.     case CMD_END:
  182.             GetParam(cParam,49);
  183.             CallParamFunc(cParam,OFF);
  184.             break;
  185.   }
  186. }
  187.  
  188. /********************************************************************************/
  189. void Paragraph(int code)
  190. /*****************************************************************************
  191.     purpose : sets the alignment for a paragraph
  192.   parameter : code: alignment centered, justified, left or right
  193.    globals  : bpard: after such a paragraph-mode the default has to be set back
  194.              bpard would do this in the function convert in the file main.c
  195.  ********************************************************************************/
  196. { static char old_alignment_before_center = JUSTIFIED;
  197.   static char old_alignment_before_right = JUSTIFIED;
  198.   static char old_alignment_before_left = JUSTIFIED;
  199.  
  200.  
  201.   switch(code)
  202.   {
  203.     case (PAR_CENTER | ON):
  204.       old_alignment_before_center = alignment;
  205.       alignment = CENTERED;
  206.       fprintf(fRtf,"\\pard \\q%c ",alignment);
  207.       break;
  208.     case (PAR_CENTER | OFF):
  209.       bPard = TRUE;
  210.       alignment = old_alignment_before_center;
  211.       break;
  212.  
  213.     case (PAR_RIGHT | ON):
  214.       old_alignment_before_right = alignment;
  215.       alignment = RIGHT;
  216.       fprintf(fRtf,"\\pard \\q%c ",alignment);
  217.       break;
  218.     case (PAR_RIGHT | OFF):
  219.       bPard = TRUE;
  220.       alignment = old_alignment_before_right;
  221.       break;
  222.  
  223.     case (PAR_LEFT | ON):
  224.       old_alignment_before_left = alignment;
  225.       alignment = LEFT;
  226.       fprintf(fRtf,"\\pard \\q%c ",alignment);
  227.       break;
  228.     case (PAR_LEFT | OFF):
  229.       bPard = TRUE;
  230.       alignment = old_alignment_before_left;
  231.       break;
  232.   }
  233. }
  234.  
  235. /******************************************************************************/
  236. void CmdToday(int code)
  237. /******************************************************************************
  238.     purpose: converts the LaTex-date-command into a Rtf-chdate-command which
  239.          prints the current date into an document
  240.  ******************************************************************************/
  241. {
  242.   fprintf(fRtf,"\\chdate ");
  243. }
  244.  
  245.  
  246. /******************************************************************************/
  247. void CmdUmlaute(int code)
  248. /******************************************************************************
  249.  purpose : converts german symbols from LaTeX to Rtf
  250.  ******************************************************************************/
  251. {
  252.   static char cHexDigits[16] = {'0', '1', '2' ,'3', '4', '5', '6', '7', '8',
  253.                 '9', 'a', 'b', 'c', 'd', 'e', 'f' };
  254.   char cParam[10];
  255.  
  256.   GetParam(cParam,9);
  257.  
  258.   switch(cParam[0])
  259.   {
  260.     case 'o': fprintf(fRtf,"\\'%c%c ",cHexDigits[('ö'>>4)&0x0f],
  261.         cHexDigits[('ö'&0x0f)]);
  262.           break;
  263.     case 'O': fprintf(fRtf,"\\'%c%c ",cHexDigits[('Ö'>>4)&0x0f],
  264.         cHexDigits[('Ö'&0x0f)]);
  265.           break;
  266.     case 'a': fprintf(fRtf,"\\'%c%c ",cHexDigits[('ä'>>4)&0x0f],
  267.         cHexDigits[('ä'&0x0f)]);
  268.           break;
  269.     case 'A': fprintf(fRtf,"\\'%c%c ",cHexDigits[('Ä'>>4)&0x0f],
  270.         cHexDigits[('Ä'&0x0f)]);
  271.           break;
  272.     case 'u': fprintf(fRtf,"\\'%c%c ",cHexDigits[('ü'>>4)&0x0f],
  273.         cHexDigits[('ü'&0x0f)]);
  274.           break;
  275.     case 'U': fprintf(fRtf,"\\'%c%c ",cHexDigits[('Ü'>>4)&0x0f],
  276.         cHexDigits[('Ü'&0x0f)]);
  277.           break;
  278.     case 'E':fprintf(fRtf, "\\ansi\\'cb\\pc ");
  279.          break;
  280.     case 'I':fprintf(fRtf, "\\ansi\\'cf\\pc ");
  281.          break;
  282.     case 'e':fprintf(fRtf, "\\ansi\\'eb\\pc ");
  283.          break;
  284.     case 'i':fprintf(fRtf, "\\ansi\\'ef\\pc ");
  285.          break;
  286.     case 'y':fprintf(fRtf, "\\ansi\\'ff\\pc ");
  287.          break;
  288.   }
  289. }
  290.  
  291. /******************************************************************************/
  292. void CmdLApostrophChar(int code)
  293. /******************************************************************************
  294.  purpose: converts special symbols from LaTex to Rtf
  295.  ******************************************************************************/
  296. {
  297.   char cParam[10];
  298.  
  299.   GetParam(cParam,9);
  300.   switch(cParam[0])
  301.   {
  302.     case 'A':fprintf(fRtf, "\\ansi\\'c0\\pc ");
  303.          break;
  304.     case 'E':fprintf(fRtf, "\\ansi\\'c8\\pc ");
  305.          break;
  306.     case 'I':fprintf(fRtf, "\\ansi\\'cc\\pc ");
  307.          break;
  308.     case 'O':fprintf(fRtf, "\\ansi\\'d2\\pc ");
  309.          break;
  310.     case 'U':fprintf(fRtf, "\\ansi\\'d9\\pc ");
  311.          break;
  312.     case 'a':fprintf(fRtf, "\\ansi\\'e0\\pc ");
  313.          break;
  314.     case 'e':fprintf(fRtf, "\\ansi\\'e8\\pc ");
  315.          break;
  316.     case 'i':fprintf(fRtf, "\\ansi\\'ec\\pc ");
  317.          break;
  318.     case 'o':fprintf(fRtf, "\\ansi\\'f2\\pc ");
  319.          break;
  320.     case 'u':fprintf(fRtf, "\\ansi\\'f9\\pc ");
  321.          break;
  322.   }
  323. }
  324.  
  325.  
  326. /******************************************************************************/
  327. void CmdRApostrophChar(int code)
  328. /******************************************************************************
  329.  purpose: converts special symbols from LaTex to Rtf
  330.  ******************************************************************************/
  331. {
  332.   char cParam[10];
  333.  
  334.   GetParam(cParam,9);
  335.   switch(cParam[0])
  336.   {
  337.     case 'A':fprintf(fRtf, "\\ansi\\'c1\\pc ");
  338.          break;
  339.     case 'E':fprintf(fRtf, "\\ansi\\'c9\\pc ");
  340.          break;
  341.     case 'I':fprintf(fRtf, "\\ansi\\'cd\\pc ");
  342.          break;
  343.     case 'O':fprintf(fRtf, "\\ansi\\'d3\\pc ");
  344.          break;
  345.     case 'U':fprintf(fRtf, "\\ansi\\'da\\pc ");
  346.          break;
  347.     case 'a':fprintf(fRtf, "\\ansi\\'e1\\pc ");
  348.          break;
  349.     case 'e':fprintf(fRtf, "\\ansi\\'e9\\pc ");
  350.          break;
  351.     case 'i':fprintf(fRtf, "\\ansi\\'ed\\pc ");
  352.          break;
  353.     case 'o':fprintf(fRtf, "\\ansi\\'f3\\pc ");
  354.          break;
  355.     case 'u':fprintf(fRtf, "\\ansi\\'fa\\pc ");
  356.          break;
  357.     case 'y':fprintf(fRtf, "\\ansi\\'fd\\pc ");
  358.          break;
  359.     case 'Y':fprintf(fRtf, "\\ansi\\'dd\\pc ");
  360.          break;
  361.   }
  362. }
  363.  
  364. /******************************************************************************/
  365. void CmdSpitzeChar(int code)
  366. /******************************************************************************
  367.  purpose: converts special symbols from LaTex to Rtf
  368.  ******************************************************************************/
  369. {
  370.   char cParam[10];
  371.  
  372.   GetParam(cParam,9);
  373.   switch(cParam[0])
  374.   {
  375.     case 'A':fprintf(fRtf, "\\ansi\\'c2\\pc ");
  376.          break;
  377.     case 'E':fprintf(fRtf, "\\ansi\\'ca\\pc ");
  378.          break;
  379.     case 'I':fprintf(fRtf, "\\ansi\\'ce\\pc ");
  380.          break;
  381.     case 'O':fprintf(fRtf, "\\ansi\\'d4\\pc ");
  382.          break;
  383.     case 'U':fprintf(fRtf, "\\ansi\\'db\\pc ");
  384.          break;
  385.     case 'a':fprintf(fRtf, "\\ansi\\'e2\\pc ");
  386.          break;
  387.     case 'e':fprintf(fRtf, "\\ansi\\'ea\\pc ");
  388.          break;
  389.     case 'i':fprintf(fRtf, "\\ansi\\'ee\\pc ");
  390.          break;
  391.     case 'o':fprintf(fRtf, "\\ansi\\'f4\\pc ");
  392.          break;
  393.     case 'u':fprintf(fRtf, "\\ansi\\'fb\\pc ");
  394.          break;
  395.   }
  396. }
  397.  
  398. /******************************************************************************/
  399. void CmdTildeChar(int code)
  400. /******************************************************************************
  401.  purpose: converts special symbols from LaTex to Rtf
  402.  ******************************************************************************/
  403. {
  404.   char cParam[10];
  405.  
  406.   GetParam(cParam,9);
  407.   switch(cParam[0])
  408.   {
  409.     case 'A':fprintf(fRtf, "\\ansi\\'c3\\pc ");
  410.          break;
  411.     case 'O':fprintf(fRtf, "\\ansi\\'d5\\pc ");
  412.          break;
  413.     case 'a':fprintf(fRtf, "\\ansi\\'e3\\pc ");
  414.          break;
  415.     case 'o':fprintf(fRtf, "\\ansi\\'f5\\pc ");
  416.          break;
  417.   }
  418. }
  419.  
  420. /******************************************************************************/
  421. void CmdFontSize(int code)
  422. /******************************************************************************
  423.  purpose : sets the fontsize to the point-size given by the LaTex-\fs_size-command
  424.  globals : fontsize : includes the actual fontsize in the document
  425.  ******************************************************************************/
  426. {
  427.   code = (code*fontsize)/20;
  428.   fprintf(fRtf,"\\fs%d ",code);
  429. }
  430.  
  431. /******************************************************************************/
  432. void CmdLogo(int code)
  433. /******************************************************************************
  434.  purpose : prints the LaTex, Tex, SLiTex and BibTex-Logos as an ordinary text
  435.        in the Rtf-File
  436.  ******************************************************************************/
  437. {
  438.   switch(code)
  439.   {
  440.     case CMD_TEX: fprintf(fRtf, "TeX"); break;
  441.     case CMD_LATEX: fprintf(fRtf, "LaTeX"); break;
  442.     case CMD_SLITEX: fprintf(fRtf, "SLiTeX"); break;
  443.     case CMD_BIBTEX: fprintf(fRtf, "BibTeX");break;
  444.   }
  445. }
  446.  
  447. /******************************************************************************/
  448. void CmdFormula(int code)
  449. /******************************************************************************
  450.  purpose: sets the Math-Formula-Mode depending on the code-parameter
  451.  parameter : code: type of braces which include the formula
  452.  ******************************************************************************/
  453. {
  454.   switch(code)
  455.   {
  456.     case FORM_DOLLAR:
  457.       fprintf(fRtf," ");
  458.       if (MathMode == TRUE)
  459.     MathMode = FALSE;
  460.       else
  461.     MathMode = TRUE;
  462.       break;
  463.     case FORM_RND_OPEN:
  464.       fprintf(fRtf," ");
  465.       if (MathMode == TRUE)
  466.       {
  467.     fprintf(stderr,"\n%s: ERROR: warning - nested formulas (1) in File: %s at linenumber: %ld\n",progname,latexname,linenumber);
  468.     fprintf(stderr,"\nprogram aborted\n");
  469.     exit(-1);
  470.       }
  471.       MathMode = TRUE;
  472.       break;
  473.     case FORM_RND_CLOSE:
  474.       fprintf(fRtf," ");
  475.       if (MathMode == FALSE)
  476.       {
  477.     fprintf(stderr,"\n%s: ERROR: warning - nested formulas (2) in File: %s at linenumber: %ld\n",progname,latexname,linenumber);
  478.     fprintf(stderr,"\nprogram aborted\n");
  479.     exit(-1);
  480.       }
  481.       MathMode = FALSE;
  482.       break;
  483.     case FORM_ECK_OPEN:
  484.       fprintf(fRtf,"\n\r\\par ");
  485.       if (MathMode == TRUE)
  486.       {
  487.     fprintf(stderr,"\n%s: ERROR: warning - nested formulas (3) in File: %s at linenumber: %ld\n",progname,latexname,linenumber);
  488.     fprintf(stderr,"\nprogram aborted\n");
  489.     exit(-1);
  490.       }
  491.       MathMode = TRUE;
  492.       break;
  493.     case FORM_ECK_CLOSE:
  494.       fprintf(fRtf,"\n\r\\par ");
  495.       if (MathMode == FALSE)
  496.       {
  497.     fprintf(stderr,"\n%s: ERROR: warning - nested formulas (4) in File: %s at linenumber: %ld\n",progname,latexname,linenumber);
  498.     fprintf(stderr,"\nprogram aborted\n");
  499.     exit(-1);
  500.       }
  501.       MathMode = FALSE;
  502.       bNewPar = TRUE;
  503.       break;
  504.   }
  505. }
  506.  
  507. /******************************************************************************/
  508. void CmdIgnore(int code)
  509. /******************************************************************************
  510.  purpose: LaTeX-commands which can't be converted in Rtf-commands are overread
  511.       as such
  512.  ******************************************************************************/
  513. {
  514. }
  515.  
  516. /******************************************************************************/
  517. void CmdLdots(int code)
  518. /******************************************************************************
  519.  purpose: converts the LaTex-\ldots-command into "..." in Rtf
  520.  ******************************************************************************/
  521. {
  522.   fprintf(fRtf, "...");
  523. }
  524.  
  525. /******************************************************************************/
  526. void CmdEmphasize(int code)
  527. /******************************************************************************
  528.  purpose: turn on/off the emphasized style for characters
  529.  ******************************************************************************/
  530. {
  531.   if (TABBING_ON == FALSE) /* TABBING-environment ignores emphasized-style */
  532.     {
  533.     static Em_on = 0;
  534.     if (!(Em_on))
  535.       fprintf(fRtf,"{\\i ");
  536.     else
  537.       fprintf(fRtf,"{\\plain ");
  538.     Em_on = ~Em_on;
  539.     Convert();
  540.     fprintf(fRtf,"}");
  541.     Em_on = ~Em_on;
  542.     }
  543. }
  544.  
  545. /******************************************************************************/
  546. void Format(int code)
  547. /******************************************************************************
  548.  purpose: makes the same as the function CmdEmphasize above
  549.       but this is an environment-handling-routine in contrast
  550.       to the function above which converts an ordinary \em-command
  551.  parameter: code: EMPHASIZED with ON at environment start;
  552.                   OFF at environment end
  553.  ******************************************************************************/
  554. {
  555.   if (TABBING_ON == FALSE) /* TABBING-environment ignores emphasized-style */
  556.     {
  557.     static Em_on = 0;
  558.     switch(code)
  559.     {
  560.       case (EMPHASIZE | ON):
  561.     if (!(Em_on))
  562.       fprintf(fRtf,"{\\i ");
  563.     else
  564.      fprintf(fRtf,"} ");
  565.     Em_on = ~Em_on;
  566.     break;
  567.       case (EMPHASIZE | OFF):
  568.     if ((Em_on))
  569.       fprintf(fRtf,"} ");
  570.     Em_on = 0;
  571.     break;
  572.     }
  573.     }
  574. }
  575.  
  576. /******************************************************************************/
  577. void Environment(int code)
  578. /******************************************************************************
  579.   purpose: pushes/pops the new environment-commands on/from the stack
  580. parameter: code includes the type of the environment
  581. globals  : bIndocument
  582.  ******************************************************************************/
  583. {
  584.   if (code & ON) /* on switch */
  585.   {
  586.     code &= ~(ON);   /* mask MSB */
  587.     if (code == DOCUMENT)
  588.     {
  589.       ClearEnvironment();
  590.       bInDocument = TRUE;
  591.     }
  592.     PushEnvironment(code);
  593.   }
  594.   else /* off switch */
  595.   {
  596.     PopEnvironment();
  597.   }
  598. }
  599.  
  600. /******************************************************************************/
  601. void CmdTitle(int code)
  602. /******************************************************************************
  603.   purpose: converts the tite, author and date-information from LaTex to Rtf
  604. parameter: code includes which type of the information listed above will be converted
  605.  ******************************************************************************/
  606. {
  607. #define TITLE_END ""
  608. #define AUTHOR_END ""
  609. #define DATE_END ""
  610.  
  611.   char TITLE_BEGIN[10];
  612.   char AUTHOR_BEGIN[10];
  613.   char DATE_BEGIN[10];
  614.   static char title[1000] = "";
  615.   static char author[1000] = "";
  616.   static char date[500] = "";
  617.  
  618.   switch (code)
  619.   {
  620.     case TITLE_TITLE: GetParam(title,999);
  621.               break;
  622.     case TITLE_AUTHOR: TITLE_AUTHOR_ON = TRUE; /* is used for the \and command */
  623.                GetParam(author,999);
  624.                TITLE_AUTHOR_ON = FALSE;
  625.                break;
  626.     case TITLE_DATE: GetParam(date,499);
  627.              break;
  628.     case TITLE_MAKE:
  629.       sprintf(TITLE_BEGIN,"%s%2d", "\\fs", (30*fontsize)/20);
  630.       sprintf(AUTHOR_BEGIN,"%s%2d", "\\fs", (24*fontsize)/20);
  631.       sprintf(DATE_BEGIN,"%s%2d", "\\fs", (24*fontsize)/20);
  632.  
  633.       fprintf(fRtf,"\n\r\\par\\pard\\qc {%s ",TITLE_BEGIN);
  634.       ConvertString(title);
  635.       fprintf(fRtf,"}%s",TITLE_END);
  636.       fprintf(fRtf,"\n\r\\par\\qc {%s ",AUTHOR_BEGIN);
  637.       ConvertString(author);
  638.       fprintf(fRtf,"}%s",AUTHOR_END);
  639.       fprintf(fRtf,"\n\r\\par\\qc {%s ",DATE_BEGIN);
  640.       ConvertString(date);
  641.       fprintf(fRtf,"}%s",DATE_END);
  642.       fprintf(fRtf,"\n\r\\par\n\\par\\pard\\q%c ",alignment);
  643.       if (titlepage == TRUE)
  644.     fprintf(fRtf,"\\page ");
  645.       break;
  646.   }
  647. }
  648.  
  649. /******************************************************************************/
  650. void CmdDocumentStyle(int code)
  651. /******************************************************************************
  652.  purpose: reads the information from the LaTex-documentsstyle-command and
  653.       converts it to a similar Rtf-information
  654.  ******************************************************************************/
  655. {
  656.   static char style[100] = "";
  657.   char cThis = ' ';
  658.   char optstring[30] = "";
  659.   int optparam = FALSE;
  660.  
  661.      while ( cThis == ' ')
  662.      {
  663.     if ( (fread(&cThis,1,1,fTex) < 1))
  664.      numerror(ERR_EOF_INPUT);
  665.      }
  666.  
  667.      for(;;) /* do forever */
  668.      {
  669.     fseek(fTex,-1L,SEEK_CUR); /* reread last character */
  670.  
  671.     switch (cThis)
  672.     {
  673.        case '{' : GetParam(style,99);  /* article, report, bookstyle are the same */
  674.               if (strcmp(style,"article") == 0)
  675.               article = TRUE;
  676.               else
  677.               article = FALSE;
  678.               break;
  679.        case '[' : GetOptParam(style,99);
  680.               optparam = TRUE;
  681.               break;
  682.        default :  /* last character was read again above.
  683.              this character will be written in the rtf-file in the
  684.              convert-routine (main.c) */
  685.  
  686.               fprintf(fRtf,"\\fs%d ",fontsize); /* default or new fontsize */
  687.               return;
  688.               break;
  689.     } /* switch */
  690.  
  691.     if (optparam)
  692.     {
  693.         /* returnstring of GetOptParam will be seperated in his components */
  694.         do
  695.         {
  696.          strcpy(optstring,(char*)GetSubString(style,','));
  697.  
  698.          if (strcmp(optstring,"11pt") == 0)
  699.             fontsize = 22; /* fontsize 11-TEX -> 22-RTF */
  700.  
  701.          else if (strcmp(optstring,"12pt") == 0)
  702.             fontsize = 24; /* fontsize 12-TEX -> 24-RTF */
  703.  
  704.          else if (strcmp(optstring,"german") == 0)
  705.             { GermanMode = TRUE; PushEnvironment(GERMANMODE); }
  706.  
  707.          else if (strcmp(optstring,"twoside") == 0)
  708.              /* default */;
  709.  
  710.          else if (strcmp(optstring,"twocolumn") == 0)
  711.             {
  712.             fprintf(fRtf,"\\cols2\\colsx709 "); /* two columns */
  713.                              /* space between columns 709 */
  714.             twocolumn = TRUE;
  715.             }
  716.         else if (strcmp(optstring,"titlepage") == 0)
  717.             {
  718.             titlepage = TRUE;
  719.             }
  720.  
  721.         }
  722.          while (strcmp(optstring,"") != 0);
  723.       } /* if */
  724.  
  725.       if ( (fread(&cThis,1,1,fTex) < 1)) /* read next character */
  726.        numerror(ERR_EOF_INPUT);
  727.  
  728.     } /* for */
  729. }
  730.  
  731.  
  732. /******************************************************************************/
  733. void CmdSection(int code)
  734. /******************************************************************************
  735.   purpose: converts the LaTex-section-commands into similar Rtf-styles
  736. parameter: code: type of section-recursion-level
  737.  ******************************************************************************/
  738. {
  739. #define SECTNORM_END "}"
  740. #define SECTSUB_END "}"
  741. #define SECTSUBSUB_END "}"
  742.  
  743.   char SECTNORM_BEGIN[10];
  744.   char SECTSUB_BEGIN[10];
  745.   char SECTSUBSUB_BEGIN[10];
  746.   char optparam[100] = "";
  747.   char cNext = ' ';
  748.  
  749.   if ( (fread(&cNext,1,1,fTex) < 1))
  750.      numerror(ERR_EOF_INPUT);
  751.   fseek(fTex,-1L,SEEK_CUR); /* reread last character */
  752.   if (cNext == '[')
  753.      GetOptParam(optparam,99);
  754.   switch (code)
  755.   {
  756.   case SECT_NORM:
  757.     sprintf(SECTNORM_BEGIN, "%s%2d%s", "{\\fs", (40*fontsize)/20, "");
  758.     fprintf(fRtf,"\n\r\\par %s ",SECTNORM_BEGIN);
  759.     Convert();
  760.     fprintf(fRtf,"%s\n\r\\par ",SECTNORM_END);
  761.     bNewPar = TRUE;
  762.     break;
  763.   case SECT_SUB:
  764.     sprintf(SECTSUB_BEGIN, "%s%2d%s", "{\\fs", (30*fontsize)/20, "");
  765.     fprintf(fRtf,"\n\r\\par %s ",SECTSUB_BEGIN);
  766.     Convert();
  767.     fprintf(fRtf,"%s\n\r\\par ",SECTSUB_END);
  768.     bNewPar = TRUE;
  769.     break;
  770.   case SECT_SUBSUB:
  771.     sprintf(SECTSUBSUB_BEGIN, "%s%2d%s", "{\\fs", (24*fontsize)/20, "");
  772.     fprintf(fRtf,"\n\r\\par %s ",SECTSUBSUB_BEGIN);
  773.     Convert();
  774.     fprintf(fRtf,"%s\n\r\\par ",SECTSUBSUB_END);
  775.     bNewPar = TRUE;
  776.     break;
  777.   }
  778. }
  779.  
  780.  
  781. /******************************************************************************/
  782. void CmdFootNote(int code)
  783. /******************************************************************************
  784.  purpose: converts footnotes from LaTex to Rtf
  785.  ******************************************************************************/
  786. {
  787.   char cText[1000] = "";
  788.   char number[255];
  789.   char cNext;
  790.  
  791.   if ( (fread(&cNext,1,1,fTex) < 1))
  792.      numerror(ERR_EOF_INPUT);
  793.   fseek(fTex,-1L,SEEK_CUR); /* reread last character */
  794.  
  795.   if (cNext == '[')
  796.       GetOptParam(number,254); /* is ignored because of the automatic footnumber-generation */
  797.  
  798.   GetParam(cText,999);
  799.   fprintf(fRtf,"{\\up6\\chftn}\n\r{\\*\\footnote \\pard\\plain\\q%c \\s246 \\fs%d",alignment,fontsize);
  800.   fprintf(fRtf," {\\up6\\chftn } %s }\n\r ",cText);
  801. }
  802.  
  803. /******************************************************************************/
  804. void CmdQuote(int code)
  805. /******************************************************************************
  806.   purpose: converts the LaTex-Quote-commands into similar Rtf-commands
  807. parameter: code: QUOTE and QUOTATION On/Off
  808.          specifies the recursion-level of these commands
  809.  globals : NoNewLine: true if no newline should be printed into the Rtf-File
  810.        indent : includes the left-indent-position
  811.  ******************************************************************************/
  812. {
  813.   switch(code)
  814.   {
  815.     case (QUOTE | ON):
  816.       indent += 512;
  817.       NoNewLine = TRUE;
  818.       fprintf(fRtf,"\n\r\\par\\li%d",indent);
  819.       break;
  820.     case (QUOTE | OFF):
  821.       indent -= 512;
  822.       NoNewLine = FALSE;
  823.       fprintf(fRtf,"\n\r\\par\\li%d",indent);
  824.       break;
  825.     case (QUOTATION | ON):
  826.       indent += 512;
  827.       NoNewLine = TRUE;
  828.       fprintf(fRtf,"\n\r\\par\\li%d",indent);
  829.       break;
  830.     case (QUOTATION | OFF):
  831.       indent -= 512;
  832.       NoNewLine = FALSE;
  833.       fprintf(fRtf,"\n\r\\par\\li%d",indent);
  834.       break;
  835.   }
  836. }
  837.  
  838.  
  839. /******************************************************************************/
  840. void CmdList(int code)
  841. /******************************************************************************
  842.   purpose : converts the LaTeX-environments itemize, description and enumerate
  843.         to similar Rtf-styles
  844.         (only the begin/end-commands and not the commands inside the environment
  845.          see also function CmdItem)
  846. parameter : code : type of environment and on/off-state
  847.  globals  : nonewline, indent: look at funtction CmdQuote
  848.  ******************************************************************************/
  849. {
  850.   switch (code)
  851.   {
  852.     case (ITEMIZE | ON):
  853.       PushEnvironment(ITEMIZE);
  854.       indent += 512;
  855.       NoNewLine = TRUE;
  856.       bNewPar = FALSE;
  857.       break;
  858.     case (ITEMIZE | OFF):
  859.       PopEnvironment();
  860.       indent -= 512;
  861.       NoNewLine = FALSE;
  862.       fprintf(fRtf,"\n\r\\par\\fi0\\li%d ",indent);
  863.       bNewPar = TRUE;
  864.       break;
  865.    case (ENUMERATE | ON):
  866.       PushEnvironment(ENUMERATE);
  867.       CmdItem(RESET);
  868.       indent += 512;
  869.       NoNewLine = TRUE;
  870.       bNewPar = FALSE;
  871.       break;
  872.     case (ENUMERATE | OFF):
  873.       PopEnvironment();
  874.       indent -= 512;
  875.       NoNewLine = FALSE;
  876.       fprintf(fRtf,"\n\r\\par\\fi0\\li%d ",indent);
  877.       bNewPar = TRUE;
  878.       break;
  879.     case (DESCRIPTION | ON):
  880.       PushEnvironment(DESCRIPTION);
  881.       indent += 512;
  882.       NoNewLine = TRUE;
  883.       bNewPar = FALSE;
  884.       break;
  885.     case (DESCRIPTION | OFF):
  886.       PopEnvironment();
  887.       indent -= 512;
  888.       NoNewLine = FALSE;
  889.       fprintf(fRtf,"\n\r\\par\\fi0\\li%d ",indent);
  890.       bNewPar = TRUE;
  891.       break;
  892.   }
  893. }
  894.  
  895. /******************************************************************************/
  896. void CmdItem(int code)
  897. /******************************************************************************
  898.  purpose : makes the same as the function CmdList except that
  899.        here are only \-commands are handled and in the function
  900.        CmdList only the \begin or \end{environment}-command is handled
  901. parameter : code : type of environment and on/off-state
  902.  globals  : nonewline, indent: look at funtction CmdQuote
  903.  ******************************************************************************/
  904. { char labeltext[100];
  905.   char cNext;
  906.   static int number = 0;
  907.   switch (code)
  908.   {
  909.     case RESET:
  910.       number = 1;
  911.       break;
  912.     case ITEMIZE:
  913.        if ( (fread(&cNext,1,1,fTex) < 1))
  914.           numerror(ERR_EOF_INPUT);
  915.        fseek(fTex,-1L,SEEK_CUR); /* reread last character */
  916.        labeltext[0] = '\0';
  917.        if (cNext == '[')
  918.        GetOptParam(labeltext,99);
  919.       fprintf(fRtf,"\n\\par\\fi-340\\li%d{\\b ",indent);
  920.       ConvertString(labeltext);
  921.       fprintf(fRtf,"}\\~");
  922.       bNewPar = TRUE;
  923.       break;
  924.     case ENUMERATE:
  925.       fprintf(fRtf,"\n\\par\\fi-340\\li%d %d \\~",indent,number++);
  926.       bNewPar = TRUE;
  927.       break;
  928.     case DESCRIPTION:
  929.        if ( (fread(&cNext,1,1,fTex) < 1))
  930.           numerror(ERR_EOF_INPUT);
  931.        fseek(fTex,-1L,SEEK_CUR); /* reread last character */
  932.        labeltext[0] = '\0';
  933.        if (cNext == '[')
  934.        GetOptParam(labeltext,99);
  935.       fprintf(fRtf,"\n\\par\\fi-340\\li%d{\\b ",indent);
  936.       ConvertString(labeltext);
  937.       fprintf(fRtf,"}\\~");
  938.       bNewPar = TRUE;
  939.       break;
  940.   }
  941. }
  942.  
  943. /******************************************************************************/
  944. void CmdMbox(int code)
  945. /******************************************************************************
  946.   purpose: converts the LaTeX \mbox-command into  an similar Rtf-style
  947.   globals: mbox
  948.  ******************************************************************************/
  949. {
  950.   mbox = TRUE;
  951.   Convert();
  952.   mbox = FALSE;
  953. }
  954.  
  955. /******************************************************************************/
  956. void ConvertFormula()
  957. /******************************************************************************
  958.  purpose : necessary commands for the formula-environment are pushed onto a stack
  959.  globals : MathMode
  960.  ******************************************************************************/
  961. {
  962.   Push(RecursLevel,BracketLevel);
  963.   ++BracketLevel;    /* Math End char is treated as } math begin as { */
  964.   Push(RecursLevel,BracketLevel);
  965.   MathMode = TRUE;
  966.   Convert();
  967.   MathMode = FALSE;
  968. }
  969.  
  970.  
  971. /******************************************************************************/
  972. void CmdSetFont(int code)
  973. /******************************************************************************
  974.   purpose: sets an font for the actual character-style
  975. parameter: code: includes the font-type
  976.  ******************************************************************************/
  977. {
  978.   int num;
  979.  
  980.   switch(code)
  981.   {
  982.     case F_ROMAN: num = GetTexFontNumber("Roman");
  983.           break;
  984.     case F_SLANTED: num = GetTexFontNumber("Slanted");
  985.           break;
  986.     case F_SANSSERIF: num = GetTexFontNumber("Sans Serif");
  987.           break;
  988.     case F_TYPEWRITER: num = GetTexFontNumber("Typewriter");
  989.           break;
  990.     default: num = 0;
  991.   }
  992.   fprintf(fRtf,"{\\f%d ",num);
  993.   Convert();
  994.   fprintf(fRtf,"}");
  995. }
  996.  
  997. /******************************************************************************/
  998. void CmdInclude(int code)
  999. /******************************************************************************
  1000.  purpose: reads an extern-LaTex-File from the into the actual document and converts it to
  1001.       an similar Rtf-style
  1002.  globals: GermanMode: is set if germanstyles are included
  1003.  ******************************************************************************/
  1004. {
  1005.   char filename[255] = "";
  1006.   FILE *fp,*LatexFile;
  1007.   /*fpos_t aktpos;*/
  1008.   char oldlatexfilename[PATHMAX];
  1009.   long oldlinenumber;
  1010.  
  1011. /*  fgetpos(fTex,&aktpos);
  1012.   if ( (n=(fread(filename,99,1,fTex)) < 1))
  1013.     numerror(ERR_EOF_INPUT);
  1014.   filename[n+1] = '\0';
  1015.  
  1016.   if (strstr(filename,"german.sty")!=NULL)
  1017.   {
  1018.     GermanMode = TRUE;
  1019.     PushEnvironment(GERMANMODE);
  1020.     return;
  1021.   }
  1022.   fsetpos(fTex,&aktpos);*/
  1023.  
  1024.   GetInputParam(filename,99);
  1025.   if (strstr(filename,"german.sty")!=NULL)
  1026.   {
  1027.     GermanMode = TRUE;
  1028.     PushEnvironment(GERMANMODE);
  1029.     return;
  1030.   }
  1031.  
  1032.  
  1033.   if (strcmp(filename,"") == 0)
  1034.      {
  1035.      fprintf(stderr,"\n%s: WARNING: invalid filename after \\include: %s\n",progname,filename);
  1036.      return;
  1037.      }
  1038.  
  1039.   /* extension .tex is appended automaticly */
  1040.   if(strchr(filename,'.')==NULL)
  1041.     strcat(filename,".tex");
  1042.   if ( (fp=(fopen(filename,"r")))==NULL )
  1043.   {
  1044.     fprintf(stderr,"\n%s: WARNING: cannot open include file: %s\n",progname,filename);
  1045.     return;
  1046.   }
  1047.  
  1048.   LatexFile = fTex;
  1049.   fTex = fp;
  1050.   oldlinenumber = linenumber;
  1051.   linenumber = 1;
  1052.   strcpy(oldlatexfilename,latexname);
  1053.   strcpy(latexname,filename);
  1054.   BracketLevel++;
  1055.   fprintf(fRtf,"{");
  1056.   Convert();
  1057.   fprintf(fRtf,"}");
  1058.   BracketLevel--;
  1059.  
  1060.   fTex = LatexFile;
  1061.   strcpy(latexname,oldlatexfilename);
  1062.   linenumber = oldlinenumber;
  1063.   fclose(fp);
  1064. }
  1065.  
  1066. /******************************************************************************/
  1067. void CmdVerb(int code)
  1068. /******************************************************************************
  1069.  purpose: converts the LaTex-verb-environment to a similar Rtf-style
  1070.  ******************************************************************************/
  1071. {
  1072.   char cThis;
  1073.   char markingchar='|';   /* Verb-Text is between | or " */
  1074.   while (fread(&cThis, 1,1,fTex) == 1)
  1075.   {
  1076.     if ((cThis == '\"') || (cThis == '|'))
  1077.     {
  1078.       markingchar = cThis;
  1079.       break;
  1080.     }
  1081.   }
  1082.   if (cThis != markingchar)
  1083.     numerror(ERR_EOF_INPUT);
  1084.   while (fread(&cThis, 1,1,fTex) == 1)
  1085.   {
  1086.     if (cThis == markingchar)
  1087.       break;
  1088.     else
  1089.     {   /* print character */
  1090.       if (cThis == '\\')    /* care for \\ */
  1091.     fprintf(fRtf,"\\\\");
  1092.       else
  1093.       {
  1094.     if (code == AST_FORM)
  1095.     {
  1096.       if (cThis == ' ')   /* print dot instead of space */
  1097.         fprintf(fRtf,"{\\ansi\\'b7\\pc}");
  1098.       else
  1099.         fprintf(fRtf,"%c",cThis);
  1100.     }
  1101.     else
  1102.       fprintf(fRtf,"%c",cThis);
  1103.       }
  1104.     }
  1105.   }
  1106.   if (cThis != markingchar)
  1107.     numerror(ERR_EOF_INPUT);
  1108. }
  1109.  
  1110. /******************************************************************************/
  1111. void CmdVerbatim(int code)  /* write anything till \end{verbatim} */
  1112. /******************************************************************************
  1113.  purpose: in this verb-environment each character is converted 1:1 from LaTex
  1114.       to Rtf without converting any LaTex-commands
  1115.  ******************************************************************************/
  1116. {
  1117.   char endstring[]="\\end{verbatim}";
  1118.   int i=0,j=0;
  1119.   char cThis;
  1120.   for(;;)
  1121.   {
  1122.     if (fread(&cThis, 1,1,fTex) != 1)
  1123.       numerror(ERR_EOF_INPUT);
  1124.     if ( (cThis != endstring[i]) || ( (i>0) && (cThis == ' ') ) )
  1125.     {
  1126.       if (i > 0)
  1127.       {
  1128.     for(j=0;j<i;j++)
  1129.     {
  1130.       if (j==0)
  1131.         fprintf(fRtf,"\\\\");
  1132.       else
  1133.         fprintf(fRtf,"%c",endstring[j]);
  1134.     }
  1135.     i = 0;
  1136.       }
  1137.       if (cThis == '\\')    /* care for \\ */
  1138.     fprintf(fRtf,"\\\\");
  1139.       else
  1140.       {
  1141.     if (cThis == '\n')
  1142.       {
  1143.       linenumber++;
  1144.       fprintf(fRtf,"\\par ");
  1145.       }
  1146.     else
  1147.       fprintf(fRtf,"%c",cThis);
  1148.       }
  1149.     }
  1150.     else
  1151.     {
  1152.       if (cThis != ' ')
  1153.     ++i;
  1154.       if ((int)i >=(int)strlen(endstring))
  1155.     return;
  1156.     }
  1157.   } /* for */
  1158. }
  1159.  
  1160. /******************************************************************************/
  1161. void CmdVerse(int code)
  1162. /******************************************************************************
  1163.   purpose: converts the LaTex-Verse-environment to a similar Rtf-style
  1164. parameter: code: turns on/off handling routine
  1165.  ******************************************************************************/
  1166. {
  1167.   switch (code)
  1168.   {
  1169.     case ON :
  1170.           fprintf(fRtf,"\n\\par\\pard\\q%c\\fi-567\\li1134\\ri1134\\keep ",alignment);
  1171.           NoNewLine = FALSE;
  1172.           bNewPar = TRUE;
  1173.           break;
  1174.     case OFF: fprintf(fRtf,"\n\\par\\pard\\q%c ",alignment);
  1175.           bNewPar = TRUE;
  1176.           break;
  1177.   }
  1178. }
  1179.  
  1180.  
  1181. /******************************************************************************/
  1182. void CmdIgnoreDef(int code)
  1183. /*****************************************************************************
  1184.  purpose: newenvironments or newcommands which are defined by the user can't
  1185.       be converted into Rtf and so they've to be ignored
  1186.  ******************************************************************************/
  1187. {
  1188.   char cThis;
  1189.   int bracket;
  1190.   /* ignore till '{'  */
  1191.   while (fread(&cThis, 1,1,fTex) == 1)
  1192.   {
  1193.     if (cThis == '{')
  1194.       break;
  1195.   }
  1196.   if (cThis != '{')
  1197.     numerror(ERR_EOF_INPUT);
  1198.   bracket = 1;
  1199.   while (fread(&cThis, 1,1,fTex) == 1)
  1200.   {
  1201.     if (cThis == '{')
  1202.       bracket++;
  1203.     if (cThis == '}')
  1204.       bracket--;
  1205.     if (cThis == '\n')
  1206.     linenumber++;
  1207.     if (bracket == 0)
  1208.       return;
  1209.    /* if (cThis == '%')
  1210.     {  in file latex.tex '%' in def means `%` no comment
  1211.       IgnoreTo('\n');
  1212.     }*/
  1213.   }
  1214.   if (cThis != '}')
  1215.     numerror(ERR_EOF_INPUT);
  1216. }
  1217.  
  1218. /******************************************************************************/
  1219. void TranslateGerman(void)
  1220. /***************************************************************************
  1221. purpose: called on active german-mode and " character in input file to
  1222.      handle " as an active (meta-)character.
  1223. globals: reads from fTex and writes to fRtf
  1224.  ***************************************************************************/
  1225. {
  1226.   char cThis;
  1227.   while (fread(&cThis, 1,1,fTex) != 1)
  1228.   {
  1229.     numerror(ERR_EOF_INPUT);
  1230.   }
  1231.   switch(cThis)
  1232.   {
  1233.     case 'a': fprintf(fRtf, "\\ansi\\'e4\\pc ");
  1234.           break;
  1235.     case 'o': fprintf(fRtf, "\\ansi\\'f6\\pc ");
  1236.           break;
  1237.     case 'u': fprintf(fRtf, "\\ansi\\'fc\\pc ");
  1238.           break;
  1239.     case 's': fprintf(fRtf, "\\ansi\\'df\\pc ");
  1240.           break;
  1241.     case '|': break;  /* ignore */
  1242.     case '-': break;  /* ignore */
  1243.     case '"': break;  /* ignore */
  1244.     case '\'':fprintf(fRtf, "\\ldblquote ");
  1245.           break;
  1246.     case '`': fprintf(fRtf, "\\rdblquote ");
  1247.           break;
  1248.     case '<': break;
  1249.     case '>': break;
  1250.     default:  fprintf(fRtf,"%c",cThis);
  1251.   }
  1252. }
  1253.  
  1254. /******************************************************************************/
  1255. void CmdPrintRtf(int code)
  1256. /***************************************************************************
  1257. purpose: writes string to RTF file
  1258. globals: writes to fRtf
  1259.  ***************************************************************************/
  1260. {
  1261.   fprintf(fRtf,(char*)code);
  1262. }
  1263.  
  1264. void GermanPrint(int code)
  1265. {
  1266.   switch(code)
  1267.   {
  1268.     case GP_CK:fprintf(fRtf,"ck");
  1269.         break;
  1270.     case GP_LDBL: fprintf(fRtf,"\\ldblquote");
  1271.           break;
  1272.     case GP_L: fprintf(fRtf,"\\lquote");
  1273.            break;
  1274.     case GP_R: fprintf(fRtf,"\\rquote");
  1275.            break;
  1276.     case GP_RDBL: fprintf(fRtf,"\\rdblquote");
  1277.   }
  1278. }
  1279.  
  1280.  
  1281. void CmdIgnoreLet(int code)
  1282. {
  1283.   char cThis;
  1284.   int count=0;
  1285.   /* Format: \let\XXXXX = \YYYYYY or \let\XXXXX\YYYYYY
  1286.   /* ignore till 2x '\' */
  1287.  
  1288.   while (fread(&cThis, 1,1,fTex) == 1)
  1289.   {
  1290.     if (cThis == '\\')
  1291.       count++;
  1292.     if (count == 2)
  1293.     break;
  1294.     if (cThis == '\n')
  1295.       linenumber++;
  1296.   }
  1297.   if (cThis != '\\')
  1298.     numerror(ERR_EOF_INPUT);
  1299.   /* ignore all following spaces */
  1300.  while (fread(&cThis, 1,1,fTex) == 1)
  1301.   {
  1302.     if (cThis != ' ')
  1303.       break;
  1304.   }
  1305.   if (cThis == ' ')
  1306.     numerror(ERR_EOF_INPUT);
  1307.   /* ignore till next space */
  1308.   while (fread(&cThis, 1,1,fTex) == 1)
  1309.   {
  1310.     if (cThis == ' ')
  1311.       break;
  1312.     if (cThis == '\n')
  1313.     {
  1314.       linenumber++;
  1315.       break;
  1316.     }
  1317.   }
  1318.   if ((cThis != ' ') && (cThis != '\n'))
  1319.     numerror(ERR_EOF_INPUT);
  1320.   /* seek back 1 */
  1321.   fseek(fTex,-1L,SEEK_CUR); /* reread last character */
  1322. }
  1323.  
  1324.  
  1325. void IgnoreNewCmd(int code)
  1326. {
  1327.   char cThis;
  1328.   /* ignore till '{' */
  1329.   if (fread(&cThis, 1,1,fTex) != 1)
  1330.     numerror(ERR_EOF_INPUT);
  1331.   fseek(fTex,-1L,SEEK_CUR); /* reread last character */
  1332.   if (cThis == '\\')
  1333.     CmdIgnoreDef(0);
  1334.   else
  1335.     CmdIgnoreParameter(No_Opt_Two_NormParam );
  1336. }
  1337.  
  1338. #define LABEL 1
  1339. #define REF 2
  1340. #define PAGEREF 3
  1341. void CmdLabel(int code)
  1342. {
  1343.   char text[500];
  1344.   char cThis;
  1345.   switch (code)
  1346.   {
  1347.    case LABEL: GetParam(text,499);
  1348.            fprintf(fRtf,"{\\v[LABEL: %s]}",text);
  1349.            break;
  1350.    case REF:   GetParam(text,499);
  1351.            fprintf(fRtf,"{\\v[REF: %s]}",text);
  1352.            break;
  1353.    case PAGEREF:GetParam(text,499);
  1354.         fprintf(fRtf,"{\\v[PAGEREF: %s]}",text);
  1355.         break;
  1356.   }
  1357.   if ( (fread(&cThis,1,1,fTex) < 1))
  1358.     numerror(ERR_EOF_INPUT);
  1359.   while (cThis == ' ')
  1360.   {
  1361.     if ( (fread(&cThis,1,1,fTex) < 1))
  1362.       numerror(ERR_EOF_INPUT);
  1363.   }
  1364.   if (cThis != '\n')
  1365.     fseek(fTex,-1L,SEEK_CUR);
  1366.   else
  1367.     ++linenumber;
  1368. }
  1369.  
  1370. void ConvertString(char *string)
  1371. {
  1372.   char *tmpname;
  1373.   FILE *fp, *LatexFile;
  1374.   long oldlinenumber;
  1375.  
  1376.   tmpname = tempnam(getenv("TMPDIR"), "l2r");
  1377.   if ((fp = fopen(tmpname,"w+")) == NULL)
  1378.   {
  1379.     fprintf(stderr,"%s: Fatal Error: cannot create temporary file\n", progname);
  1380.     exit(1);
  1381.   }
  1382.   fwrite(string,strlen(string),1,fp);
  1383.   fseek(fp,0L,SEEK_SET);
  1384.  
  1385.   LatexFile = fTex;
  1386.   fTex = fp;
  1387.   oldlinenumber = linenumber;
  1388.   linenumber = 1;
  1389.   BracketLevel++;
  1390.   Convert();
  1391.   BracketLevel--;
  1392.  
  1393.   fTex = LatexFile;
  1394.   linenumber = oldlinenumber;
  1395.   fclose(fp);
  1396.   remove(tmpname);
  1397.   free(tmpname);
  1398. }
  1399.