src/Tools/8bit/c-sources/isa2latex/conv-main.c
changeset 1826 2a2c0dbeb4ac
child 4170 6b8bbcc9f05f
equal deleted inserted replaced
1825:88d4c33d7947 1826:2a2c0dbeb4ac
       
     1 /*  Title:      Tools/8bit/c-sources/isa2latex/conv-main.c
       
     2     ID:         $Id$
       
     3     Author:     Franz Regensburger
       
     4     Copyright   1996 TU Muenchen
       
     5 
       
     6 converter for isabelle files
       
     7 main file (ANSI-C)
       
     8 
       
     9    derived from
       
    10 
       
    11       spec2latex: Version from 30.3.93
       
    12       Authors  Franz Huber, B. Rumpe, David v. Oheimb 
       
    13 
       
    14    New or changed features:
       
    15 
       
    16      - flex is used to scan for multi character sequences
       
    17      - automatic generation of flex source from user translation tables
       
    18      - semantics of modes have changed, see the manpage 
       
    19      - flag for latex2e
       
    20 */         
       
    21 
       
    22 #include <stdio.h>
       
    23 
       
    24 /*
       
    25  * VERSION:
       
    26  */
       
    27 
       
    28 void version(void) {
       
    29   fprintf(stderr, "Isabelle Converter, Version 1.4, 30 May 1996\n");
       
    30 }
       
    31 
       
    32 #include "conv-defs.h"
       
    33 #include "conv-tables.h"
       
    34 
       
    35 extern char *translateHi(int ch, int code);
       
    36 extern char *translateLow(int ch);
       
    37 extern char *translateLong(int ch);
       
    38 extern void reset_tabs(void);
       
    39 
       
    40 extern int yylex(void);
       
    41 
       
    42 FILE* finput;                /* input file, default = stdin */
       
    43 FILE* foutput;               /* output file,default = stdout */
       
    44 
       
    45 int use2e = FALSE;           /* generate latex2e output */
       
    46 int bigTabs = FALSE;         /* flag for big tabs */
       
    47 int tabBlanks = TABBLANKS;   /* number of blanks subsituted for a tab */
       
    48 char isa_env_beg[200];       /* latex command to begin isa environment */
       
    49 char isa_env_end[200];       /* latex command to end   isa environment */
       
    50 int cc;                      /* character counter in line  */
       
    51 int tabcount;                /* counter for tab positions  */
       
    52 
       
    53 int destCode = DEFAULT_DEST; /* default destination */
       
    54 int convMode = DEFAULT_MODE; /* default conversion mode  */
       
    55 int accept_ASCII = FALSE;    /* accept ASCII input for 8bit characters */
       
    56 
       
    57 /*
       
    58  * einfache Fehlerbehandlung:
       
    59  */
       
    60  
       
    61 void error(char* s, char* t) {
       
    62   fprintf(stderr, "Error! %s: %s\n", s, t);
       
    63 }
       
    64 
       
    65 
       
    66 /*
       
    67  * erklaert Programmbenutzung:
       
    68  */
       
    69  
       
    70 void usage(void) {
       
    71   fprintf(stderr, "Isabelle converter. Valid Options:\n");
       
    72   fprintf(stderr, "<file>:    input file other than stdin\n");
       
    73   fprintf(stderr, "-o <file>: output file other than stdout\n");
       
    74   fprintf(stderr, "-a:        generate 7 bit ASCII representation\n");
       
    75   fprintf(stderr, "-A:        accept ASCII representation of graphical characters (unsafe)\n");
       
    76   fprintf(stderr, "-i:        generate LaTeX representation (default)\n");
       
    77   fprintf(stderr, "           (for inclusion into other LaTeX documents)\n"); 
       
    78   fprintf(stderr, "-s:        generate standalone LaTeX document\n");
       
    79   fprintf(stderr, "-x:        allows mixture of specifications and given LaTeX parts\n");
       
    80   fprintf(stderr, "-e:        generate LaTeX2e code (if option -s given)\n");
       
    81   fprintf(stderr, "-t <num>:  set tabulator every <num> characters\n");
       
    82   fprintf(stderr, "           (for conversion to LaTeX; default: 8)\n");
       
    83   fprintf(stderr, "-b:        'BigTabs'; generates bigger tabbings\n");
       
    84   fprintf(stderr, "           than standard for the LaTeX conversion\n");
       
    85   fprintf(stderr, "-f <strg>: use another font than the default cmr-font when converting\n");
       
    86   fprintf(stderr, "           to LaTeX. <strg> is the font-string in LaTeX syntax\n");
       
    87   fprintf(stderr, "-v:        show version number and release date\n");
       
    88   fprintf(stderr, "-h(elp):   print this message\n");
       
    89 }
       
    90 
       
    91 
       
    92 /*
       
    93  * main programm
       
    94  */
       
    95 
       
    96 int main(int argc, char* argv[]) {
       
    97   char *s;                /* pointer to traverse components of argv */
       
    98   char texFont[200];      /* string for TeX font change if destCode==TO_LaTeX */
       
    99   int i,j;
       
   100 
       
   101   /*
       
   102    * initialize users font string:
       
   103    */
       
   104   texFont[0] = '\0';
       
   105 
       
   106   finput = stdin;
       
   107   foutput = stdout;
       
   108 
       
   109   /*
       
   110    * process command line
       
   111    */
       
   112   while (--argc > 0) {
       
   113     s = *++argv;
       
   114     if (*s++ == '-')
       
   115       switch (*s) {
       
   116         case 'v':
       
   117           version();
       
   118           exit(0);
       
   119         case 'h':
       
   120           usage();
       
   121           exit(0);
       
   122         case 'a':
       
   123           destCode = TO_7bit;
       
   124           break;
       
   125         case 'A':
       
   126           accept_ASCII = TRUE;
       
   127           break;
       
   128         case 'i':
       
   129           destCode = TO_LaTeX;
       
   130 	  convMode = INCLUDE;
       
   131           break;
       
   132         case 's':
       
   133           destCode = TO_LaTeX;
       
   134 	  convMode = STANDALONE;
       
   135           break;
       
   136         case 'x':
       
   137           destCode = TO_LaTeX;
       
   138 	  convMode = MIXED;
       
   139           break;
       
   140         case 'e':
       
   141           use2e = TRUE;
       
   142           break;
       
   143         case 'b':
       
   144           bigTabs = TRUE;
       
   145           break;
       
   146         case 'f':
       
   147           if (--argc)
       
   148             strncpy(texFont, *++argv, 200);
       
   149           else
       
   150             error("No font specified with -f option, using default", s);
       
   151           break;
       
   152         case 'o':
       
   153           if (--argc) {
       
   154             if ((foutput = fopen(*++argv, "w")) == NULL) {
       
   155              error("Creating output file", *argv);
       
   156               exit(-1);
       
   157             }
       
   158           } else {
       
   159             error("No output file specified for option", s);
       
   160             usage();
       
   161             exit(-1);
       
   162           }
       
   163           break;
       
   164         case 't':
       
   165           { int temp;
       
   166             if (--argc) {
       
   167               if (temp = atoi(*++argv))
       
   168 			    tabBlanks = temp;
       
   169 			  else {
       
   170                 error("Not a valid tabulator value", *argv);
       
   171                 exit(-1);
       
   172               }
       
   173             } else {
       
   174               error("No value specified for option", s);
       
   175               usage();
       
   176               exit(-1);
       
   177             }
       
   178 		  }
       
   179           break;
       
   180         default:
       
   181           error("Unknown option", s);
       
   182           usage();
       
   183           exit(-1);
       
   184       } /* switch */
       
   185     else
       
   186       /*
       
   187        * no further parameters with "-"; therefore we see input file:
       
   188        */
       
   189        if ((finput = fopen(--s, "r")) == NULL) {
       
   190          error("Opening input file", s);
       
   191          exit(-1);
       
   192         }
       
   193   }
       
   194 
       
   195   /*
       
   196    * if destination is TO_LaTeX and mode is STANDALONE then produce LaTeX header
       
   197    */
       
   198   
       
   199   if (convMode == STANDALONE) {
       
   200     if (use2e){
       
   201       fprintf(foutput, 
       
   202 	 "\\documentclass[a4paper,11pt]{article}\n");
       
   203       fprintf(foutput, 
       
   204 	 "\\usepackage{latexsym,amssymb,isa2latex}\n");
       
   205     } else {
       
   206       fprintf(foutput, 
       
   207 	 "\\documentstyle[11pt,a4,latexsym,amssymb,isa2latex]{article}\n");
       
   208     }
       
   209       fprintf(foutput, "\\begin{document}\n");
       
   210   }
       
   211 
       
   212   if(texFont[0] != '\0') /* adjust font definition */
       
   213     fprintf(foutput, "%s\n", texFont);
       
   214 
       
   215   /*
       
   216    * prepare a tabbing environment with tabstops every 'tabBlanks' blanks:
       
   217    */
       
   218   strcpy(isa_env_beg, "{\\isamode\\begin{tabbing}");
       
   219   for (i = 0; i < NUM_TABS; i++) {
       
   220     for (j = 0; j < tabBlanks; j++)
       
   221       strcat(isa_env_beg, bigTabs ? BIG_TABBING_UNIT : NORMAL_TABBING_UNIT);
       
   222     strcat(isa_env_beg, "\\=");
       
   223   }
       
   224   strcat(isa_env_beg, "\\kill{}\\hspace{-1ex}\n");
       
   225   strcpy(isa_env_end, "\n\\end{tabbing}}");
       
   226   
       
   227   if (convMode == STANDALONE || convMode == INCLUDE)
       
   228     fprintf(foutput, isa_env_beg);
       
   229 
       
   230   /*
       
   231    * start the conversion: use lexer in all modes to do the job.
       
   232    */
       
   233   
       
   234   reset_tabs();
       
   235   yylex();
       
   236 
       
   237   /*
       
   238    * output footers
       
   239    */
       
   240 
       
   241   if(convMode == STANDALONE || convMode == INCLUDE)
       
   242     fprintf(foutput, isa_env_end);
       
   243 
       
   244   if(convMode == STANDALONE) 
       
   245       fprintf(foutput, "\\end{document}\n");
       
   246   return(0);
       
   247 }
       
   248 
       
   249