summaryrefslogtreecommitdiff
path: root/systems/os2/dviware/hp-deskjet/dviinit.h
blob: 58423e7fffb2d0a18800c227ac1291c543c5bb60 (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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/* -*-C-*- dviinit.h */
/*-->dviinit*/
/**********************************************************************/
/****************************** dviinit *******************************/
/**********************************************************************/

void
dviinit(filestr)		/* initialize DVI file processing */
char *filestr;			/* command line filename string  */
{
    int i;			/* temporary */
    INT16 k;			/* index in curpath[] and curname[] */
    char* tcp;			/* temporary string pointers */
    char* tcp1;			/* temporary string pointers */

#if    OS_UNIX
/***********************************************************************
Unix allows binary I/O on stdin and stdout; most other operating systems
do not.  In order  to support this,  we use the  convention that a  null
filestr (NOT  a (char*)NULL)  means the  dvifile is  on stdin,  and  the
translated output is on stdout.  Error logging will be to dvixxx.err  or
dvixxx.dvi-err.  Because random access is required of the dvifile, stdin
may NOT be a pipe; it must be a disk file.
***********************************************************************/
#define NO_FILENAME (filestr[0] == '\0')
#endif

#if    CANON_A2

#ifdef CANON_TEST
    char modestring[10];	/* for dynamic fopen() mode string */
#endif /* CANON_TEST */

#endif

#if    (OS_TOPS20 | OS_VAXVMS)
    char* tcp2;			/* temporary string pointers */
#endif

    for (k = 0; k < 10; ++k)
	tex_counter[k] = (INT32)0L;

    fontptr = (struct font_entry *)NULL;
    hfontptr = (struct font_entry *)NULL;
    pfontptr = (struct font_entry *)NULL;
    fontfp = (FILE *)NULL;
    cache_size = 0;
    nopen = 0;

    /***********************************************************
    Set up file names and open dvi and plot files.  Simple
    filename parsing assumes forms like:

    Unix:	name
		name.ext
		/dir/subdir/.../subdir/name
		/dir/subdir/.../subdir/name.ext
    TOPS-20:	any Unix style (supported by PCC-20)
		<directory>name
		<directory>name.ext
		<directory>name.ext.gen
		device:<directory>name
		device:<directory>name.ext
		device:<directory>name.ext.gen
		[directory]name
		[directory]name.ext
		[directory]name.ext.gen
		device:[directory]name
		device:[directory]name.ext
		device:[directory]name.ext.gen
		logname:name
		logname:name.ext
		logname:name.ext.gen

    The Unix style should work  under IBM PC DOS (backslash  can
    usually be  replaced for  forward  slash), and  the  TOPS-20
    style contains VAX VMS as  a subset.  Fancier TOPS-20  names
    are possible (control-V quoting of arbitrary characters, and
    attributes), but they are rare enough that we do not support
    them.  For  TOPS-20  and  VAX VMS,  generation  numbers  are
    recognized as a digit following  the last dot, and they  are
    preserved for the DVI file only.  For the output files,  the
    highest generation  will always  be  assumed.  This  is  for
    convenience with the  TOPS-20 TeX  implementation, which  on
    completion types  in a  command "TeXspool:  foo.dvi.13"  and
    waits for the user to type a carriage return.

    We only  need  to  extract the  directory  path,  name,  and
    extension, so the parsing is simple-minded.

    ***********************************************************/

    tcp = strrchr(filestr,'/'); /* find end of Unix file path */

#if    (OS_ATARI | OS_PCDOS | OS_IBMOS2)
    if (tcp == (char*)NULL)	/* no Unix-style file path */
	tcp = strrchr(filestr, '\\');	/* try \dos\path\ */
#endif

#if    OS_TOPS20
    if (tcp == (char*)NULL)	/* no Unix-style file path */
    {
	tcp = strrchr(filestr, '>');	/* try <dir> */
	if (tcp == (char*)NULL)			/* no <dir> */
	    tcp = strrchr(filestr, ']');	/* try [dir] */
	if (tcp == (char*)NULL)			/* no [dir] */
	    tcp = strrchr(filestr, ':');	/* try logname: */
    }
#endif

#if    OS_VAXVMS
    if (tcp == (char*)NULL)	/* no Unix-style file path */
    {
	tcp = strrchr(filestr, ']');	/* try [dir] */
	if (tcp == (char*)NULL)			/* no [dir] */
	    tcp = strrchr(filestr, ':');	/* try logname: */
    }
#endif

    if (tcp == (char*)NULL)	/* no file path */
    {
	curpath[0] = '\0';	/* empty path */
	tcp = filestr;	/* point to start of name */
    }
    else			/* save path for later use */
    {
	k = (INT16)(tcp-filestr+1);
	(void)strncpy(curpath, filestr, (int)k);
	curpath[k] = '\0';
	tcp++;			/* point to start of name */
    }

    tcp1 = strrchr(tcp, '.');	/* find last dot in filename */

#if    (OS_TOPS20 | OS_VAXVMS)
    if ((tcp1 != (char*)NULL) && isdigit(*(tcp1+1)))
    {				/* then assume generation number */
	tcp2 = tcp1;		/* remember dot position */
	*tcp1 = '\0';		/* discard generation number */
	tcp1 = strrchr(tcp,'.');/* find last dot in filename */
	*tcp2 = '.';		/* restore dot */
    }
#endif

    if (tcp1 == (char*)NULL)
    {				/* no dot, so name has no extension */
	(void)strcpy(curname, tcp);	/* save name */
	tcp1 = strchr(tcp, '\0');	/* set empty extension */
    }
    else			/* save name part */
    {
	k = (INT16)(tcp1-tcp);
	(void)strncpy(curname, tcp, (int)k);
	curname[k] = '\0';
    }

    (void)strcpy(curext, tcp1);	/* save extension */


    /* DVI file must always have extension DVIEXT; supply one if
    necessary (e.g /u/jones/foo.dvi) */

    (void)strcpy(dviname, curpath);
    (void)strcat(dviname, curname);
    if (curext[0] == '\0')
	(void)strcat(dviname, DVIEXT);
    else
	(void)strcat(dviname, curext);

    /* Device output file is PATH NAME . DVIPREFIX OUTFILE_EXT (e.g.
       /u/jones/foo.dvi-alw) */

    (void)strcpy(dvoname, curpath);
    (void)strcat(dvoname, curname);
    (void)strcat(dvoname, ".");
    (void)strcat(dvoname, DVIPREFIX);
    (void)strcat(dvoname, OUTFILE_EXT);

    /* Font substitution file is PATH NAME SUBEXT (e.g.
       /u/jones/foo.sub).  We do not tell user (via stderr)
       about it until it is needed. */

    if (subfile[0] == '\0')	/* no -fsubfile; make default */
    {
	(void)strcpy(subfile, curpath);
	(void)strcat(subfile, curname);
	(void)strcat(subfile, subext);
    }


#if    OS_UNIX
    if (NO_FILENAME)
    {
	dvifp = stdin;		/* already open, so no DEBUG_OPEN call */
	if (fseek(dvifp,0L,0))
	{
	    (void)fprintf(stderr,
		"%s: Unable to fseek() on stdin--was it a pipe?\n",
		g_progname);
	    (void)EXIT(1);
	}
    }
    else
    {
	dvifp = FOPEN(dviname,RB_OPEN);
	DEBUG_OPEN(dvifp,dviname,RB_OPEN);
    }
#else

    dvifp = FOPEN(dviname,RB_OPEN);
    DEBUG_OPEN(dvifp,dviname,RB_OPEN);
#endif

    if (dvifp == (FILE*)NULL)
    {
	(void)sprintf(message,"dviinit(): %s: can't open [%s]",
	    g_progname, dviname);
	(void)fatal(message);
    }

    /* We try both
	PATH NAME . DVIPREFIX OUTFILE_EXT and
	     NAME . DVIPREFIX OUTFILE_EXT,
        in case the user does not have write access to the directory PATH */
    for (i = 1; i <= 2; ++i)		/* two tries here */
    {

#if    BBNBITGRAPH
	strcpy(dvoname,"stdout");	/* BitGraph always goes to stdout */
	plotfp = stdout;
#else /* NOT BBNBITGRAPH */

#if    OS_VAXVMS

#if    POSTSCRIPT
	plotfp = FOPEN(dvoname,WB_OPEN);
#else
	/* Create binary files for other devices; they cause less trouble
        with VMS spooler programs. */
	plotfp = FOPEN(dvoname,WB_OPEN,"rfm=fix","bls=512","mrs=512");
#endif /* POSTSCRIPT */

#else /* NOT OS_VAXVMS */

#if    OS_UNIX
	plotfp = NO_FILENAME ? stdout : FOPEN(dvoname,WB_OPEN);
#else
	plotfp = FOPEN(dvoname,WB_OPEN);
#endif /* OS_UNIX */

#endif /* OS_VAXVMS */

#endif /* BBNBITGRAPH */

#if    OS_UNIX
	if (!NO_FILENAME)
#endif

	DEBUG_OPEN(plotfp,dvoname,WB_OPEN);
	if (plotfp != (FILE*)NULL)
	    break;			/* open okay */
	if (i == 2)
	{
	    (void)strcpy(dvoname, curname);
	    (void)strcat(dvoname, ".");
	    (void)strcat(dvoname, DVIPREFIX);
	    (void)strcat(dvoname, OUTFILE_EXT);
	}
    }

    if (plotfp == (FILE*)NULL)
    {
	(void)sprintf(message,"dviinit(): %s: can't open [%s]",
	    g_progname, dvoname);
	(void)fatal(message);
    }

#if    OS_TOPS20
    /* Because of the PCC-20 arithmetic (instead of logical)
       shift bug wherein a constant expression (1<<35) evaluates
       to 0 instead of 400000,,000000, we must set CF_nud using a
       variable, instead of just using a constant */
    /* "ac1 = makefield(CF_nud,1);" */
    ac1 = 1;
    ac1 = makefield(CF_nud,ac1);
    setfield(ac1,CF_jfn,jfnof(fileno(plotfp)));	/* jfn */
    setfield(ac1,CF_dsp,FBbyv);	/* generation number index in fdb */
    ac2 = makefield(FB_ret,-1);
    ac3 = makefield(FB_ret,0);	/* set generation count to 0 (infinite) */
    (void)jsys(JSchfdb,acs);	/* ignore any errors */
#endif /* OS_TOPS20 */

#if    CANON_A2

#ifdef CANON_TEST

#if    OS_ATARI
    strcpy(tmoname,"\\ca2XXX\.");
#else
    strcpy(tmoname,"ca2XXXXXX");
#endif

    mktemp(tmoname);
    savefp = plotfp;
    (void)sprintf(modestring,"%s+",WB_OPEN);
    plotfp = FOPEN(tmoname, modestring);
    stor_total = 0;
#endif /* CANON_TEST */

#endif /* CANON_A2 */

    if (!quiet

#if    OS_UNIX
	&& !NO_FILENAME
#endif

    )
    {
	(void)fprintf(stderr,"[Input from DVI file %s]",dviname);
	NEWLINE(stderr);
	(void)fprintf(stderr,"[Output on file %s]",dvoname);
	NEWLINE(stderr);
    }

    if (strncmp(curpath,dvoname,strlen(curpath)) == 0)
	(void)strcpy(g_logname, curpath);	/* used PATH on output file */
    else
	g_logname[0] = '\0';		/* no PATH on output file */

#if    OS_UNIX
    if (NO_FILENAME)			/* use dvixxx as file prefix */
    {
	(void)strcpy(g_logname, "dvi");
	(void)strcat(g_logname, OUTFILE_EXT);
    }
#endif

    (void)strcat(g_logname, curname);
    (void)strcat(g_logname, ".");
    (void)strcat(g_logname, DVIPREFIX);

#if    (OS_ATARI | OS_PCDOS | OS_IBMOS2 | OS_UNIX)
    (void)strcat(g_logname, "err");
#endif

#if    (OS_TOPS20 | OS_VAXVMS)
    /* Force new generation; otherwise fopen(,"w+") reuses existing file */
    (void)strcat(g_logname, "err.-1");
#endif

    lmargin = (COORDINATE)(leftmargin*((float)XDPI));
    tmargin = (COORDINATE)(topmargin*((float)YDPI));

#if    (CANON_A2 | IMPRESS | HPJETPLUS)
    /* Printer has (0,0) origin at (XORIGIN,YORIGIN) near, but not at,
    upper left corner */
    lmargin -= XORIGIN;
    tmargin -= YORIGIN;
#endif /* (CANON_A2 | IMPRESS | HPJETPLUS) */

    if ((BYTE)nosignex(dvifp,(BYTE)1) != PRE)
	(void)fatal("dviinit(): PRE doesn't occur first--are you sure \
this is a DVI file?");

    i = (int)signex(dvifp,(BYTE)1);
    if (i != DVIFORMAT)
    {
	(void)sprintf(message,
	    "dviinit(): DVI format = %d, can only process DVI format %d files.",
	    i, (int)DVIFORMAT);
	(void)fatal(message);
    }
}