Beispiel #1
0
int	main (int argc, char *argv[])
{
GEN_PAR	Pg;
IN_PAR	Pi;
OUT_PAR	Po;
int	i;

char	*shortopts = "a:c:d:D:f:h:l:m:o:O:p:P:r:s:S:V:w:x:X:y:Y:CFHinqtvN";
struct	option longopts[] =
{
	{"mode",	1, NULL,	'm'},
	{"pencolors",	1, NULL,	'c'},
	{"pensizes",	1, NULL,	'p'},
	{"pages",	1, NULL,	'P'},
	{"quiet",	0, NULL,	'q'},
	{"nofill",	0, NULL,	'n'},
	{"no_ps",	0, NULL,	'N'},

	{"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'},
	{"center",	0, NULL,	'C'},

#ifdef DOS
	{"VGAmodebyte",	1, NULL,	'V'},
#endif
	{"help",	0, NULL,	'H'},
	{"version",	0, NULL,	'v'},
	{NULL,		0, NULL,	'\0'}
};


  preset_par (&Pg, &Pi, &Po);
  if (argc == 1)
  {
	usage_msg (&Pg, &Pi, &Po);
	exit (ERROR);
  }
#ifdef WIN32
   /* set stdin and stdout to binary mode: */
   _setmode( _fileno(stdin), _O_BINARY );
   _setmode( _fileno(stdout), _O_BINARY );
#endif /* WIN32 */
  process_opts (argc, argv, shortopts, longopts, &Pg, &Pi, &Po);

/**
 ** Determine internal mode code
 **/

  for (i=0; ModeList[i].mode != XX_TERM; i++)
/*	if (strncmp(Pg.mode, ModeList[i].modestr,
		strlen(ModeList[i].modestr)) == 0)*/
	if (strcmp(Pg.mode, ModeList[i].modestr)==0)
	{
		Pg.xx_mode = ModeList[i].mode;
		break;
	}
/**
 ** Place consistency checks & adjustments here if you like
 **/

  if (Po.dpi_y == 0)
	Po.dpi_y = Po.dpi_x;

/**
 ** Action loop over all input files
 **/

  if (optind == argc)		/* No  filename: use stdin	*/
  {
	Pi.in_file = "-";
	autoset_outfile_name (Pg.mode, Pi.in_file, &Po.outfile);
	action_oldstyle (&Pg, &Pi, &Po);
  }
  else	for ( ; optind < argc; optind++)
	{			/* Multiple-input file handling: */
		Pi.in_file = argv[optind];
		autoset_outfile_name (Pg.mode, Pi.in_file, &Po.outfile);
		action_oldstyle (&Pg, &Pi, &Po);
		reset_par (&Pi);
	}

  cleanup (&Pg, &Pi, &Po);
  if (*Pg.logfile)
	fclose (stderr);
  return NOERROR;
}
Beispiel #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);
}