void main (int argc, char *argv[]) { PAR par; double width, height; int c, i,j, longind; char *p; FILE *hd; char *shortopts = "a:c:d:D:f:h:l:m:o:O:p:P:r:s:S:V:w:x:X:y:Y:FHiqt"; struct option longopts[] = { {"mode", 1, NULL, 'm'}, {"pencolors", 1, NULL, 'c'}, {"pensizes", 1, NULL, 'p'}, {"pages", 1, NULL, 'P'}, {"quiet", 0, NULL, 'q'}, {"DPI", 1, NULL, 'd'}, {"DPI_x", 1, NULL, 'd'}, {"DPI_y", 1, NULL, 'D'}, {"PCL_formfeed",0, NULL, 'F'}, {"PCL_init", 0, NULL, 'i'}, {"PCL_Deskjet", 1, NULL, 'S'}, {"outfile", 1, NULL, 'f'}, {"logfile", 1, NULL, 'l'}, {"swapfile", 1, NULL, 's'}, {"aspectfactor",1, NULL, 'a'}, {"height", 1, NULL, 'h'}, {"width", 1, NULL, 'w'}, {"truesize", 0, NULL, 't'}, {"x0", 1, NULL, 'x'}, {"x1", 1, NULL, 'X'}, {"y0", 1, NULL, 'y'}, {"y1", 1, NULL, 'Y'}, {"xoffset", 1, NULL, 'o'}, {"yoffset", 1, NULL, 'O'}, #ifdef DOS {"VGAmodebyte",1, NULL, 'V'}, #endif {"help", 0, NULL, 'H'} }; preset_par (&par); width = par.width; /* Copy defaults */ height= par.height; if (argc == 1) { usage_msg (&par); exit (0); } while ((c=getopt_long(argc,argv, shortopts, longopts, &longind)) != EOF) switch (c) /* Easy addition of options ... */ { case 'a': par.aspectfactor = atof (optarg); if (par.aspectfactor <= 0.0) { fprintf(stderr,"Aspect factor: %g illegal\n", par.aspectfactor); exit(ERROR); } break; case 'c': i = strlen(optarg); if ((i<1) || (i>8)) { fprintf(stderr,"Invalid pencolor string: %s\n", optarg); exit(ERROR); } for (j=1, p = optarg; j <= i; j++, p++) { switch (*p-'0') { case xxBackground:par.pencolor[j] = xxBackground; break; case xxForeground:par.pencolor[j] = xxForeground; break; case xxRed: par.pencolor[j] = xxRed; break; case xxGreen: par.pencolor[j] = xxGreen; break; case xxBlue: par.pencolor[j] = xxBlue; break; case xxCyan: par.pencolor[j] = xxCyan; break; case xxMagenta: par.pencolor[j] = xxMagenta; break; case xxYellow: par.pencolor[j] = xxYellow; break; default : fprintf(stderr, "Invalid color of pen %d: %c\n", j, *p); exit(ERROR); } if (par.pencolor[j] != xxBackground && par.pencolor[j] != xxForeground) par.is_color = TRUE; } break; case 'd': switch (par.dpi_x = atoi (optarg)) { case 75: break; case 100: case 150: case 300: if ((!par.quiet) && (strcmp(par.mode,"pcl")==0)) fprintf(stderr, "Warning: DPI setting is no PCL level 3 feature!\n"); break; default: if ((!par.quiet) && (strcmp(par.mode,"pcl")==0)) fprintf(stderr, "Warning: DPI value %d is invalid for PCL mode\n", par.dpi_x); break; } break; case 'D': par.dpi_y = atoi (optarg); if ((!par.quiet) && (strcmp(par.mode,"pcl")==0)) fprintf(stderr,"Warning: %s\n", "Different DPI for x & y is invalid for PCL mode"); break; case 'F': par.formfeed = TRUE; break; case 'f': par.outfile = optarg; break; case 'h': par.height = height = atof (optarg); if (height < 0.1) fprintf(stderr, "Warning: Small height: %g mm\n", height); if (height > 300.0) fprintf(stderr, "Warning: Huge height: %g mm\n", height); break; case 'i': par.init_p = TRUE; break; case 'l': par.logfile = optarg; if (freopen(par.logfile, "w", stderr) == NULL) { perror ("Cannot open log file"); fprintf(stderr, "Error redirecting stderr\n"); fprintf(stderr, "Continuing with output to stderr\n"); } else Logfile_flag = TRUE; break; case 'm': par.mode = optarg; for (i=0; ModeList[i].mode != XX_TERM; i++) if (strcmp(ModeList[i].modestr, par.mode) == 0) break; if (ModeList[i].mode == XX_TERM) { fprintf(stderr, "'%s': unknown mode!\n", par.mode); fprintf(stderr,"Supported are: "); print_supported_modes(); Send_Copyright(); } break; case 'o': par.xoff = atof (optarg); if (par.xoff < 0.0) { fprintf(stderr,"Illegal X offset: %g < 0\n", par.xoff); exit(ERROR); } if (par.xoff > 210.0) /* About DIN A4 width */ { fprintf(stderr,"Illegal X offset: %g > 210\n", par.xoff); exit(ERROR); } break; case 'O': par.yoff = atof (optarg); if (par.yoff < 0.0) { fprintf(stderr,"Illegal Y offset: %g < 0\n", par.yoff); exit(ERROR); } if (par.yoff > 300.0) /* About DIN A4 height */ { fprintf(stderr,"Illegal Y offset: %g > 300\n", par.yoff); exit(ERROR); } break; case 'p': i = strlen(optarg); if ((i<1) || (i>8)) { fprintf(stderr,"Invalid pensize string: %s\n", optarg); exit(ERROR); } for (j=1, p = optarg; j <= i; j++, p++) { if ((*p < '0') || (*p > '9')) { fprintf(stderr,"Invalid size of pen %d: %c\n", j, *p); exit(ERROR); } par.pensize[j] = *p - '0'; if (par.maxpensize < par.pensize[j]) par.maxpensize = par.pensize[j]; } break; case 'P': if (*optarg == ':') { par.first_page = 0; optarg++; if (sscanf(optarg,"%d", &par.last_page) != 1) par.last_page = 0; } else switch (sscanf(optarg,"%d%*c%d", &par.first_page, &par.last_page)) { case 1: par.last_page = 0; break; case 2: break; default: fprintf(stderr,"Illegal page range.\n"); usage_msg (&par); exit(ERROR); } break; case 'q': par.quiet = TRUE; break; case 'r': par.rotation = atof(optarg); break; case 'S': par.specials = atoi (optarg); break; case 's': par.swapfile = optarg; break; case 't': par.truesize = TRUE; break; case 'V': par.vga_mode = atoi (optarg); break; case 'w': par.width = width = atof (optarg); if (width < 0.1) fprintf(stderr, "Warning: Small width: %g mm\n", width); if (width > 300.0) fprintf(stderr, "Warning: Huge width: %g mm\n", width); break; case 'x': par.x0 = atof (optarg); break; case 'X': par.x1 = atof (optarg); break; case 'y': par.y0 = atof (optarg); break; case 'Y': par.y1 = atof (optarg); break; case 'H': case '?': default: usage_msg (&par); exit (ERROR); } /** ** Place consistency checks here ** - I'm just not in the mood for writing them myself ... **/ if (par.dpi_y == 0) par.dpi_y = par.dpi_x; if (optind == argc) /* No filename: use stdin */ { autoset_outfile_name (&par, argv[optind]); action (&par, stdin); } else for ( ; optind < argc; optind++) { /* Multiple-input file handling: */ autoset_outfile_name (&par, argv[optind]); if ((hd=fopen (argv[optind], READ_BIN)) == NULL) { perror("hp2xx"); exit (ERROR); } action (&par, hd); /* action() closes file */ reset_par (&par); par.width = width; /* Restore width/height */ par.height= height; /* Changed in hpgl.c ! */ } if (*par.logfile) fclose (stderr); exit (0); }
static void process_opts (int argc, char* argv[], const char* shortopts, struct option longopts[], GEN_PAR* pg, IN_PAR* pi, OUT_PAR* po) { int c, i,j, longind; char *p, cdummy; while ((c=getopt_long(argc,argv, shortopts, longopts, &longind)) != EOF) switch (c) /* Easy addition of options ... */ { case 'a': pi->aspectfactor = atof (optarg); if (pi->aspectfactor <= 0.0) { Eprintf("Aspect factor: %g illegal\n", pi->aspectfactor); exit(ERROR); } break; case 'c': i = strlen(optarg); if ((i<1) || (i>8)) { Eprintf("Invalid pencolor string: %s\n", optarg); exit(ERROR); } for (j=1, p = optarg; j <= i; j++, p++) { switch (*p-'0') { case xxBackground:pt.color[j] = xxBackground; break; case xxForeground:pt.color[j] = xxForeground; break; case xxRed: pt.color[j] = xxRed; break; case xxGreen: pt.color[j] = xxGreen; break; case xxBlue: pt.color[j] = xxBlue; break; case xxCyan: pt.color[j] = xxCyan; break; case xxMagenta: pt.color[j] = xxMagenta; break; case xxYellow: pt.color[j] = xxYellow; break; default : Eprintf( "Invalid color of pen %d: %c\n", j, *p); exit(ERROR); } if (pt.color[j] != xxBackground && pt.color[j] != xxForeground) pg->is_color = TRUE; } pi->hwcolor=TRUE; break; case 'C': pi->center_mode = TRUE; break; case 'd': switch (po->dpi_x = atoi (optarg)) { case 75: break; case 100: case 150: case 300: case 600: if ((!pg->quiet) && (strcmp(pg->mode,"pcl")==0) && po->specials == 0) Eprintf( "Warning: DPI setting is no PCL level 3 feature!\n"); break; default: if ((!pg->quiet) && (strcmp(pg->mode,"pcl")==0)) Eprintf( "Warning: DPI value %d is invalid for PCL mode\n", po->dpi_x); break; } break; case 'D': po->dpi_y = atoi (optarg); if ((!pg->quiet) && strcmp(pg->mode,"pcl")==0 && po->specials==0) Eprintf("Warning: %s\n", "Different DPI for x & y is invalid for PCL mode"); break; case 'F': po->formfeed = TRUE; break; case 'f': po->outfile = optarg; break; case 'h': pi->height = atof (optarg); if (pi->height < 0.1) Eprintf("Warning: Small height: %g mm\n", pi->height); if (pi->height > 300.0) Eprintf("Warning: Huge height: %g mm\n", pi->height); break; case 'i': po->init_p = TRUE; break; case 'l': pg->logfile = optarg; if (freopen(pg->logfile, "w", stderr) == NULL) { PError ("Cannot open log file"); Eprintf("Error redirecting stderr\n"); Eprintf("Continuing with output to stderr\n"); } else Logfile_flag = TRUE; break; case 'm': pg->mode = optarg; for (i=0; ModeList[i].mode != XX_TERM; i++) if (strcmp(ModeList[i].modestr, pg->mode) == 0) break; if (ModeList[i].mode == XX_TERM) { Eprintf("'%s': unknown mode!\n", pg->mode); Eprintf("Supported are:\n\t"); print_supported_modes(); Send_Copyright(); } break; case 'n': pg->nofill = TRUE; break; case 'N': pg->no_ps = TRUE; break; case 'o': pi->xoff = atof (optarg); if (pi->xoff < 0.0) { Eprintf("Illegal X offset: %g < 0\n", pi->xoff); exit(ERROR); } if (pi->xoff > 210.0) /* About DIN A4 width */ { Eprintf("Illegal X offset: %g > 210\n", pi->xoff); exit(ERROR); } break; case 'O': pi->yoff = atof (optarg); if (pi->yoff < 0.0) { Eprintf("Illegal Y offset: %g < 0\n", pi->yoff); exit(ERROR); } if (pi->yoff > 300.0) /* About DIN A4 height */ { Eprintf("Illegal Y offset: %g > 300\n", pi->yoff); exit(ERROR); } break; case 'p': i = strlen(optarg); if ((i<1) || (i>8)) { Eprintf("Invalid pensize string: %s\n", optarg); exit(ERROR); } for (j=1, p = optarg; j <= i; j++, p++) { if ((*p < '0') || (*p > '9')) { Eprintf("Invalid size of pen %d: %c\n", j, *p); exit(ERROR); } pt.width[j] = *p - '0'; if (pg->maxpensize < pt.width[j]) pg->maxpensize = pt.width[j]; } pi->hwsize=TRUE; break; case 'P': if (*optarg == ':') { pi->first_page = 0; optarg++; if (sscanf(optarg,"%d", &pi->last_page) != 1) pi->last_page = 0; } else switch (sscanf(optarg,"%d%c%d", &pi->first_page, &cdummy, &pi->last_page)) { case 1: pi->last_page = pi->first_page; break; case 2: if (cdummy == ':') { pi->last_page = 0; break; } /* not ':' Syntax error -- drop through */ case 3: if (cdummy == ':') break; /* not ':' Syntax error -- drop through */ default: Eprintf("Illegal page range.\n"); usage_msg (pg, pi, po); exit(ERROR); } break; case 'q': pg->quiet = TRUE; break; case 'r': pi->rotation = atof(optarg); break; case 'S': po->specials = atoi (optarg); break; case 's': pg->swapfile = optarg; break; case 't': pi->truesize = TRUE; break; case 'V': po->vga_mode = atoi (optarg); break; case 'w': pi->width = atof (optarg); if (pi->width < 0.1) Eprintf("Warning: Small width: %g mm\n", pi->width); if (pi->width > 300.0) Eprintf("Warning: Huge width: %g mm\n", pi->width); break; case 'v': Send_version(); exit (NOERROR); case 'x': pi->x0 = atof (optarg); break; case 'X': pi->x1 = atof (optarg); break; case 'y': pi->y0 = atof (optarg); break; case 'Y': pi->y1 = atof (optarg); break; case 'H': case '?': default: usage_msg (pg, pi, po); exit (ERROR); } }
void usage_msg (PAR *p) { if (p->quiet) return; Send_ID(); #ifdef ATARI fprintf (stderr,"Usage:\tdouble-click on HP2XX.TTP, type parameters into\n"); fprintf (stderr,"\tcommand-line with following syntax:\n"); fprintf (stderr,"\t[options] [hpglfile]\n"); fprintf (stderr,"\n\t(if command-line offers not enough space for all parameters\n"); fprintf (stderr,"\tuse a command-line interpreter for starting HP2xx)\n"); #else fprintf (stderr,"Usage:\thp2xx [options] [file1 [file2 ...]]\n"); #endif /* ATARI */ fprintf (stderr,"\tUnix: Filter usage (.. | hp2xx -q -f- [options] | ..) ok\n"); Wait(); fprintf (stderr,"\nOpt fmt defaults\tComment:\n"); fprintf (stderr, "---------------------------------------------------------------------------\n"); fprintf (stderr,"-m strg %s\t\tMode ", p->mode); print_supported_modes(); fprintf (stderr,"-f strg (auto gen.)\tName of output file ('-' = to stdout)\n"); fprintf (stderr,"-l strg (stderr)\tName of log file\n"); fprintf (stderr,"-p strg %1d%1d%1d%1d%1d%1d%1d%1d\tPensize(s) (in 1/10 mm (mf,ps) or dots (rest)).\n", p->pensize[1], p->pensize[2], p->pensize[3], p->pensize[4], p->pensize[5], p->pensize[6], p->pensize[7], p->pensize[8]); fprintf (stderr,"\t\t\t\"strg\" must consist of 1 to 8 digits '0'-'9'\n"); fprintf (stderr,"-c strg %1d%1d%1d%1d%1d%1d%1d%1d\tPen color(s) (see manual for details).\n", p->pencolor[1], p->pencolor[2], p->pencolor[3], p->pencolor[4], p->pencolor[5], p->pencolor[6], p->pencolor[7], p->pencolor[8]); fprintf (stderr,"-P n:n %d:%d\t\tPage range (0:0 = all pages).\n", p->first_page, p->last_page); fprintf (stderr,"-q %s\t\tQuiet mode (no diagnostics)\n", FLAGSTATE(p->quiet)); fprintf (stderr,"-r float%5.1f\t\tRotation angle [deg]. -r90 = landscape\n", p->rotation); fprintf (stderr,"-s strg %s\tName of swap file\n", p->swapfile); fprintf (stderr,"\nBitmap controls:\n"); fprintf (stderr,"-d int %d\t\tDPI value for x or x&y, if -D unused.\n", p->dpi_x); fprintf (stderr,"-D int %d\t\tDPI value for y ONLY\n", p->dpi_x); /* x, not y! */ Wait(); fprintf (stderr,"\nPCL-exclusive options:\n"); fprintf (stderr,"-i %s\tPre-initialize printer\n", FLAGSTATE (p->init_p)); fprintf (stderr,"-F %s\tSend a FormFeed at end\n", FLAGSTATE(p->formfeed)); fprintf (stderr,"-S int %d\tUse Deskjet special commands (0=off, 1=B/W, 3=CMY, 4=CMYK)\n", p->specials); fprintf (stderr,"NOTE: \tOnly valid for -d: 300/150/100/75; -D invalid!\n"); fprintf (stderr,"\nPCL / PostScript / Preview options:\n"); fprintf (stderr,"-o float %5.1f\tX offset [mm] of picture\n", p->xoff); fprintf (stderr,"-O float %5.1f\tY offset [mm] of picture\n", p->yoff); fprintf (stderr,"\nSize controls:\n"); fprintf (stderr,"-a float %5.1f\tAspect factor (x/y correction). Valid: > 0.0\n", p->aspectfactor); fprintf (stderr,"-h float %5.1f\tHeight [mm] of picture\n",p->height); fprintf (stderr,"-w float %5.1f\tWidth [mm] of picture\n",p->width ); fprintf (stderr,"-t %s\tShow true HPGL size. Disables -a -h -w !\n", FLAGSTATE (p->truesize)); fprintf (stderr,"-x float -\tManual HPGL-coord range presetting: x0\n"); fprintf (stderr,"-X float -\tManual HPGL-coord range presetting: x1\n"); fprintf (stderr,"-y float -\tManual HPGL-coord range presetting: y0\n"); fprintf (stderr,"-Y float -\tManual HPGL-coord range presetting: y1\n"); #ifdef DOS fprintf (stderr,"\n-V int %d\tVGA mode byte (decimal). Change at own risk!\n", p->vga_mode); #endif Wait(); fprintf (stderr,"Corresponding long options:\n\n"); fprintf (stderr, "hp2xx [--mode] [--colors] [--pensizes] [--pages] [--quiet]\n"); fprintf (stderr,"\t[--width] [--height] [--aspectfactor] [--truesize]\n"); fprintf (stderr,"\t[--x0] [--x1] [--y0] [--y1] [--xoffset] [--yoffset]\n"); fprintf (stderr,"\t[--DPI] [--DPI_x] [--DPI_y]\n"); fprintf (stderr,"\t[--outfile] [--logfile] [--swapfile]\n"); fprintf (stderr,"\t[--PCL_formfeed] [--PCL_init] [--PCL_Deskjet]\n"); #ifdef DOS fprintf (stderr,"\t[--VGAmodebyte]"); #endif fprintf (stderr,"\t[--help]\n"); #ifdef PURE_C fprintf(stderr,"\nPress RETURN key\n"); getchar(); #endif }