📄 source.htm
字号:
<html>
<head>
<title>Guide to Ghostscript source code</title>
<!-- $Id: Source.htm $ -->
<!-- Originally: source.txt -->
</head>
<body>
<!-- [1.0 begin visible header] -------------------------------------------- -->
<!-- [1.1 begin headline] -------------------------------------------------- -->
<p><table width="100%" border="0">
<tr><th align="center" bgcolor="#CCCC00"><font size=6>
Guide to Ghostscript source code
</font>
</table>
<!-- [1.1 end headline] ---------------------------------------------------- -->
<!-- [1.2 begin table of contents] ----------------------------------------- -->
<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>
</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">Aladdin's 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] -------------------------------------------------- -->
<h1><a name="Overview"></a>Conceptual overview</h1>
<p>
The Ghostscript source code is divided conceptually as follows:
<blockquote><table cellpadding=0 cellspacing=0>
<tr valign=top> <th align=left colspan=4><a href="#PostScript_interpreter">PostScript interpreter</a>:
<tr valign=top> <td>
<td>PostScript operators
<td>
<td><b><tt>z</tt></b>*<b><tt>.h</tt></b> and <b><tt>z</tt></b>*<b><tt>.c</tt></b>
<tr valign=top> <td>
<td>Other interpreter code
<td>
<td><b><tt>i</tt></b>*<b><tt>.h</tt></b> and <b><tt>i</tt></b>*<b><tt>.c</tt></b>
<tr valign=top> <td>
<td>PostScript code
<td>
<td><b><tt>gs_</tt></b>*<b><tt>.ps</tt></b>
<tr valign=top> <th align=left colspan=4><a href="#PDF_interpreter">PDF interpreter</a>:
<tr valign=top> <td>
<td>PostScript code
<td>
<td><b><tt>pdf_</tt></b>*<b><tt>.ps</tt></b>
<tr valign=top> <th align=left colspan=4><a href="#Graphics_library">Graphics library</a>:
<tr valign=top> <td>
<td>Main library code
<td>
<td><b><tt>g</tt></b>*<b><tt>.h</tt></b> and <b><tt>g</tt></b>*<b><tt>.c</tt></b>
<tr valign=top> <td>
<td>Streams
<td>
<td><b><tt>s</tt></b>*<b><tt>.h</tt></b> and <b><tt>s</tt></b>*<b><tt>.c</tt></b>
<tr valign=top> <td>
<td><a href="#Drivers">Device drivers</a>
<td>
<td><b><tt>gdev</tt></b>*<b><tt>.h</tt></b> and <b><tt>gdev</tt></b>*<b><tt>.c</tt></b>
<tr valign=top> <td>
<td><a href="#Platform_specific_code">Platform-specific code</a>
<td>
<td><b><tt>gp</tt></b>*<b><tt>.h</tt></b> and <b><tt>gp</tt></b>*<b><tt>.c</tt></b>
</table></blockquote>
<hr>
<h1><a name="PostScript_interpreter"></a>PostScript Interpreter</h1>
<p>
<b><tt>gs.c</tt></b> is the main program for the interactive language
interpreter; <b><tt>gserver.c</tt></b> 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 <b><tt>gserver.c</tt></b> instead
of <b><tt>gs.c</tt></b>.
<p>
Files named <b><tt>z</tt></b>*<b><tt>.c</tt></b> are Ghostscript operator
files. The names of the files generally follow the section headings of the
operator summary in section 6.2 of the PostScript Language Reference
Manual. Each operator XXX is implemented by a procedure named
<b><tt>z</tt></b>XXX, for example, <b><tt>zfill</tt></b> and
<b><tt>zarray</tt></b>.
<p>
Files named <b><tt>i</tt></b>*<b><tt>.c</tt></b>, and *<b><tt>.h</tt></b>
other than <b><tt>g</tt></b>*<b><tt>.h</tt></b>, 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 <b><tt>interp</tt></b>
procedure in <b><tt>interp.c</tt></b>. When the interpreter is reading
from an input file, it calls the token scanner in
<b><tt>iscan</tt></b>*<b><tt>.c</tt></b>.
<p>
<b><tt>idebug.c</tt></b> contains a lot of debugger-callable routines
useful for printing PostScript objects when debugging.
<hr>
<h1><a name="PDF_interpreter"></a>PDF interpreter</h1>
<p>
The PDF interpreter is written entirely in PostScript. Its main loop is
the <b><tt>.pdfrun</tt></b> procedure in <b><tt>pdf_base.ps</tt></b>. When
the PDF interpreter is configured into the build, it redefines the
"<b><tt>run</tt></b>" operator to test whether the file is a PDF file.
This redefinition is near the beginning of <b><tt>pdf_main.ps</tt></b>.
<hr>
<h1><a name="Graphics_library"></a>Graphics library</h1>
<p>
Files beginning with <b><tt>gs</tt></b>, <b><tt>gx</tt></b>, or
<b><tt>gz</tt></b> (both <b><tt>.c</tt></b> and <b><tt>.h</tt></b>), other
than <b><tt>gs.c</tt></b> and <b><tt>gserver.c</tt></b>, are the
Ghostscript library. Files beginning with <b><tt>gdev</tt></b> are device
drivers or related code, also part of the library. Other files beginning
with <b><tt>g</tt></b> are library files that don't fall neatly into either
the kernel or the driver category.
<p>
Files named <b><tt>s</tt></b>*<b><tt>.c</tt></b> and
<b><tt>s</tt></b>*<b><tt>.h</tt></b> are a flexible stream package,
including the Level 2 PostScript "filters" supported by Ghostscript. See
<b><tt>stream.h</tt></b>, <b><tt>scommon.h</tt></b>, and
<b><tt>strimpl.h</tt></b> for all the details.
<h2><a name="Drivers"></a>Device drivers</h2>
<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
<b><tt>devs.mak</tt></b> and <b><tt>contrib.mak</tt></b>, a number of
drivers are used for internal purposes. You can search
<b><tt>lib.mak</tt></b> for files named
<b><tt>gdev</tt></b>*<b><tt>.c</tt></b> 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 <b><tt>gdev_prn_alloc</tt></b> in
<b><tt>gdevprn.c</tt></b>: 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
<b><tt>gdevmiff.c</tt></b>: 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
<b><tt>gdevm8.c</tt></b>, which implements 8-bit-deep devices that only
store the bits in memory.
<h2><a name="Platform_specific_code"></a>Platform-specific code</h2>
<p>
There are very few platform dependencies in Ghostscript. Ghostscript deals
with them in three ways:
<ul>
<li>Files named *<b><tt>_.h</tt></b> substitute for the corresponding
<b><tt><</tt></b>*<b><tt>.h></tt></b> file by adding conditionals
that provide a uniform set of system interfaces on all platforms.
<li>The file <b><tt>arch.h</tt></b> contains a set of
mechanically-discovered platform properties like byte order, size of
<b><tt>int</tt></b>, 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 <b><tt>gp</tt></b>*<b><tt>.h</tt></b> 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
<b><tt>gp</tt></b>*<b><tt>.h</tt></b> interfaces have names of the form
"<b><tt>gp_</tt></b><em>{platform}</em><b><tt>.c</tt></b>, specifically
(this list may be out of date):
<blockquote><table cellpadding=0 cellspacing=0>
<tr><th colspan=3 bgcolor="#CCCC00"><hr><font size="+1">Platform-specific interfaces</font><hr>
<tr valign=bottom>
<th align=left>Routine
<td>
<th align=left>Platform
<tr> <td colspan=3><hr>
<tr valign=top> <td><b><tt>gp_dosfb.c</tt></b>
<td>
<td>DOS
<tr valign=top> <td><b><tt>gp_dosfs.c</tt></b>
<td>
<td>DOS and MS Windows
<tr valign=top> <td><b><tt>gp_itbc.c</tt></b>
<td>
<td>DOS, Borland compilers
<tr valign=top> <td><b><tt>gp_iwatc.c</tt></b>
<td>
<td>DOS, Watcom or Microsoft compiler
<tr valign=top> <td><b><tt>gp_msdos.c</tt></b>
<td>
<td>DOS and MS Windows
<tr valign=top> <td><b><tt>gp_ntfs.c</tt></b>
<td>
<td>MS-Windows Win32s and Windows NT
<tr valign=top> <td><b><tt>gp_os2.c</tt></b>
<td>
<td>OS/2
<tr valign=top> <td><b><tt>gp_os9.c</tt></b>
<td>
<td>OS-9
<tr valign=top> <td><b><tt>gp_unifs.c</tt></b>
<td>
<td>Unix, OS-9, and QNX
<tr valign=top> <td><b><tt>gp_unix.c</tt></b>
<td>
<td>Unix and QNX
<tr valign=top> <td><b><tt>gp_sysv.c</tt></b>
<td>
<td>System V Unix
<tr valign=top> <td><b><tt>gp_vms.c</tt></b>
<td>
<td>VMS
<tr valign=top> <td><b><tt>gp_win32.c</tt></b>
<td>
<td>MS-Windows Win32s and Windows NT
</table></blockquote>
<p>
If you are going to extend Ghostscript to new machines or operating
systems, check the *<b><tt>_.h</tt></b> files for <b><tt>ifdef</tt></b> on
things other than <b><tt>DEBUG</tt></b>. You should probably plan to make
a new makefile and a new <b><tt>gp_</tt></b>XXX<b><tt>.c</tt></b> file.
<!-- [2.0 end contents] ---------------------------------------------------- -->
<!-- [3.0 begin visible trailer] ------------------------------------------- -->
<hr>
<font size=2>
<p>Copyright © 1996, 1997, 1998 Aladdin Enterprises. All rights reserved.
<p>This file is part of Aladdin Ghostscript. See the
<a href="Public.htm">Aladdin Free Public License</a> (the "License") for
full details of the terms of using, copying, modifying, and redistributing
Aladdin Ghostscript.
<p>
Ghostscript version 5.50, 16 September 1998
</font>
<!-- [3.0 end visible trailer] --------------------------------------------- -->
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -