Back to index

tetex-bin  3.0
Defines | Functions | Variables
mpto.c File Reference
#include "c-auto.h"
#include "cpascal.h"
#include <stdio.h>
#include <stdlib.h>
#include <kpathsea/config.h>
#include <kpathsea/variable.h>

Go to the source code of this file.

Defines

#define INF_BUF_SIZE   500
#define SUP_BUF_SIZE   300000
#define BUF_SIZE_NAME   "buf_size"

Functions

void err P1C (char *, msg)
char * getline ()
int match_str P2C (char *, s, char *, t)
int getbta P1C (char *, s)
void copytex ()
void do_line ()
int main P2C (int, argc, char **, argv)

Variables

char * tex_predoc = ""
char * tex_postdoc = "\\end{document}\n"
char * tex_pretex1 = "\\shipout\\hbox{\\smash{\\hbox{\\hbox{%% line %d %s\n"
char * tex_pretex = "\\shipout\\hbox{\\smash{\\hbox{\\hbox{%% line %d %s\n"
char * tex_posttex = "}\\vrule width1sp}}}\n"
char * tex_preverb1 = ""
char * tex_preverb = "%% line %d %s\n"
char * tex_postverb = "%\n"
char * troff_predoc = ".po 0\n"
char * troff_postdoc = ""
char * troff_pretex1 = ".lf %d %s\n"
char * troff_pretex = ".bp\n.lf %d %s\n"
char * troff_posttex = "\n"
char * troff_preverb1 = ".lf %d %s\n"
char * troff_preverb = ".lf %d %s\n"
char * troff_postverb = "\n"
char * predoc
char * postdoc
char * pretex1
char * pretex
char * posttex
char * preverb1
char * preverb
char * postverb
char * mpname
FILEmpfile
int lnno = 0
int texcnt = 0
int verbcnt = 0
char * buf
long bufsize = 0
char * bb
char * tt
char * aa
static const_string MPTOHELP []

Define Documentation

#define BUF_SIZE_NAME   "buf_size"

Definition at line 49 of file mpto.c.

#define INF_BUF_SIZE   500

Definition at line 47 of file mpto.c.

#define SUP_BUF_SIZE   300000

Definition at line 48 of file mpto.c.


Function Documentation

Definition at line 199 of file mpto.c.

