1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
|
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro" rel="stylesheet">
<link rel="shortcut icon" type="image/png" href="../../images/favicon.png">
<title>Guide to Ghostscript Source Code</title>
<!-- Originally: source.txt -->
<link href="style.css" rel="stylesheet" type="text/css">
<link href="gs-style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="header">
<div class="row">
<div class="col-lt-6 logo"><a href="https://www.ghostscript.com/"><img src="images/ghostscript_logo.png" width="108" height="119" alt=""></a></div>
<div class="col-6"><div class="row"><div class="artifexlogo"><a href="https://artifex.com" target="_blank"><img src="images/Artifex_logo.png" width="194" height="40" alt=""></a></div>
<div class="col-12"><div class="button button1"><a href="https://artifex.com/contact-us/" title="Contact Us" target="_blank">Contact Us</a></div>
<div class="button button2 hidden-xs"><a href="https://www.ghostscript.com/download.html" title="Download">Download</a></div></div></div>
</div>
</div>
</div>
<div class="banner">
<div class="row">
<div class="col-12">Guide to Ghostscript Source Code</div>
</div>
</div>
<div class="main">
<div class="row">
<div id="sidebar">
<div class="sidebar-item"></div>
<div class="col-2 leftnav">
<ul>
<li><a href="https://www.ghostscript.com/">Home</a></li>
<li><a href="https://www.ghostscript.com/license.html">Licensing</a></li>
<li><a href="https://www.ghostscript.com/releases.html">Releases</a></li>
<li><a href="https://www.ghostscript.com/documentation.html" title="Documentation">Documentation</a></li>
<li><a href="https://www.ghostscript.com/download.html" title="Download">Download</a></li>
<li><a href="https://www.ghostscript.com/performance.html" title="Performance">Performance</a></li>
<li><a href="http://jbig2dec.com/" title="jbig2dec">jbig2dec</a></li>
<li><a href="http://git.ghostscript.com/?p=ghostpdl.git;a=summary">Source</a></li>
<li><a href="http://bugs.ghostscript.com/">Bugs</a></li>
<li><a href="https://www.ghostscript.com/faq.html" title="FAQ">FAQ</a></li>
</ul>
</div>
</div>
<div class="col-10 page">
<!--START EDITING HERE-->
<h2>Table of contents</h2>
<blockquote><ul>
<li><a href="#Overview">Conceptual overview</a>
<li><a href="#PostScript_interpreter">PostScript Interpreter</a>
<li><a href="#PDF_interpreter">PDF interpreter</a>
<li><a href="#Graphics_library">Graphics library</a>
<ul>
<li><a href="#Drivers">Device drivers</a>
<li><a href="#Platform_specific_code">Platform-specific code</a>
</ul>
<li><a href="#Makefiles">Makefiles</a>
</ul></blockquote>
<!-- [1.2 end table of contents] =========================================== -->
<!-- [1.3 begin hint] ====================================================== -->
<p>For other information, see the <a href="Readme.htm">Ghostscript
overview</a> and the documents on <a href="Make.htm">how to build
Ghostscript</a> from source, <a href="C-style.htm">Ghostscript C coding
guidelines</a>, <a href="Drivers.htm">drivers</a>, the
<a href="Lib.htm">Ghostscript library</a> and <a href="Install.htm">how to
install Ghostscript</a>.
<!-- [1.3 end hint] ======================================================== -->
<hr>
<!-- [1.0 end visible header] ============================================== -->
<!-- [2.0 begin contents] ================================================== -->
<h2><a name="Overview"></a>Conceptual overview</h2>
<p>
The Ghostscript source code is divided conceptually as follows:
<blockquote><table>
<tr> <a href="#PostScript_interpreter"></a>
<th align="left" colspan="4">PostScript interpreter:</th>
</tr>
<tr>
<td> </td>
<td>PostScript operators</td>
<td> </td>
<td><code>z</code>*<code>.h</code> and <code>z</code>*<code>.c</code></td>
</tr>
<tr>
<td> </td>
<td>Other interpreter code</td>
<td> </td>
<td><code>i</code>*<code>.h</code> and <code>i</code>*<code>.c</code></td>
</tr>
<tr>
<td> </td>
<td>PostScript code</td>
<td> </td>
<td><code>gs_</code>*<code>.ps</code></td>
</tr>
<tr> <a href="#PDF_interpreter"></a>
<th align="left" colspan="4">PDF interpreter:</th>
</tr>
<tr>
<td> </td>
<td>PostScript code</td>
<td> </td>
<td><code>pdf_</code>*<code>.ps</code></td>
</tr>
<tr> <a href="#Graphics_library"></a>
<th align="left" colspan="4">Graphics library:</th>
</tr>
<tr>
<td> </td>
<td>Main library code</td>
<td> </td>
<td><code>g</code>*<code>.h</code> and <code>g</code>*<code>.c</code></td>
</tr>
<tr>
<td> </td>
<td>Streams</td>
<td> </td>
<td><code>s</code>*<code>.h</code> and <code>s</code>*<code>.c</code></td>
</tr>
<tr>
<td> </td>
<td><a href="#Drivers">Device drivers</a></td>
<td> </td>
<td><code>gdev</code>*<code>.h</code> and <code>gdev</code>*<code>.c</code></td>
</tr>
<tr>
<td> </td>
<td><a href="#Platform_specific_code">Platform-specific code</a></td>
<td> </td>
<td><code>gp</code>*<code>.h</code> and <code>gp</code>*<code>.c</code></td>
</tr>
</table></blockquote>
<hr>
<h2><a name="PostScript_interpreter"></a>PostScript Interpreter</h2>
<p>
<code>gs.c</code> is the main program for the interactive language
interpreter; <code>gserver.c</code> is an alternative main program that
is a rudimentary server. If you configure Ghostscript as a server rather
than an interactive program, you will use <code>gserver.c</code> instead
of <code>gs.c</code>.
<p>
Files named <code>z</code>*<code>.c</code> are Ghostscript operator
files. The names of the files generally follow the section headings of the
operator summary in section 6.2 (Second Edition) or 8.2 (Third Edition) of
the PostScript Language Reference Manual. Each operator XXX is implemented
by a procedure named <code>z</code>XXX, for example,
<code>zfill</code> and <code>zarray</code>.
<p>
Files named <code>i</code>*<code>.c</code>, and *<code>.h</code>
other than <code>g</code>*<code>.h</code>, are the rest of the
interpreter. See the makefile for a little more information on how the
files are divided functionally.
<p>
The main loop of the PostScript interpreter is the <code>interp</code>
procedure in <code>interp.c</code>. When the interpreter is reading
from an input file, it calls the token scanner in
<code>iscan</code>*<code>.c</code>.
<p>
<code>idebug.c</code> contains a lot of debugger-callable routines
useful for printing PostScript objects when debugging.
<hr>
<h2><a name="PDF_interpreter"></a>PDF interpreter</h2>
<p>
The PDF interpreter is written entirely in PostScript. Its main loop is
the <code>.pdfrun</code> procedure in <code>pdf_base.ps</code>. When
the PDF interpreter is configured into the build, it redefines the
"<code>run</code>" operator to test whether the file is a PDF file.
This redefinition is near the beginning of <code>pdf_main.ps</code>.
<hr>
<h2><a name="Graphics_library"></a>Graphics library</h2>
<p>
Files beginning with <code>gs</code>, <code>gx</code>, or
<code>gz</code> (both <code>.c</code> and <code>.h</code>), other
than <code>gs.c</code> and <code>gserver.c</code>, are the
Ghostscript library. Files beginning with <code>gdev</code> are device
drivers or related code, also part of the library. Other files beginning
with <code>g</code> are library files that don't fall neatly into either
the kernel or the driver category.
<p>
Files named <code>s</code>*<code>.c</code> and
<code>s</code>*<code>.h</code> are a flexible stream package,
including the Level 2 PostScript "filters" supported by Ghostscript. See
<code>stream.h</code>, <code>scommon.h</code>, and
<code>strimpl.h</code> for all the details.
<h3><a name="Drivers"></a>Device drivers</h3>
<p>
The interface between the graphics library and device drivers is the only
really well documented one in all of Ghostscript: see the
<a href="Drivers.htm">documentation on drivers</a>.
<p>
In addition to many real device and file format drivers listed in
<code>devs.mak</code> and <code>contrib.mak</code>, a number of
drivers are used for internal purposes. You can search
<code>lib.mak</code> for files named
<code>gdev</code>*<code>.c</code> to find almost all of them.
<p>
Drivers are divided into "printer" drivers, which support banding, and
non-printer drivers, which don't. The decision whether banding is
required is made (by default on the basis of how much memory is available)
in the procedure <code>gdev_prn_alloc</code> in
<code>gdevprn.c</code>: it implements this decision by filling the
virtual procedure table for the printer device in one of two different
ways.
<p>
A good simple "printer" (bandable) driver to read is
<code>gdevmiff.c</code>: it's less than 100 lines, of which much is
boilerplate. There are no simple non-printer drivers that actually drive
devices: probably the simplest non-printer driver for reading is
<code>gdevm8.c</code>, which implements 8-bit-deep devices that only
store the bits in memory.
<h3><a name="Platform_specific_code"></a>Platform-specific code</h3>
<p>
There are very few platform dependencies in Ghostscript. Ghostscript deals
with them in three ways:
<ul>
<li>Files named *<code>_.h</code> substitute for the corresponding
<code><</code>*<code>.h></code> file by adding conditionals
that provide a uniform set of system interfaces on all platforms.
<li>The file <code>arch.h</code> contains a set of
mechanically-discovered platform properties like byte order, size of
<code>int</code>, etc. These properties, <b>not</b> the names of
specific platforms, are used to select between different algorithms or
parameters at compile time.
<li>Files named <code>gp</code>*<code>.h</code> define interfaces
that are intended to be implemented differently on each platform, but whose
specification is common to all platforms.
</ul>
<p>
The platform-specific implementations of the
<code>gp</code>*<code>.h</code> interfaces have names of the form
"<code>gp_</code><em>{platform}</em><code>.c</code>, specifically
(this list may be out of date):
<blockquote><table>
<tr>
<th colspan="3">Platform-specific interfaces</th>
</tr>
<tr>
<th align="left">Routine</th>
<th> </th>
<th align="left">Platform</th>
</tr>
<tr>
<td><code>gp_dosfb.c</code></td>
<td> </td>
<td>DOS</td>
</tr>
<tr>
<td><code>gp_dosfs.c</code></td>
<td> </td>
<td>DOS and MS Windows</td>
</tr>
<tr>
<td><code>gp_itbc.c</code></td>
<td> </td>
<td>DOS, Borland compilers</td>
</tr>
<tr>
<td><code>gp_iwatc.c</code></td>
<td> </td>
<td>DOS, Watcom or Microsoft compiler</td>
</tr>
<tr>
<td><code>gp_msdos.c</code></td>
<td> </td>
<td>DOS and MS Windows</td>
</tr>
<tr>
<td><code>gp_ntfs.c</code></td>
<td> </td>
<td>MS Windows NT</td>
</tr>
<tr>
<td><code>gp_os2.c</code></td>
<td> </td>
<td>OS/2</td>
</tr>
<tr>
<td><code>gp_os9.c</code></td>
<td> </td>
<td>OS-9</td>
</tr>
<tr>
<td><code>gp_unifs.c</code></td>
<td> </td>
<td>Unix, OS-9, and QNX</td>
</tr>
<tr>
<td><code>gp_unix.c</code></td>
<td> </td>
<td>Unix and QNX</td>
</tr>
<tr>
<td><code>gp_vms.c</code></td>
<td> </td>
<td>VMS</td>
</tr>
<tr>
<td><code>gp_win32.c</code></td>
<td> </td>
<td>MS Windows NT</td>
</tr>
</table></blockquote>
<p>
If you are going to extend Ghostscript to new machines or operating
systems, check the *<code>_.h</code> files for <code>ifdef</code> on
things other than <code>DEBUG</code>. You should probably plan to make
a new makefile and a new <code>gp_</code>XXX<code>.c</code> file.
<hr>
<h2><a name="Makefiles"></a>Makefiles</h2>
<p>
This section is only for advanced developers who need to integrate
Ghostscript into a larger program at build time.
<p>
NOTE: THIS SECTION IS INCOMPLETE. IT WILL BE IMPROVED IN A LATER REVISION.
<p>
The Ghostscript makefiles are meant to be organized according to the
following two principles:
<ul>
<li>All the parameters that vary from platform to platform appear in the
top-level makefile for a given platform. ("Platform" = OS + compiler +
choice of interpreter vs. library)
<li>All the rules and definitions that can meaningfully be shared among more
than 1 platform appear in a makefile that is "included" by a makefile
(normally the top-level makefile) for those platforms.
</ul>
<p>
Thus, for example:
<ul>
<li>Rules and definitions shared by all builds are in
<code>gs.mak</code>.
<li>Rules and definitions specific to the library (on all platforms) are in
<code>lib.mak</code>. In principle this could be merged with
<code>gs.mak</code>, but we wanted to leave open the possibility that
<code>gs.mak</code> might be useful with hypothetical interpreter-only
products.
<li>Stuff specific to interpreters (on all platforms) is in
<code>int.mak</code>.
<li>Stuff specific to all Unix platforms should be in a single
<code>unix.mak</code> file, but because <code>make</code> sometimes
cares about the order of definitions, and because some of it is shared with
DV/X, it got split between <code>unix-aux.mak</code>,
<code>unix-end.mak</code>, <code>unixhead.mak</code>,
<code>unixinst.mak</code>, and <code>unixlink.mak</code>.
</ul>
<p>
For MS-DOS and MS Windows builds, there should be:
<ul>
<li>A makefile for all MS OS (DOS or Windows) builds, for all
compilers and products.
<li>Perhaps a makefile for all MS-DOS builds, for all compilers and
products, although since Watcom is the only such compiler we're likely to
support this may be overkill.
<li>A makefile for all MS Windows builds, for all compilers and products.
<li>A makefile for all Watcom builds (DOS or Windows), for all products.
<li>A top-level makefile for the Watcom DOS interpreter product.
<li>A top-level makefile for the Watcom Windows interpreter product.
<li>A top-level makefile for the Watcom DOS library "product".
<li>A top-level makefile for the Watcom Windows library "product".
<li>A makefile for all Borland builds (DOS or Windows), for all
products.
</ul>
<p>
and so on.
<!-- [2.0 end contents] ==================================================== -->
<!-- [3.0 begin visible trailer] =========================================== -->
<hr>
<p>
<small>Copyright © 2000-2021 Artifex Software, Inc. All rights reserved.</small>
<p>
This software is provided AS-IS with no warranty, either express or
implied.
This software is distributed under license and may not be copied, modified
or distributed except as expressly authorized under the terms of that
license. Refer to licensing information at <a href="https://www.artifex.com">https://www.artifex.com</a>
or contact Artifex Software, Inc., 1305 Grant Avenue - Suite 200,
Novato, CA 94945, U.S.A., +1(415)492-9861, for further information.
<p>
<small>Ghostscript version 9.55.0, 27 September 2021
<!-- [3.0 end visible trailer] ============================================= -->
<!--FINISH EDITING HERE-->
</div>
</div>
</div>
<div class="footer">
<div class="row">
<div class="col-7 footleft">
<ul>
<li><a href="https://artifex.com/contact-us/" target="blank">CONTACT US</a></li>
<li><a href="https://artifex.com/about-us/" target="blank">ABOUT</a></li>
<li><a href="https://ghostscript.com/security.html">SECURITY</a></li>
</ul>
</div>
<div class="col-1 footcenter">
<ul>
<li><a href="https://artifex.com/support/" target="blank">SUPPORT</a></li>
<li><a href="https://artifex.com/blog/artifex/" target="blank">BLOG</a></li>
<li><a href="https://artifex.com/privacy-policy/" target="blank">PRIVACY</a></li>
</ul>
</div>
<div class="col-ft-3 footright"><img src="images/Artifex_logo.png" width="194" height="40" alt=""/> <br>
© Copyright 2019-2021 Artifex Software, Inc. <br>
All rights reserved.
</div>
</div>
</div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="index.js"></script>
</body>
</html>
|