1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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);
}
|