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

📄 eprnparm.c

📁 openmeetings组件之GS openmeetings组件之GS openmeetings组件之GS
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************  File:     $Id: eprnparm.c,v 1.24 2001/08/18 17:42:34 Martin Rel $  Contents: Device parameter handling for the ghostscript device 'eprn'  Author:   Martin Lottermoser, Greifswaldstrasse 28, 38124 Braunschweig,            Germany. E-mail: Martin.Lottermoser@t-online.de.********************************************************************************									      **	Copyright (C) 2000, 2001 by Martin Lottermoser			      **	All rights reserved						      **									      ********************************************************************************  Preprocessor symbols:    EPRN_GS_HAS_MEDIAPOSITION	Define this if ghostscript should in the future implement the standard	PostScript page device parameter "MediaPosition" as a device parameter.	Otherwise it will be stored in the eprn device. Note that	ghostscript's input media selection algorithm *does* react to the	parameter, and you could also specify it from PostScript. This	implementation is only needed to make the parameter available as a	command line option.    EPRN_NO_PAGECOUNTFILE	Define this if you do not want to use eprn's pagecount-file feature.	You very likely must define this on Microsoft Windows.    EPRN_TRACE	Define this to enable tracing. Only useful for development.******************************************************************************//* Configuration management identification */#ifndef lintstatic const char  cm_id[] = "@(#)$Id: eprnparm.c,v 1.24 2001/08/18 17:42:34 Martin Rel $";#endif/*****************************************************************************/#ifndef _XOPEN_SOURCE#define _XOPEN_SOURCE	500#endif/* Special Aladdin header, must be included before <sys/types.h> on some   platforms (e.g., FreeBSD). */#include "std.h"/* Standard headers */#include <assert.h>#include <ctype.h>#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <string.h>/* Ghostscript headers */#ifdef EPRN_TRACE#include "gdebug.h"#endif	/* EPRN_TRACE *//* Special headers */#include "gdeveprn.h"/*****************************************************************************/#define ERRPREF		"? eprn: "#define WARNPREF	"?-W eprn: "/*****************************************************************************//*  Data structures for string arguments to parameters */const eprn_StringAndInt  /* Colour models */  eprn_colour_model_list[] = {    /* Values of type 'eprn_ColourModel' are assumed to be usable as indices       into this array in order to find string representations for them. */    { "Gray",	eprn_DeviceGray },    { "RGB",	eprn_DeviceRGB },    { "CMY",	eprn_DeviceCMY },    { "CMY+K",	eprn_DeviceCMY_plus_K },    { "CMYK",	eprn_DeviceCMYK },    { NULL,	0 }  };static const eprn_StringAndInt  /* Intensity rendering methods */  intensity_rendering_list[] = {    { "printer",	eprn_IR_printer },    { "halftones",	eprn_IR_halftones },    { "Floyd-Steinberg", eprn_IR_FloydSteinberg },    { NULL, 0}  };/******************************************************************************  Function: eprn_get_string  This function returns a string representation of 'in_value' in '*out_value',  based on 'table'. 'table' must be an array terminated with an entry having  NULL as the 'name' value and must be permanently allocated and constant.  If 'in_value' cannot be found in 'table', the function returns a non-zero  value, otherwise zero.  The string buffer in '*out_value' will be a statically allocated area which  must not be modified.******************************************************************************/int eprn_get_string(int in_value, const eprn_StringAndInt *table,  gs_param_string *out_value){  while (table->name != NULL && table->value != in_value) table++;  if (table->name == NULL) return -1;  out_value->data = (const byte *)table->name;  out_value->size = strlen(table->name);  out_value->persistent = true;  return 0;}/******************************************************************************  Function: eprn_get_int  This function parses 'in_value' based on 'table' and returns the result in  '*out_value'. 'table' must be an array, terminated with an entry having NULL  as the value for 'name'.  'in_value' must be a string present in 'table'. If it is, the function  returns 0, otherwise a non-zero ghostscript error value.  On returning 'gs_error_VMerror', the function will have issued an error  message.******************************************************************************/int eprn_get_int(const gs_param_string *in_value,  const eprn_StringAndInt *table, int *out_value){  char *s;  /* First we construct a properly NUL-terminated string */  s = (char *) malloc(in_value->size + 1);  if (s == NULL) {    eprintf1(ERRPREF      "Memory allocation failure in eprn_get_int(): %s.\n",      strerror(errno));    return_error(gs_error_VMerror);  }  strncpy(s, (const char *)in_value->data, in_value->size);  s[in_value->size] = '\0';  /* Loop over table */  while (table->name != NULL && strcmp(table->name, s) != 0) table++;  if (table->name != NULL) *out_value = table->value;  else {    free(s); s = NULL;    return_error(gs_error_rangecheck);  }  free(s); s = NULL;  return 0;}/******************************************************************************  Function: eprn_dump_parameter_list  This function is only used for debugging. It dumps the names of the  parameters in the parameter list 'plist' on the debugging stream.******************************************************************************/#ifdef EPRN_TRACEvoid eprn_dump_parameter_list(gs_param_list *plist){  gs_param_enumerator_t iterator;  gs_param_key_t key;  int count = 0;  param_init_enumerator(&iterator);  while (param_get_next_key(plist, &iterator, &key) == 0) {    int j;    count++;    dlprintf("  `");    for (j = 0; j < key.size; j++) dputc(key.data[j]);    dprintf("'\n");  }  dlprintf1("  Number of parameters: %d.\n", count);  return;}#endif	/* EPRN_TRACE *//******************************************************************************  Function: eprn_get_params  This function returns to the caller information about the values of  parameters defined for the device in the 'eprn' part and its base devices.  The function returns zero on success and a negative value on error.******************************************************************************/int eprn_get_params(gx_device *device, gs_param_list *plist){  gs_param_string string_value;  const eprn_Eprn *eprn = &((eprn_Device *)device)->eprn;  int rc;#ifdef EPRN_TRACE  if_debug0(EPRN_TRACE_CHAR, "! eprn_get_params()...\n");#endif  /* Base class parameters */  rc = gdev_prn_get_params(device, plist);  if (rc < 0) return rc;  /* Number of intensity levels. The casts are used to get rid of compiler     warnings because the *_levels are unsigned. */  if ((rc = param_write_int(plist, "BlackLevels",      (const int *)&eprn->black_levels)) < 0) return rc;  if ((rc = param_write_int(plist, "CMYLevels",      (const int *)&eprn->non_black_levels)) < 0) return rc;  if ((rc = param_write_int(plist, "RGBLevels",      (const int *)&eprn->non_black_levels)) < 0) return rc;  /* Colour model */  eprn_get_string(eprn->colour_model, eprn_colour_model_list, &string_value);  if ((rc = param_write_string(plist, "ColourModel", &string_value)) < 0 ||      (rc = param_write_string(plist, "ColorModel", &string_value)) < 0)    return rc;  /* CUPS page accounting */  if ((rc = param_write_bool(plist, "CUPSAccounting", &eprn->CUPS_accounting))    < 0) return rc;  /* CUPS message format */  if ((rc = param_write_bool(plist, "CUPSMessages", &eprn->CUPS_messages)) < 0)    return rc;  /* Intensity rendering */  eprn_get_string(eprn->intensity_rendering, intensity_rendering_list,    &string_value);  if ((rc = param_write_string(plist, "IntensityRendering", &string_value)) < 0)    return rc;  /* Leading edge */  if (eprn->leading_edge_set) {    if ((rc = param_write_int(plist, "LeadingEdge", &eprn->default_orientation))      < 0) return rc;  }  else    if ((rc = param_write_null(plist, "LeadingEdge")) < 0) return rc;  /* Media configuration file */  if (eprn->media_file == NULL) {    if ((rc = param_write_null(plist, "MediaConfigurationFile")) < 0)      return rc;  }  else {    string_value.data = (const byte *)eprn->media_file;    string_value.size = strlen((const char *)string_value.data);    string_value.persistent = false;    if ((rc =        param_write_string(plist, "MediaConfigurationFile", &string_value)) < 0)      return rc;  }#ifndef EPRN_GS_HAS_MEDIAPOSITION  /* Requested input media position */  if (eprn->media_position_set) {    if ((rc = param_write_int(plist, "MediaPosition", &eprn->media_position))      < 0) return rc;  }  else    if ((rc = param_write_null(plist, "MediaPosition")) < 0) return rc;#endif	/* EPRN_GS_HAS_MEDIAPOSITION */#ifndef EPRN_NO_PAGECOUNTFILE  /* Page count file */  if (eprn->pagecount_file == NULL) {    if ((rc = param_write_null(plist, "PageCountFile")) < 0) return rc;  }  else {    string_value.data = (const byte *)eprn->pagecount_file;    string_value.size = strlen((const char *)string_value.data);    string_value.persistent = false;    if ((rc = param_write_string(plist, "PageCountFile", &string_value)) < 0)      return rc;  }#endif	/* EPRN_NO_PAGECOUNTFILE */  return 0;}/******************************************************************************  Function: is_word  This function returns a non-zero value iff the string beginning at 's' is  identical with the string pointed to by 'word' and is followed either by a  blank character or '\0'.******************************************************************************/static int is_word(const char *s, const char *word){  size_t l = strlen(word);  if (strncmp(s, word, l) != 0) return 0;  return s[l] == '\0' || isspace(s[l]);}/******************************************************************************  Function: next_word  This function returns a pointer to the beginning of the next blank-separated  word in the string pointed to by 's'. If s[0] is not blank, the character is  considered to be part of the current word, i.e. the word to be returned is  the one following.  If there is no next word in this sense, the function returns NULL.******************************************************************************/static char *next_word(char *s){  /* Skip current word */  while (*s != '\0' && !isspace(*s)) s++;  /* Skip intermediate blanks */  while (*s != '\0' && isspace(*s)) s++;  return *s == '\0'? NULL: s;}/******************************************************************************  Function: eprn_read_media_data  This function reads a media configuration file and stores the result in  '*eprn'.  The file name must already have been stored in 'eprn->media_file',  'eprn->media_overrides' should be NULL.  The function returns zero on success and a non-zero ghostscript error value  otherwise. In the latter case, an error message will have been issued.******************************************************************************/#define BUFFER_SIZE	200  /* should be large enough for a single line */#define cleanup()	(free(list), fclose(f))static int eprn_read_media_data(eprn_Eprn *eprn){  char buffer[BUFFER_SIZE];  const char    *epref = eprn->CUPS_messages? CUPS_ERRPREF: "",    *wpref = eprn->CUPS_messages? CUPS_WARNPREF: "";  FILE *f;  float conversion_factor = BP_PER_IN;    /* values read have to be multiplied by this value to obtain bp */  int    line = 0,	/* line number */    read = 0;	/* number of entries read so far */  eprn_PageDescription *list = NULL;  /* Open the file */  if ((f = fopen(eprn->media_file, "r")) == NULL) {    eprintf5("%s" ERRPREF "Error opening the media configuration file\n"      "%s    `%s'\n%s  for reading: %s.\n",      epref, epref, eprn->media_file, epref, strerror(errno));    return_error(gs_error_invalidfileaccess);  }  /* Loop over input lines */  while (fgets(buffer, BUFFER_SIZE, f) != NULL) {    char *s, *t;    eprn_PageDescription *current;    int chars_read;    line++;    /* Check for buffer overflow */    if ((s = strchr(buffer, '\n')) == NULL && fgetc(f) != EOF) {      eprintf5("%s" ERRPREF "Exceeding line length %d in "	  "media configuration file\n%s  %s, line %d.\n",	epref, BUFFER_SIZE - 2 /* '\n'+'\0' */, epref, eprn->media_file, line);      cleanup();      return_error(gs_error_limitcheck);    }    /* Eliminate the newline character */    if (s != NULL) *s = '\0';    /*  Originally, I did nothing further at this point and used a        "%g %g %g %g %n" format in the sscanf() call below to skip trailing        blanks. This does not work with Microsoft Visual C up to at least        version 6 (_MSC_VER is 1200) because the variable for %n will never be

⌨️ 快捷键说明

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