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
|
/* this translates Adobe fonts in IBM PC format (.pfb) to plain PostScript */
static char rcsid[] = "$Header: /usr/jjc/dvitops/RCS/pfbtops.c,v 1.2 90/08/14 13:04:24 jjc Rel $";
#include "util.h"
char *program_name = "pfbtops";
int main(argc, argv)
int argc;
char **argv;
{
int c;
int err;
FILE *fp, *outfp;
char filename[FILENAME_MAX];
if (argc < 2 || argc > 3)
message(FATAL_ERROR, "usage: pfbtops pfbfile [psfile]");
if (strlen(filename) > FILENAME_MAX - 5)
message(FATAL_ERROR, "file name too long");
strcpy(filename, argv[1]);
if (strchr(filename, '.') == NULL)
strcat(filename, ".pfb");
if ((fp = FOPEN_RB(filename)) == NULL)
message(FATAL_ERROR, "can't open %s", filename);
if (argc == 3) {
if (strlen(filename) > FILENAME_MAX - 5)
message(FATAL_ERROR, "filename too long");
strcpy(filename, argv[2]);
if (strchr(filename, '.') == NULL)
strcat(filename, ".ps");
}
else
strcpy(strchr(filename, '.'), ".ps");
if ((outfp = fopen(filename, "w")) == NULL)
message(FATAL_ERROR, "can't open %s", filename);
for (;;) {
long n;
c = getc(fp);
if (c != 128)
goto bad;
c = getc(fp);
if (c == 3) {
(void)getc(fp);
if (!feof(fp) || ferror(fp))
goto bad;
fclose(fp);
break;
}
n = (unsigned long)getc(fp);
n |= (unsigned long)getc(fp) << 8;
n |= (unsigned long)getc(fp) << 16;
n |= (unsigned long)getc(fp) << 24;
if (n < 0)
{ err =1; goto bad;}
if (c == 1) {
while (n--) {
c = getc(fp);
if (c == '\r')
putc('\n', outfp);
else
putc(c, outfp);
}
if (ferror(fp) || feof(fp))
{ err = 2; goto bad;}
}
else if (c == 2) {
int cols = 0;
putc('\n', outfp);
while (n--) {
static char hexdigits[] = "0123456789ABCDEF";
c = getc(fp);
if ((cols += 2) > 70) {
putc('\n', outfp);
cols = 0;
}
putc(hexdigits[(unsigned)c >> 4], outfp);
putc(hexdigits[c & 15], outfp);
}
putc('\n', outfp);
if (ferror(fp) || feof(fp))
{err = 3 ; goto bad;}
}
else
{err = 4 ; goto bad;}
}
exit(history);
bad:
fprintf(stderr,"Error: %d\n",err);
message(FATAL_ERROR, "bad font file");
}
|