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

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "globals.h"

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

/*
 * Put the selected options into global variables
*/

getoptions(argc, argv, envp, bitname, dviname, usgname,
   pcllevel, numcopies, device, maxdown, outreverse, resolution, twosided)
int	argc;
char	**argv;
char	**envp;
char    bitname[];
char    dviname[];
char    usgname[];
short	*pcllevel;
short	*numcopies;
short	*device;
short	*maxdown;
bool	*outreverse;
short	*resolution;
short	*twosided;
{ 
  	char		buffer[1024];
  	char		*bufptr;
  	char		*strptr;
	int		k;
	int		c, errflag=0;
	extern char	*optarg;
	extern int	optind;

	strcpy(bitname,"");
	verbose = FALSE;

	while ((c = getopt(argc, argv, "12345c:d:f:lmo:p:rR:s:tvx:X:y:?")) != EOF)

	switch (c) {
	case '1':			/* PCL level 1 */
	case '2':			/* PCL level 2 */
	case '3':			/* PCL level 3 */
	case '4':			/* PCL level 4 */
	case '5':			/* PCL level 5 */
		*pcllevel = -(short)atoi(argv[optind-1]);
		break;
	case 'c':			/* Number of copies of each page */
		if((*numcopies = (short)atoi(optarg)) <= 0)
			*numcopies = 1;
		break;
	case 'd':			/* Specify output device */
		if(strcmp(optarg,"lj+") == 0)
		  *device = DEV_LJPLUS;
		else if (strcmp(optarg,"lj2") == 0)
		  *device = DEV_LJ2;
		else if (strcmp(optarg,"lj2d") == 0)
		  *device = DEV_LJ2D;
		else if (strcmp(optarg,"lj2p") == 0)
		  *device = DEV_LJ2P;
		else if (strcmp(optarg,"lj3si") == 0){
		  *device = DEV_LJ3SI;
		  *pcllevel = 5;
		}
		else if (strcmp(optarg,"lj3p") == 0){
		  *device = DEV_LJ3P;
		  *pcllevel = 5;
		}
		else if (strcmp(optarg,"pj") == 0)
		  *device = DEV_PJ;
		else if (strcmp(optarg,"pjxl") == 0)
		  *device = DEV_PJXL;
		break;
	case 'f':			/* Max number of downloadable fonts */
		
		if((*maxdown = (short)atoi(optarg)) < 0)
			*maxdown = 32;
		break;
	case 'l':			/* Landscape mode flag */
		landscape = TRUE;
		break;
	case 'm':			/* Manual feed flag */
		manualfeed = TRUE;
		break;
	case 'o':			/* Output file name */
		strcpy(bitname, optarg);
		break;
	case 'p':			/* Max number of output pages */
		if((maxpages = atoi(optarg)) <= 0)
			maxpages = MAXPAGES;
		break;
	case 'r':			/* Reverse output order flag */
		*outreverse *= *outreverse;
		break;	
	case 'R':			/* Set PCL resolution */
		*resolution = (short)atoi(optarg);
		break;	
	case 's':			/* Start page */
		startvals = 0;
		startthere[0] = FALSE;
        	strcpy(buffer,optarg);
        	bufptr = buffer;
		k = 0;
		do { 
			if(*bufptr == '*') { 
				startthere[k] = FALSE;
				bufptr++;
			}
			else { 
				startthere[k] = TRUE;
				startcount[k] = (long)getcount(bufptr);
			}

			if((k<9) && (*bufptr == '.')) { 
				k++;
				bufptr++;
			}
			else 
				if((*bufptr==' ')||(*bufptr=='\0'))
					startvals = k;
			else { 
				startvals = 0;
				k = 0;
			}
		} while(startvals != k);
		break;
	case 't':			/* Two-sided mode flag */
		*twosided = TRUE;
		break;
	case 'v':			/* Verbose mode flag */
		verbose = TRUE;
		break;
	case 'x':			/* Left offset for odd sides */
		h_offset = dim_to_dots(optarg, resolution);
		break;
	case 'X':			/* Left offset for even sides */
		r_offset = dim_to_dots(optarg, resolution);
		break;
	case 'y':			/* Vertical top offset */
		v_offset = dim_to_dots(optarg, resolution);
		break;
	case '?':
		errflag++;
		break;
	default:
		break;
	}

	if (errflag) {
		fprintf(stderr, "\nUsage: %s [-12345lmrt] [-c <copies>] [-f <fonts>] [-o <outfile>]\n       [-p <pages>] [-R resolution] [-s <startpage>] [-x <offset>]\n       [-X <offset>] [-y <offset>] [<infile>]\n", argv[0]);
		exit(2);
	}

	/*
 	 * Allow for input file names of type
	 * xx.dvi, xx.yy.dvi, xx, or xx.yy
	 * Append ".dvi" if it's not already there.
	 *
	 * Get the .dvi file name from the input line
	 */
	strcpy(dviname, argv[optind]);
	if((strstr(dviname, DVIFILE_SUFFIX)) == NULL)
		strcat(dviname, DVIFILE_SUFFIX);

	/*
  	 * Allow for output file names of type;
 	 * xx.pcl, xx.yy.pcl, xx, or xx.yy
 	 * Append ".pcl" if it's not already there.
	 *
	 * The .dvi file name was input via the -o option.
	if((strstr(bitname, BITFILE_SUFFIX)) == NULL)
		strcat(bitname, BITFILE_SUFFIX);
 	 */

	if(verbose) { 
		strcpy(usgname, dviname);
		strcat(usgname, USGFILE_SUFFIX);
	}

	if(*twosided) { 
		if(!startvals && !(startcount[0] % 2)) { 
			if(startthere[0])
				startcount[0]--;
			else { 
				startthere[0] = TRUE;
				startcount[0] = 1;
			}
		}
		if(maxpages % 2)
			maxpages++;
		o_offset = h_offset;
		e_offset = r_offset;
	}

	if(verbose) { 
		fprintf(stderr,"Options selected:\n");
		fprintf(stderr,"Starting page:	 ");
		for(k=0; k<=startvals; k++) { 
			if(startthere[k])
				fprintf(stderr,"%d",startcount[k]);
			else
				fprintf(stderr,"*");
			if(k<startvals)
				fprintf(stderr,".");
			else
				fprintf(stderr,"\n");
		}
		fprintf(stderr,"Maximum numbers of pages:	%d\n",maxpages);
		fprintf(stderr,"Number of copies:		%d\n",*numcopies);
		if(*twosided)
			fprintf(stderr,"Two-sided printing\n");
		if(manualfeed)
			fprintf(stderr,"Feed pages maually\n");
	}
}