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

  1. /* Copyright (C) 1991, 1992, 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. /* opdef.h */
  20. /* Operator definition interface for Ghostscript */
  21.  
  22. /* Typedef for an operator procedure. */
  23. /*
  24.  * Operator procedures return 0 for success, a negative code for an error, 
  25.  * or a positive code for some uncommon situations (see below).
  26.  */
  27.  
  28. /* Structure for initializing the operator table. */
  29. /*
  30.  * Each operator file declares an array of these, of the following kind:
  31.  
  32. op_def my_defs[] = {
  33.     {"1name", zname},
  34.         ...
  35.     op_def_end(iproc)
  36. }
  37.  
  38.  * where iproc is an initialization procedure for the file, or 0.
  39.  * This definition always appears at the END of the file,
  40.  * to avoid the need for forward declarations for all the
  41.  * operator procedures.
  42.  */
  43. typedef struct {
  44.     const char _ds *oname;
  45.     op_proc_p proc;
  46. } op_def;
  47. typedef const op_def _ds *op_def_ptr;
  48. #define op_def_end(iproc) {(char _ds *)0, (op_proc_p)iproc}
  49. /*
  50.  * Operators may be stored in dictionaries other than systemdict.
  51.  * We support this with op_def entries of a special form:
  52.  */
  53. #define op_def_begin_dict(dname) {dname, 0}
  54. #define op_def_begin_level2() op_def_begin_dict("level2dict")
  55. #define op_def_is_begin_dict(def) ((def)->proc == 0)
  56. /*
  57.  * Internal operators whose names begin with %, such as continuation
  58.  * operators, do not appear in systemdict.  Ghostscript assumes
  59.  * that these operators cannot appear anywhere (in executable form)
  60.  * except on the e-stack; to maintain this invariant, the execstack
  61.  * operator converts them to literal form, and cvx refuses to convert
  62.  * them back.  As a result of this invariant, they do not need to
  63.  * push themselves back on the e-stack when executed, since the only
  64.  * place they could have come from was the e-stack.
  65.  *
  66.  * All operators are catalogued in a table, primarily so
  67.  * that they can have a convenient packed representation.
  68.  * The `size' of an operator is normally its index in this table;
  69.  * however, internal operators have a `size' of 0, and their true index
  70.  * must be found by searching the table for their procedure address.
  71.  */
  72. ushort op_find_index(P1(const ref *));
  73. #define op_index(opref)\
  74.   (r_size(opref) == 0 ? op_find_index(opref) : r_size(opref))
  75. /*
  76.  * There are actually two kinds of operators: the real ones (t_operator),
  77.  * and ones defined by procedures (t_oparray).  The catalog for the former
  78.  * is op_def_table, and their index is in the range [1..op_def_count).
  79.  */
  80. /* Because of a bug in Sun's SC1.0 compiler, */
  81. /* we have to spell out the typedef for op_def_ptr here: */
  82. extern const op_def _ds **op_def_table;
  83. extern uint op_def_count;
  84. #define op_num_args(opref) (op_def_table[op_index(opref)]->oname[0] - '0')
  85. /*
  86.  * The catalog for the latter is op_array_table, and their index is in
  87.  * the range [op_def_count..op_def_count+op_array_count).  The actual
  88.  * index in op_array_table is the operator index minus op_def_count.
  89.  */
  90. extern ref op_array_table;        /* t_array */
  91. extern ushort *op_array_nx_table;
  92. extern uint op_array_count;
  93. #define op_index_ref(index,pref)\
  94.   ((index) < op_def_count ?\
  95.    make_oper(pref, index, op_def_table[index]->proc) :\
  96.    (r_set_type_attrs(pref, t_oparray, a_executable), r_set_size(pref, index)))
  97.