{
       char *s;      /* where a string to print stops */
       char c;

       while (*aa==' ' || *aa=='\t') aa++;
       if (*aa==0)
              if ((aa=getline())==NULL)
                     err("btex section does not end");
       do {   if (*aa==0)
                     if ((aa=getline())==NULL)
                            err("btex section does not end");
                     else printf("\n");
              if (getbta(aa) && *tt=='e') {
                     s = tt-1;
                     while (s>=bb && (*s==' ' || *s=='\t'))
                            s--;
                     s++;
              } else {
                     if (*tt=='b') err("btex in TeX mode");
                     if (*tt=='v') err("verbatimtex in TeX mode");
                     s = aa;
              }
              c = *s;
              *s = 0;
              printf("%s", bb);
              *s = c;
       } while (*tt!='e');
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 230 of file mpto.c.

{
       aa = buf;
       while (getbta(aa))
              if (*tt=='%') break;
              else if (*tt=='"') {
                     do if (!getbta(aa)) err("string does not end");
                     while (*tt!='"');
              } else if (*tt=='b') {
                     if (texcnt++ ==0) printf(pretex1,lnno,mpname);
                     else printf(pretex,lnno,mpname);
                     copytex();
                     printf("%s",posttex);
              } else if (*tt=='v') {
                     if (verbcnt++ ==0 && texcnt==0)
                            printf(preverb1,lnno,mpname);
                     else printf(preverb,lnno,mpname);
                     copytex();
                     printf("%s",postverb);
              } else err("unmatched etex");
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* getline ( )

Definition at line 98 of file mpto.c.

{
       int c;
       unsigned loc = 0;
       while ((c = getc (mpfile)) != EOF && c != '\n' && c != '\r') {
              buf[loc++] = c;
              if (loc == bufsize)
                     err("Line is too long");
       }
       if (c == EOF) return NULL;
       buf[loc] = 0;
       if (c == '\r') {
              c = getc(mpfile);
              if (c != '\n') ungetc(c, mpfile);
       }
       lnno++;
       return buf;
}

Here is the caller graph for this function:

void err P1C ( char *  ,
msg   
)

Definition at line 91 of file mpto.c.

{
       fprintf(stderr, "mpto: %s:%d: %s\n",
              mpname, lnno, msg);
       exit(1);
}

Here is the call graph for this function:

int getbta P1C ( char *  ,
s   
)

Definition at line 152 of file mpto.c.

{
       int ok=1;     /* zero if last character was a-z, A-Z, or _ */

       bb = s;
       for (tt=bb; *tt!=0; tt++)
              switch (*tt) {
              case '"': case '%':
                     aa = tt+1;
                     return 1;
              case 'b':
                     if (ok && match_str(tt,"btex")) {
                            aa = tt+4;
                            return 1;
                     } else ok=0;
                     break;
              case 'e':
                     if (ok && match_str(tt,"etex")) {
                            aa = tt+4;
                            return 1;
                     } else ok=0;
                     break;
              case 'v':
                     if (ok && match_str(tt,"verbatimtex")) {
                            aa = tt+11;
                            return 1;
                     } else ok=0;
                     break;
              case 'a': case 'c': case 'd': case 'f': case 'g': case 'h':
              case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
              case 'o': case 'p': case 'q': case 'r': case 's': case 't':
              case 'u': case 'w': case 'x': case 'y': case 'z': case '_':
              case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
              case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
              case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
              case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
              case 'Y': case 'Z':
                     ok = 0;
                     break;
              default:
                     ok = 1;
              }
       aa = tt;
       return 0;
}
int match_str P2C ( char *  ,
s  ,
char *  ,
t   
)

Definition at line 121 of file mpto.c.

{
       while (*t!=0) {
              if (*s!=*t) return 0;
              s++; t++;
       }
       switch (*s) {
       case 'a': case 'c': case 'd': case 'f': case 'g': case 'h':
       case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
       case 'o': case 'p': case 'q': case 'r': case 's': case 't':
       case 'u': case 'w': case 'x': case 'y': case 'z': case '_':
       case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
       case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
       case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
       case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
       case 'Y': case 'Z': case 'b': case 'e': case 'v':
              return 0;
       default:
              return 1;
       }
}
int main P2C ( int  ,
argc  ,
char **  ,
argv   
)

Definition at line 265 of file mpto.c.

{
        int mode;
        char *buf_size_str;
        
        kpse_set_program_name(argv[0], NULL);
       
       if (argc == 1) {
         fputs ("mpto: Need exactly one file argument.\n", stderr);
         fputs ("Try `mpto --help' for more information.\n", stderr);
         exit(1);
       } else if (argc > 1 && strcmp (argv[1], "--help") == 0) {
            usagehelp (MPTOHELP, NULL);
       } else if (argc > 1 && strcmp (argv[1], "--version") == 0) {
          printf ("mpto%s 0.63\n\
Copyright (C) 1996 AT&T Bell Laboratories.\n\
There is NO warranty.  You may redistribute this software\n\
under the terms of the GNU General Public License\n\
and the mpto copyright.\n\
For more information about these matters, see the files\n\
named COPYING and the mpto source.\n\
Primary author of mpto: John Hobby.\n",
WEB2CVERSION);
         exit (0);
       } else if (argc == 2) {
         mpname = argv[1];
         mode = 0;
#ifdef AMIGA
       } else if (argc == 3) {
         if (strcmp (argv[1], "-tex") == 0) {
           mpname = argv[2];
           mode = 0;
         } else if (strcmp (argv[1], "-troff") == 0) {
           mpname = argv[2];
           mode = 1;
         } else if (strncmp(argv[2], "-E", 2) || (argv[2]+2 == NULL)) {
           usage(argv[0]);
         } else {
           mpname = argv[1];
           freopen(argv[2]+2, "w", stderr);
         }
       } else if (argc == 4) {
         if (strcmp (argv[1], "-tex") == 0) {
           mode = 0;
         } else if (strcmp (argv[1], "-troff") == 0) {
           mode = 1;
         } else {
           usage(argv[0]);
         }
         if (strncmp(argv[3], "-E", 2) || (argv[3]+2 == NULL)) {
           usage(argv[0]);
         } else {
           mpname = argv[2];
           freopen(argv[3]+2, "w", stderr);
         }
       } else {
         usage(argv[0]);
       }
#else /* not AMIGA */
       } else if (argc == 3) {
         if (strcmp (argv[1], "-tex") == 0) {
           mode = 0;
         } else if (strcmp (argv[1], "-troff") == 0) {
           mode = 1;
         } else {
           usage (argv[0]);
         }
         mpname = argv[2];
       } else {
         usage(argv[0]);
       }
#endif /* not AMIGA */
       mpfile = fopen(mpname, "r");
       if (mpfile==NULL) {
         fprintf (stderr, "%s: ", argv[0]);
         perror (mpname);
         exit (1);
       }

        buf_size_str = kpse_var_value(BUF_SIZE_NAME);
        if (buf_size_str)
           bufsize = atoi(buf_size_str);
        if (bufsize < INF_BUF_SIZE)
           bufsize = INF_BUF_SIZE;
        if (bufsize > SUP_BUF_SIZE)
           bufsize = SUP_BUF_SIZE;
        buf = (char*)xmalloc(bufsize);
        if (buf_size_str) free(buf_size_str);

       /* This is far from elegant, but life is short.  */
       if (mode == 0) {
          predoc = tex_predoc;
          postdoc = tex_postdoc;
          pretex1 = tex_pretex1;
          pretex = tex_pretex;
          posttex = tex_posttex;
          preverb1 = tex_preverb1;
          preverb = tex_preverb;
          postverb = tex_postverb;
       } else {
          predoc = troff_predoc;
          postdoc = troff_postdoc;
          pretex1 = troff_pretex1;
          pretex = troff_pretex;
          posttex = troff_posttex;
          preverb1 = troff_preverb1;
          preverb = troff_preverb;
          postverb = troff_postverb;
       }
       printf("%s",predoc);
       while (getline()!=NULL)
              do_line();
       printf("%s",postdoc);
        free(buf);
       exit(0);
}

Here is the call graph for this function:


Variable Documentation

char * aa

Definition at line 89 of file mpto.c.

char* bb

Definition at line 89 of file mpto.c.

char* buf

Definition at line 87 of file mpto.c.

long bufsize = 0

Definition at line 88 of file mpto.c.

int lnno = 0

Definition at line 84 of file mpto.c.

Definition at line 83 of file mpto.c.

char* mpname

Definition at line 82 of file mpto.c.

const_string MPTOHELP[] [static]
Initial value:
 {
    "Usage: mpto [-tex|-troff] MPFILE",
    "  Strip btex..etex and verbatimtex...etex parts from MetaPost input",
    "  file MPFILE, converting to either TeX or troff (TeX by default).",
    "",
    "--help      display this help and exit",
    "--version   output version information and exit",



    NULL
}

Definition at line 252 of file mpto.c.

char* postdoc

Definition at line 74 of file mpto.c.

char* posttex

Definition at line 77 of file mpto.c.

char* postverb

Definition at line 80 of file mpto.c.

char* predoc

Definition at line 73 of file mpto.c.

char* pretex

Definition at line 76 of file mpto.c.

char* pretex1

Definition at line 75 of file mpto.c.

char* preverb

Definition at line 79 of file mpto.c.

char* preverb1

Definition at line 78 of file mpto.c.

char* tex_postdoc = "\\end{document}\n"

Definition at line 52 of file mpto.c.

char* tex_posttex = "}\\vrule width1sp}}}\n"

Definition at line 55 of file mpto.c.

char* tex_postverb = "%\n"

Definition at line 58 of file mpto.c.

char* tex_predoc = ""

Definition at line 51 of file mpto.c.

char* tex_pretex = "\\shipout\\hbox{\\smash{\\hbox{\\hbox{%% line %d %s\n"

Definition at line 54 of file mpto.c.

char* tex_pretex1 = "\\shipout\\hbox{\\smash{\\hbox{\\hbox{%% line %d %s\n"

Definition at line 53 of file mpto.c.

char* tex_preverb = "%% line %d %s\n"

Definition at line 57 of file mpto.c.

char* tex_preverb1 = ""

Definition at line 56 of file mpto.c.

int texcnt = 0

Definition at line 85 of file mpto.c.

char* troff_postdoc = ""

Definition at line 65 of file mpto.c.

char* troff_posttex = "\n"

Definition at line 68 of file mpto.c.

char* troff_postverb = "\n"

Definition at line 71 of file mpto.c.

char* troff_predoc = ".po 0\n"

Definition at line 64 of file mpto.c.

char* troff_pretex = ".bp\n.lf %d %s\n"

Definition at line 67 of file mpto.c.

char* troff_pretex1 = ".lf %d %s\n"

Definition at line 66 of file mpto.c.

char* troff_preverb = ".lf %d %s\n"

Definition at line 70 of file mpto.c.

char* troff_preverb1 = ".lf %d %s\n"

Definition at line 69 of file mpto.c.

char * tt

Definition at line 89 of file mpto.c.

int verbcnt = 0

Definition at line 86 of file mpto.c.