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