⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcl3opts.c

📁 openmeetings组件之GS openmeetings组件之GS openmeetings组件之GS
💻 C
📖 第 1 页 / 共 3 页
字号:
	  power *= 2;	  ip->first_colorant_planes++;	}      }    }    else {      emessage(31,	"This file contains a Configure Raster Data command with an\n"	"  illegal number of colorants (%d) and the following data:\n",	buffer[1]);      print_CRD(stderr, buffer);      errors++;    }  }  else {    emessage(32,      "This file contains a Configure Raster Data command with an\n"      "  unknown format (%d).\n",      (int)buffer[0]);    if (cmd->i > 2 && cmd->i == 2 + buffer[1]*6) {      imessage(stderr, 33, "  It *might* mean the following:\n");      print_CRD(stderr, buffer);      imessage(stderr, 34, "  This format is not supported by pcl3.\n");    }    errors++;  }  free(buffer);  return errors > 0? -1: 0;}/*****************************************************************************/static int action_old_quality(FILE *in, const pcl_Command *cmd, void *i){  CollectedInfo *ip = i;  ip->seen_old_quality = TRUE;  if (cmd->chars[1] == 'o') {    if (cmd->chars[2] == 'D') ip->fdata.depletion = cmd->i;    else if (cmd->chars[2] == 'Q') ip->fdata.shingling = cmd->i;  }  else if (cmd->chars[1] == 'r' && cmd->chars[2] == 'Q')    ip->fdata.raster_graphics_quality = cmd->i;  return 0;}/*****************************************************************************/static int action_quality(FILE *in, const pcl_Command *cmd, void *i){  CollectedInfo *ip = i;  ip->seen_new_quality = TRUE;  ip->fdata.print_quality = cmd->i;  return 0;}/*****************************************************************************/								/* NLS: 40 */static int action_colour(FILE *in, const pcl_Command *cmd, void *i){  CollectedInfo *ip = i;  if (!ip->CRD_active) {    switch (cmd->i) {      case -4:	ip->fdata.palette = pcl_CMYK; break;      case -3:	ip->fdata.palette = pcl_CMY; break;      case -1:	/*FALLTHROUGH*/      case 0:	/*FALLTHROUGH*/      case 1:	ip->fdata.palette = pcl_black; break;      case 3:	ip->fdata.palette = pcl_RGB; break;      default:	emessage(41, "This file uses a palette (%d) not supported by pcl3.\n",	  cmd->i);	return -1;    }    ip->fdata.number_of_colorants = abs(cmd->i);    {      int j;      for (j = 0; j < ip->fdata.number_of_colorants; j++) {	ip->fdata.colorant_array[j].hres = ip->fdata.colorant_array[j].vres =	  ip->fdata.colorant_array[0].hres;	ip->fdata.colorant_array[j].levels = 2;      }    }    ip->first_colorant_planes = 1;  }  return 0;}/*****************************************************************************/static int action_resolution(FILE *in, const pcl_Command *cmd, void *i){  CollectedInfo *ip = i;  ip->seen_RGR = TRUE;  if (!ip->CRD_active) {    int j;    for (j = 0; j < ip->fdata.number_of_colorants; j++) {      ip->fdata.colorant_array[j].hres =	ip->fdata.colorant_array[j].vres = cmd->i;      ip->fdata.colorant_array[j].levels = 2;    }  }  return 0;}/*****************************************************************************/static int action_end_raster(FILE *in, const pcl_Command *cmd, void *i){  CollectedInfo *ip = i;  if (cmd->chars[2] == 'B') ip->seen_ERG_B = TRUE;  else if (cmd->chars[2] == 'C') ip->seen_ERG_C = TRUE;  if (ip->seen_raster_data &&      memcmp(&ip->fdata, &ip->fdata_old, sizeof(pcl_FileData)) != 0) {    print_result(ip);    memcpy(&ip->fdata_old, &ip->fdata, sizeof(pcl_FileData));  }  ip->seen_raster_data = FALSE;  return 0;}/*****************************************************************************/typedef struct {  char cmd[4];  pcl_CommandInterpreter action;} ActionEntry;static ActionEntry action_table[] = {  {"%-X", &action_UEL},			/* Universal Exit Language */  {"&bT", &action_dry_time},		/* Set Dry Time */  {"&lA", &action_PageSize},		/* Page Size */  {"&lG", &action_destination},		/* Set Output Bin */  {"&lH", &action_source},		/* Media Source */  {"&lM", &action_media_type},		/* Media Type */  {"&lS", &action_duplex},		/* Simplex/Duplex Print */  {"*bM", &action_compression},		/* Raster Graphics Compression Method */  {"*bV", &action_raster_data},	    /* Transfer Raster Graphics Data by Plane */  {"*bW", &action_raster_data},	      /* Transfer Raster Graphics Data by Row */  {"*gW", &action_CRD},			/* Configure Raster Data */  {"*oD", &action_old_quality},		/* Set Raster Graphics Depletion */  {"*oM", &action_quality},		/* Print Quality */  {"*oQ", &action_old_quality},		/* Set Raster Graphics Shingling */  {"*rB", &action_end_raster},		/* End Raster Graphics (old) */  {"*rC", &action_end_raster},		/* End Raster Graphics (new) */  {"*rQ", &action_old_quality},		/* Raster Graphics Quality */  {"*rU", &action_colour},		/* Set Number of Planes Per Row */  {"*tR", &action_resolution}		/* Set Raster Graphics Resolution */};/*****************************************************************************/static int cmp_entries(const void *a, const void *b){  return    strncmp(((const ActionEntry *)a)->cmd, ((const ActionEntry *)b)->cmd, 3);}/*****************************************************************************/static int analyzer(FILE *in, const pcl_Command *cmd, void *i){  ActionEntry key;  const ActionEntry *entry;  CollectedInfo *ip = i;  /* Control codes */  if (cmd->kind == 1) {    if (cmd->chars[0] == '\0' &&	/* Guard against NULs somewhere else except initially */	!ip->seen_RGR && !ip->seen_CRD)      ip->fdata.NULs_to_send = cmd->i;    return 0;  }  /* Two-character escape sequences */  if (cmd->kind == 2) {    switch (cmd->chars[0]) {    case 'E':	/* Printer Reset */      {	/* Preserve some global data (mostly PJL state) across PCL Reset	   invocations */	unsigned int NULs_to_send = ip->fdata.NULs_to_send;	char *PJL_language = ip->fdata.PJL_language;	char *PJL_job = ip->fdata.PJL_job;	ip->CRD_active = FALSE;	ip->seen_raster_data = FALSE;	memset(&ip->fdata, 0, sizeof(pcl_FileData));	ip->fdata.colorant_array[0].hres =	  ip->fdata.colorant_array[0].vres = 75;	ip->fdata.colorant_array[0].levels = 2;	ip->fdata.number_of_colorants = 1;	ip->fdata.duplex = -1;	ip->fdata.dry_time = -1;	ip->fdata.raster_graphics_quality = -1;	ip->fdata.shingling = -1;	ip->fdata.NULs_to_send = NULs_to_send;	ip->fdata.PJL_language = PJL_language;	ip->fdata.PJL_job = PJL_job;      }      break;    default:      return 1;    }    return 0;  }  /* Parameterized escape sequences */  strncpy(key.cmd, cmd->chars, 3);  entry = (const ActionEntry *)bsearch(&key, action_table,    sizeof(action_table)/sizeof(ActionEntry), sizeof(ActionEntry), cmp_entries);  if (entry != NULL) return (*entry->action)(in, cmd, ip);  return 1;}/******************************************************************************  Function: work  On errors, the return value is positive, on success it is zero.******************************************************************************/static int work(FILE *in, FILE *out)				/* NLS: 50 */{  CollectedInfo info;  int rc;  memset(&info, 0, sizeof(CollectedInfo));  info.out = out;  info.fdata.duplex = -1;  info.fdata.dry_time = -1;  info.fdata.raster_graphics_quality = -1;  info.fdata.shingling = -1;  rc = pcl_scan(in, &analyzer, &info, NULL, NULL);  if (rc != 0) return 1;  if (info.number_of_outputs == 0) {    emessage(50,      "This does not seem to be a PCL file containing raster data.\n");    return 1;  }  return 0;}/******************************************************************************  Function: main  Usage: pcl3opts <options> <input files>  <option> ::= '-o' <output file>  <input files> ::= <empty> | <input file> <input files>******************************************************************************/int main(int argc, char **argv){  char    *outfile_name = NULL;  FILE    *outfile,    *infile;  int    c,    errors = 0,    number_of_infiles;#ifndef NDEBUG  {    int j;    for (j = 1; j < sizeof(action_table)/sizeof(ActionEntry); j++)      assert(cmp_entries(action_table + (j - 1), action_table + j) < 0);  }#endif /* !NDEBUG */  /* Set the locale depending on the environment */  setlocale(LC_ALL, "");  catd = catopen("pcl3opts", 0);  puts("*** pcl3opts\n");	/* Note that puts() appends another '\n'. */  /* Set the program's name. We assume: argc <= 0 || parts(argv) >= 1. */  if (argc <= 0 || argv[0] == NULL || argv[0][0] == '\0')    progname = "pcl3opts";  else {    if ((progname = strrchr(argv[0], '/')) == NULL || progname[1] == '\0')      progname = argv[0];    else      progname++;  }  /* Parse the options */  while ((c = getopt(argc, argv, "o:")) != EOF) {    switch(c) {    case 'o':      outfile_name = optarg;      break;    default:      errors++;      break;    }  }  /* Leave on errors in the command line */  if (errors > 0) {    emessage(1, "Usage: %s [<options>] [<input files>].\n"      "  <option> ::= -o <output file>\n",      progname);    exit(EXIT_FAILURE);  }  /* Open the output file */  if (outfile_name == NULL) outfile = stdout;  else {    outfile = fopen(outfile_name, "w");    if (outfile == NULL) {      emessage(2, "The file `%s' could not be opened for writing:\n  %s.\n",	outfile_name, strerror(errno));      exit(EXIT_FAILURE);    }  }  /* Loop over the input files */  number_of_infiles = argc - optind;  if (number_of_infiles <= 0) errors += work(stdin, outfile);  else do {    char *infile_name;    /* Open */    infile_name = argv[optind];    infile = fopen(infile_name, "rb");    if (infile == NULL) {      emessage(3, "Could not open the input file `%s':\n  %s.\n",	infile_name, strerror(errno));      exit(EXIT_FAILURE);    }    if (number_of_infiles > 1) fprintf(outfile, "*** %s:\n", infile_name);    errors += work(infile, outfile);    /* Close */    if (fclose(infile) != 0) {      emessage(4, "Error closing `%s':\n  %s.\n",	infile_name, strerror(errno));      errors++;    }    optind++;    if (errors == 0 && optind < argc) fputs("\n", outfile);  } while (errors == 0 && optind < argc);  /* Close the output file */  if (fclose(outfile) != 0) {    emessage(4, "Error closing `%s':\n  %s.\n",      outfile_name == NULL? "[standard output]": outfile_name, strerror(errno));    errors++;  }  catclose(catd);  exit(errors == 0? EXIT_SUCCESS: EXIT_FAILURE);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -