386BSD 0.1 development
[unix-history] / usr / othersrc / public / ghostscript-2.4.1 / opdef.h
CommitLineData
eac745a0
WJ
1/* Copyright (C) 1991, 1992 Aladdin Enterprises. All rights reserved.
2 Distributed by Free Software Foundation, Inc.
3
4This file is part of Ghostscript.
5
6Ghostscript is distributed in the hope that it will be useful, but
7WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
8to anyone for the consequences of using it or for whether it serves any
9particular purpose or works at all, unless he says so in writing. Refer
10to the Ghostscript General Public License for full details.
11
12Everyone is granted permission to copy, modify and redistribute
13Ghostscript, but only under the conditions described in the Ghostscript
14General Public License. A copy of this license is supposed to have been
15given to you along with Ghostscript so you can know your rights and
16responsibilities. It should be in a file named COPYING. Among other
17things, the copyright notice and this notice must be preserved on all
18copies. */
19
20/* opdef.h */
21/* Operator definition interface for Ghostscript */
22
23/* Typedef for an operator procedure. */
24/*
25 * Operator procedures return 0 for success, a negative code for an error,
26 * or a positive code for some uncommon situations (see below).
27 */
28typedef int (*op_proc_p)(P1(os_ptr));
29
30/* Structure for initializing the operator table. */
31/*
32 * Each operator file declares an array of these, of the following kind:
33
34op_def my_defs[] = {
35 {"1name", zname}, --or-- {"1%name", zname, &iname},
36 ...
37 op_def_end(iproc)
38}
39
40 * where iproc is an initialization procedure for the file, or 0.
41 * This definition always appears at the END of the file,
42 * to avoid the necessity for forward declarations for all the
43 * operator procedures.
44 *
45 * The second form of definition is for internal operators, such as
46 * continuation operators, that do not appear in systemdict and whose
47 * name indices must be stored in a static variable. Ghostscript assumes
48 * that these operators cannot appear anywhere (in executable form)
49 * except on the e-stack; to maintain this invariant, the execstack
50 * operator converts them to literal form, and cvx refuses to convert
51 * them back. As a result of this invariant, they do not need to
52 * push themselves back on the e-stack when executed, since the only
53 * place they could have come from was the e-stack.
54 */
55typedef struct {
56 const char _ds *oname;
57 op_proc_p proc;
58 int _ds *oindex;
59} op_def;
60typedef op_def const _ds *op_def_ptr;
61#define op_def_end(iproc) {(char _ds *)0, (op_proc_p)iproc}
62
63/*
64 * All operators are catalogued in a table, primarily so
65 * that they can have a convenient packed representation.
66 * The `size' of an operator is its index in this table.
67 */
68#define op_index(opref) r_size(opref)
69/*
70 * There are actually two kinds of operators: the real ones (t_operator),
71 * and ones defined by procedures (t_oparray). The catalog for the former
72 * is op_def_table, and their index is in the range [1..op_def_count).
73 */
74extern op_def_ptr *op_def_table;
75extern uint op_def_count;
76#define op_num_args(opref) (op_def_table[op_index(opref)]->oname[0] - '0')
77/*
78 * The catalog for the latter is op_array_table, and their index is in
79 * the range [op_def_count..op_def_count+op_array_count). The actual
80 * index in op_array_table is the operator index minus op_def_count.
81 */
82extern ref op_array_table; /* t_array */
83extern ushort *op_array_nx_table;
84extern uint op_array_count;
85#define op_index_ref(index,pref)\
86 ((index) < op_def_count ?\
87 make_oper(pref, index, op_def_table[index]->proc) :\
88 (r_set_type_attrs(pref, t_oparray, a_executable), r_set_size(pref, index)))