1*17294Sopcode /*
2*17294Sopcode  * @(#)startup.c	1.1	10/21/84
3*17294Sopcode  *
4*17294Sopcode  * Startup file processing for the SUN Gremlin picture editor.
5*17294Sopcode  *
6*17294Sopcode  * Mark Opperman (opcode@monet.BERKELEY)
7*17294Sopcode  *
8*17294Sopcode  */
9*17294Sopcode 
10*17294Sopcode #include "gremlin.h"
11*17294Sopcode #include <vfont.h>
12*17294Sopcode #include <sys/types.h>
13*17294Sopcode #include <sys/stat.h>
14*17294Sopcode #include <ctype.h>
15*17294Sopcode 
16*17294Sopcode /* imports from C */
17*17294Sopcode 
18*17294Sopcode extern char *malloc();
19*17294Sopcode extern FILE *fopen();
20*17294Sopcode 
21*17294Sopcode /* imports from path.c */
22*17294Sopcode 
23*17294Sopcode extern PSetPath();
24*17294Sopcode 
25*17294Sopcode /* imports from graphics files */
26*17294Sopcode 
27*17294Sopcode extern char *font_types[];		/* normally "R", "I", "B", "S" */
28*17294Sopcode extern font_sizes[];			/* normally 7, 10, 14, 24 */
29*17294Sopcode extern char fontdir[];			/* font directory */
30*17294Sopcode extern char stippledir[];		/* stipple directory */
31*17294Sopcode extern char stippletype[];		/* stipple font type ("ug" or "cf") */
32*17294Sopcode extern stipple_index[];			/* stipple font numbers */
33*17294Sopcode 
34*17294Sopcode /* imports from main.c */
35*17294Sopcode 
36*17294Sopcode extern Artmode;				/* point display size */
37*17294Sopcode extern CBRUSH;				/* current brush */
38*17294Sopcode extern CFONT;				/* current font */
39*17294Sopcode extern CJUST;				/* current text justification */
40*17294Sopcode extern CSIZE;				/* current size */
41*17294Sopcode extern CSTIPPLE;			/* current stipple pattern */
42*17294Sopcode extern Alignment;			/* point alignment indicator */
43*17294Sopcode extern Adjustment;			/* point adjustment mode */
44*17294Sopcode extern GravityOn;			/* gravity mode flag */
45*17294Sopcode extern Gridon;				/* grid mode indicator */
46*17294Sopcode extern SymbolicLines;			/* pr_vector OK for all lines */
47*17294Sopcode extern long timeon_s, timeon_ms;	/* current set flash on rate */
48*17294Sopcode extern long timeoff_s, timeoff_ms;	/* current set flash off rate */
49*17294Sopcode 
50*17294Sopcode /* locally defined variables */
51*17294Sopcode 
52*17294Sopcode #define STon(s)  (strncmp(s, "on", 2) == 0)
53*17294Sopcode 
54*17294Sopcode int STERROR = FALSE;			/* indicates error on startup */
55*17294Sopcode 
56*17294Sopcode static char *lines[] = { "broken", "dashed", "dotted",
57*17294Sopcode 			 "medium", "narrow", "thick", NULL };
58*17294Sopcode static lnum[] = { 2, 4, 1, 6, 5, 3 };
59*17294Sopcode 
60*17294Sopcode static char *textpos[JUSTMODES] = { "tl", "tc", "tr",
61*17294Sopcode 				    "cl", "cc", "cr",
62*17294Sopcode 				    "bl", "bc", "br",
63*17294Sopcode 				    "lt", "ct", "rt",
64*17294Sopcode 				    "lc",       "rc",
65*17294Sopcode 				    "lb", "cb", "rb"  };
66*17294Sopcode static textmode[JUSTMODES] = { TOPLEFT,  TOPCENT,  TOPRIGHT,
67*17294Sopcode 			       CENTLEFT, CENTCENT, CENTRIGHT,
68*17294Sopcode 			       BOTLEFT,  BOTCENT,  BOTRIGHT,
69*17294Sopcode 			       TOPLEFT,  TOPCENT,  TOPRIGHT,
70*17294Sopcode 			       CENTLEFT,           CENTRIGHT,
71*17294Sopcode 			       BOTLEFT,  BOTCENT,  BOTRIGHT  };
72*17294Sopcode 
73*17294Sopcode static char *fonts[] = { "bold", "italics", "roman", "special", NULL };
74*17294Sopcode static fnum[] = { 3, 2, 1, 4 };
75*17294Sopcode 
76*17294Sopcode /* The following are defined to allow creation of the command lookup table. */
77*17294Sopcode 
78*17294Sopcode extern ST1(), ST2(), ST3(), ST4(), STB(), STI(), STR(), STS(),
79*17294Sopcode     STalign(), STbrush(), STflashoff(), STflashon(), STfont(), STfontdir(),
80*17294Sopcode     STgravity(), STgrid(), SThadjust(), STjustify(), STlittlepoint(),
81*17294Sopcode     STmadjust(), STpath(), STsize(), STstipple(),
82*17294Sopcode     STstipple1(), STstipple2(), STstipple3(), STstipple4(),
83*17294Sopcode     STstipple5(), STstipple6(), STstipple7(), STstipple8(),
84*17294Sopcode     STstippledir(), STstippletype(), STsymboliclines(), STvadjust();
85*17294Sopcode 
86*17294Sopcode /* The following two arrays define the startup commands and the routines
87*17294Sopcode    that process them. */
88*17294Sopcode 
89*17294Sopcode static char *startupcmds[] = {
90*17294Sopcode     "1",
91*17294Sopcode     "2",
92*17294Sopcode     "3",
93*17294Sopcode     "4",
94*17294Sopcode     "B",
95*17294Sopcode     "I",
96*17294Sopcode     "R",
97*17294Sopcode     "S",
98*17294Sopcode     "align",
99*17294Sopcode     "brush",
100*17294Sopcode     "flashoff",
101*17294Sopcode     "flashon",
102*17294Sopcode     "font",
103*17294Sopcode     "fontdir",
104*17294Sopcode     "gravity",
105*17294Sopcode     "grid",
106*17294Sopcode     "hadjust",
107*17294Sopcode     "justify",
108*17294Sopcode     "l1",
109*17294Sopcode     "l2",
110*17294Sopcode     "l3",
111*17294Sopcode     "l4",
112*17294Sopcode     "l5",
113*17294Sopcode     "l6",
114*17294Sopcode     "l7",
115*17294Sopcode     "l8",
116*17294Sopcode     "littlepoint",
117*17294Sopcode     "madjust",
118*17294Sopcode     "path",
119*17294Sopcode     "size",
120*17294Sopcode     "stipple",
121*17294Sopcode     "stipple1",
122*17294Sopcode     "stipple2",
123*17294Sopcode     "stipple3",
124*17294Sopcode     "stipple4",
125*17294Sopcode     "stipple5",
126*17294Sopcode     "stipple6",
127*17294Sopcode     "stipple7",
128*17294Sopcode     "stipple8",
129*17294Sopcode     "stippledir",
130*17294Sopcode     "stippletype",
131*17294Sopcode     "symboliclines",
132*17294Sopcode     "vadjust",
133*17294Sopcode     NULL
134*17294Sopcode };
135*17294Sopcode 
136*17294Sopcode static (*(strtns[]))() = {
137*17294Sopcode     ST1,			/* set size 1 point size */
138*17294Sopcode     ST2,			/* set size 2 point size */
139*17294Sopcode     ST3,			/* set size 3 point size */
140*17294Sopcode     ST4,			/* set size 4 point size */
141*17294Sopcode     STB,			/* set B font type */
142*17294Sopcode     STI,			/* set I font type */
143*17294Sopcode     STR,			/* set R font type */
144*17294Sopcode     STS,			/* set S font type */
145*17294Sopcode     STalign,			/* set point alignment */
146*17294Sopcode     STbrush,			/* set brush */
147*17294Sopcode     STflashoff,			/* set current set flash off time */
148*17294Sopcode     STflashon,			/* set current set flash on time */
149*17294Sopcode     STfont,			/* set font */
150*17294Sopcode     STfontdir,			/* font directory */
151*17294Sopcode     STgravity,			/* toggle gravity */
152*17294Sopcode     STgrid,			/* toggle grid display */
153*17294Sopcode     SThadjust,			/* horizontal adjust */
154*17294Sopcode     STjustify,			/* text justification */
155*17294Sopcode     STstipple1,			/* set stipple #1 index equivalent */
156*17294Sopcode     STstipple2,			/* set stipple #2 index equivalent */
157*17294Sopcode     STstipple3,			/* set stipple #3 index equivalent */
158*17294Sopcode     STstipple4,			/* set stipple #4 index equivalent */
159*17294Sopcode     STstipple5,			/* set stipple #5 index equivalent */
160*17294Sopcode     STstipple6,			/* set stipple #6 index equivalent */
161*17294Sopcode     STstipple7,			/* set stipple #7 index equivalent */
162*17294Sopcode     STstipple8,			/* set stipple #8 index equivalent */
163*17294Sopcode     STlittlepoint,		/* point size */
164*17294Sopcode     STmadjust,			/* manhattan adjust */
165*17294Sopcode     STpath,			/* set path or toggle search mode */
166*17294Sopcode     STsize,			/* character size */
167*17294Sopcode     STstipple,			/* set stipple pattern */
168*17294Sopcode     STstipple1,			/* set stipple #1 index */
169*17294Sopcode     STstipple2,			/* set stipple #2 index */
170*17294Sopcode     STstipple3,			/* set stipple #3 index */
171*17294Sopcode     STstipple4,			/* set stipple #4 index */
172*17294Sopcode     STstipple5,			/* set stipple #5 index */
173*17294Sopcode     STstipple6,			/* set stipple #6 index */
174*17294Sopcode     STstipple7,			/* set stipple #7 index */
175*17294Sopcode     STstipple8,			/* set stipple #8 index */
176*17294Sopcode     STstippledir,		/* stipple directory */
177*17294Sopcode     STstippletype,		/* stipple font file name */
178*17294Sopcode     STsymboliclines,		/* toggle symbolic lines */
179*17294Sopcode     STvadjust			/* vertical adjust */
180*17294Sopcode };
181*17294Sopcode 
182*17294Sopcode 
183*17294Sopcode /*
184*17294Sopcode  *  Check for .gremlinrc file(s) and process if found.
185*17294Sopcode  *  The only globally accessible routine in this file.
186*17294Sopcode  */
STgremlinrc(altfile)187*17294Sopcode STgremlinrc(altfile)
188*17294Sopcode char *altfile;			/* alternate startup file */
189*17294Sopcode {
190*17294Sopcode     FILE *fp;
191*17294Sopcode     struct stat buf;
192*17294Sopcode     ino_t home_inode, cwd_inode;
193*17294Sopcode     char home[128];
194*17294Sopcode 
195*17294Sopcode     /* look in home directory */
196*17294Sopcode     sprintf(home, "%s/.gremlinrc", getenv("HOME"));
197*17294Sopcode     fp = fopen(home, "r");
198*17294Sopcode     if (fp != NULL) {
199*17294Sopcode 	fstat(fileno(fp), &buf);
200*17294Sopcode 	home_inode = buf.st_ino;
201*17294Sopcode 	STstartup(fp);
202*17294Sopcode 	fclose(fp);
203*17294Sopcode     }
204*17294Sopcode     else
205*17294Sopcode 	home_inode = 0;
206*17294Sopcode 
207*17294Sopcode     /* look in current directory */
208*17294Sopcode     fp = fopen(".gremlinrc", "r");
209*17294Sopcode     if (fp != NULL) {
210*17294Sopcode 	fstat(fileno(fp), &buf);
211*17294Sopcode 	cwd_inode = buf.st_ino;
212*17294Sopcode 	if (cwd_inode != home_inode)        /* not in home directory */
213*17294Sopcode 	    STstartup(fp);
214*17294Sopcode 	fclose(fp);
215*17294Sopcode     }
216*17294Sopcode 
217*17294Sopcode     /* check for alternate startup file */
218*17294Sopcode     if (*altfile != '\0') {
219*17294Sopcode 	fp = fopen(altfile, "r");
220*17294Sopcode 	if (fp != NULL) {
221*17294Sopcode 	    fstat(fileno(fp), &buf);
222*17294Sopcode 	    if ((buf.st_ino != home_inode) && (buf.st_ino != cwd_inode))
223*17294Sopcode 		STstartup(fp);
224*17294Sopcode 	    fclose(fp);
225*17294Sopcode 	}
226*17294Sopcode     }
227*17294Sopcode }  /* end STgremlinrc */
228*17294Sopcode 
229*17294Sopcode 
230*17294Sopcode static
STerror(s)231*17294Sopcode STerror(s)
232*17294Sopcode register char *s;
233*17294Sopcode {
234*17294Sopcode     char msg[256];
235*17294Sopcode 
236*17294Sopcode     STERROR = 1;
237*17294Sopcode     sprintf(msg, "startup: %s", s);
238*17294Sopcode     TxPutMsg(msg);
239*17294Sopcode }  /* end STerror */
240*17294Sopcode 
241*17294Sopcode 
242*17294Sopcode /*
243*17294Sopcode  *  Do startup processing on open file referenced by fp.
244*17294Sopcode  */
245*17294Sopcode static
STstartup(fp)246*17294Sopcode STstartup(fp)
247*17294Sopcode register FILE *fp;
248*17294Sopcode {
249*17294Sopcode     register char *s;
250*17294Sopcode     register i;
251*17294Sopcode     char buf[256];
252*17294Sopcode 
253*17294Sopcode     s = fgets(buf, 256, fp);
254*17294Sopcode     while (s != NULL) {
255*17294Sopcode 	for (i=0; (buf[i] != '\n'); ++i)
256*17294Sopcode 	    if (i > 255)
257*17294Sopcode 		break;
258*17294Sopcode 	buf[i] = '\0';
259*17294Sopcode 	STcommand(buf);
260*17294Sopcode 	s = fgets(buf, 400, fp);
261*17294Sopcode     }
262*17294Sopcode }  /* end STstartup */
263*17294Sopcode 
264*17294Sopcode 
265*17294Sopcode /*
266*17294Sopcode  *  Make a string lower case.
267*17294Sopcode  */
STtolower(s)268*17294Sopcode STtolower(s)
269*17294Sopcode register char *s;
270*17294Sopcode {
271*17294Sopcode     register c;
272*17294Sopcode 
273*17294Sopcode     while ((c = (int) *s) != 0) {
274*17294Sopcode 	if (isupper(c))
275*17294Sopcode 	    *s = tolower(c);
276*17294Sopcode 	s++;
277*17294Sopcode     }
278*17294Sopcode }
279*17294Sopcode 
280*17294Sopcode 
281*17294Sopcode /*
282*17294Sopcode  *  STlookup searches a table of strings to find one that matches a
283*17294Sopcode  *  given string.
284*17294Sopcode  *
285*17294Sopcode  *  If str is an unambiguous abbreviation for one of the entries
286*17294Sopcode  *  in table, then the index of the matching entry is returned.
287*17294Sopcode  *  If str is an abbreviation for more than one entry in table,
288*17294Sopcode  *  then -1 is returned.  If str doesn't match any entry, then
289*17294Sopcode  *  -2 is returned.
290*17294Sopcode  *
291*17294Sopcode  *  The search is carried out by using two pointers, one which moves
292*17294Sopcode  *  forward through table from its start, and one which moves backward
293*17294Sopcode  *  through table from its end.  The two pointers mark the range of
294*17294Sopcode  *  strings that match the portion of str that we have scanned.  When
295*17294Sopcode  *  all of the characters of str have been scanned, then the two
296*17294Sopcode  *  pointers better be identical.
297*17294Sopcode  */
298*17294Sopcode static
STlookup(str,table,next)299*17294Sopcode STlookup(str, table, next)
300*17294Sopcode char str[];			/* Pointer to a string to be looked up */
301*17294Sopcode char *(table[]);		/* Pointer to an array of string pointers
302*17294Sopcode 				   which are the valid commands.  The strings
303*17294Sopcode 				   must be ordered monotonically (i.e. all
304*17294Sopcode 				   strings whose first characters are identical
305*17294Sopcode 				   must be adjacent in the table). */
306*17294Sopcode int *next;			/* Index to delimiter after search */
307*17294Sopcode {
308*17294Sopcode     char **bot, **top;
309*17294Sopcode     int match, index;
310*17294Sopcode 
311*17294Sopcode     match = 0;
312*17294Sopcode     bot = table;
313*17294Sopcode     for (top = table; *top != NULL; top++)
314*17294Sopcode 	;
315*17294Sopcode     if (top == bot)
316*17294Sopcode 	return(-2);
317*17294Sopcode     top--;
318*17294Sopcode 
319*17294Sopcode     for (index=0; ; index++) {
320*17294Sopcode         *next = index;
321*17294Sopcode 
322*17294Sopcode 	/* Check for the end of string */
323*17294Sopcode 	if (Delimiter(str[index]))
324*17294Sopcode 	    return(((bot == top) || Delimiter((*bot)[index])) ? match : -1);
325*17294Sopcode 
326*17294Sopcode 	/*
327*17294Sopcode 	 * Move bot up until the string it points to matches str
328*17294Sopcode 	 * in the index'th position.
329*17294Sopcode 	 * Make match refer to the index of bot in table.
330*17294Sopcode 	 */
331*17294Sopcode 
332*17294Sopcode 	while ((*bot)[index] != str[index]) {
333*17294Sopcode 	    if (bot == top)
334*17294Sopcode 		return(-2);
335*17294Sopcode 	    bot++;
336*17294Sopcode 	    match++;
337*17294Sopcode 	}
338*17294Sopcode 
339*17294Sopcode 	/* Move top down until it matches */
340*17294Sopcode 
341*17294Sopcode 	while ((*top)[index] != str[index]) {
342*17294Sopcode 	    if (bot == top)
343*17294Sopcode 		return(-2);
344*17294Sopcode 	    top--;
345*17294Sopcode 	}
346*17294Sopcode     }
347*17294Sopcode }  /* end STlookup */
348*17294Sopcode 
349*17294Sopcode 
350*17294Sopcode /*
351*17294Sopcode  *  This routine looks up and executes a startup command.
352*17294Sopcode  */
353*17294Sopcode static
STcommand(line)354*17294Sopcode STcommand(line)
355*17294Sopcode register char *line;
356*17294Sopcode {
357*17294Sopcode     register index;
358*17294Sopcode     register char *save;
359*17294Sopcode     char buf[256];
360*17294Sopcode     int next;
361*17294Sopcode 
362*17294Sopcode     if ((*line == '\0') || (*line == '#'))
363*17294Sopcode         return;
364*17294Sopcode 
365*17294Sopcode     index = STlookup(save = line, startupcmds, &next);
366*17294Sopcode 
367*17294Sopcode     if (index >= 0) {
368*17294Sopcode 	line = line + next;
369*17294Sopcode 
370*17294Sopcode 	/* skip to first non-blank */
371*17294Sopcode 	while ((*line == '\t') || (*line == ' '))
372*17294Sopcode 	    line++;
373*17294Sopcode 
374*17294Sopcode 	(*(strtns[index]))(line);
375*17294Sopcode     }
376*17294Sopcode     else if (index == -1) {
377*17294Sopcode 	sprintf(buf, "ambigous command: %s", save);
378*17294Sopcode 	STerror(buf);
379*17294Sopcode     }
380*17294Sopcode     else if (index == -2) {
381*17294Sopcode 	sprintf(buf, "unknown command: %s", save);
382*17294Sopcode 	STerror(buf);
383*17294Sopcode     }
384*17294Sopcode }  /* end STcommand */
385*17294Sopcode 
386*17294Sopcode 
387*17294Sopcode /*
388*17294Sopcode  * This routine interprets the string starting at line
389*17294Sopcode  * as a positive integral numeric parameter.  The function
390*17294Sopcode  * returns the numeric equivalent or -1 it there is some
391*17294Sopcode  * error in interpreting the string.
392*17294Sopcode  * NOTE: expects line with at least one non-space character.
393*17294Sopcode  */
394*17294Sopcode static
STgetnum(line)395*17294Sopcode STgetnum(line)
396*17294Sopcode register char *line;
397*17294Sopcode {
398*17294Sopcode     register i;
399*17294Sopcode     char num[128];
400*17294Sopcode     int result;
401*17294Sopcode 
402*17294Sopcode     for (i=0; !Delimiter(*line); ++i) {
403*17294Sopcode 	num[i] = *line++;
404*17294Sopcode 	if (!isdigit(num[i]))
405*17294Sopcode 	    return(-1);
406*17294Sopcode     }
407*17294Sopcode 
408*17294Sopcode     num[i] = '\0';
409*17294Sopcode     (void) sscanf(num, "%d", &result);
410*17294Sopcode     return(result);
411*17294Sopcode }  /* end STgetnum */
412*17294Sopcode 
413*17294Sopcode 
414*17294Sopcode static
ST1(line)415*17294Sopcode ST1(line)
416*17294Sopcode register char *line;
417*17294Sopcode {
418*17294Sopcode     register size;
419*17294Sopcode 
420*17294Sopcode     if (*line == '\0')
421*17294Sopcode 	return;
422*17294Sopcode 
423*17294Sopcode     size = STgetnum(line);
424*17294Sopcode     if (size != -1)
425*17294Sopcode 	font_sizes[0] = size;
426*17294Sopcode     else
427*17294Sopcode 	STerror("bad size 1");
428*17294Sopcode }
429*17294Sopcode 
430*17294Sopcode 
431*17294Sopcode static
ST2(line)432*17294Sopcode ST2(line)
433*17294Sopcode register char *line;
434*17294Sopcode {
435*17294Sopcode     register size;
436*17294Sopcode 
437*17294Sopcode     if (*line == '\0')
438*17294Sopcode 	return;
439*17294Sopcode 
440*17294Sopcode     size = STgetnum(line);
441*17294Sopcode     if (size != -1)
442*17294Sopcode 	font_sizes[1] = size;
443*17294Sopcode     else
444*17294Sopcode 	STerror("bad size 2");
445*17294Sopcode }
446*17294Sopcode 
447*17294Sopcode 
448*17294Sopcode static
ST3(line)449*17294Sopcode ST3(line)
450*17294Sopcode register char *line;
451*17294Sopcode {
452*17294Sopcode     register size;
453*17294Sopcode 
454*17294Sopcode     if (*line == '\0')
455*17294Sopcode 	return;
456*17294Sopcode 
457*17294Sopcode     size = STgetnum(line);
458*17294Sopcode     if (size != -1)
459*17294Sopcode 	font_sizes[2] = size;
460*17294Sopcode     else
461*17294Sopcode 	STerror("bad size 3");
462*17294Sopcode }
463*17294Sopcode 
464*17294Sopcode 
465*17294Sopcode static
ST4(line)466*17294Sopcode ST4(line)
467*17294Sopcode register char *line;
468*17294Sopcode {
469*17294Sopcode     register size;
470*17294Sopcode 
471*17294Sopcode     if (*line == '\0')
472*17294Sopcode 	return;
473*17294Sopcode 
474*17294Sopcode     size = STgetnum(line);
475*17294Sopcode     if (size != -1)
476*17294Sopcode 	font_sizes[3] = size;
477*17294Sopcode     else
478*17294Sopcode 	STerror("bad size 4");
479*17294Sopcode }
480*17294Sopcode 
481*17294Sopcode 
482*17294Sopcode static
STB(line)483*17294Sopcode STB(line)
484*17294Sopcode register char *line;
485*17294Sopcode {
486*17294Sopcode     register char *f;
487*17294Sopcode     register i = 0;
488*17294Sopcode 
489*17294Sopcode     if (*line == '\0')
490*17294Sopcode 	return;
491*17294Sopcode 
492*17294Sopcode     f = line;
493*17294Sopcode     while (!Delimiter(*f))
494*17294Sopcode 	f++, i++;
495*17294Sopcode 
496*17294Sopcode     f = malloc((unsigned) i+1);
497*17294Sopcode     strncpy(f, line, i+1);
498*17294Sopcode     font_types[BFONT] = f;
499*17294Sopcode }
500*17294Sopcode 
501*17294Sopcode 
502*17294Sopcode static
STI(line)503*17294Sopcode STI(line)
504*17294Sopcode register char *line;
505*17294Sopcode {
506*17294Sopcode     register char *f;
507*17294Sopcode     register i = 0;
508*17294Sopcode 
509*17294Sopcode     if (*line == '\0')
510*17294Sopcode 	return;
511*17294Sopcode 
512*17294Sopcode     f = line;
513*17294Sopcode     while (!Delimiter(*f))
514*17294Sopcode 	f++, i++;
515*17294Sopcode 
516*17294Sopcode     f = malloc((unsigned) i+1);
517*17294Sopcode     strncpy(f, line, i+1);
518*17294Sopcode     font_types[IFONT] = f;
519*17294Sopcode }
520*17294Sopcode 
521*17294Sopcode 
522*17294Sopcode static
STR(line)523*17294Sopcode STR(line)
524*17294Sopcode register char *line;
525*17294Sopcode {
526*17294Sopcode     register char *f;
527*17294Sopcode     register i = 0;
528*17294Sopcode 
529*17294Sopcode     if (*line == '\0')
530*17294Sopcode 	return;
531*17294Sopcode 
532*17294Sopcode     f = line;
533*17294Sopcode     while (!Delimiter(*f))
534*17294Sopcode 	f++, i++;
535*17294Sopcode 
536*17294Sopcode     f = malloc((unsigned) i+1);
537*17294Sopcode     strncpy(f, line, i+1);
538*17294Sopcode     font_types[RFONT] = f;
539*17294Sopcode }
540*17294Sopcode 
541*17294Sopcode 
542*17294Sopcode static
STS(line)543*17294Sopcode STS(line)
544*17294Sopcode register char *line;
545*17294Sopcode {
546*17294Sopcode     register char *f;
547*17294Sopcode     register i = 0;
548*17294Sopcode 
549*17294Sopcode     if (*line == '\0')
550*17294Sopcode 	return;
551*17294Sopcode 
552*17294Sopcode     f = line;
553*17294Sopcode     while (!Delimiter(*f))
554*17294Sopcode 	f++, i++;
555*17294Sopcode 
556*17294Sopcode     f = malloc((unsigned) i+1);
557*17294Sopcode     strncpy(f, line, i+1);
558*17294Sopcode     font_types[SFONT] = f;
559*17294Sopcode }
560*17294Sopcode 
561*17294Sopcode 
562*17294Sopcode static
STalign(line)563*17294Sopcode STalign(line)
564*17294Sopcode register char *line;
565*17294Sopcode {
566*17294Sopcode     register a;
567*17294Sopcode     register align = 1;
568*17294Sopcode 
569*17294Sopcode     if (*line == '\0')
570*17294Sopcode 	return;
571*17294Sopcode 
572*17294Sopcode     a = STgetnum(line);
573*17294Sopcode     if (a <= 0)
574*17294Sopcode 	STerror("bad alignment");
575*17294Sopcode     else {
576*17294Sopcode 	a >>= 1;
577*17294Sopcode 	while (a != 0) {
578*17294Sopcode 	    align <<= 1;
579*17294Sopcode 	    a >>= 1;
580*17294Sopcode 	}
581*17294Sopcode 	Alignment = (align > 512) ? 512 : align;
582*17294Sopcode     }
583*17294Sopcode }
584*17294Sopcode 
585*17294Sopcode 
586*17294Sopcode static
STbrush(line)587*17294Sopcode STbrush(line)
588*17294Sopcode register char *line;
589*17294Sopcode {
590*17294Sopcode     register newbrush;
591*17294Sopcode     int index = 0;
592*17294Sopcode 
593*17294Sopcode     if (*line == '\0')
594*17294Sopcode 	return;
595*17294Sopcode 
596*17294Sopcode     STtolower(line);		/* force argument to lower case */
597*17294Sopcode 
598*17294Sopcode     if ((newbrush = STlookup(line, lines, &index)) >= 0)
599*17294Sopcode 	CBRUSH = lnum[newbrush];
600*17294Sopcode     else
601*17294Sopcode 	STerror("bad brush name");
602*17294Sopcode }
603*17294Sopcode 
604*17294Sopcode 
605*17294Sopcode static
STflashoff(line)606*17294Sopcode STflashoff(line)
607*17294Sopcode register char *line;
608*17294Sopcode {
609*17294Sopcode     register flashoff;
610*17294Sopcode     int index = 0;
611*17294Sopcode 
612*17294Sopcode     if (*line == '\0')
613*17294Sopcode 	return;
614*17294Sopcode 
615*17294Sopcode     flashoff = STgetnum(line);
616*17294Sopcode     if (flashoff == -1)
617*17294Sopcode 	STerror("bad flash off time");
618*17294Sopcode     else {
619*17294Sopcode 	timeoff_s = flashoff / 1000;
620*17294Sopcode 	timeoff_ms = flashoff % 1000;
621*17294Sopcode     }
622*17294Sopcode }
623*17294Sopcode 
624*17294Sopcode 
625*17294Sopcode static
STflashon(line)626*17294Sopcode STflashon(line)
627*17294Sopcode register char *line;
628*17294Sopcode {
629*17294Sopcode     register flashon;
630*17294Sopcode     int index = 0;
631*17294Sopcode 
632*17294Sopcode     if (*line == '\0')
633*17294Sopcode 	return;
634*17294Sopcode 
635*17294Sopcode     flashon = STgetnum(line);
636*17294Sopcode     if (flashon == -1)
637*17294Sopcode 	STerror("bad flash on time");
638*17294Sopcode     else {
639*17294Sopcode 	timeon_s = flashon / 1000;
640*17294Sopcode 	timeon_ms = flashon % 1000;
641*17294Sopcode     }
642*17294Sopcode }
643*17294Sopcode 
644*17294Sopcode 
645*17294Sopcode static
STfont(line)646*17294Sopcode STfont(line)
647*17294Sopcode register char *line;
648*17294Sopcode {
649*17294Sopcode     int font;
650*17294Sopcode     int index = 0;
651*17294Sopcode 
652*17294Sopcode     if (*line == '\0')
653*17294Sopcode 	return;
654*17294Sopcode 
655*17294Sopcode     STtolower(line);		/* force argument to lower case */
656*17294Sopcode 
657*17294Sopcode     if ((font = STlookup(line, fonts, &index)) >= 0)
658*17294Sopcode 	CFONT = fnum[font];
659*17294Sopcode     else
660*17294Sopcode         STerror("bad font number");
661*17294Sopcode }
662*17294Sopcode 
663*17294Sopcode 
664*17294Sopcode static
STfontdir(line)665*17294Sopcode STfontdir(line)
666*17294Sopcode register char *line;
667*17294Sopcode {
668*17294Sopcode     register i = 0;
669*17294Sopcode 
670*17294Sopcode     if (*line == '\0')
671*17294Sopcode 	return;
672*17294Sopcode 
673*17294Sopcode     while (!Delimiter(*line))
674*17294Sopcode 	fontdir[i++] = *line++;
675*17294Sopcode 
676*17294Sopcode     if (fontdir[--i] != '/')
677*17294Sopcode 	fontdir[++i] = '/';
678*17294Sopcode 
679*17294Sopcode     fontdir[++i] = '\0';
680*17294Sopcode }
681*17294Sopcode 
682*17294Sopcode 
683*17294Sopcode static
STgravity(line)684*17294Sopcode STgravity(line)
685*17294Sopcode register char *line;
686*17294Sopcode {
687*17294Sopcode     STtolower(line);
688*17294Sopcode     GravityOn = STon(line);
689*17294Sopcode }
690*17294Sopcode 
691*17294Sopcode 
692*17294Sopcode static
STgrid(line)693*17294Sopcode STgrid(line)
694*17294Sopcode register char *line;
695*17294Sopcode {
696*17294Sopcode     STtolower(line);
697*17294Sopcode     Gridon = STon(line);
698*17294Sopcode }
699*17294Sopcode 
700*17294Sopcode 
701*17294Sopcode static
SThadjust(line)702*17294Sopcode SThadjust(line)
703*17294Sopcode register char *line;
704*17294Sopcode {
705*17294Sopcode     STtolower(line);
706*17294Sopcode 
707*17294Sopcode     if (STon(line))
708*17294Sopcode 	Adjustment = HORZ;
709*17294Sopcode     else if (Adjustment == HORZ)
710*17294Sopcode 	Adjustment = NOADJ;
711*17294Sopcode     /*
712*17294Sopcode     Adjustment = (Adjustment == HORZ) ? NOADJ : HORZ;
713*17294Sopcode     */
714*17294Sopcode }
715*17294Sopcode 
716*17294Sopcode 
717*17294Sopcode static
STjustify(line)718*17294Sopcode STjustify(line)
719*17294Sopcode register char *line;
720*17294Sopcode {
721*17294Sopcode     int new;
722*17294Sopcode     int index = 0;
723*17294Sopcode 
724*17294Sopcode     if (*line == '\0')
725*17294Sopcode 	return;
726*17294Sopcode 
727*17294Sopcode     STtolower(line);		/* force argument to lower case */
728*17294Sopcode 
729*17294Sopcode     for (new = 0; (strcmp(line, textpos[new]) != 0); ++new) {
730*17294Sopcode 	if (new >= JUSTMODES) {
731*17294Sopcode 	   STerror("bad justification mode");
732*17294Sopcode 	   return;
733*17294Sopcode 	}
734*17294Sopcode     }
735*17294Sopcode 
736*17294Sopcode     CJUST = textmode[new];
737*17294Sopcode }
738*17294Sopcode 
739*17294Sopcode 
740*17294Sopcode static
STlittlepoint(line)741*17294Sopcode STlittlepoint(line)
742*17294Sopcode register char *line;
743*17294Sopcode {
744*17294Sopcode     /*
745*17294Sopcode     Artmode = !Artmode;
746*17294Sopcode     */
747*17294Sopcode     STtolower(line);
748*17294Sopcode     Artmode = STon(line);
749*17294Sopcode }
750*17294Sopcode 
751*17294Sopcode 
752*17294Sopcode static
STmadjust(line)753*17294Sopcode STmadjust(line)
754*17294Sopcode register char *line;
755*17294Sopcode {
756*17294Sopcode     STtolower(line);		/* force argument to lower case */
757*17294Sopcode 
758*17294Sopcode     if (STon(line))
759*17294Sopcode 	Adjustment = MAN;
760*17294Sopcode     else if (Adjustment == MAN)
761*17294Sopcode 	Adjustment = NOADJ;
762*17294Sopcode     /*
763*17294Sopcode     Adjustment = (Adjustment == MAN) ? NOADJ : MAN;
764*17294Sopcode     */
765*17294Sopcode }
766*17294Sopcode 
767*17294Sopcode 
768*17294Sopcode static
STpath(line)769*17294Sopcode STpath(line)
770*17294Sopcode register char *line;
771*17294Sopcode {
772*17294Sopcode     if (*line == '\0')
773*17294Sopcode 	return;
774*17294Sopcode 
775*17294Sopcode     PSetPath(line);
776*17294Sopcode }
777*17294Sopcode 
778*17294Sopcode 
779*17294Sopcode static
STsize(line)780*17294Sopcode STsize(line)
781*17294Sopcode register char *line;
782*17294Sopcode {
783*17294Sopcode     int new;
784*17294Sopcode 
785*17294Sopcode     if (*line == '\0')
786*17294Sopcode 	return;
787*17294Sopcode 
788*17294Sopcode     new = STgetnum(line);
789*17294Sopcode 
790*17294Sopcode     if ((new == -1) || (new > NSIZES))
791*17294Sopcode         STerror("bad font size");
792*17294Sopcode     else
793*17294Sopcode         CSIZE = new;
794*17294Sopcode }
795*17294Sopcode 
796*17294Sopcode 
797*17294Sopcode static
STstipple(line)798*17294Sopcode STstipple(line)
799*17294Sopcode register char *line;
800*17294Sopcode {
801*17294Sopcode     int newstipple;
802*17294Sopcode 
803*17294Sopcode     if (*line == '\0')
804*17294Sopcode 	return;
805*17294Sopcode 
806*17294Sopcode     newstipple = STgetnum(line);
807*17294Sopcode 
808*17294Sopcode     if ((newstipple == -1) || (newstipple > NSTIPPLES))
809*17294Sopcode         STerror("bad stipple number");
810*17294Sopcode     else
811*17294Sopcode 	CSTIPPLE = newstipple;
812*17294Sopcode }
813*17294Sopcode 
814*17294Sopcode 
815*17294Sopcode static
STstipplenum(line,num)816*17294Sopcode STstipplenum(line, num)
817*17294Sopcode register char *line;
818*17294Sopcode register num;
819*17294Sopcode {
820*17294Sopcode     register index;
821*17294Sopcode 
822*17294Sopcode     if (*line == '\0')
823*17294Sopcode 	return;
824*17294Sopcode 
825*17294Sopcode     index = STgetnum(line);
826*17294Sopcode 
827*17294Sopcode     if ((index == -1) || (index >= NUM_DISPATCH))
828*17294Sopcode         STerror("bad stipple font index");
829*17294Sopcode     else
830*17294Sopcode 	stipple_index[num-1] = index;
831*17294Sopcode }
832*17294Sopcode 
833*17294Sopcode 
834*17294Sopcode static
STstipple1(line)835*17294Sopcode STstipple1(line)
836*17294Sopcode register char *line;
837*17294Sopcode {
838*17294Sopcode     STstipplenum(line, 1);
839*17294Sopcode }
840*17294Sopcode 
841*17294Sopcode 
842*17294Sopcode static
STstipple2(line)843*17294Sopcode STstipple2(line)
844*17294Sopcode register char *line;
845*17294Sopcode {
846*17294Sopcode     STstipplenum(line, 2);
847*17294Sopcode }
848*17294Sopcode 
849*17294Sopcode 
850*17294Sopcode static
STstipple3(line)851*17294Sopcode STstipple3(line)
852*17294Sopcode register char *line;
853*17294Sopcode {
854*17294Sopcode     STstipplenum(line, 3);
855*17294Sopcode }
856*17294Sopcode 
857*17294Sopcode 
858*17294Sopcode static
STstipple4(line)859*17294Sopcode STstipple4(line)
860*17294Sopcode register char *line;
861*17294Sopcode {
862*17294Sopcode     STstipplenum(line, 4);
863*17294Sopcode }
864*17294Sopcode 
865*17294Sopcode 
866*17294Sopcode static
STstipple5(line)867*17294Sopcode STstipple5(line)
868*17294Sopcode register char *line;
869*17294Sopcode {
870*17294Sopcode     STstipplenum(line, 5);
871*17294Sopcode }
872*17294Sopcode 
873*17294Sopcode 
874*17294Sopcode static
STstipple6(line)875*17294Sopcode STstipple6(line)
876*17294Sopcode register char *line;
877*17294Sopcode {
878*17294Sopcode     STstipplenum(line, 6);
879*17294Sopcode }
880*17294Sopcode 
881*17294Sopcode 
882*17294Sopcode static
STstipple7(line)883*17294Sopcode STstipple7(line)
884*17294Sopcode register char *line;
885*17294Sopcode {
886*17294Sopcode     STstipplenum(line, 7);
887*17294Sopcode }
888*17294Sopcode 
889*17294Sopcode 
890*17294Sopcode static
STstipple8(line)891*17294Sopcode STstipple8(line)
892*17294Sopcode register char *line;
893*17294Sopcode {
894*17294Sopcode     STstipplenum(line, 8);
895*17294Sopcode }
896*17294Sopcode 
897*17294Sopcode 
898*17294Sopcode static
STstippledir(line)899*17294Sopcode STstippledir(line)
900*17294Sopcode register char *line;
901*17294Sopcode {
902*17294Sopcode     register i = 0;
903*17294Sopcode 
904*17294Sopcode     if (*line == '\0')
905*17294Sopcode 	return;
906*17294Sopcode 
907*17294Sopcode     while (!Delimiter(*line))
908*17294Sopcode 	stippledir[i++] = *line++;
909*17294Sopcode 
910*17294Sopcode     if (stippledir[--i] != '/')
911*17294Sopcode 	stippledir[++i] = '/';
912*17294Sopcode 
913*17294Sopcode     stippledir[++i] = '\0';
914*17294Sopcode }
915*17294Sopcode 
916*17294Sopcode 
917*17294Sopcode static
STstippletype(line)918*17294Sopcode STstippletype(line)
919*17294Sopcode register char *line;
920*17294Sopcode {
921*17294Sopcode     register i = 0;
922*17294Sopcode 
923*17294Sopcode     if (*line == '\0')
924*17294Sopcode 	return;
925*17294Sopcode 
926*17294Sopcode     while (!Delimiter(*line))
927*17294Sopcode 	stippletype[i++] = *line++;
928*17294Sopcode 
929*17294Sopcode     stippletype[i] = '\0';
930*17294Sopcode }
931*17294Sopcode 
932*17294Sopcode 
933*17294Sopcode static
STsymboliclines(line)934*17294Sopcode STsymboliclines(line)
935*17294Sopcode register char *line;
936*17294Sopcode {
937*17294Sopcode     /*
938*17294Sopcode     SymbolicLines = !SymbolicLines;
939*17294Sopcode     */
940*17294Sopcode     STtolower(line);
941*17294Sopcode     SymbolicLines = STon(line);
942*17294Sopcode }
943*17294Sopcode 
944*17294Sopcode 
945*17294Sopcode static
STvadjust(line)946*17294Sopcode STvadjust(line)
947*17294Sopcode register char *line;
948*17294Sopcode {
949*17294Sopcode     STtolower(line);
950*17294Sopcode 
951*17294Sopcode     if (STon(line))
952*17294Sopcode 	Adjustment = VERT;
953*17294Sopcode     else if (Adjustment == VERT)
954*17294Sopcode 	Adjustment = NOADJ;
955*17294Sopcode     /*
956*17294Sopcode     Adjustment = (Adjustment == VERT) ? NOADJ : VERT;
957*17294Sopcode     */
958*17294Sopcode }
959