|
|
1.1 root 1: /*
2: * Copyright (c) 1984, 1985, 1986 Xerox Corp.
3: *
4: * Handle old C/A/T troff metrics here.
5: *
6: * note that Troff uses "fat points" of which there are exactly 72 per inch.
7: *
8: * HISTORY
9: * 15-Apr-86 Lee Moore (lee) at Xerox Webster Research Center
10: * Now prints out the number of special character names in the
11: * DESC file.
12: *
13: * Nov, 1985 Lee Moore, Xerox Webster Research Center
14: * Created.
15: */
16:
17: #include <stdio.h>
18: #include <math.h>
19: #include "stack.h"
20: #include "token.h"
21: #include "config.h"
22: #include "ipmetrics.h"
23: #include "troff.h"
24: #include "strings.h"
25:
26: #define TRUE 1
27: #define FALSE 0
28:
29:
30: #define public
31: #define private static
32:
33: public char *malloc();
34:
35: public char *DeviceName;
36:
37: public
38: CleanUpOTroff(configChain)
39: struct FontConfig *configChain; {
40: struct FontConfig *p;
41:
42: WriteInstallFile(configChain);
43: WriteCleanUpFile(configChain);
44:
45: for( p = configChain; p != NULL; p = p->Next )
46: if( !p->SeenFlag )
47: printf("couldn't find: %s/%s/%s\n",
48: p->FontPt1, p->FontPt2, p->FontPt3);
49: }
50:
51: private
52: WriteInstallFile(configChain)
53: struct FontConfig *configChain; {
54: FILE *installFile;
55: struct FontConfig *p;
56:
57: if( (installFile = fopen(INSTALLNAME, "w")) == NULL ) {
58: fprintf(stderr, "can't open the file 'install' for writing\n");
59: return; }
60:
61: fprintf(installFile, "#! /bin/sh\n");
62:
63: for( p = configChain; p != NULL; p = p->Next )
64: if( p->SeenFlag )
65: fprintf(installFile, "cp %s /usr/lib/fonts\n",
66: p->TargetName);
67:
68: (void) fclose(installFile);
69: (void) chmod(INSTALLNAME, 0755); }
70:
71:
72: /*
73: * write a file that rm's all the files created by this program
74: */
75:
76: private
77: WriteCleanUpFile(configChain)
78: struct FontConfig *configChain; {
79: FILE *cleanupFile;
80: struct FontConfig *p;
81:
82: if( (cleanupFile = fopen(CLEANUPNAME, "w")) == NULL ) {
83: fprintf(stderr, "can't open the file 'cleanup' for writing\n");
84: return; }
85:
86: fprintf(cleanupFile, "#! /bin/sh\n");
87:
88: for( p = configChain; p != NULL; p = p->Next )
89: if( p->SeenFlag )
90: fprintf(cleanupFile, "rm %s\n", p->TargetName);
91:
92: fprintf(cleanupFile, "rm %s\n", INSTALLNAME);
93: fprintf(cleanupFile, "rm %s\n", CLEANUPNAME);
94: (void) fclose(cleanupFile);
95: (void) chmod(CLEANUPNAME, 0755); }
96:
97: /*
98: * called once per font on the stack
99: */
100:
101: public
102: PerOTroffFont(configChain, fontDescVec)
103: struct FontConfig *configChain;
104: unsigned char *fontDescVec; {
105: unsigned char *charMetricsProperty,
106: *metricsProperty,
107: *width,
108: *charMetric;
109: char iSender[MAXTOKENSIZE],
110: iCharName[MAXTOKENSIZE],
111: fileType[MAXTOKENSIZE],
112: *fontName[3],
113: iCharSet[MAXTOKENSIZE],
114: iCharCode[MAXTOKENSIZE];
115: FILE *descFile,
116: *modelFile;
117: struct FontConfig *p;
118: struct TokenState *ts;
119: int charSet,
120: charNumber,
121: charIndex,
122: xWidth;
123:
124: if( !GetFontNameProperty(fontDescVec, fontName) ) {
125: fprintf(stderr, "ipmetrics: can't get font name\n");
126: return;
127: }
128:
129: if( (charMetricsProperty = GetStringProp("characterMetrics", fontDescVec))
130: == NULL ) {
131: printf("ipmetrics: can't find 'characterMetrics' property\n");
132: return; }
133:
134: for( p = configChain; p != NULL; p = p->Next ) {
135: if( !(strcmp(p->FontPt1, fontName[0]) == 0 &&
136: strcmp(p->FontPt2, fontName[1]) == 0 &&
137: strcmp(p->FontPt3, fontName[2]) == 0) )
138: continue;
139:
140: if( (descFile = fopen(p->TargetName , "w")) == NULL ) {
141: printf("ipmetrics: can't open %s for writing\n", p->TargetName);
142: return;}
143:
144: fprintf(stderr, "writing %s\n", p->TargetName);
145:
146: if( (modelFile = fopen(p->MapFile, "r")) == NULL ) {
147: printf("ipmetrics: can't open %s for reading\n", p->MapFile);
148: return;}
149:
150: p->SeenFlag = TRUE;
151:
152: ts = InitTokenStream(modelFile);
153:
154: fprintf(descFile, "#\n");
155: fprintf(descFile, "# %s/%s/%s for Interpress device %s\n", p->FontPt1, p->FontPt2, p->FontPt3, DeviceName);
156: fprintf(descFile, "name %s\n", p->TargetName);
157:
158: GetToken(ts, fileType, MAXTOKENSIZE);
159:
160: while( !EndOfFile(ts) ) {
161: GetToken(ts, iCharSet, MAXTOKENSIZE);
162:
163: if( sscanf(iCharSet, "%o", &charSet) != 1 )
164: printf("ipmetrics: couldn't convert iCharSet number. Token was: %s\n", iCharSet);
165:
166: if( EndOfLine(ts) ) {
167: printf("ipmetrics: premature end of line in map file: %s!\n", p->MapFile);
168: printf("\tlast token was iCharSet: `%s'\n", iCharSet);
169: continue; }
170:
171: GetToken(ts, iCharCode, MAXTOKENSIZE);
172:
173: if( sscanf(iCharCode, "%o", &charNumber) != 1 )
174: printf("ipmetrics: couldn't convert iCharCode. Token was: %s\n", iCharCode);
175:
176: if( EndOfLine(ts) ) {
177: printf("ipmetrics: premature end of line in map file: %s!\n", p->MapFile);
178: printf("\tlast token was iCharCode: `%s'\n", iCharCode);
179: continue; }
180:
181: GetToken(ts, iSender, MAXTOKENSIZE);
182:
183: if( EndOfLine(ts) ) {
184: printf("ipmetrics: premature end of line in map file: %s!\n", p->MapFile);
185: printf("\tlast token was iSender: `%s'\n", iSender);
186: continue; }
187:
188: GetToken(ts, iCharName, MAXTOKENSIZE);
189: charIndex = Make16BitChar(charSet, charNumber);
190:
191: /* skip the rest of this loop if the character is 0 */
192: if( charIndex == 0 ) {
193: fprintf(descFile, "\t 0,\t\t/*(unused)*/\n");
194: EatRestOfLine(ts);
195: continue; }
196:
197: /* skip the rest of this loop if it's not in this font */
198: if( (charMetric =
199: GetIntegerProp(charIndex, charMetricsProperty)) == NULL ) {
200: fprintf(descFile, "\t 0,\t\t/*(not in file) %s */\n", iCharName);
201: EatRestOfLine(ts);
202: continue; }
203:
204: if( (width = GetStringProp("widthX", charMetric)) == NULL ){
205: printf("ipmetrics: can't find widthX property of %d\n",
206: charIndex);
207: EatRestOfLine(ts);
208: continue;}
209:
210: if( gettype(width) != type_number ) {
211: printf("ipmetrics: width not of type number for %d\n",
212: charIndex);
213: EatRestOfLine(ts);
214: continue;}
215:
216: if( getsubtype(width) != subtype_rational ) {
217: printf("ipmetrics: width not of subtype number for %d\n",
218: charIndex);
219: EatRestOfLine(ts);
220: continue;}
221:
222: xWidth = (getnumerator(width)*36)/
223: getdenominator(width) + .5;
224:
225: fprintf(descFile, "\t%3d + 0%s00,\t/* %s ",
226: xWidth, iSender, iCharName);
227:
228: while( !EndOfLine(ts) ) {
229: GetToken(ts, iCharName, MAXTOKENSIZE);
230: fprintf(descFile, "%s ", iCharName); }
231:
232: fprintf(descFile, "*/\n"); }
233:
234: CloseTokenStream(ts);
235: (void) fclose(descFile);
236: (void) fclose(modelFile);
237: }
238: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.