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
|
#include <signal.h>
#include "defs.h"
#include "global.h"
#define ChangeFlag(bool) ((bool) = (bool)?FALSE:TRUE)
static BOOLEAN stdindvi = FALSE;
void
sigabort(sig)
int sig;
{
AbortRun(2);
}
/*
* decode args and read fontdesc
*/
void
init_settings(argc, argv, fontdescfile)
int argc;
char *argv[];
char *fontdescfile;
{
int argind; /* argument index for flags */
int argdvi;
int nff = 0; /* number of fontdesc files */
char curname[STRSIZE]; /* current file name */
char *outfile = NULL;
char *tcp, *tcp1; /* temporary character pointers */
char *tmp;
int ch;
for (argind = 1; argind < argc; argind++) {
tcp = argv[argind];
if (*tcp == '-') {
switch (*++tcp) {
case 'D': /* D defines a variable */
if (++argind >= argc)
Fatal("No argument following -D\n");
arg_define(argv[argind]);
break;
case 'F': /* F selects different fontdesc */
if (++argind >= argc)
Fatal("No argument following -F\n");
nff++;
break;
case 'K': /* remove comments from included PS files */
ChangeFlag(G_removecomments);
break;
#ifdef MSDOS
case 'L': /* L truncate file name to 8 characters */
ChangeFlag(G_longfontname);
break;
#endif
case 'R': /* R selects different resolution */
if (++argind >= argc)
Fatal("No argument following -R\n");
break;
#ifdef STATS
case 'S': /* print some statistics */
ChangeFlag(Stats);
break;
#endif
case 'c': /* next arg is an output dvi file */
if (++argind >= argc)
Fatal("No argument following -c\n");
outfile = argv[argind];
break;
case 'd': /* d selects Debug output */
if (*++tcp == '\0')
debug = DEBUGuser;
else
debug = DEBUGsys;
break;
case 'f': /* next arg is starting pagenumber */
if (++argind >= argc ||
sscanf(argv[argind], "%d", &FirstPage) != 1)
Fatal("Argument is not a valid integer\n");
break;
case 'i': /* next arg is a PostScript prologue file */
if (++argind >= argc)
Fatal("No argument following -i\n");
break;
case 'l': /* l prohibits logging of errors */
G_logging = -1;
break;
#ifdef USEGLOBALMAG
case 'm': /* specify magnification to use */
switch(*++tcp) {
case '\0': /* next arg is a magnification to use */
if (++argind >= argc ||
sscanf(argv[argind], "%d", &usermag) != 1)
Fatal("Argument is not a valid integer\n", 0);
break;
case '0': usermag = 1000; break;
case 'h': usermag = 1095; break;
case '1': usermag = 1200; break;
case '2': usermag = 1440; break;
case '3': usermag = 1728; break;
case '4': usermag = 2074; break;
case '5': usermag = 2488; break;
default: Fatal("%c is a bad mag step\n", *tcp);
}
break;
#endif
case 'n': /* next arg is number of copies to print */
if (++argind >= argc ||
sscanf(argv[argind], "%d", &ncopies) != 1)
Fatal("Argument is not a valid integer\n");
break;
case 'o': /* next arg is a PostScript command to send */
if (++argind >= argc)
Fatal("No argument following -o\n");
dev_arg('o', argv[argind]);
break;
case 'p': /* p prohibits pre-font loading */
ChangeFlag(PreLoad);
if (PreLoad == FALSE)
Reverse = FALSE; /* must then process in forward order */
break;
case 'q': /* quiet operation */
ChangeFlag(G_quiet);
break;
case 'r': /* don't process pages in reverse order */
ChangeFlag(Reverse);
break;
case 's': /* next arg is a PostScript setup file */
if (++argind >= argc)
Fatal("No argument following -s\n");
break;
case 't': /* next arg is ending pagenumber */
if (++argind >= argc ||
sscanf(argv[argind], "%d", &LastPage) != 1)
Fatal("Argument is not a valid integer\n");
break;
case 'w': /* don't print out warnings */
ChangeFlag(G_nowarn);
break;
default:
usage(*tcp);
}
} else
break;
}
/* dvifilename, dvidirpath, dvifp, (rootname, G_Logname) are set */
if (argind < argc) {
tcp = rindex(argv[argind], DIR_SEP); /* split into directory + file name */
if (tcp == NULL) {
dvidirpath[0] = '\0';
tcp = argv[argind];
} else {
(void)strcpy(dvidirpath, argv[argind]);
dvidirpath[tcp-argv[argind]+1] = '\0';
tcp += 1;
}
(void)strcpy(curname, tcp);
tcp1 = rindex(tcp, '.'); /* split into file name + extension */
if (tcp1 == NULL) {
(void)strcpy(rootname, curname); /* not used now */
(void)strcat(curname, ".dvi");
} else {
*tcp1 = '\0';
(void)strcpy(rootname, curname); /* not used now */
*tcp1 = '.';
}
(void)strcpy(dvifilename, dvidirpath);
(void)strcat(dvifilename, curname);
if ((dvifp = BINARYOPEN(dvifilename)) == NULL)
Fatal("can't find DVI file \"%s\"", dvifilename);
/* not used now */
(void)strcpy(G_Logname, rootname);
(void)strcat(G_Logname, ".log");
} else { /* get dvi file from stdin */
dvidirpath[0] = '\0';
if ((tmp = getenv("TMP")) == NULL)
tmp = TMP;
(void)strcpy(dvifilename, tmp);
(void)mktemp(strcat(dvifilename, DVITEMPLATE));
(void)strcpy(rootname, dvifilename); /* not used now */
(void)strcat(dvifilename, ".dvi");
if ((dvifp = BINARYWOPEN(dvifilename)) == NULL)
Fatal("can't create DVI file for stdin");
stdindvi = TRUE;
(void)signal(SIGHUP, sigabort);
(void)signal(SIGINT, sigabort);
#ifdef MSDOS
setmode(fileno(stdin), O_BINARY);
#endif
for (; !ferror(stdin) && (ch = getchar()) != EOF; )
(void)putc(ch, dvifp);
if (ferror(stdin))
Fatal("can't input DVI from stdin");
(void)fseek(dvifp, 0L, 0);
/* not used now */
(void)strcpy(G_Logname, "dvi2.log");
}
if (nff == 0)
read_fontdesc(fontdescfile, TRUE);
argdvi = argind;
for (argind = 1; argind < argdvi; argind++)
switch (*(argv[argind]+1)) {
case 'F': /* F selects different fontdesc */
arg_fontdesc(argv[++argind]);
break;
case 'R': /* R selects different resolution */
resolution = atoi(argv[++argind]);
break;
case 'i': /* next arg is a PostScript prologue file */
add_include(argv[++argind], TRUE);
break;
case 's': /* next arg is a PostScript setup file */
add_setup(argv[++argind], TRUE);
break;
}
if (outfile == NULL) {
outfp = stdout;
#ifdef MSDOS
setmode(fileno(outfp), O_BINARY);
#endif
} else if ((outfp = BINARYWOPEN(outfile)) == NULL)
Fatal("can't write to output file \"%s\"", outfile);
}
usage(c)
char c;
{
(void)fprintf(stderr, "%c is not a legal flag\n", c);
(void)fprintf(stderr, "Usage: %s %s\n\t%s\n\t%s\n\t%s\n",
G_progname,
"[-d] [-f n] [-i file] [-l] [-m{0|h|1|2|3|4|5}] [-m mag]",
"[-n n] [-o option] [-q] [-r] [-s file] [-t n] [-w]",
"[-D var=val] [-F fontdesc] [-K] [-L] [-R resolution] [-S]",
"[dvifile]");
(void)fprintf(stderr, "%s\n", version);
AbortRun(2);
}
/*-->AbortRun*/
/**********************************************************************/
/*************************** AbortRun *******************************/
/**********************************************************************/
void
AbortRun(code)
int code;
{
if (stdindvi)
(void)unlink(dvifilename);
exit(code);
}
/*-->AllDone*/
/**********************************************************************/
/****************************** AllDone ******************************/
/**********************************************************************/
void
AllDone()
{
struct font_entry *p;
dev_finish();
if (!G_quiet)
(void)fprintf(stderr,"\n");
#ifdef STATS
if (Stats) {
(void)fprintf(stderr, "Total chars diff chars raster bytes\n");
(void)fprintf(stderr, " # %% # %% # %%\n");
(void)fprintf(stderr, "------- --- ------ --- ----- ---\n");
for (p = hdfontent; p != NULL; p = p->next) {
(void)fprintf(stderr, "%7d%4d", p->ncts, 100*p->ncts/Stnc);
if (Sndc != 0)
(void)fprintf(stderr, "%9d%4d", p->ncdl, 100*p->ncdl/Sndc);
else
(void)fprintf(stderr, "%9d --", p->ncdl);
if (Snbpxl != 0)
(void)fprintf(stderr, "%8d%4d", p->nbpxl, 100*p->nbpxl/Snbpxl);
else
(void)fprintf(stderr, "%8d --", p->nbpxl);
(void)fprintf(stderr, " %s\n", p->name);
}
(void)fprintf(stderr, "\nTotal number of characters typeset: %d\n", Stnc);
(void)fprintf(stderr, "Number of different characters downloaded: %d\n", Sndc);
(void)fprintf(stderr, "Number of bytes of raster data downloaded: %d\n", Snbpxl);
(void)fprintf(stderr, "Optimal # of bytes of raster data: %d\n", Sonbpx);
}
#endif
AbortRun(G_errenc ? 1 : 0);
}
/*-->Fatal*/
/**********************************************************************/
/****************************** Fatal *******************************/
/**********************************************************************/
/* VARARGS1 */
void
Fatal(fmt, a, b, c) /* issue a fatal error message */
char *fmt; /* format */
char *a, *b, *c; /* arguments */
{
if (G_logging == 1 && G_logfile) {
(void)fprintf(G_logfp, "%s: FATAL-- ", G_progname);
(void)fprintf(G_logfp, fmt, a, b, c);
(void)fprintf(G_logfp, "\n");
}
(void)fprintf(stderr,"\n");
(void)fprintf(stderr, "%s: FATAL-- ", G_progname);
(void)fprintf(stderr, fmt, a, b, c);
(void)fprintf(stderr, "\n\n");
AbortRun(2);
}
/*-->Warning*/
/**********************************************************************/
/***************************** Warning ******************************/
/**********************************************************************/
/* VARARGS1 */
void
Warning(fmt, a, b, c) /* issue a warning */
char *fmt; /* format */
char *a, *b, *c; /* arguments */
{
if (G_logging == 0) {
if (G_logfile)
G_logfp = fopen(G_Logname, "w+");
else {
G_logfp = stderr;
if (G_nowarn) return;
}
G_logging = 1;
if (G_logfp == NULL) G_logging = -1;
}
G_errenc = TRUE;
if (G_logging == 1) {
(void)fprintf(G_logfp, fmt, a, b, c);
(void)fprintf(G_logfp,"\n");
}
}
|