summaryrefslogtreecommitdiff
path: root/dviware/dvi2pcl/main.c
blob: d77b4d322f8869287c943f76af77f66805d5baba (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
/* $Log:	main.c,v $
 * Revision 0.8  92/11/23  19:46:49  19:46:49  bt (Bo Thide')
 * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support
 * 
 * Revision 0.7  92/11/13  02:41:34  02:41:34  bt (Bo Thide')
 * More bug fixes and improvements. Support for PaintJet XL
 * 
 * Revision 0.6  92/11/10  21:47:50  21:47:50  bt (Bo Thide')
 * Bug fixes. Added -R option. Better font handling.
 * 
 * Revision 0.5  92/11/09  16:25:37  16:25:37  bt (Bo Thide')
 * Rewrite of dospecial.c. Extended \special support
 * 
 * Revision 0.4  92/11/08  02:45:53  02:45:53  bt (Bo Thide')
 * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's.
 * 
 * Revision 0.3  92/08/24  12:45:44  12:45:44  bt (Bo Thide')
 * Fixed 8 bit (dc font) support.
 * 
 * Revision 0.2  92/08/23  17:28:58  17:28:58  bt (Bo Thide')
 * Source cleaned up.  Changed certain function calls.  Removed globals.
 * 
 * Revision 0.1  92/08/22  23:58:48  23:58:48  bt (Bo Thide')
 * First Release.
 *  */

#pragma COPYRIGHT "Bo Thide' and Helmut Kopka, 1992"
#include <stdio.h>
#include <string.h>
#include "globals.h"
#include "paths.h"
#include "pcl.h"

static char rcsid[] = "$Header: main.c,v 0.8 92/11/23 19:46:49 bt Exp $";

static char fatal_error[] = "This was a fatal error.\n";
static char copyright[] = "Copyright (c) Bo Thide' and Helmut Kopka, 1992.";

#ifdef TIMING
#include <sys/timeb.h>
#endif /* TIMING */

main(argc, argv, envp)
int	argc;
char	**argv;
char	**envp;
{
	char	bitname[NAMELENGTH];
	char	curname[NAMELENGTH];
	char	dviname[NAMELENGTH];
	char	usgname[NAMELENGTH];
	bool	outreverse=TRUE;
	short	device=DEV_LJPLUS;
	short	maxdown=MAXDOWN;
	short	numcopies=1;
	short	pcllevel=PCLLEVEL;
	short	resolution=RESOLUTION;
	short	twosided=FALSE;
	long	startloc=0;
	FILE	*bitfile;
	FILE	*dvifile;
	FILE	*resfile;
	FILE	*usgfile;

#ifdef TIMING
	struct timeb timebuffer;
	double  start_time, time;

        ftime(&timebuffer);
        start_time = (double)((timebuffer.time) + (timebuffer.millitm)/1000.0);
#endif /* TIMING */

	/* Get things started properly */
	initialize();

	/* Process all dvi2pcl options and construct the filenames. */
	getoptions(argc, argv, envp, bitname, dviname, usgname,
	  &pcllevel, &numcopies, &device, &maxdown, &outreverse,
	  &resolution, &twosided);

	/*
	 * Open the output bitfile or, if bitname is an empty string, stdout.
	 */
	if(strcmp(bitname, "") == 0) {
		bitfile = stdout;
	}
	else {
		if((bitfile = fopen(bitname,"w")) == NULL) {
			fprintf(stderr,"Cannot open the bit file %s for output.\n", bitname);
		exit(-1);
		}
	}

	/*
	 * Open the input dvifile or stdin.
	 */
	if(strcmp(dviname, DVIFILE_SUFFIX) == 0) {
		dvifile = stdin;
 	}
	else {
		if((dvifile = fopen(dviname,"r")) == NULL) {
			fprintf(stderr,"Cannot open the dvi file %s for input.\n", dviname);
		exit(-1);
		}
	}

	/*
	 * Open the input resident font info file
	 */
	strcpy(curname, respath);
	if((resfile = fopen(curname,"r")) == NULL) {
		fprintf(stderr,"Cannot open the resident font file %s for input.\n", curname);
		exit(-1);
	}

	/* Prescan the input file. */ 
	preamble(dvifile, resolution);
	startloc = skippages(bitfile, dvifile, pcllevel, resolution);	
	if(!inpostamble){
		/* If not in postamble, prescan the file up to maxpages */
		while(maxpages-- > 0){
			/* Prescan up to maxpages or postamble */
			prescanpage(bitfile, dvifile, pcllevel, resolution);
			if(inpostamble){
				postamble(dvifile);
				break;	/* font_def agreement */
      			}
			if(!betweenpages(dvifile, PRESCAN_ON))
				break;
    		}
	}

	/* Initialize the printer */
	fprintf(bitfile, PCL4_INIT_PRINTER);
	fprintf(bitfile, PCL4_COPIES, numcopies);
	fprintf(bitfile, PCL4_RESOLUTION, resolution);
	fprintf(bitfile, PCL5_PRINT_DIRECTION, 0);

	/* Download the defined fonts */
	cachefonts(bitfile, resfile, maxdown, device);

	/* Now do the main work */
	if(twosided)
		doodevpages(bitfile, dvifile, pcllevel, outreverse,
		  resolution, device);
	else
		doallpages(bitfile, dvifile, pcllevel, outreverse,
		  resolution, device);
	fprintf(bitfile, PCL4_CLEAN_PRINTER);

#ifdef TIMING
                ftime(&timebuffer);
                time = ((timebuffer.time) + (timebuffer.millitm)/1000.0)
                    -start_time;
                fprintf(stderr,"Time of complete run:		%.3lf sec,  %.3lf sec/page  (%.2lf ppm)\n",
		time, time/actualpagecount, (double)(actualpagecount*60)/time);
#endif /* TIMING */


	if(verbose){
		fprintf(stderr,"%s done.\n",argv[0]);
		if((usgfile = fopen(usgname,"w")) == NULL) {
			fprintf(stderr,"Cannot open the output file %s\n", usgname);
			exit(-1);
		}
		diagnostics(usgfile);
	}

	exit(0);
}
   
/*
 * Error and die routines.
 * Print error messages and exits.
 */

prerror(s)
char *s;
{
	fprintf(stderr,s);
	fprintf(stderr,fatal_error);
	fflush(stderr);
	exit(-1);
}

void sterror(s, st)
char *s;
char *st;
{
	fprintf(stderr,s, st);
	fprintf(stderr,fatal_error);
	fflush(stderr);
	exit(-1);
}

valerror(s,v)
char *s;
int  v;
{
	fprintf(stderr,s,v);
	fprintf(stderr,fatal_error);
	fflush(stderr);
	exit(-1);
}

valvalerror(s,u,v)
char *s;
int u,v;
{
	fprintf(stderr,s,u,v);
	fprintf(stderr,fatal_error);
	fflush(stderr);
	exit(-1);
}