diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /graphics/mma2ltx/extpro.c |
Initial commit
Diffstat (limited to 'graphics/mma2ltx/extpro.c')
-rw-r--r-- | graphics/mma2ltx/extpro.c | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/graphics/mma2ltx/extpro.c b/graphics/mma2ltx/extpro.c new file mode 100644 index 0000000000..43d21732c0 --- /dev/null +++ b/graphics/mma2ltx/extpro.c @@ -0,0 +1,119 @@ +/* + * extpro.c - Copyright (C) 1995 by Giuseppe Ghibo` + * + * Written by Giuseppe Ghibo` + * + * Version 1.0 - 16 May 1995 + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +typedef int bool; +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif + +#define TMPLEN 2048 +char tmpbuf[TMPLEN]; + +void main(int argc, char **argv) +{ + FILE *fpin, *fpout; + char *fnamein, *fnameout, *p; + bool copylines, mathstart; + + if (argc < 3) + { + fprintf(stderr,"extpro v1.0 (C) 1995 by Giuseppe Ghibò\n" + "Usage:\n" + "\textpro <mma psfile> <prologue file>\n\n" + "extracts a PS prologue file from a MMA PS file <mma psfile>,\n" + "and writes it into <prologue file>.\n"); + exit(1); + } + else + { + fnamein = argv[1]; + fnameout = argv[2]; + } + + if ((fpin = fopen(fnamein,"r")) == NULL) + { + fprintf(stderr,"Can't open file `%s' (r): %s\n", + fnamein, strerror(errno)); + exit(1); + } + + if ((fpout = fopen(fnameout,"w")) == NULL) + { + fprintf(stderr,"Can't open file `%s' (w): %s\n", + fnameout, strerror(errno)); + exit(1); + } + + fprintf(fpout,"%%%% Mathematica prologue.\n" + "%%%% Extracted from a picture saved by Mathematica in 'PS' form.\n%%%%\n"); + + copylines = FALSE; + mathstart = FALSE; + + while ((fgets(tmpbuf, TMPLEN, fpin) != NULL)) + { + if ((p = strstr(tmpbuf,"/Mathdict")) && !mathstart) + { + copylines = TRUE; + fputs(p, fpout); + continue; + } + else if (strstr(tmpbuf,"MathPictureStart") && !mathstart) + mathstart = TRUE; + else if (strstr(tmpbuf,"/Mlmarg") && !mathstart) + { + fprintf(fpout,"/Mlmarg\t\t0 def\n"); + continue; + } + else if (strstr(tmpbuf,"/Mrmarg") && !mathstart) + { + fprintf(fpout,"/Mrmarg\t\t0 def\n"); + continue; + } + else if (strstr(tmpbuf,"/Mbmarg") && !mathstart) + { + fprintf(fpout,"/Mbmarg\t\t0 def\n"); + continue; + } + else if (strstr(tmpbuf,"/Mtmarg") && !mathstart) + { + fprintf(fpout,"/Mtmarg\t\t0 def\n"); + continue; + } + else if (strstr(tmpbuf,"/Mwidth") && !mathstart) + continue; + else if (strstr(tmpbuf,"/Mheight") && !mathstart) + continue; + else if (strstr(tmpbuf,"/Mtransform") && !mathstart) + { + fprintf(fpout,"/Mtransform\t\173 \175 bind def\n"); + continue; + } + else if (strstr(tmpbuf,"/Mnodistort") && !mathstart) + continue; + else if (strstr(tmpbuf,"%!") && mathstart) + break; + + if (copylines) + fputs(tmpbuf,fpout); + } + + fprintf(fpout,"end\n"); + + fclose(fpin); + fclose(fpout); +} |