summaryrefslogtreecommitdiff
path: root/dviware/beebe/src/option.h
blob: ae5c160b4bd9ece46dab13194af51dbc8fee6204 (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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/* -*-C-*- option.h */
/*-->option*/
/**********************************************************************/
/******************************* option *******************************/
/**********************************************************************/

void
option(optstr)			/* process command-line option */
char *optstr;			/* option string (e.g. "-m1500") */
{
    register UNSIGN32 k;	/* magnification */
    register int value;		/* converted digit string value */
    register int m;		/* loop index */
    char *p;			/* pointer into optstr */
    int p1,p2,p3;		/* temp values for sscanf() */
    double fltmag;		/* floating-point mag value */

    typedef struct
    {
	char* envname;
	char* envvar;
    } envstruct;

    static envstruct envlist[] =
    {	/* names and addresses of environment vars (alphabetical order) */
	"DVIHELP",	helpcmd,
	"FONTLIST",	fontlist,
	"TEXFONTS",	fontpath,
	"TEXINPUTS",	subpath,
    };

    if (*optstr != '-')
	return;			/* return if this is not an option */

    switch (*(optstr+1))
    {

    case 'a':	/* A selects virtual font caching */
    case 'A':

#if    VIRTUAL_FONTS
	virt_font = TRUE;
#endif
	break;

    case 'b':	/* b selects backwards printing order */
    case 'B':
	backwards = TRUE;
	break;


    case 'c':	/* c selects number of copies */
    case 'C':
	copies = (UNSIGN16) atoi(optstr+2);
	copies = MAX(1,MIN(copies,256)); /* enforce reasonable limits */
	break;


    case 'd':	/* d selects debug output */
    case 'D':
	debug_code |= (BYTE)atoi(optstr+2);
	break;


    case 'e':	/* e specifies ``environment'' variable definition */
    case 'E':	/* We ignore letter case since these come from */
		/* the command line */
	if (!(p = strrchr(optstr,'=')))
	{
	    (void)usage(stderr);
	    (void)sprintf(message,
	        "option():  Bad switch [%s]--expected -eENVNAME=value",
		optstr);
	    (void)fatal(message);
	}
	*p = '\0';		/* clobber "=" by string terminator */
	for (m = 0; m < sizeof(envlist)/sizeof(envlist[0]); ++m)
	{
	    if (strcm2(optstr+2,envlist[m].envname) == 0)
	    {
		(void)strcpy(envlist[m].envvar,p+1);
		return;
	    }
	}
	(void)usage(stderr);

	(void)sprintf(message,"option():  Bad switch [%s]--expected one of:",
	    optstr);
	for (m = 0; m < sizeof(envlist)/sizeof(envlist[0]); ++m)
	{
	    (void)strcat(message," ");
	    (void)strcat(message,envlist[m].envname);
	}
	(void)fatal(message);
	break;


    case 'f':	/* f specifies font substitution file */
    case 'F':
	(void)strcpy(subfile,optstr+2);
	break;


#if    CANON_A2

#ifdef CANON_TEST
    case 'g':
    case 'G':
		stor_fonts = (UNSIGN32)atoi(optstr + 2 );
		break;
#endif /* CANON_TEST */

#endif

    case 'l':	/* l prohibits logging of errors */
    case 'L':
	g_dolog = FALSE;
	break;


    case 'm':	/* m selects alternate magnification */
    case 'M':
	/* Collect 2*value initially.  Then if value is small, assume
	user specified magstep value; magstep k means 1.2**k, where k
	is integral, or half-integral.  Otherwise, assume user has
	specified pxl file magnification (1000 == 200dpi, 1500 ==
	300dpi, etc.).  */


	if (strchr(optstr+2,'.') != (char *)NULL)
	    fltmag = (double)(2.0 * atof(optstr+2));
	else
	    fltmag = (double)(2 * atoi(optstr+2));
	if ((0.0 != fltmag) && 
	    (-30.0 <= fltmag) && (fltmag <= 30.0)) /* magstep 15 is limit */
	{
	    if (fltmag < 0.0)
	        runmag = (UNSIGN32)(0.5 + 
		    (1.0/pow((double)sqrt(1.2),-fltmag))*(double)STDMAG);
	    else
	        runmag = (UNSIGN32)(0.5 + pow((double)sqrt(1.2),fltmag)*
	            (double)STDMAG);
	}
	else
	    runmag = (UNSIGN32)(0.5 + fltmag/2.0);

	k = MAGSIZE(actfact(runmag));  /* rounded magnification */
	if (k != runmag)
	{
	    (void)sprintf(message,
		"option():  Requested magnification %d not available.",
		(int)runmag);
	    (void)warning(message);
	    runmag = k;
	    k = (UNSIGN32) MAX(1,MIN(mag_index,(MAGTABSIZE-1)));
	    (void)sprintf(message,
		"  Magnification reset to nearest legal value %d in \
family ..%d..%d..%d..",
		(int)runmag,(int)MAGSIZE(mag_table[k-1]),
		(int)MAGSIZE(mag_table[k]),
		(int)MAGSIZE(mag_table[k+1]));
	    (void)warning(message);
	}
	break;


    case 'o':
    case 'O':	/* o selects output page range (-o# or -o#:# or -o#:#:#) */
        p1 = p2 = p3 = 0;
	value = (int)sscanf(optstr+2,"%d:%d:%d",&p1,&p2,&p3);
	page_begin[npage] = p1;
	page_end[npage] = p2;
	page_step[npage] = p3;
	switch (value)
	{
	case 1:
	    optstr++;			/* point past "-" */

	    do				/* skip over digit string */
	    {
		optstr++;
	    }
	    while (isdigit(*optstr) || (*optstr == '-') || (*optstr == '+'));

	    if (*optstr)		/* trash follows number */
	    {
	        (void)usage(stderr);
		(void)sprintf(message,
		    "option():  %s is not a legal page number switch",optstr);
		(void)fatal(message);
	    }
	    else			/* had expected end-of-string */
	        page_end[npage] = (INT16)page_begin[npage];
	    page_step[npage] = 1;
	    break;

	case 2:		/* supply default step */
	    page_step[npage] = 1;
	    /* FALL THROUGH to case 3 for order check */

	case 3:		/* check for positive step */
	    page_step[npage] = ABS(page_step[npage]);
	    if (page_step[npage] == 0)
		page_step[npage] = 1;
	    break;

	default:	/* illegal value */
	    (void)usage(stderr);
	    (void)sprintf(message,
		"option():  %s is not a legal page number switch",optstr);
	    (void)fatal(message);
	}
	npage++;
	break;


    case 'p':	/* p prohibits pre-font loading */
    case 'P':
#if    (HPLASERJET|HPJETPLUS|GOLDENDAWNGL100|POSTSCRIPT|IMPRESS|CANON_A2)
	preload = TRUE;	/* preloading required for Canon engines */
			/* because of reverse printing order */
#else
	preload = FALSE;
#endif /*NOT(HPLASERJET|HPJETPLUS|GOLDENDAWNGL100|POSTSCRIPT|IMPRESS|CANON_A2)*/
	break;


    case 'q':	/* q inhibits status display */
    case 'Q':
	quiet = TRUE;
	break;


#if    HPLASERJET
    case 'r':	/* r selects output resolution */
    case 'R':
	hpres = (INT16)atoi(optstr+2);
	if ((hpres != 75) && (hpres != 100) && (hpres != 150) &&
	    (hpres != 300))
	    {
	    (void)sprintf(message,
		"option():  Output resolution not in [75,100,150,300] dpi; \
reset to %d",
		DEFAULT_RESOLUTION);
	    (void)warning(message);
	    hpres = DEFAULT_RESOLUTION;
	    }
	break;
#endif /* HPLASERJET */


#if    (APPLEIMAGEWRITER | EPSON | GOLDENDAWNGL100 | TOSHIBAP1351)
    case 'r':	/* r selects run-length coding of output */
    case 'R':
	runlengthcode = TRUE;
	break;
#endif /* (APPLEIMAGEWRITER | EPSON | GOLDENDAWNGL100 | TOSHIBAP1351) */


#if    CANON_A2

#ifdef CANON_TEST
    case 's':	/* pixel size limit to force character reloading */
    case 'S':
	size_limit = (UNSIGN16)atoi(optstr+2);
	break;
#endif /* CANON_TEST */

#endif /* CANON_A2 */

#if    POSTSCRIPT
    case 's':	/* pixel size limit to force character reloading */
    case 'S':
	size_limit = (UNSIGN16)atoi(optstr+2);
	break;
#endif

#if    EPSON
    case 't':
    case 'T':

#if    HIRES
	twice_a_line = TRUE;
#endif /* HIRES */

	break;
#endif /* EPSON */


#if    CANON_A2

#ifdef CANON_TEST
    case 'u':
    case 'U':
	merit_fact = (UNSIGN16)atoi(optstr+2);
	break;

    case 'v':
    case 'V':
	stor_limit = (UNSIGN32)atoi(optstr+2);
	break;
#endif /* CANON_TEST */

#endif /* CANON_A2 */

#if    POSTSCRIPT
    case 'v':	/* vmbug -- reload fonts on each page */
    case 'V':
	ps_vmbug = TRUE;
	break;
#endif /* POSTSCRIPT */


    case 'x':
    case 'X':
	leftmargin = inch(optstr+2);
	break;


    case 'y':
    case 'Y':
	topmargin = inch(optstr+2);
	break;

#if    (OS_TOPS20 | BSD42)
    case 'z':
    case 'Z':
	spool_output = TRUE;	/* offer to send output to spooler */
	break;
#endif /* (OS_TOPS20 | BSD42) */

    default:
	(void)usage(stderr);
	(void)sprintf(message,"option():  %s is not a legal switch", optstr);
	(void)fatal(message);
    }
}