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

  1. /*
  2.  * $Id: funct2.c,v 1.2 1994/06/21 08:14:11 ralf Exp $
  3.  * History:
  4.  * $Log: funct2.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 : funct2.c
  14.  author : DORNER Fernando, GRANZER Andreas
  15. purpose : includes besides funct1.c all functions which are called from the programm commands.c;
  16.  ****************************************************************************/
  17.  
  18. /********************************* includes *********************************/
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <ctype.h>
  22. #include <stdlib.h>
  23. #include <malloc.h>
  24. #include "main.h"
  25. #include "funct1.h"
  26. #include "commands.h"
  27. #include "funct2.h"
  28. #include "stack.h"
  29. /******************************************************************************/
  30.  
  31. /********************************   extern variables   *************************/
  32. extern int tabcounter;
  33. extern FILE *fRtf;
  34. extern FILE *fTex;
  35. extern int bPard;
  36. extern BOOL bInDocument;
  37. extern int BracketLevel;
  38. extern int RecursLevel;
  39. extern BOOL twocolumn;
  40. extern BOOL TABBING_ON;
  41. extern BOOL TABBING_ON_itself;
  42. extern BOOL TABBING_RETURN;
  43. extern BOOL article;
  44. extern BOOL titlepage;
  45. extern int fontsize;
  46. extern char *progname;
  47. extern BOOL MathMode;
  48. extern char alignment;
  49. extern long linenumber;
  50. extern fpos_t pos_begin_kill;
  51. /*****************************************************************************/
  52.  
  53. /***************************** global variables ********************************/
  54. int tabstoparray[100];
  55. int number_of_tabstops=0;
  56. /*****************************************************************************/
  57.  
  58. /*----------------------------Tabbing Environment ------------------------*/
  59. /******************************************************************************/
  60. void Tabbing(int code)
  61. /******************************************************************************
  62.   purpose: pushes all tabbing-commands on a stack
  63. parameter: code : on/off at begin/end-environment
  64.   globals: TABBING_ON: true if tabbing-mode is on (only in this environment)
  65.        TABBING_RETURN, TABBING_ITSELF: true if environmend ends
  66.  ******************************************************************************/
  67. {
  68.   if (code & ON)  /* on switch */
  69.   {
  70.     code &= ~(ON);  /* mask MSB */
  71.     if (code == TABBING)
  72.     {
  73.       TABBING_ON = TRUE;
  74.       /*TABBING_ON_itself = FALSE; */
  75.  
  76.       PushEnvironment(code);
  77.  
  78.       fprintf(fRtf,"\\par\\line ");
  79.       fgetpos(fRtf,&pos_begin_kill);
  80.       /* Test ConvertTabbing(); */
  81.     }
  82.   }
  83.   else /* off switch */
  84.   {
  85.     /* TABBING_RETURN = TRUE;
  86.     TABBING_ON_itself = TRUE; */
  87.     TABBING_ON = FALSE;
  88.     PopEnvironment();
  89.  
  90.     fprintf(fRtf,"\\par\\pard\\line\\q%c ",alignment);
  91.   }
  92. }
  93.  
  94. /******************************************************************************/
  95. void CmdTabset(int code)
  96. /******************************************************************************
  97.  purpose: sets an tabstop
  98. globals:  tabcounter: specifies the tabstop-position
  99.  ******************************************************************************/
  100. {int tabstop;
  101.     tabstop = (tabcounter/6)*567;
  102.     tabstoparray[number_of_tabstops] = tabstop;
  103.     number_of_tabstops++;
  104.     fprintf(fRtf,"\\tx%d ",tabstop); /* Tab at tabstop/567 centimeters */
  105. }
  106.  
  107. /******************************************************************************/
  108. void CmdTabjump(int code)
  109. /******************************************************************************
  110.  purpose: jumps to an tabstop
  111.  ******************************************************************************/
  112. {
  113.     fprintf(fRtf,"\\tab ");
  114. }
  115.  
  116. /******************************************************************************/
  117. void CmdTabkill(int code)
  118. /******************************************************************************
  119.  purpose: a line in the TABBING-Environment which ends with an kill-command won't be
  120.      written to the rtf-FILE
  121.  ******************************************************************************/
  122. {int i;
  123.  
  124.   fsetpos(fRtf,&pos_begin_kill);
  125.  
  126.   for(i=0;i<number_of_tabstops;i++)
  127.     {
  128.     fprintf(fRtf,"\\tx%d ",tabstoparray[i]); /* Tab at tabstop/567 centimeters */
  129.     }
  130.  
  131.   number_of_tabstops = 0;
  132. }
  133. /*-------------------- End of Tabbing Environment -------------------------*/
  134.  
  135.  
  136.  
  137. /******************************************************************************/
  138. void CmdIgnoreFigure(int code)
  139. /******************************************************************************
  140.   purpose: function, which overreads the Figure,Picture,Bibliopgraphy and Minipage
  141.        Environment
  142. parameter: code: which environment to ignore
  143.  ******************************************************************************/
  144. {
  145.  char endfigure[20];
  146.  char zeichen;
  147.  BOOL found = FALSE;
  148.  int i, endstring=0;
  149.  
  150.     switch (code & ~(ON))  /* mask MSB */
  151.     {
  152.      case FIGURE : {
  153.                strcpy(endfigure,"end{figure}");
  154.                endstring = strlen(endfigure) -1;
  155.                break;
  156.                }
  157.      case FIGURE_1 : {
  158.                strcpy(endfigure,"end{figure*}");
  159.                endstring = strlen(endfigure) -1;
  160.                break;
  161.                }
  162.      case PICTURE : {
  163.                strcpy(endfigure,"end{picture}");
  164.                endstring = strlen(endfigure) -1;
  165.                break;
  166.             }
  167.      case MINIPAGE : {
  168.                strcpy(endfigure,"end{minipage}");
  169.                endstring = strlen(endfigure) -1;
  170.                break;
  171.             }
  172.      case THEBIBLIOGRAPHY : {
  173.                strcpy(endfigure,"end{thebibliography}");
  174.                endstring = strlen(endfigure) -1;
  175.                break;
  176.             }
  177.  
  178.     } /* end switch */
  179.  
  180.     while (fread(&zeichen,1,1,fTex) >=1)
  181.     {
  182.        if (zeichen == '\\')
  183.        {
  184.       int found_space = FALSE;
  185.       for (i=0; i<=endstring; i++)
  186.         {
  187.         int nl = FALSE;
  188.         if (fread(&zeichen,1,1,fTex) < 1)
  189.         numerror(ERR_EOF_INPUT);
  190.         if (zeichen == '\\')
  191.         linenumber++;                   /* \\-in figure is a line !!! */
  192.         while(zeichen == ' ' || zeichen == '\t' || zeichen == '\n' && !nl)
  193.         {
  194.         if(zeichen == '\n')
  195.             nl = TRUE;
  196.         if(fread(&zeichen,1,1,fTex) !=1)
  197.             numerror(ERR_EOF_INPUT);
  198.         found_space = TRUE;
  199.         }
  200.         if(found_space && zeichen != '{') /* for vi } */
  201.         break;
  202.         found_space = FALSE;
  203.         if (zeichen != endfigure[i])
  204.         break;
  205.         if (i == endstring)                 /* end-figure-found */
  206.         found = TRUE;
  207.         } /* for */
  208.        } /* if */
  209.        if (zeichen == '%')
  210.       IgnoreTo('\n');
  211.        if (zeichen == '\n')
  212.       linenumber++;                         /* count lines */
  213.        if (found)
  214.        return;
  215.     } /* while */
  216.     numerror(ERR_EOF_INPUT);
  217. }
  218. /*------------------------------------------------------------------------*/
  219.  
  220.  
  221. /******************************************************************************/
  222. void CmdIgnoreParameter(int code)
  223. /******************************************************************************
  224.   purpose: function, which ignores both: optional and normal parameters
  225. parameter: code: number of optional/normal parameters to ignore
  226.  ******************************************************************************/
  227. {int count_opt_param_close = 0;
  228.  int count_norm_param = 0;
  229.  int count_opt_param_open = 0;
  230.  char cThis = ' ';
  231.  char cNext = ' ';
  232.  BOOL firstloop = TRUE;
  233.  int bracket_open = 0;
  234.  
  235.     for(;;)  /* forever */
  236.     {
  237.        if ( (fread(&cThis,1,1,fTex) < 1))
  238.       numerror(ERR_EOF_INPUT);
  239.        switch(cThis)
  240.        {
  241.      case '{':
  242.       {
  243.        bracket_open++ ;
  244.       } break;
  245.      case '}':
  246.      {
  247.        bracket_open--;
  248.        if (bracket_open == 0)
  249.           count_norm_param++;
  250.        if ( (fread(&cNext,1,1,fTex) < 1))
  251.         {
  252.              numerror(ERR_EOF_INPUT);
  253.         }
  254.        fseek(fTex,-1L,SEEK_CUR); /* reread last character */
  255.        if (cNext == '[')         /* count open braces */
  256.            count_opt_param_open++;
  257.      } break;
  258.        case ']':
  259.      {
  260.        count_opt_param_close++;
  261.        if ( (fread(&cNext,1,1,fTex) < 1))
  262.            numerror(ERR_EOF_INPUT);
  263.        fseek(fTex,-1L,SEEK_CUR); /* reread last character */
  264.        if (cNext == '[')         /* count open braces */
  265.            count_opt_param_open++;
  266.      } break;
  267.        case '%':
  268.      {
  269.      IgnoreTo('\n');
  270.      } break;
  271.        } /* end switch */
  272.        if ((firstloop) && (cThis == '['))
  273.        count_opt_param_open++;
  274.        switch (code)
  275.        {
  276.       case Two_Opt_One_NormParam :
  277.       case One_Opt_One_NormParam :
  278.       case No_Opt_One_NormParam  : if ((count_opt_param_close ==
  279.                         count_opt_param_open) &&
  280.                        (count_norm_param == 1))
  281.                        return;
  282.                        break;
  283.       case Two_Opt_Two_NormParam :
  284.       case One_Opt_Two_NormParam :
  285.       case No_Opt_Two_NormParam  :if ((count_opt_param_close ==
  286.                        count_opt_param_open) &&
  287.                        (count_norm_param == 2))
  288.                        return;
  289.                       break;
  290.       case Two_Opt_Three_NormParam:
  291.       case One_Opt_Three_NormParam:
  292.       case No_Opt_Three_NormParam:if ((count_opt_param_close ==
  293.                        count_opt_param_open) &&
  294.                        (count_norm_param == 3))
  295.                        return;
  296.                       break;
  297.       case Two_Opt_No_NormParam  :
  298.       case One_Opt_No_NormParam  :if ((count_opt_param_close ==
  299.                        count_opt_param_open) &&
  300.                        (count_norm_param == 0))
  301.                        {
  302.                         if (firstloop == TRUE)
  303.                         fseek(fTex,-1L,SEEK_CUR); /* reread last character */
  304.                         return;
  305.                        }
  306.                       break;
  307.        } /* switch */
  308.        firstloop = FALSE;
  309.     } /* for */
  310. }
  311. /*------------------------------------------------------------------------*/
  312.  
  313.  
  314. /******************************************************************************/
  315. void Ignore_Environment(char *searchstring)
  316. /******************************************************************************
  317.   purpose: function, which ignores an unconvertable environment in LaTex
  318. parameter: searchstring : includes the string to search for
  319.        example: \begin{unknown} ... \end{unknown}
  320.             searchstring="end{unknown}"
  321.  ******************************************************************************/
  322. {
  323.  char zeichen;
  324.  BOOL found = FALSE;
  325.  int i, endstring;
  326.     endstring = strlen(searchstring) - 1;
  327.     while (fread(&zeichen,1,1,fTex) >=1)
  328.     {
  329.        if (zeichen == '\\')
  330.        {
  331.       for (i=0; i<=endstring; i++)
  332.         {
  333.         if (fread(&zeichen,1,1,fTex) < 1)
  334.         numerror(ERR_EOF_INPUT);
  335.         if (zeichen != searchstring[i])
  336.         break;
  337.         if (i == endstring)                 /* end-environment-found */
  338.         found = TRUE;
  339.         } /* for */
  340.     } /* if */
  341.        if (zeichen == '%')
  342.        IgnoreTo('\n');
  343.        if (zeichen == '\n')
  344.        linenumber++;
  345.        if (found)
  346.        return;
  347.     } /* while */
  348.     numerror(ERR_EOF_INPUT);
  349. }
  350. /*------------------------------------------------------------------------*/
  351.  
  352.  
  353. /******************************************************************************/
  354. void GetOptParam(char *string, int size)
  355. /******************************************************************************
  356.   purpose: function to get an optional parameter
  357. parameter: string: returnvalue of optional parameter
  358.        size: max. size of returnvalue
  359.  ******************************************************************************/
  360. {
  361. char cThis;
  362. int i,PopLevel,PopBrack;
  363.  
  364.   if ( (fread(&cThis,1,1,fTex) < 1))
  365.     numerror(ERR_EOF_INPUT);
  366.  
  367.   if ( cThis != '[' )
  368.   {
  369.     string = "";
  370.     return;
  371.   }
  372.   else
  373.   {
  374.     ++BracketLevel;
  375.     Push(RecursLevel,BracketLevel);
  376.   }
  377.   for (i = 0; ;i++)   /* get param from input stream */
  378.   {
  379.     if (fread(&cThis,1,1,fTex) < 1)
  380.        numerror(ERR_EOF_INPUT);
  381.     if (cThis == ']')
  382.     {
  383.       --BracketLevel;
  384.       Pop(&PopLevel,&PopBrack);
  385.       break;
  386.     }
  387.     if (cThis == '%')
  388.       {
  389.        IgnoreTo('\n');
  390.        continue;
  391.       }
  392.     if (size-- > 0)
  393.       string[i] = cThis;
  394.   }
  395.   string[i] = '\0';
  396. }
  397. /*------------------------------------------------------------------------*/
  398.  
  399. /******************************************************************************/
  400. void CmdIgnoreEnvironment(int code)
  401. /******************************************************************************
  402.   purpose: overreads an ignoreable environment
  403. parameter: code: type of environment & ON/OFF
  404.  ******************************************************************************/
  405. {
  406.      switch (code & ~(ON))   /* ON/OFF-parameter exclude */
  407.      {
  408.     case BIBLIOGRAPHY :
  409.               Ignore_Environment("end{thebibliography}");
  410.               break;                
  411.     case LETTER : Ignore_Environment("end{letter}");
  412.               break;
  413.     case TABLE : Ignore_Environment("end{table}");
  414.               break;
  415.     case TABLE_1 : Ignore_Environment("end{table*}");
  416.               break;
  417.     default : numerror(ERR_WRONG_COMMAND);
  418.      } /* switch */
  419. }
  420.  
  421. /******************************************************************************/
  422. void CmdColumn (int code)
  423. /******************************************************************************
  424.   purpose: chooses beetween one/two-columns
  425. parameter: number of columns
  426.  globals: twocolumn: true if twocolumn-mode is set
  427.  ******************************************************************************/
  428. {
  429.    switch (code)
  430.    {
  431.        case One_Column : fprintf(fRtf,"\\page \\colsx709\\endnhere "); /* new page & one column */
  432.              twocolumn = FALSE;
  433.              break;
  434.        case Two_Column : fprintf(fRtf,"\\page \\cols2\\colsx709\\endnhere "); /* new page & two columns */
  435.              twocolumn = TRUE;
  436.              break;
  437.    } /* switch */
  438. }
  439.  
  440. /******************************************************************************/
  441. char *GetSubString(char *s, char terminatesymbol)
  442. /******************************************************************************
  443. purpose:
  444. -----------------------------------------------------------------------------
  445.  GetString is a function which returns the substrings of the string s
  446.    seperated by the terminatesymbol 
  447.  after calling this funtion the first substring to the terminatesymbol
  448.    is cut off the string s 
  449. -----------------------------------------------------------------------------*/
  450. {char *substring;
  451.  char *hilfstring;
  452.  int i=0;
  453.  
  454.       substring =(char*) malloc((strlen(s)+1) * sizeof(char)); /* get heap-memory */
  455.       if (substring == NULL)
  456.       error(" malloc error -> out of memory!\n");
  457.       strcpy(substring,"");
  458.  
  459.       for(i=0; (int)i<=(int)strlen(s); i++)  /* if *s == "" -> for won't be executed */
  460.       {                            /* <= is used for recognising the endmark of the string */
  461.     if (s[i] == '\0')
  462.     {
  463.        strcpy(s,"");
  464.        break;
  465.     }
  466.     if (s[i] == terminatesymbol)
  467.     {
  468.        hilfstring = &s[i+1];
  469.        strcpy(s,hilfstring);    /* is also replaced in the calling-function */
  470.        break;
  471.     }
  472.     substring[i] = s[i];
  473.       }  /* for */
  474.  
  475.       substring[i] = '\0'; /* end-mark */
  476.       return substring;
  477. }
  478. /*-----------------------------------------------------------------------------*/
  479.  
  480. /******************************************************************************/
  481. void CmdNewPage(int code)
  482. /******************************************************************************
  483.   purpose: starts a new page
  484. parameter: code: newpage or newcolumn-option
  485.  globals: twocolumn: true if twocolumn-mode is set
  486.  ******************************************************************************/
  487. {
  488.    switch (code)
  489.    {
  490.       case NewPage :  fprintf(fRtf,"\\page "); /* causes new page */
  491.               break;
  492.       case NewColumn : if (twocolumn == TRUE)
  493.               fprintf(fRtf,"\\column "); /* new column */
  494.                else
  495.               fprintf(fRtf,"\\page ");  /* causes new page */
  496.                break;
  497.    } /* switch */
  498. }
  499.  
  500. /******************************************************************************/
  501. void Cmd_OptParam_Without_braces(int code)
  502. /******************************************************************************
  503.  purpose: gets an optional parameter which isn't surrounded by braces but by spaces
  504.  ******************************************************************************/
  505. {char cNext=' ';
  506.  char cLast=' ';
  507.  
  508.     do
  509.     {
  510.        cLast = cNext;
  511.        if (fread(&cNext,1,1,fTex) < 1)
  512.        numerror(ERR_EOF_INPUT);
  513.  
  514.     } while ((cNext != ' ') &&
  515.          (cNext != '\\') &&
  516.          (cNext != '{') &&
  517.          (cNext != '\n') &&
  518.          (cNext != ',') &&
  519.          ((cNext != '.')  || (isdigit(cLast))) && /* . doesn't mean the end of an command inside an number of the type real */
  520.          (cNext != '}') &&
  521.          (cNext != '\"') &&
  522.          (cNext != '[') &&
  523.          (cNext != '$'));
  524.  
  525.     fseek(fTex,-1L,SEEK_CUR);
  526. }
  527.  
  528.  
  529. /******************************************************************************/
  530. void GetInputParam(char *string, int size)
  531. /******************************************************************************
  532.   purpose: gets the parameter followed the \include or \input -command
  533. parameter: string: returnvalue of the input/include-parameter
  534.        size: max. size of the returnvalue
  535.          must be determined by the calling-function
  536.  ******************************************************************************/
  537. {
  538.   char cThis;
  539.   int i,PopLevel,PopBrack;
  540.   BOOL readuntilnewline = FALSE;
  541.  
  542.   if ( (fread(&cThis,1,1,fTex) < 1))
  543.     numerror(ERR_EOF_INPUT);
  544.   if ( cThis == '{' )
  545.   {
  546.     ++BracketLevel;
  547.     Push(RecursLevel,BracketLevel);
  548.  
  549.   }
  550.   else
  551.   {
  552.     readuntilnewline = TRUE;
  553.     fseek(fTex,-1L,SEEK_CUR); /* reread last character */
  554.   }
  555.   for (i = 0; ;i++)   /* get param from input stream */
  556.   {
  557.     if (fread(&cThis,1,1,fTex) < 1)
  558.        numerror(ERR_EOF_INPUT);
  559.     if (cThis == '}')
  560.     {
  561.       --BracketLevel;
  562.       Pop(&PopLevel,&PopBrack);
  563.       break;
  564.     }
  565.  
  566.     if ((readuntilnewline == TRUE) &&
  567.     ((cThis == ' ') || (cThis == '\n')))
  568.     {
  569.     if (cThis == '\n')
  570.         linenumber++;
  571.     break;
  572.     }
  573.  
  574.     if (size-- > 0)
  575.       string[i] = cThis;
  576.   }
  577.   string[i] = '\0';
  578. }
  579.  
  580. /******************************************************************************/
  581. void ConvertTabbing(void)
  582. /******************************************************************************
  583.  purpose: routine which converts the tabbing-commands from LaTex to Rtf
  584.  ******************************************************************************/
  585. { int read_end = 1024;
  586.   char cCommand[MAXCOMMANDLEN];
  587.   int i;
  588.   long j=0;
  589.   char cThis;
  590.   BOOL getcommand;
  591.   BOOL command_end_line_found;
  592.   BOOL command_kill_found;
  593.  
  594. while (TABBING_ON)
  595. {
  596. command_end_line_found = FALSE;
  597. command_kill_found = FALSE;
  598.  
  599. while (command_end_line_found == FALSE)
  600.   {
  601.   for (;;) /* do forever */
  602.   {
  603.     getcommand=FALSE;
  604.     if (fread(&cThis,1,1,fTex) < 1)
  605.        numerror(ERR_EOF_INPUT);
  606.     j++;
  607.  
  608.     if (cThis == '\\')
  609.        {
  610.        getcommand=TRUE;
  611.        strcpy(cCommand,"");
  612.  
  613.        for (i = 0; ;i++)   /* get command from input stream */
  614.        {
  615.        if (fread(&cThis,1,1,fTex) < 1)
  616.           numerror(ERR_EOF_INPUT);
  617.        j++;
  618.  
  619.        if (i == 0) /* test for special characters */
  620.           {
  621.           switch(cThis)
  622.           {
  623.           case '\\':    command_end_line_found=TRUE;
  624.                 break;
  625.             } /* switch */
  626.           }  /* if */
  627.  
  628.        if (!isalpha(cThis))
  629.            {
  630.            while (cThis == ' ')   /* all spaces after commands are ignored */
  631.            {
  632.            if (fread(&cThis,1,1,fTex) < 1)
  633.            numerror(ERR_EOF_INPUT);
  634.            j++;
  635.            }
  636.  
  637.            fseek(fTex,-1L,SEEK_CUR); /* position of next character after command
  638.                         except space */
  639.            j--;
  640.            break; /* for */
  641.            }
  642.        cCommand[i] = cThis;
  643.        }  /* for */
  644.  
  645.        cCommand[i] = '\0';  /* mark end of string with zero */
  646.     }  /* if \\ */
  647.  
  648.     if ((getcommand) &&
  649.     ((command_end_line_found) ||
  650.      (strcmp(cCommand,"kill") == 0) ||
  651.      (strcmp(cCommand,"end") == 0)))
  652.     {
  653.     command_end_line_found = TRUE;
  654.     if (strcmp(cCommand,"kill") == 0)
  655.         command_kill_found = TRUE;
  656.     break;
  657.     }
  658.  
  659.     if (j >= read_end)
  660.     {
  661.     command_end_line_found = TRUE;
  662.     break;
  663.     }
  664.   } /* for */
  665.   } /* while command_end_line_found */
  666.  
  667.   fseek(fTex,-j,SEEK_CUR); /* re_read line */
  668.   if (command_kill_found)
  669.     Convert_Tabbing_with_kill();
  670.   else
  671.     Convert();
  672. } /* while Tabbing_ON */
  673.  
  674. TABBING_ON = FALSE;
  675. } /* ConvertTabbing */
  676.  
  677.  
  678. /******************************************************************************/
  679. void Convert_Tabbing_with_kill(void)
  680. /******************************************************************************
  681.  purpose: routine which converts the tabbing-kill-option from LaTex to Rtf
  682.  globals: tabcounter:
  683.  ******************************************************************************/
  684. { int i=0;
  685.   BOOL command_kill_found=FALSE;
  686.   char cThis;
  687.   char cCommand[MAXCOMMANDLEN];
  688.  
  689. tabcounter=0;
  690.  
  691. while (command_kill_found == FALSE)
  692.    {
  693.     if (fread(&cThis,1,1,fTex) < 1)
  694.        numerror(ERR_EOF_INPUT);
  695.  
  696.     strcpy(cCommand,"");
  697.  
  698.     if (cThis == '\\')
  699.        {
  700.  
  701.        for (i = 0; ;i++)   /* get command from input stream */
  702.        {
  703.        if (fread(&cThis,1,1,fTex) < 1)
  704.           numerror(ERR_EOF_INPUT);
  705.  
  706.        if (i == 0) /* test for special characters */
  707.           {
  708.           switch(cThis)
  709.           {
  710.           case '=': CmdTabset(0);
  711.                 break;
  712.           default : if(!isalpha(cThis))
  713.                  numerror(ERR_WRONG_COMMAND_IN_TABBING);
  714.             } /* switch */
  715.           }  /* if */
  716.  
  717.        if (!isalpha(cThis))
  718.            {
  719.            while (cThis == ' ')   /* all spaces after commands are ignored */
  720.            {
  721.            if (fread(&cThis,1,1,fTex) < 1)
  722.            numerror(ERR_EOF_INPUT);
  723.            }
  724.  
  725.            fseek(fTex,-1L,SEEK_CUR); /* position of next character after command
  726.                         except space */
  727.            break; /* for */
  728.            }
  729.        cCommand[i] = cThis;
  730.        }  /* for */
  731.  
  732.        cCommand[i] = '\0';  /* mark end of string with zero */
  733.     }  /* if \\ */
  734.     else
  735.       tabcounter++;
  736.  
  737.       if (strcmp(cCommand,"kill") == 0)
  738.     {
  739.     command_kill_found = TRUE;
  740.     tabcounter = 0;
  741.     break;
  742.     }
  743.   } /* while command_kill_found */
  744. } /* Convert_Tabbing_with_kill */
  745.  
  746.  
  747. /******************************************************************************/
  748. void CmdBottom(int code)
  749. /******************************************************************************/
  750. {
  751.   /* it's conventional for the height of the text to be the same on all full pages */
  752. }
  753.  
  754. /******************************************************************************/
  755. void CmdAbstract(int code)
  756. /******************************************************************************
  757.   purpose: converts the LaTex-abstract-command to an similar Rtf-style
  758. parameter: code: on/off-option
  759.  globals : article and titlepage from the documentstyle
  760.  ******************************************************************************/
  761. { static char oldalignment = JUSTIFIED;
  762.  
  763.  
  764.   switch (code)
  765.      {
  766.      case  ON:
  767.      if ((article) && (titlepage))
  768.         {
  769.         fprintf(fRtf,"\n\r\\par\n\\par\\pard ");
  770.         fprintf(fRtf,"\\pard\\qj ");  /* blocked */
  771.         fprintf(fRtf,"{\\b\\fs%d Abstract}",fontsize);
  772.         }
  773.      else
  774.         {
  775.         fprintf(fRtf,"\n\r\\par\n\\par\\pard \\page ");
  776.         fprintf(fRtf,"\\pard\\qj ");   /* blocked */
  777.         fprintf(fRtf,"{\\b\\fs%d Abstract:}\\par ",fontsize);
  778.         }
  779.       oldalignment = alignment;
  780.       alignment = JUSTIFIED;
  781.       break;
  782.     case  OFF:
  783.       fprintf(fRtf,"\\pard ");
  784.       alignment = oldalignment;
  785.       fprintf(fRtf,"\n\r\\par\\q%c ",alignment);
  786.       break;
  787.      } /* switch */
  788. }
  789.  
  790.  
  791.  
  792. /******************************************************************************/
  793. void CmdTitlepage(int code)
  794. /******************************************************************************
  795.   purpose: converts the LaTex-Titlepage-command to an similar Rtf-style
  796. parameter: on/off option
  797.  globals : alignment: is used for the default-alignment-setting after this environment
  798.  ******************************************************************************/
  799. {
  800.   switch (code)
  801.      {
  802.      case  ON:
  803.         fprintf(fRtf,"\n\r\\par\\pard \\page ");  /* new page */
  804.         fprintf(fRtf,"\n\r\\par\\q%c ",alignment);
  805.         break;
  806.     case  OFF:
  807.       fprintf(fRtf,"\\pard ");
  808.       fprintf(fRtf,"\n\r\\par\\q%c \\page ",alignment);
  809.      break;
  810.      } /* switch */
  811. }
  812.  
  813. /******************************************************************************/
  814. void CmdHyphenation(int code)
  815. /******************************************************************************
  816.  purpose: the parameter surrrounded by braces after the hyphenation-command
  817.       won't be seperated at a line-end.
  818.  ******************************************************************************/
  819. { char hyphenparameter[10240];
  820.   unsigned int i;
  821.  
  822.     GetParam(hyphenparameter,10239);
  823.  
  824. /* In a future version we may correctly hyphenate all occurencies of
  825.  * hyphenation-words
  826.  */
  827. # ifdef notdef
  828.     for (i=0; i<(strlen(hyphenparameter)-1); i++)
  829.     {
  830.     if (hyphenparameter[i] != '-')
  831.         fprintf(fRtf,"%c",hyphenparameter[i]);
  832.     else
  833.         fprintf(fRtf,"\\-");
  834.     } /* for */
  835. # endif /* notdef */
  836. }
  837.  
  838. /******************************************************************************/
  839. void CmdFormula2(int code)
  840. /******************************************************************************
  841.  purpose: the same as the function CmdFormula: see above!
  842.  ******************************************************************************/
  843. {
  844.   if (code & ON)  /* on switch */
  845.   {
  846.      MathMode = TRUE;
  847.   }
  848.   else /* off switch */
  849.   {
  850.      MathMode = FALSE;
  851.   }
  852. }
  853.  
  854. /******************************************************************************/
  855. void CmdLetter(int code)
  856. /******************************************************************************
  857.   purpose: pushes all necessary letter-commands on a stack
  858. parameter: code: on/off-option for environment
  859.  ******************************************************************************/
  860. {
  861.   if (code & ON)  /* on switch */
  862.   {
  863.     code &= ~(ON);  /* mask MSB */
  864.     if (code == LETTER)
  865.     {
  866.       PushEnvironment(code);
  867.     }
  868.   }
  869.   else /* off switch */
  870.   {
  871.     PopEnvironment();
  872.   }
  873. }
  874.  
  875. /******************************************************************************/
  876. void CmdAddress(int code)
  877. /******************************************************************************
  878.  purpose: prints the address in a letter
  879.  globals: alignment
  880.  ******************************************************************************/
  881. { static char oldalignment = JUSTIFIED;
  882.  
  883.      oldalignment = alignment;
  884.      alignment = RIGHT;
  885.      fprintf(fRtf,"\n\r\\par\\pard\\q%c ",alignment);   /* address will be printed on the right top */
  886.  
  887.      Convert(); /* convert routine is called again for evaluating the contens
  888.          hold in braces after the \address-command */
  889.  
  890.      alignment = oldalignment;
  891.      fprintf(fRtf,"\\par\\chdate "); /* additional to the address the actual date is printed */
  892.  
  893.      fprintf(fRtf,"\n\r\\par\\pard\\q%c ",alignment);
  894. }
  895.  
  896.  
  897. /******************************************************************************/
  898. void CmdSignature(int code)
  899. /******************************************************************************
  900.  purpose: prints the signature in a letter
  901.  globals: alignment
  902.  ******************************************************************************/
  903. { static char oldalignment = JUSTIFIED;
  904.  
  905.      oldalignment = alignment;
  906.      alignment = RIGHT;
  907.      fprintf(fRtf,"\n\r\\par\\pard\\q%c ",alignment);   /* signature will be printed on the right top */
  908.  
  909.      Convert(); /* convert routine is called again for evaluating the contens
  910.          hold in braces after the \signature-command */
  911.  
  912.      alignment = oldalignment;
  913.      fprintf(fRtf,"\n\r\\par\\pard\\q%c ",alignment);
  914. }
  915.  
  916. /******************************************************************************/
  917. void CmdOpening(int code)
  918. /******************************************************************************
  919.  purpose: special command in the LaTex-letter-environment will be converted to a
  920.       similar Rtf-style
  921.  globals: alignment
  922.  ******************************************************************************/
  923. { static char oldalignment;
  924.  
  925.      oldalignment = alignment;
  926.      alignment = LEFT;
  927.      fprintf(fRtf,"\n\r\\par\\pard\\q%c ",alignment);   /* opening will be printed on the right top */
  928.  
  929.      Convert(); /* convert routine is called again for evaluating the contens
  930.          hold in braces after the \opening-command */
  931.  
  932.      alignment = oldalignment;
  933.      fprintf(fRtf,"\n\r\\par\\pard\\q%c ",alignment);
  934. }
  935.  
  936. /******************************************************************************/
  937. void CmdClosing(int code)
  938. /******************************************************************************
  939.  purpose: special command in the LaTex-letter-environment will be converted to a
  940.       similar Rtf-style
  941.  globals: alignment
  942.  ******************************************************************************/
  943. { static char oldalignment;
  944.  
  945.      oldalignment = alignment;
  946.      alignment = LEFT;
  947.      fprintf(fRtf,"\n\r\\par\\pard\\q%c ",alignment);   /* closing will be printed on the right top */
  948.  
  949.      Convert(); /* convert routine is called again for evaluating the contens
  950.          hold in braces after the \closing-command */
  951.  
  952.      alignment = oldalignment;
  953.      fprintf(fRtf,"\n\r\\par\\pard\\q%c ",alignment);
  954. }
  955.  
  956. void CmdPs(int code)
  957. {
  958.     /* additional text to the \ps-command will be converted by the basic convert-routine */
  959.     /* but you'll have to type the 'P.S.:'-text yourself */
  960. }
  961.  
  962. /******************************************************************************/
  963. void CmdArray(int code)
  964. /******************************************************************************
  965.  purpose: converts the LaTex-Array/eqnarray to a similar Rtf-style
  966.       this converting is only partially
  967.       so the user has to convert some part of the array/eqnarray-environment by hand
  968. parameter: type of array-environment
  969.  ******************************************************************************/
  970. {
  971.   if (code & ON)  /* on switch */
  972.   {
  973.     code &= ~(ON);  /* mask MSB */
  974.     fprintf(stderr,"%s: WARNING: Following environment cannot be converted completely!\n",progname);
  975.     fprintf(stderr,"Some parts of this environment have to be converted and corrected by hand\n");
  976.  
  977.     if (code == ARRAY)
  978.       {
  979.       fprintf(stderr,"Begin of environment: ARRAY\n");
  980.       fprintf(fRtf,"\\par ***begin of environment: ARRAY ***\\par");
  981.       }
  982.     if (code == EQNARRAY)
  983.       {
  984.       fprintf(stderr,"Begin of environment: EQNARRAY\n");
  985.       fprintf(fRtf,"\\par ***begin of environment: EQNARRAY ***\\par");
  986.       }
  987.     if (code == EQNARRAY_1)
  988.       {
  989.       fprintf(stderr,"Begin of environment: EQNARRAY* \n");
  990.       fprintf(fRtf,"\\par ***begin of environment: EQNARRAY*    ***\\par");
  991.       }
  992.   }
  993.   else /* off switch */
  994.   {
  995.     code &= ~(OFF);  /* mask MSB */
  996.     if (code == ARRAY)
  997.       {
  998.       fprintf(stderr,"End of environment: ARRAY\n");
  999.       fprintf(fRtf,"\\par ***end of environment: ARRAY ***\\par");
  1000.       }
  1001.     if (code == EQNARRAY)
  1002.       {
  1003.       fprintf(stderr,"End of environment: EQNARRAY\n");
  1004.       fprintf(fRtf,"\\par ***end of environment: EQNARRAY ***\\par");
  1005.       }
  1006.     if (code == EQNARRAY_1)
  1007.       {
  1008.       fprintf(stderr,"End of environment: EQNARRAY* \n");
  1009.       fprintf(fRtf,"\\par ***end of environment: EQNARRAY*    ***\\par");
  1010.       }
  1011.   }
  1012. }
  1013.  
  1014. /******************************************************************************/
  1015. void CmdTabular(int code)
  1016. /******************************************************************************
  1017.  purpose: converts the LaTex-Tabular to a similar Rtf-style
  1018.       this converting is only partially
  1019.       so the user has to convert some part of the Tabular-environment by hand
  1020. parameter: type of array-environment
  1021.  ******************************************************************************/
  1022. {
  1023.   if (code & ON)  /* on switch */
  1024.   {
  1025.     code &= ~(ON);  /* mask MSB */
  1026.     fprintf(stderr,"%s: WARNING: Following environment cannot be converted completely!\n",progname);
  1027.     fprintf(stderr,"Some parts of this environment have to be converted and corrected by hand\n");
  1028.  
  1029.     if (code == TABULAR)
  1030.       {
  1031.       fprintf(stderr,"Begin of environment: TABULAR\n");
  1032.       fprintf(fRtf,"{\\v\\par ***begin of environment: TABULAR ***\\par}");
  1033.       }
  1034.     if (code == TABULAR_1)
  1035.       {
  1036.       fprintf(stderr,"Begin of environment: TABULAR*  \n");
  1037.       fprintf(fRtf,"{\\v\\par ***begin of environment: TABULAR*   ***\\par}");
  1038.       }
  1039.   }
  1040.   else /* off switch */
  1041.   {
  1042.     code &= ~(OFF);  /* mask MSB */
  1043.     if (code == TABULAR)
  1044.       {
  1045.       fprintf(stderr,"End of environment: TABULAR\n");
  1046.       fprintf(fRtf,"{\\v\\par ***end of environment: TABULAR ***\\par}");
  1047.       }
  1048.     if (code == TABULAR_1)
  1049.       {
  1050.       fprintf(stderr,"End of environment: TABULAR*  \n");
  1051.       fprintf(fRtf,"{\\v\\par ***end of environment: TABULAR*  ***\\par}");
  1052.       }
  1053.   }
  1054. }
  1055.  
  1056. /******************************************************************************/
  1057. void CmdTable(int code)
  1058. /******************************************************************************
  1059.  purpose: converts the LaTex-Table to a similar Rtf-style
  1060.       this converting is only partially
  1061.       so the user has to convert some part of the Table-environment by hand
  1062. parameter: type of array-environment
  1063.  ******************************************************************************/
  1064. {
  1065.   if (code & ON)  /* on switch */
  1066.   {
  1067.     code &= ~(ON);  /* mask MSB */
  1068.     fprintf(stderr,"%s: WARNING: Following environment cannot be converted completely!\n",progname);
  1069.     fprintf(stderr,"Some parts of this environment have to be converted and corrected by hand\n");
  1070.  
  1071.     if (code == TABLE)
  1072.       {
  1073.       fprintf(stderr,"Begin of environment: TABLE\n");
  1074.       fprintf(fRtf,"{\\v\\par ***begin of environment: TABLE ***\\par}");
  1075.       }
  1076.     if (code == TABLE_1)
  1077.       {
  1078.       fprintf(stderr,"Begin of environment: TABLE*  \n");
  1079.       fprintf(fRtf,"{\\v\\par ***begin of environment: TABLE*   ***\\par}");
  1080.       }
  1081.   }
  1082.   else /* off switch */
  1083.   {
  1084.     code &= ~(OFF);  /* mask MSB */
  1085.     if (code == TABLE)
  1086.       {
  1087.       fprintf(stderr,"End of environment: TABLE\n");
  1088.       fprintf(fRtf,"{\\v\\par ***end of environment: TABLE ***\\par}");
  1089.       }
  1090.     if (code == TABLE_1)
  1091.       {
  1092.       fprintf(stderr,"End of environment: TABLE*  \n");
  1093.       fprintf(fRtf,"{\\v\\par ***end of environment: TABLE*  ***\\par}");
  1094.       }
  1095.   }
  1096. }
  1097.