xref: /plan9/sys/src/cmd/gs/src/gconfig.c (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1989, 1995, 1996, 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: gconf.c,v 1.6 2002/08/22 07:12:28 henrys Exp $ */
18 /* Configuration tables */
19 #include "memory_.h"
20 #include "gx.h"
21 #include "gscdefs.h"		/* interface */
22 #include "gconf.h"		/* for #defines */
23 #include "gxdevice.h"
24 #include "gxdhtres.h"
25 #include "gxiclass.h"
26 #include "gxiodev.h"
27 #include "gxiparam.h"
28 #include "gxcomp.h"
29 
30 /*
31  * The makefile generates the file gconfig.h, which consists of
32  * lines of the form
33  *      device_(gs_xxx_device)
34  * or
35  *      device2_(gs_xxx_device)
36  * for each installed device;
37  *      emulator_("emulator", strlen("emulator"))
38  * for each known emulator;
39  *	function_type_(xxx, gs_function_type_xxx)
40  * for each known function type;
41  *	halftone_(gs_dht_xxx)
42  * for each known (device) halftone;
43  *	image_class_(gs_image_class_xxx)
44  * for each known image class;
45  *	image_type_(xxx, gs_image_type_xxx)
46  * for each known image type;
47  *      init_(gs_xxx_init)
48  * for each initialization procedure;
49  *      io_device_(gs_iodev_xxx)
50  * for each known IODevice;
51  *      oper_(xxx_op_defs)
52  * for each operator option;
53  *      psfile_("gs_xxxx.ps", strlen("gs_xxxx.ps"))
54  * for each optional initialization file.
55  *      plug_(gs_xxx_init)
56  * for each plugin;
57  *
58  * We include this file multiple times to generate various different
59  * source structures.  (It's a hack, but we haven't come up with anything
60  * more satisfactory.)
61  */
62 
63 /* ---------------- Resources (devices, inits, IODevices) ---------------- */
64 
65 /* Declare devices, image types, init procedures, and IODevices as extern. */
66 #define compositor_(comp_type) extern gs_composite_type_t comp_type;
67 #define device_(dev) extern gx_device dev;
68 #define device2_(dev) extern const gx_device dev;
69 #define halftone_(dht) extern DEVICE_HALFTONE_RESOURCE_PROC(dht);
70 #define image_class_(cls) extern iclass_proc(cls);
71 #define image_type_(i,type) extern const gx_image_type_t type;
72 #define init_(proc) extern init_proc(proc);
73 #define io_device_(iodev) extern const gx_io_device iodev;
74 #include "gconf.h"
75 #undef io_device_
76 #undef init_
77 #undef image_type_
78 #undef image_class_
79 #undef halftone_
80 #undef device2_
81 #undef device_
82 #undef compositor_
83 
84 /* Set up compositor type table. */
85 #define compositor_(comp_type) &comp_type,
86 private const gs_composite_type_t *const gx_compositor_list[] = {
87 #include "gconf.h"
88     0
89 };
90 #undef compositor_
91 
92 /* Set up the device table. */
93 #define device_(dev) (const gx_device *)&dev,
94 #define device2_(dev) &dev,
95 private const gx_device *const gx_device_list[] = {
96 #include "gconf.h"
97 	 0
98 };
99 #undef device2_
100 #undef device_
101 
102 /* Set up the (device) halftone table. */
103 extern_gx_device_halftone_list();
104 #define halftone_(dht) dht,
105 const gx_dht_proc gx_device_halftone_list[] = {
106 #include "gconf.h"
107     0
108 };
109 #undef halftone_
110 
111 /* Set up the image class table. */
112 extern_gx_image_class_table();
113 #define image_class_(cls) cls,
114 const gx_image_class_t gx_image_class_table[] = {
115 #include "gconf.h"
116     0
117 };
118 #undef image_class_
119 /* We must use unsigned here, not uint.  See gscdefs.h. */
120 const unsigned gx_image_class_table_count = countof(gx_image_class_table) - 1;
121 
122 /* Set up the image type table. */
123 extern_gx_image_type_table();
124 #define image_type_(i,type) &type,
125 const gx_image_type_t *const gx_image_type_table[] = {
126 #include "gconf.h"
127     0
128 };
129 #undef image_type_
130 /* We must use unsigned here, not uint.  See gscdefs.h. */
131 const unsigned gx_image_type_table_count = countof(gx_image_type_table) - 1;
132 
133 /* Set up the initialization procedure table. */
134 extern_gx_init_table();
135 #define init_(proc) proc,
136 const gx_init_proc gx_init_table[] = {
137 #include "gconf.h"
138     0
139 };
140 #undef init_
141 
142 /* Set up the IODevice table.  The first entry must be %os%, */
143 /* since it is the default for files with no explicit device specified. */
144 extern_gx_io_device_table();
145 extern gx_io_device gs_iodev_os;
146 #define io_device_(iodev) &iodev,
147 const gx_io_device *const gx_io_device_table[] = {
148     &gs_iodev_os,
149 #include "gconf.h"
150     0
151 };
152 #undef io_device_
153 /* We must use unsigned here, not uint.  See gscdefs.h. */
154 const unsigned gx_io_device_table_count = countof(gx_io_device_table) - 1;
155 
156 /* Find a compositor by name. */
157 extern_gs_find_compositor();
158 const gs_composite_type_t *
gs_find_compositor(int comp_id)159 gs_find_compositor(int comp_id)
160 {
161     const gs_composite_type_t *const * ppcomp = gx_compositor_list;
162     const gs_composite_type_t *  pcomp;
163 
164     while ((pcomp = *ppcomp++) != 0 && pcomp->comp_id != comp_id)
165         ;
166     return pcomp;
167 }
168 
169 /* Return the list of device prototypes, a NULL list of their structure */
170 /* descriptors (no longer used), and (as the value) the length of the lists. */
171 extern_gs_lib_device_list();
172 int
gs_lib_device_list(const gx_device * const ** plist,gs_memory_struct_type_t ** pst)173 gs_lib_device_list(const gx_device * const **plist,
174 		   gs_memory_struct_type_t ** pst)
175 {
176     if (plist != 0)
177 	*plist = gx_device_list;
178     if (pst != 0)
179 	*pst = NULL;
180     return countof(gx_device_list) - 1;
181 }
182