summaryrefslogtreecommitdiff
path: root/dviware/quicspool/src/dumpdesc.c
blob: 4b249de919fae3be96985cde7047ba87e0ef686e (plain)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#ifndef lint
static char *rcs = "$Header: dumpdesc.c,v 1.1 88/01/15 13:03:43 simpson Rel $";
#endif
/*
$Log:	dumpdesc.c,v $
 * Revision 1.1  88/01/15  13:03:43  simpson
 * initial release
 * 
 * Revision 0.1  87/12/11  18:30:50  simpson
 * beta test
 * 
*/
#include <stdio.h>
#include <local/standard.h>
#include "dev.h"

char EOFName[81];
char *WhoAmI;
char *Usage = "Usage: %s DESCfile\n";

main(argc, argv)
int	argc;
char	*argv[];
{
    extern int	    optind;
    extern char	    *optarg;
    int		    c;
    FILE	    *f;
    void	    dumpdescfile(), desceofsoexit(), seteoffunction();
    char            *strcpy();

    WhoAmI = argv[0];
    while ((c = getopt(argc, argv, "")) != EOF)
	switch (c) {
	case '?':
badusage:   fprintf(stderr, Usage, WhoAmI);
	    exit(FAIL);
	}
    if (optind != argc - 1)
	goto badusage;
    if (!(f = fopen(argv[optind], "r"))) {
	perror(argv[optind]);
	exit(FAIL);
    }
    seteoffunction(desceofsoexit);
    (void)strcpy(EOFName, argv[optind]);
    dumpdescfile(f);
    (void)fclose(f);
    exit(SUCCEED);
}

/* Symbolically dumps a DESC.out file.  The parameter should be an open
 * DESC.out file.
 */
void dumpdescfile(f)
FILE	*f;
{
    unsigned char   spacewidth, widthindex;
    struct dev	devheader;
    struct font	fontheader;
    int		count, c;
    short	size, index;
    long	funnycharoffset;  /* Static file offset - Before */
				    /* funnycharindextable. */
    long	fontstructoffset; /* Floating offset - Beginning of each */
				    /* font structure. */

    rewind(f);
    (void)cfread((char *)&devheader, sizeof(struct dev), 1, f);
    printf("filesize: (%d+%d)=%d\n", sizeof(struct dev), devheader.filesize,
    sizeof(struct dev) + devheader.filesize);
    printf("res: %d\tmotion (hor,ver): (%d,%d)\n", devheader.res, 
    devheader.hor, devheader.vert);
    printf("unitwidth: %d\tsizescale: %d\n", devheader.unitwidth,
    devheader.sizescale);
    printf("nfonts: %d\tnsizes: %d\n", devheader.nfonts, devheader.nsizes);
    printf("paper (width,length): (%d,%d)\n", devheader.paperwidth,
    devheader.paperlength);
    /* Read the sizes table */
    printf("point sizes available:\n");
    (void)cfread((char *)&size, sizeof(short), 1, f);
    for (count = 0; size; count++) {
	if ((count + 1) % 20 == 0)
	    putchar('\n');
	printf("%d, ", size);
	(void)cfread((char *)&size, sizeof(short), 1, f);
    }
    if (count > 0)
	putchar('\n');
    /* Read the funnycharstrings */
    printf("special character names:\n");
    funnycharoffset = ftell(f);
    for (count = 0; count < devheader.nchtab; count++) {
	if ((count + 1) % 20 == 0)
	    putchar('\n');
	(void)fseek(f, funnycharoffset + count * sizeof(short), 0);
	(void)cfread((char *)&index, sizeof(short), 1, f);
	(void)fseek(f, funnycharoffset + devheader.nchtab * sizeof(short) + 
	index, 0);
	while ((c = cgetc(f)) != '\0')
	    putchar(c);
	putchar(',');
    }
    if (count > 0)
	putchar('\n');
    (void)fseek(f, funnycharoffset + devheader.nchtab * sizeof(short) +
    devheader.lchname, 0);
    /* Read each individual font information */
    fontstructoffset = ftell(f);
    while (fread((char *)&fontheader, sizeof(struct font), 1, f) == 1) {
	printf("\n%s font %s (internal %s)\n",
	fontheader.specfont == 1 ? "Special" : "Regular",
	fontheader.namefont, fontheader.intname);
	if (fontheader.ligfont > 0) {
	    printf("ligatures: ");
	    if (fontheader.ligfont & LFI)
		printf("fi, ");
	    if (fontheader.ligfont & LFL)
		printf("fl, ");
	    if (fontheader.ligfont & LFF)
		printf("ff, ");
	    if (fontheader.ligfont & LFFI)
		printf("ffi, ");
	    if (fontheader.ligfont & LFFL)
		printf("ffl, ");
	    printf("\n");
	}
	spacewidth = cgetc(f);
	if (spacewidth > (unsigned)0)
	    printf("spacewidth: %u\n", spacewidth);
	for (count = 0; count < 96 + devheader.nchtab; count++) {
	    /* Seek to fontindextable */
	    (void)fseek(f, fontstructoffset + sizeof(struct font) + 3 * 
	    fontheader.nwfont + count, 0);
	    widthindex = cgetc(f);
	    if (widthindex == 0)
		continue;
	    if (count < 96)
		if (count + 32 == 0177)	    /* Delete */
		    printf("0177\t");
		else
		    printf("%c\t", count + 32);
	    else {
		/* Print out special character sequence. */
		(void)fseek(f, funnycharoffset + (count - 96) * sizeof(short),
		0);
		(void)cfread((char *)&index, sizeof(short), 1, f);
		(void)fseek(f, funnycharoffset + devheader.nchtab *
		sizeof(short) + index, 0);
		while ((c = cgetc(f)) != '\0')
		    putchar(c);
		putchar('\t');
	    }
	    /* Print out width, kerning and code info */
	    (void)fseek(f, fontstructoffset + sizeof(struct font) + widthindex,
	    0);
	    printf("width %d\t", cgetc(f));
	    (void)fseek(f, fontstructoffset + sizeof(struct font) +
	    fontheader.nwfont + widthindex, 0);
	    printf("kerning %d\t", cgetc(f));
	    (void)fseek(f, fontstructoffset + sizeof(struct font) +
	    fontheader.nwfont * 2 + widthindex, 0);
	    printf("code %d\n", cgetc(f));
	}
	/* Go to next font structure */
	(void)fseek(f, fontstructoffset + sizeof(struct font) + 3 *
	fontheader.nwfont + 96 + devheader.nchtab, 0);
	fontstructoffset = ftell(f);
    }
}

void desceofsoexit()
{
    fprintf(stderr, "%s: unexpected eof in DESC.out file %s\n", WhoAmI,
    EOFName);
    exit(FAIL);
}