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
|
/* checksum.c
* ----------
* Provides a function for reading the checksum of a tfm- and a pk-file.
* (Derived from Nelson Beebe's dviXXX driver family.)
*/
#include <stdio.h>
#include "checksum.h"
#ifdef AMIGA
char * index();
char * strcmp();
#else
#include <string.h>
#endif
static unsigned long
nosignex(fp, n) /* return n byte quantity from file fd */
FILE *fp; /* file pointer */
int n; /* number of bytes (1..4) */
{
unsigned long number; /* number being constructed */
number = 0;
while (n--)
{
number <<= 8;
number |= getc(fp);
}
return(number);
}
#define warning(msg) fprintf(stderr, msg)
#define PKPRE 247
#define PKID 89
/* readfile() returns (iff succesfull) the checksum of a tfm-file
* or a pk-file. Other TeXfiles (gf and pxl) are not supported.
*/
int
readfile(name, checksum) /* return 0 on success, otherwise errorcode */
char *name; unsigned long *checksum;
{
FILE *fontfp; char * ext;
if (strcmp(name+strlen(name)-4, ".tfm") ==0) {
if ((fontfp= fopen(name, "r")) == NULL) {
return NOFILE;
}
if (fseek(fontfp, 24L, 0))
{
fclose(fontfp);
return WRONGTFMFILE;
}
*checksum = nosignex(fontfp,4); /* checksum */
fclose(fontfp);
return NOERROR;
}
if (strcmp(name+strlen(name)-2, "pk") ==0)
{
if ((fontfp= fopen(name, "r")) == NULL) {
return NOFILE;
}
if (((int)nosignex(fontfp,1) != PKPRE) ||
((int)nosignex(fontfp,1) != PKID) ||
(fseek(fontfp,(long)nosignex(fontfp,1)+4L,1)))
{
fclose(fontfp);
return WRONGPKFILE;
}
*checksum = nosignex(fontfp,4); /* checksum */
fclose(fontfp);
return NOERROR;
}
return NOTFMORPK;
}
|