% $Id: mp.web,v 1.8 2005/08/24 10:54:02 taco Exp $ % MetaPost, by John Hobby. Public domain. % Much of this program was copied with permission from MF.web Version 1.9 % It interprets a language very similar to D.E. Knuth's METAFONT, but with % changes designed to make it more suitable for PostScript output. % TeX is a trademark of the American Mathematical Society. % METAFONT is a trademark of Addison-Wesley Publishing Company. % PostScript is a trademark of Adobe Systems Incorporated. % Here is TeX material that gets inserted after \input webmac \def\hang{\hangindent 3em\noindent\ignorespaces} \def\textindent#1{\hangindent2.5em\noindent\hbox to2.5em{\hss#1 }\ignorespaces} \def\PASCAL{Pascal} \def\ps{PostScript} \def\ph{\hbox{Pascal-H}} \def\psqrt#1{\sqrt{\mathstrut#1}} \def\k{_{k+1}} \def\pct!{{\char`\%}} % percent sign in ordinary text \font\tenlogo=logo10 % font used for the METAFONT logo \font\logos=logosl10 \def\MF{{\tenlogo META}\-{\tenlogo FONT}} \def\MP{{\tenlogo META}\-{\tenlogo POST}} \def\[#1]{#1.} % from pascal web \def\<#1>{$\langle#1\rangle$} \def\section{\mathhexbox278} \let\swap=\leftrightarrow \def\round{\mathop{\rm round}\nolimits} \mathchardef\vb="026A % synonym for `\|' \def\(#1){} % this is used to make section names sort themselves better \def\9#1{} % this is used for sort keys in the index via @@:sort key}{entry@@> \def\title{MetaPost} \def\glob{15} % this should be the section number of "" \def\gglob{23, 28} % this should be the next two sections of "" \pdfoutput=1 \pageno=3 @* \[1] Introduction. This is \MP, a graphics-language processor based on D. E. Knuth's \MF. The main purpose of the following program is to explain the algorithms of \MP\ as clearly as possible. As a result, the program will not necessarily be very efficient when a particular \PASCAL\ compiler has translated it into a particular machine language. However, the program has been written so that it can be tuned to run efficiently in a wide variety of operating environments by making comparatively few changes. Such flexibility is possible because the documentation that follows is written in the \.{WEB} language, which is at a higher level than \PASCAL; the preprocessing step that converts \.{WEB} to \PASCAL\ is able to introduce most of the necessary refinements. Semi-automatic translation to other languages is also feasible, because the program below does not make extensive use of features that are peculiar to \PASCAL. A large piece of software like \MP\ has inherent complexity that cannot be reduced below a certain level of difficulty, although each individual part is fairly simple by itself. The \.{WEB} language is intended to make the algorithms as readable as possible, by reflecting the way the individual program pieces fit together and by providing the cross-references that connect different parts. Detailed comments about what is going on, and about why things were done in certain ways, have been liberally sprinkled throughout the program. These comments explain features of the implementation, but they rarely attempt to explain the \MP\ language itself, since the reader is supposed to be familiar with {\sl The {\logos METAFONT\/}book} as well as the manual @.WEB@> @:METAFONTbook}{\sl The {\logos METAFONT\/}book@> {\sl A User's Manual for MetaPost}, Computing Science Technical Report 162, AT\AM T Bell Laboratories. @ The present implementation is a preliminary version, but the possibilities for new features are limited by the desire to remain as nearly compatible with \MF\ as possible. On the other hand, the \.{WEB} description can be extended without changing the core of the program, and it has been designed so that such extensions are not extremely difficult to make. The |banner| string defined here should be changed whenever \MP\ undergoes any modifications, so that it will be clear which version of \MP\ might be the guilty party when a problem arises. @^extensions to \MP@> @^system dependencies@> @d banner "This is MetaPost, Version 1.002" /* printed when \MP\ starts */ @d metapost_version "1.002" @d mplib_version "0.10" @d version_string " (Cweb version 0.10)" @ Different \PASCAL s have slightly different conventions, and the present @:PASCAL H}{\ph@> program is expressed in a version of \PASCAL\ that D. E. Knuth used for \MF. Constructions that apply to this particular compiler, which we shall call \ph, should help the reader see how to make an appropriate interface for other systems if necessary. (\ph\ is Charles Hedrick's modification of a compiler @^Hedrick, Charles Locke@> for the DECsystem-10 that was originally developed at the University of Hamburg; cf.\ {\sl SOFTWARE---Practice \AM\ Experience \bf6} (1976), 29--42. The \MP\ program below is intended to be adaptable, without extensive changes, to most other versions of \PASCAL\ and commonly used \PASCAL-to-C translators, so it does not fully @:C@> use the admirable features of \ph. Indeed, a conscious effort has been made here to avoid using several idiosyncratic features of standard \PASCAL\ itself, so that most of the code can be translated mechanically into other high-level languages. For example, the `\&{with}' and `\\{new}' features are not used, nor are pointer types, set types, or enumerated scalar types; there are no `\&{var}' parameters, except in the case of files; there are no tag fields on variant records; there are no |real| variables; no procedures are declared local to other procedures.) The portions of this program that involve system-dependent code, where changes might be necessary because of differences between \PASCAL\ compilers and/or differences between operating systems, can be identified by looking at the sections whose numbers are listed under `system dependencies' in the index. Furthermore, the index entries for `dirty \PASCAL' list all places where the restrictions of \PASCAL\ have not been followed perfectly, for one reason or another. @^system dependencies@> @^dirty \PASCAL@> @ The program begins with a normal \PASCAL\ program heading, whose components will be filled in later, using the conventions of \.{WEB}. @.WEB@> For example, the portion of the program called `\X\glob:Global variables\X' below will be replaced by a sequence of variable declarations that starts in $\section\glob$ of this documentation. In this way, we are able to define each individual global variable when we are prepared to understand what it means; we do not have to define all of the globals at once. Cross references in $\section\glob$, where it says ``See also sections \gglob, \dots,'' also make it possible to look at the set of all global variables, if desired. Similar remarks apply to the other portions of the program heading. Actually the heading shown here is not quite normal: The |program| line does not mention any |output| file, because \ph\ would ask the \MP\ user to specify a file name if |output| were specified here. @^system dependencies@> @d true 1 @d false 0 @(mplib.h@>= typedef struct MP_instance * MP; @ typedef struct MP_options { @