home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / GSPARAM.H < prev    next >
C/C++ Source or Header  |  1994-07-27  |  8KB  |  194 lines

  1. /* Copyright (C) 1993, 1994 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gsparam.h */
  20. /* Client interface to parameter dictionaries */
  21.  
  22. /*
  23.  * Several interfaces use parameter dictionaries to communicate sets of
  24.  * (key, value) pairs from a client to an object with complex state.
  25.  * (Several of these correspond directly to similar interfaces in the
  26.  * PostScript language.) This file defines the API for parameter dictionaries.
  27.  */
  28.  
  29. #ifndef gs_param_list_DEFINED
  30. #  define gs_param_list_DEFINED
  31. typedef struct gs_param_list_s gs_param_list;
  32. #endif
  33. typedef const char _ds *gs_param_name;
  34.  
  35. /*
  36.  * Define a structure for representing a variable-size value
  37.  * (string/name, integer array, or floating point array).
  38.  * The size is the number of elements, not the size in bytes.
  39.  * A value is persistent if it is defined as static const,
  40.  * or if it is allocated in garbage-collectable space and never freed.
  41.  */
  42.  
  43. #define _param_array_struct(sname,etype)\
  44.   struct sname { const etype *data; uint size; bool persistent; }
  45. typedef _param_array_struct(gs_param_string_s, byte) gs_param_string;
  46. typedef _param_array_struct(gs_param_int_array_s, int) gs_param_int_array;
  47. typedef _param_array_struct(gs_param_float_array_s, float) gs_param_float_array;
  48.  
  49. #define param_string_from_string(ps, str)\
  50.   (ps).data = (const byte *)(str), (ps).size = strlen((char *)(ps).data),\
  51.   (ps).persistent = true
  52.  
  53. /* Define the 'policies' for handling out-of-range parameter values. */
  54. /* This is not an enum, because some parameters may recognize other values. */
  55. #define gs_policy_signal_error 0
  56. #define gs_policy_ignore 1
  57. #define gs_policy_consult_user 2
  58.  
  59. /*
  60.  * Define the object procedures.  Note that the same interface is used
  61.  * both for getting and for setting parameter values.  (This is a bit
  62.  * of a hack, and we might change it someday.)  The procedures return
  63.  * 1 for a missing parameter, 0 for a valid parameter, <0 on error.
  64.  * Note that 'reading' a parameter corresponds to 'put' operations from
  65.  * the client's point of view, and 'writing' corresponds to 'get'.
  66.  */
  67.  
  68. typedef struct gs_param_list_procs_s {
  69.  
  70.     /* Transmit a null value. */
  71.     /* Note that this is the only 'transmit' operation */
  72.     /* that does not actually pass any data. */
  73.  
  74. #define param_proc_xmit_null(proc)\
  75.   int proc(P2(gs_param_list *, gs_param_name))
  76.     param_proc_xmit_null((*xmit_null));
  77. #define param_read_null(plist, pkey)\
  78.   (*(plist)->procs->xmit_null)(plist, pkey)
  79. #define param_write_null(plist, pkey)\
  80.   (*(plist)->procs->xmit_null)(plist, pkey)
  81.  
  82.     /* Transmit a Boolean value. */
  83.  
  84. #define param_proc_xmit_bool(proc)\
  85.   int proc(P3(gs_param_list *, gs_param_name, bool *))
  86.     param_proc_xmit_bool((*xmit_bool));
  87. #define param_read_bool(plist, pkey, pvalue)\
  88.   (*(plist)->procs->xmit_bool)(plist, pkey, pvalue)
  89. #define param_write_bool(plist, pkey, pvalue)\
  90.   (*(plist)->procs->xmit_bool)(plist, pkey, pvalue)
  91.  
  92.     /* Transmit an integer value. */
  93.  
  94. #define param_proc_xmit_int(proc)\
  95.   int proc(P3(gs_param_list *, gs_param_name, int *))
  96.     param_proc_xmit_int((*xmit_int));
  97. #define param_read_int(plist, pkey, pvalue)\
  98.   (*(plist)->procs->xmit_int)(plist, pkey, pvalue)
  99. #define param_write_int(plist, pkey, pvalue)\
  100.   (*(plist)->procs->xmit_int)(plist, pkey, pvalue)
  101.  
  102.     /* Transmit a long value. */
  103.  
  104. #define param_proc_xmit_long(proc)\
  105.   int proc(P3(gs_param_list *, gs_param_name, long *))
  106.     param_proc_xmit_long((*xmit_long));
  107. #define param_read_long(plist, pkey, pvalue)\
  108.   (*(plist)->procs->xmit_long)(plist, pkey, pvalue)
  109. #define param_write_long(plist, pkey, pvalue)\
  110.   (*(plist)->procs->xmit_long)(plist, pkey, pvalue)
  111.  
  112.     /* Transmit a float value. */
  113.  
  114. #define param_proc_xmit_float(proc)\
  115.   int proc(P3(gs_param_list *, gs_param_name, float *))
  116.     param_proc_xmit_float((*xmit_float));
  117. #define param_read_float(plist, pkey, pvalue)\
  118.   (*(plist)->procs->xmit_float)(plist, pkey, pvalue)
  119. #define param_write_float(plist, pkey, pvalue)\
  120.   (*(plist)->procs->xmit_float)(plist, pkey, pvalue)
  121.  
  122.     /* Transmit a string value. */
  123.  
  124. #define param_proc_xmit_string(proc)\
  125.   int proc(P3(gs_param_list *, gs_param_name, gs_param_string *))
  126.     param_proc_xmit_string((*xmit_string));
  127. #define param_read_string(plist, pkey, pvalue)\
  128.   (*(plist)->procs->xmit_string)(plist, pkey, pvalue)
  129. #define param_write_string(plist, pkey, pvalue)\
  130.   (*(plist)->procs->xmit_string)(plist, pkey, pvalue)
  131.  
  132.     /* Transmit a name value. */
  133.  
  134. #define param_proc_xmit_name(proc)\
  135.   int proc(P3(gs_param_list *, gs_param_name, gs_param_string *))
  136.     param_proc_xmit_name((*xmit_name));
  137. #define param_read_name(plist, pkey, pvalue)\
  138.   (*(plist)->procs->xmit_name)(plist, pkey, pvalue)
  139. #define param_write_name(plist, pkey, pvalue)\
  140.   (*(plist)->procs->xmit_name)(plist, pkey, pvalue)
  141.  
  142.     /* Transmit an integer array value. */
  143.  
  144. #define param_proc_xmit_int_array(proc)\
  145.   int proc(P3(gs_param_list *, gs_param_name, gs_param_int_array *))
  146.     param_proc_xmit_int_array((*xmit_int_array));
  147. #define param_read_int_array(plist, pkey, pvalue)\
  148.   (*(plist)->procs->xmit_int_array)(plist, pkey, pvalue)
  149. #define param_write_int_array(plist, pkey, pvalue)\
  150.   (*(plist)->procs->xmit_int_array)(plist, pkey, pvalue)
  151.  
  152.     /* Transmit a float array value. */
  153.  
  154. #define param_proc_xmit_float_array(proc)\
  155.   int proc(P3(gs_param_list *, gs_param_name, gs_param_float_array *))
  156.     param_proc_xmit_float_array((*xmit_float_array));
  157. #define param_read_float_array(plist, pkey, pvalue)\
  158.   (*(plist)->procs->xmit_float_array)(plist, pkey, pvalue)
  159. #define param_write_float_array(plist, pkey, pvalue)\
  160.   (*(plist)->procs->xmit_float_array)(plist, pkey, pvalue)
  161.  
  162.     /* Get the 'policy' associated with an out-of-range parameter value. */
  163.     /* (Only used when reading.) */
  164.  
  165. #define param_proc_get_policy(proc)\
  166.   int proc(P2(gs_param_list *, gs_param_name))
  167.     param_proc_get_policy((*get_policy));
  168. #define param_get_policy(plist, pkey)\
  169.   (*(plist)->procs->get_policy)(plist, pkey)
  170.  
  171.     /*
  172.      * Signal an error.  (Only used when reading.)
  173.      * The procedure may return a different error code,
  174.      * or may return 0 indicating that the error is to be ignored.
  175.      */
  176.  
  177. #define param_proc_signal_error(proc)\
  178.   int proc(P3(gs_param_list *, gs_param_name, int))
  179.     param_proc_signal_error((*signal_error));
  180. #define param_signal_error(plist, pkey, code)\
  181.   (*(plist)->procs->signal_error)(plist, pkey, code)
  182. #define param_return_error(plist, pkey, code)\
  183.   return_error(param_signal_error(plist, pkey, code))
  184.  
  185. } gs_param_list_procs;
  186.  
  187. /* Define an abstract parameter dictionary.  Implementations are */
  188. /* concrete subclasses. */
  189. #define gs_param_list_common\
  190.     const gs_param_list_procs _ds *procs
  191. struct gs_param_list_s {
  192.     gs_param_list_common;
  193. };
  194.