Ejemplo n.º 1
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);
	}
}
Ejemplo n.º 2
0
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);
}