user.tex 109 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868
  1. %
  2. % $Id$
  3. % This file is part of the FPC documentation.
  4. % Copyright (C) 1997, by Michael Van Canneyt
  5. %
  6. % The FPC documentation is free text; you can redistribute it and/or
  7. % modify it under the terms of the GNU Library General Public License as
  8. % published by the Free Software Foundation; either version 2 of the
  9. % License, or (at your option) any later version.
  10. %
  11. % The FPC Documentation is distributed in the hope that it will be useful,
  12. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. % Library General Public License for more details.
  15. %
  16. % You should have received a copy of the GNU Library General Public
  17. % License along with the FPC documentation; see the file COPYING.LIB. If not,
  18. % write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. % Boston, MA 02111-1307, USA.
  20. %
  21. \documentclass{report}
  22. \usepackage{a4}
  23. \usepackage{html}
  24. \makeindex
  25. \latex{\usepackage{multicol}}
  26. \latex{\usepackage{fpcman}}
  27. \latex{\usepackage{epsfig}}
  28. \html{\input{fpc-html.tex}}
  29. \usepackage{fancyheadings}
  30. \pagestyle{fancy}
  31. \renewcommand{\chaptermark}[1]{\markboth{#1}{}}
  32. \newcommand{\remark}[1]{\par$\rightarrow$\textbf{#1}\par}
  33. \newcommand{\olabel}[1]{\label{option:#1}}
  34. % We should change this to something better. See \seef etc.
  35. \newcommand{\seeo}[1]{See \ref{option:#1}}
  36. \begin{document}
  37. \title{Free Pascal :\\ Users' manual}
  38. \docdescription{Users' manual for \fpc, version \fpcversion}
  39. \docversion{1.2}
  40. \input{date.inc}
  41. \author{Micha\"el Van Canneyt\\Florian Kl\"ampfl}
  42. \maketitle
  43. \tableofcontents
  44. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  45. % Introduction
  46. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  47. \chapter{Introduction}
  48. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  49. % About this document
  50. \section{About this document}
  51. This is the user's manual for \fpc . It describes the installation and use of
  52. the \fpc compiler on the different supported platforms.
  53. It does not attempt to give an exhaustive list of all supported commands,
  54. nor a definition of the Pascal language. Look at the
  55. \refref for these things.
  56. For a description of the
  57. possibilities and the inner workings of the compiler, see the
  58. \progref. In the appendices of this document you will find lists of
  59. reserved words and compiler error messages (with descriptions).
  60. This document describes the compiler as it is/functions at the time of
  61. writing. Since the compiler is under continuous development, some of the
  62. things described here may be outdated. In case of doubt, consult the
  63. \file{README} files, distributed with the compiler.
  64. The \file{README} files are, in case of conflict with this manual,
  65. authoritative.
  66. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  67. % About the compiler
  68. \section{About the compiler}
  69. \fpc is a 32-bit compiler for the i386 and m68k processors\footnote{Work is being done
  70. on a port to ALPHA Architecture}. Currently, it supports 3 operating systems:
  71. \begin{itemize}
  72. \item \dos
  73. \item \linux
  74. \item \windowsnt
  75. \end{itemize}
  76. and work is in progress to port it to other platforms (notably, \ostwo and
  77. ).
  78. \fpc is designed to be, as much as possible, source compatible with
  79. Turbo Pascal 7.0 and Delphi 4 (although this goal is not yet attained),
  80. but it also enhances these languages with elements like function overloading.
  81. And, unlike these ancestors, it supports multiple platforms.
  82. It also differs from them in the sense that you cannot use compiled units
  83. from one system for the other.
  84. Also, at the time of writing, there is no Integrated Development Environment
  85. (IDE) available for \fpc. This gap will, hopefully, be filled in the future.
  86. \fpc consists of three parts :
  87. \begin{enumerate}
  88. \item The compiler program itself.
  89. \item The Run-Time Library (RTL).
  90. \item Utility programs and units.
  91. \end{enumerate}
  92. Of these you only need the first two, in order to be able to use the compiler.
  93. In this document, we describe the use of the compiler. The RTL is described in the
  94. \refref.
  95. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  96. % Getting more information.
  97. \section{Getting more information.}
  98. If the documentation doesn't give an answer to your questions,
  99. you can obtain more information on the Internet, on the following addresses:
  100. \begin{itemize}
  101. \item
  102. \htmladdnormallink{http://tfdec1.fys.kuleuven.ac.be/\~{}michael/fpc/fpc.html}
  103. {http://tfdec1.fys.kuleuven.ac.be/\~{}michael/fpc/fpc.html} is the main
  104. site. It contains also useful mail addresses and
  105. links to other places.
  106. It also contains the instructions for inscribing to the
  107. \textit{mailing-list}.
  108. \item
  109. \htmladdnormallink{http://www.brain.uni-freiburg.de/\~{}klaus/fpc/fpc.html}
  110. {http://www.brain.uni-freiburg.de/\~{}klaus/fpc/fpc.html} is a mirror
  111. of the main \fpc information site.
  112. \end{itemize}
  113. Both places can be used to download the \fpc distribution, although you can
  114. probably find them on other places also.
  115. Finally, if you think something should be added to this manual
  116. (entirely possible), please do not hesitate and contact me at
  117. \htmladdnormallink{[email protected]}{mailto:[email protected]}
  118. .
  119. Let's get on with something useful.
  120. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  121. % Installation
  122. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  123. \chapter{Installing the compiler}
  124. \label{ch:Installation}
  125. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  126. % Before Installation : Requirements
  127. \section{Before Installation : Requirements}
  128. %
  129. % System requirements
  130. %
  131. \subsection{System requirements}
  132. The compiler needs at least the following hardware:
  133. \begin{enumerate}
  134. \item An I386 or higher processor. A coprocessor is not required, although it
  135. will slow down your program's performance if you do floating point calculations.
  136. \item 2 Mb of free memory. Under \dos, if you use DPMI memory management,
  137. such as under Windows, you will need at least 16 Mb.
  138. \item At least 500 Kb. free disk space.
  139. \end{enumerate}
  140. %
  141. %
  142. % Software requirements
  143. \subsection{Software requirements}
  144. \subsubsection{Under DOS}
  145. The \dos distribution contains all the files you need to run the compiler
  146. and compile pascal programs.
  147. \subsubsection{Under Linux}
  148. Under \linux you need to have the following programs installed :
  149. \begin{enumerate}
  150. \item \gnu \file{as}, the \gnu assembler.
  151. \item \gnu \file{ld}, the \gnu linker.
  152. \item Optionally (but highly recommended) : \gnu \file{make}. For easy
  153. recompiling of the compiler and Run-Time Library, this is needed.
  154. \end{enumerate}
  155. Other than that, \fpc should run on almost any I386 \linux system.
  156. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  157. % Installing the compiler.
  158. \section{Installing the compiler.}
  159. The installation of \fpc is easy, but is platform-dependent.
  160. We discuss the process for each platform separately.
  161. % Installing under DOS
  162. \subsection{Installing under DOS}
  163. \subsubsection{Mandatory installation steps.}
  164. First, you must get the latest distribution files of \fpc. They come as zip
  165. files, which you must unzip first, or you can download the compiler as a
  166. series of separate files. This is especially useful if you have a slow
  167. connection, but it is also nice if you want to install only some pats of the
  168. compiler distribution. The distribution zip file contains an
  169. installation program \file{INSTALL.EXE}. You must run this program to install
  170. the compiler.
  171. \begin{htmlonly}
  172. The screen of the installation program looks like this:
  173. \htmladdimg{../pics/install.gif}
  174. \end{htmlonly}
  175. \begin{latexonly}
  176. The screen of the installation program looks like figure \ref{fig:install}.
  177. \begin{figure}
  178. \caption{The \dos install program screen.}
  179. \label{fig:install}
  180. \epsfig{file=pics/install.eps,width=\textwidth}
  181. \end{figure}
  182. \end{latexonly}
  183. The program allows you to select:
  184. \begin{itemize}
  185. \item What components you wish to install. e.g do you want the sources or
  186. not, do you want docs or not. Items that you didn't download when
  187. downloading as separate files, will not be enabled, i.e. you can't
  188. select them.
  189. \item Where you want to install (the default location is \verb|C:\PP|).
  190. \end{itemize}
  191. In order to run \fpc from any directory on your system, you must extend
  192. your path variable to contain the \verb|C:\PP\BIN| directory.
  193. Usually this is done in the \file{AUTOEXEC.BAT} file.
  194. It should look something like this :
  195. \begin{verbatim}
  196. SET PATH=%PATH%;C:\PP\BIN
  197. \end{verbatim}
  198. (Again, assuming that you installed in the default location).
  199. If you want to use the graphic drivers you must modify the
  200. environment variable \var{GO32}. Instructions for doing this can be found
  201. in the documentation of the Graph unit, at the \var{InitGraph} procedure.
  202. \subsubsection{Optional Installation: The coprocessor emulation}
  203. For people who have an older CPU type, without math coprocessor (i387)
  204. it is necessary to install a coprocessor emulation, since \fpc uses the
  205. coprocessor to do all floating point operations.
  206. The installation of the coprocessor emulation is handled by the
  207. installation program (\file{INSTALL.EXE}). However,
  208. %
  209. % Installing under Linux
  210. %
  211. \subsection{Installing under Linux}
  212. \subsubsection{Mandatory installation steps.}
  213. The \linux distribution of \fpc comes in three forms:
  214. \begin{itemize}
  215. \item a \file{tar.gz} version, also available as seperate files.
  216. \item a \file{.rpm} (Red Hat Package Manager) version, and
  217. \item a \file{.deb} (debian) version.
  218. \end{itemize}
  219. All of these packages contain a \var{ELF} version of the compiler binaries and
  220. units. the older \var{aout} binaries are no longer distributed, although you
  221. still can use the comiler on an \var{aout} system if you recompile it.
  222. If you use the \file{.rpm} format, installation is limited to
  223. \begin{verbatim}
  224. rpm -i fpc-pascal-XXX.rpm
  225. \end{verbatim}
  226. (\var{XXX} is the version number of the \file{.rpm} file)
  227. If you use debian, installation is limited to
  228. \begin{verbatim}
  229. dpkg -i fpc-XXX.deb
  230. \end{verbatim}
  231. Here again, \var{XXX} is the version number of the \file{.deb} file.
  232. You need root access to install these packages. The \file{.tar} file
  233. allows you to do an installation if you don't have root permissions.
  234. When downloading the \var{.tar} file, or the separate files,
  235. installation is more interactive.
  236. I nCAse you downloaded the \file{.tar} file, you should first untar
  237. the file, in some directory where
  238. you have write permission, using the following command:
  239. \begin{verbatim}
  240. tar -xvf fpc.tar
  241. \end{verbatim}
  242. We supposed here that you downloaded the file \file{fpc.tar} somewhere
  243. from the Internet. (The real filename will have some version number in it,
  244. which we omit here for clarity.)
  245. When the file is untarred, you will be left with more archive files, and
  246. an install program: an installation shell script.
  247. If you downloaded the files as separate files, you should at least download
  248. the \file{install.sh} script, and the libraries (in \file{libs.tar.gz}).
  249. To install \fpc, all that you need to do now is give the following command:
  250. \begin{verbatim}
  251. ./install.sh
  252. \end{verbatim}
  253. And then you must answer some questions. They're very simple, they're
  254. mainly concerned with 2 things :
  255. \begin{enumerate}
  256. \item Places where you can install different things.
  257. \item Deciding if you want to install certain components (such as sources
  258. and demo programs).
  259. \end{enumerate}
  260. The script will automatically detect which components are present and can be
  261. installed. It will only offer to install what has been found.
  262. because of this feature, you must keep the original names when downloading,
  263. since the script expects this.
  264. If you run the installation script as the \var{root} user, you can just accept all installation
  265. defaults. If you don't run as \var{root}, you must take care to supply the
  266. installation program with directory names where you have write permission,
  267. as it will attempt to create the directories you specify.
  268. In principle, you can install it wherever you want, though.
  269. At the end of installation, the installation program will generate a
  270. configuration file for the \fpc compiler which reflects the settings
  271. that you chose. It will install this file in the \file{/etc} directory, (if
  272. you are not installing as \var{root}, this will fail), and in the
  273. directory where you installed the libraries.
  274. If you want the \fpc compiler to use this configuration file, it must be
  275. present in \file{/etc}, or you can set the environment variable
  276. \var{PPC\_CONFIG\_PATH}. Under \file{csh}, you can do this by adding a
  277. \begin{verbatim}
  278. setenv PPC_CONFIG_PATH /usr/lib/ppc/0.99.1
  279. \end{verbatim}
  280. line to your \file{.login} file in your home directory.
  281. (see also the next section)
  282. \section{Optional configuration steps}
  283. You may wish to set some environment variables. The \fpc compiler
  284. recognizes the following variables :
  285. \begin{itemize}
  286. \item \verb|PPC_EXEC_PATH| contains the directory where '\file{as}' and
  287. '\file{ld}' are. (default \file{/usr/bin})
  288. \item \verb|PPC_GCCLIB_PATH| contains the directory where \file{libgcc.a}
  289. is (no default). This if for \linux only.
  290. \item \verb|PPC_CONFIG_PATH| specifies an alternate path to find
  291. \file{ppc386.cfg} (default under \linux is \file{/etc})
  292. \item \verb|PPC_ERROR_FILE| specifies the path and name of the error-definition file.
  293. (default \file{/usr/lib/fpc/errorE.msg})
  294. \end{itemize}
  295. These locations are, however, set in the sample configuration file which is
  296. built at the end of the installation process, except for the
  297. \verb|PPC_CONFIG_PATH| variable, which you must set if you didn't install
  298. things in the default places.
  299. \subsubsection{finally}
  300. Also distributed in \fpc is a README file. It contains the latest
  301. instructions for installing \fpc, and should always be read first.
  302. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  303. % Testing the compiler
  304. \section{Testing the compiler}
  305. After the installation is completed and the environment variables are
  306. set as described above, your first program can be compiled.
  307. Included in the \fpc distribution are some demonstration programs,
  308. showing what the compiler can do.
  309. You can test if the compiler functions correctly by trying to compile
  310. these programs.
  311. The compiler is called
  312. \begin{itemize}
  313. \item \file{PPC386.EXE} under \dos, and
  314. \item \file{ppc386} under \linux
  315. \end{itemize}
  316. To compile a program (e.g \verb|demo\hello.pp|) simply type :
  317. \begin{verbatim}
  318. ppc386 hello
  319. \end{verbatim}
  320. at the command prompt. If you don't have a configuretion file, then you may
  321. need to tell the compiler where it can find the units, for instance as
  322. follows:
  323. \begin{verbatim}
  324. ppc386 -Upc:\pp\rtl\dos\go32v2 hello
  325. \end{verbatim}
  326. under \dos, and under\linux you could type
  327. \begin{verbatim}
  328. ppc386 -Up/usr/lib/fpc/0.99.7/linuxunits hello
  329. \end{verbatim}
  330. This is, of course, assuming that you installed under \verb|C:\PP| or
  331. \file{/usr/lib/fpc/0.99.7}, respectively.
  332. If you got no error messages, the compiler has generated an executable
  333. called \file{hello} (no extension) under \linux, and a file \file{hello.exe}
  334. under \dos.
  335. To execute the program, simply type :
  336. \begin{verbatim}
  337. hello
  338. \end{verbatim}
  339. If all went well, you should see the following friendly greeting:
  340. \begin{verbatim}
  341. Hello world
  342. \end{verbatim}
  343. In the \dos case, this friendly greeting may be preceded by some ugly
  344. message from the \file{GO32} extender program. This unfriendly behavior can
  345. be switched off by setting the \file{GO32} environment variable.
  346. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  347. % Usage
  348. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  349. \chapter{Compiler usage}
  350. \label{ch:Usage}
  351. Here we describe the essentials to compile a program and a unit.
  352. We also describe how to make a stand-alone executable of the
  353. compiled program under \dos. For more advanced uses of the compiler,
  354. see the section on configuring the compiler, and the
  355. \progref.
  356. The examples in this section suppose that you have a \file{ppc386.cfg} which
  357. is set up correctly, and which contains at least the path setting for the
  358. RTL units. In principle this file is generated by the installation program.
  359. You may have to check that it is in the correct place (see section
  360. \ref{se:config_file} for more information on this).
  361. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  362. % Where the compiler looks for its files.
  363. \section{File searching}
  364. Before you start compiling a program or a series of units, it is
  365. important to know where the compiler looks for its source files and other
  366. files. In this section we discuss this, and we indicate how to influence
  367. this.
  368. {\em Remark:}
  369. The use of slashes (/) and backslashes (\verb+\+) as directory separators
  370. is irrelevant, the compiler will convert to whatever character is used on
  371. the current operating system. Examples will be given using slashes, since
  372. this avoids problems on \linux.
  373. % Command-line files.
  374. \subsection{Command line files}
  375. The file that you specify on the command line, such as in
  376. \begin{verbatim}
  377. ppc386 foo.pp
  378. \end{verbatim}
  379. will be looked for ONLY in the current directory. If you specify a directory
  380. in the filename, then the compiler will look in that directory:
  381. \begin{verbatim}
  382. ppc386 subdir/foo.pp
  383. \end{verbatim}
  384. will look for \file{foo.pp} in the subdirectory \file{subdir} of the current
  385. directory.
  386. Under \linux, the name of this file is case sensitive, under other operating
  387. systems (\dos, \windowsnt, \ostwo) this is not the case.
  388. % Unit files.
  389. \subsection{Unit files}
  390. When you compile a unit or program that needs other units, the compiler will
  391. look for compiled versions of these units in the following way:
  392. \begin{enumerate}
  393. \item It will look in the current directory.
  394. \item It will look in the directory where the compiler binary is.
  395. (not under \linux)
  396. \item It will look in all the directories specified in the unit search path.
  397. \end{enumerate}
  398. You can add a directory to the unit search path with the \var{-Up} or
  399. \var{-Fu} options (\seeo{Up}, \seeo{Fu}). Every occurrence of one of
  400. those options will append a directory to the unit search path.
  401. On \linux, the compiler will first convert the filename of a unit to
  402. all-lowercase. This is necessary, since Pascal is case-independent, and
  403. the statements \var{Uses Unit1;} or \var{uses unit1;} should have the same
  404. effect.
  405. Also, unit names that are longer than 8 characters will first be looked for
  406. with their full length. If the unit is not found with this name, the name
  407. will be truncated to 8 characters, and the compiler will look again in the
  408. same directories, but with the truncated name.
  409. For instance, suppose that the file \file{foo.pp} needs the unit
  410. \file{bar}. Then the command
  411. \begin{verbatim}
  412. ppc386 -Up.. -Upunits foo.pp
  413. \end{verbatim}
  414. will tell the compiler to look for the unit \file{bar} in the following
  415. places:
  416. \begin{enumerate}
  417. \item In the current directory.
  418. \item In the directory where the compile binary is (not under \linux).
  419. \item In the parent directory of the current directory.
  420. \item In the subdirectory \file{units} of the current directory
  421. \end{enumerate}
  422. If the compiler finds the unit it needs, it will look for the source file of
  423. this unit in the same directory where it found the unit.
  424. If it finds the source of the unit, then it will compare the file times.
  425. If the source file was modified more recent than the unit file, the
  426. compiler will attempt to recompile the unit with this source file.
  427. If the compiler doesn't find a compiled version of the unit, or when the
  428. \var{-B} option is specified, then the compiler will look in the same
  429. manner for the unit source file, and attempt to recompile it.
  430. It is recommended to set the unit search path in the configuration file
  431. \file{ppc386.cfg}. If you do this, you don't need to specify the unit search
  432. path on the command-line every time you want to compile something.
  433. % Include files.
  434. \section{Include files}
  435. If you include files in your source with the \var{\{\$I filename\}}
  436. directive, the compiler will look for it in the following places:
  437. \begin{enumerate}
  438. \item It will look in the path specified in the incude file name.
  439. \item It will look in the directory where the current source file is.
  440. \item it will look in all directories specified in the include file search
  441. path.
  442. \end{enumerate}
  443. You can add files to the include file search
  444. path with the \var{-I} (\seeo{I})
  445. option.
  446. As an example, consider the following include statement in a file
  447. \file{units/foo.pp}:
  448. \begin{verbatim}
  449. {$i ../bar.inc}
  450. \end{verbatim}
  451. Then the following command :
  452. \begin{verbatim}
  453. ppc386 -Iincfiles units/foo.pp
  454. \end{verbatim}
  455. will cause the compiler to look in the following directories for
  456. \file{bar.inc}:
  457. \begin{enumerate}
  458. \item the parent directory of the current directory
  459. \item the \file{units} subdirectory of the current directory
  460. \item the \file{incfiles} directory of the current directory.
  461. \end{enumerate}
  462. % Object files.
  463. \section{Object files}
  464. When you link to object files (using the \var{\{\$L file.o\}} directive,
  465. the compiler will look for this file in the same way as it looks for include
  466. files:
  467. \begin{enumerate}
  468. \item It will look in the path specified in the object file name.
  469. \item It will look in the directory where the current source file is.
  470. \item it will look in all directories specified in the object file search path.
  471. \end{enumerate}
  472. You can add files to the object file search path with the \var{-Fo} (\seeo{Fo})
  473. option.
  474. % Configuration file
  475. \subsection{Configuration file}
  476. Unless you specify the \var{-n} (\seeo{n}) option, the compiler will look
  477. for a configuration file \file{ppc386.cfg} in the following places:
  478. \begin{itemize}
  479. \item Under \linux
  480. \begin{enumerate}
  481. \item The current directory.
  482. \item In your home directory, it looks for \file{.ppc386.cfg}.
  483. \item The directory specified in the environment variable
  484. \var{PPC\_CONFIG\_PATH}, and if it's not set under \file{/etc}.
  485. \end{enumerate}
  486. \item Under all other OSes:
  487. \begin{enumerate}
  488. \item The current directory.
  489. \item If it is set, the directory specified in the environment variable.
  490. \var{PPC\_CONFIG\_PATH}.
  491. \item The directory where the compiler is.
  492. \end{enumerate}
  493. \end{itemize}
  494. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  495. % Compiling a program
  496. \section{Compiling a program}
  497. Compiling a program is very simple. Assuming that you have a program source
  498. in the file \file{prog.pp}, you can compile this with the following command:
  499. \begin{verbatim}
  500. ppc386 [options] prog.pp
  501. \end{verbatim}
  502. The square brackets \var{[\ ]} indicate that what is between them is optional.
  503. If your program file has the \file{.pp} or \file{.pas} extension,
  504. you can omit this on the command line, e.g. in the previous example you
  505. could have typed:
  506. \begin{verbatim}
  507. ppc386 [options] prog
  508. \end{verbatim}
  509. If all went well, the compiler will produce an executable, or, for version 1
  510. of the \dos extender, a file which can be converted to an executable.
  511. Unless you are using \dos and version 1 of the \dos extender,
  512. the file you obtained is the executable.
  513. You can execute it straight away, you don't need to do
  514. anything else. Under version 1 of the \dos extender,
  515. additional processing is required. See section \ref{go32v1} on how to
  516. create an executable in this case.
  517. You will notice that there is also another file in your directory, with
  518. extensions \file{.o}. This contains the object file for your program.
  519. If you compiled a program, you can delete the object file (\file{.o}),
  520. but not if you compiled a unit.
  521. Then the object file contains the code of the unit, and will be
  522. linked in any program that uses the unit you compiled, so you shouldn't
  523. remove it.
  524. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  525. % Compiling a unit
  526. \section{Compiling a unit}
  527. Compiling a unit is not essentially different from compiling a program.
  528. The difference is mainly that the linker isn't called in this case.
  529. To compile a unit in the file \file{foo.pp}, just type :
  530. \begin{verbatim}
  531. ppc386 foo
  532. \end{verbatim}
  533. Recall the remark about file extensions in the previous section.
  534. When all went well, you will be left with 2 (two) unit files:
  535. \begin{enumerate}
  536. \item \file{foo.ppu} This is the file describing the unit you just
  537. compiled.
  538. \item \file{foo.o} This file contains the actual code of the unit.
  539. This file will eventually end up in the executables.
  540. \end{enumerate}
  541. Both files are needed if you plan to use the unit for some programs.
  542. So don't delete them. If you want to distribute the unit, you must
  543. provide both the \file{.ppu} and \file{.o} file. One is useless without the
  544. other.
  545. {\em Remark:}
  546. Under \linux, a unit source file {\em must} have a lowercase filename.
  547. Since Pascal is case independent, you can specify the names of units in the
  548. \var{uses} clause in either case. To get a unique filename, the \fpc compiler
  549. changes the name of the unit to all lowercase when looking for unit files.
  550. The compiler produces lowercase files, so your unit will be found, even if
  551. your source file has uppercase letters in it. Only when the compiler tries to
  552. recompile the unit, it will not find your source because of the uppercase
  553. letters.
  554. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  555. % Creating an executable for GO32V1, PMODE/DJ targets
  556. \section{Creating an executable for GO32V1 and PMODE/DJ targets}
  557. \label{go32v1}
  558. The GO32V1 platform is officially no longer supported, so this section
  559. is of interest only to people who wish to make go32V1 binaries anyway.
  560. %
  561. % GO32V1
  562. %
  563. \subsection{GO32V1}
  564. When compiling under \dos, GO32V2 is the default target. However, if you use
  565. go32V1 (using the \var{-TGO32V1} switch), the
  566. compilation process leaves you with a file which you cannot execute right away.
  567. There are 2 things you can do when compiling has finished.
  568. The first thing is to use the \dos extender from D.J. Delorie to execute
  569. your program :
  570. \begin{verbatim}
  571. go32 prog
  572. \end{verbatim}
  573. This is fine for testing, but if you want to use a program regularly, it
  574. would be easier if you could just type the program name, i.e.
  575. \begin{verbatim}
  576. prog
  577. \end{verbatim}
  578. This can be accomplished by making a \dos executable of your compiled program.
  579. There two ways to create a \dos executable (under \dos only):
  580. \begin{enumerate}
  581. \item if the \file{GO32.EXE} is already
  582. installed on the computers where the program should run, you must
  583. only copy a program called \file{STUB.EXE} at the begin of
  584. the AOUT file. This is accomplished with the \file{AOUT2EXE.EXE} program.
  585. which comes with the compiler:
  586. \begin{verbatim}
  587. AOUT2EXE PROG
  588. \end{verbatim}
  589. and you get a \dos executable which loads the \file{GO32.EXE} automatically.
  590. the \file{GO32.EXE} executable must be in current directory or be
  591. in a directory in the \var{PATH} variable.
  592. \item
  593. The second way to create a \dos executable is to put
  594. \file{GO32.EXE} at the beginning of the \file{AOUT} file. To do this, at the
  595. command prompt, type :
  596. \begin{verbatim}
  597. COPY /B GO32.EXE+PROG PROG.EXE
  598. \end{verbatim}
  599. (assuming \fpc created a file called \file{PROG}, of course.)
  600. This becomes then a stand-alone executable for \dos, which doesn't need the
  601. \file{GO32.EXE} on the machine where it should run.
  602. \end{enumerate}
  603. %
  604. %
  605. % PMODE/DJ
  606. \subsection{PMODE/DJ}
  607. You can also use the PMODE/DJ extender to run your \fpc applications.
  608. To make an executable which works with the PMODE extender, you can simply
  609. create an GO32V2 executable (the default), and then convert it to a PMODE
  610. executable with the following two extra commands:
  611. \begin{enumerate}
  612. \item First, strip the GO32V2 header of the executable:
  613. \begin{verbatim}
  614. EXE2COFF PROG.EXE
  615. \end{verbatim}
  616. (we suppose that \file{PROG.EXE} is the program generated by the compilation
  617. process.
  618. \item Secondly, add the PMODE stub:
  619. \begin{verbatim}
  620. COPY /B PMODSTUB.EXE+PROG PROG.EXE
  621. \end{verbatim}
  622. If the \file{PMODSTUB.EXE} file isn't in your local directory, you need to
  623. supply the whole path to it.
  624. \end{enumerate}
  625. That's it. No additional steps are needed to create a PMODE extender
  626. executable.
  627. Be aware, though, that the PMODE extender doesn't support virtual memory, so
  628. if you're short on memory, you may run unto trouble. Also, officially there
  629. is not support for the PMODE/DJ extender. It just happens that the compiler
  630. and some of the programs it generates, run under this extender too.
  631. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  632. % Reducing the size of your program
  633. \section{Reducing the size of your program}
  634. When you created your program, it is possible to reduce its size. This
  635. is possible, because the compiler leaves a lot of information in the
  636. program which, strictly speaking, isn't required for the execution of
  637. it. The surplus of information can be removed with a small program
  638. called \file{strip}. It comes with the \var{GO32} development
  639. environment under \dos, and is standard on \linux machines where you can
  640. do development. The usage is simple. Just type
  641. \begin{verbatim}
  642. strip prog
  643. \end{verbatim}
  644. On the command line, and the \file{strip} program will remove all unnecessary
  645. information from your program. This can lead to size reductions of up to
  646. 30 \%.
  647. You can use the \var{-Xs} switch to let the compiler do this stripping
  648. automatically at program compile time (the switch has no effect when
  649. compiling units).
  650. Another technique to reduce the size of a program is to use smartlinking.
  651. Normally, units (including the system unit) are linked in as a whole.
  652. It is however possible to compile units such that the can be smartlinked.
  653. This means that only the functions and procedures are linked in your
  654. program, leaving out any unnecessary code. This technique is described in
  655. full in the programmers guide.
  656. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  657. % Problems
  658. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  659. \chapter{Compiling problems}
  660. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  661. % General problems
  662. \section{General problems}
  663. \begin{itemize}
  664. \item \textbf{IO-error -2 at ...} : Under \linux you can get this message at
  665. compiler startup. It means typically that the compiler doesn't find the
  666. error definitions file. You can correct this mistake with the \var{-Fr}
  667. option under \linux. (\seeo{Fr})
  668. \item \textbf {Error : File not found : xxx} or \textbf{Error: couldn't compile
  669. unit xxx}: This typically happens when
  670. your unit path isn't set correctly. Remember that the compiler looks for
  671. units only in the current directory, and in the directory where the compiler
  672. itself is. If you want it to look somewhere else too, you must explicitly
  673. tell it to do so using the \var{-Up} option (\seeo{Up}). Or you must set op
  674. a configuration file.
  675. \end{itemize}
  676. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  677. % Problems you may encounter under DOS
  678. \section{Problems you may encounter under DOS}
  679. \begin{itemize}
  680. \item \textbf{No space in environment}.\\
  681. An error message like this can occur, if you call
  682. \verb|SET_PP.BAT| in the \file{AUTOEXEC.BAT}.\\
  683. To solve this problem, you must extend your environment memory.
  684. To do this, search a line in the \file{CONFIG.SYS} like
  685. \begin{verbatim}
  686. SHELL=C:\DOS\COMMAND.COM
  687. \end{verbatim}
  688. and change it to the following:
  689. \begin{verbatim}
  690. SHELL=C:\DOS\COMMAND.COM /E:1024
  691. \end{verbatim}
  692. You may just need to specify a higher value, if this parameter is already set.
  693. \item \textbf{ Coprocessor missing}\\
  694. If the compiler writes
  695. a message that there is no coprocessor, install
  696. the coprocessor emulation.
  697. \item \textbf{Not enough DPMI memory}\\
  698. If you want to use the compiler with \var{DPMI} you must have at least
  699. 7-8 MB free \var{DPMI} memory, but 16 Mb is a more realistic amount.
  700. \end{itemize}
  701. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  702. % Configuration.
  703. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  704. \chapter{Compiler configuration}
  705. \label{ch:CompilerConfiguration}
  706. The output of the compiler can be controlled in many ways. This can be done
  707. essentially in two distinct ways:
  708. \begin{itemize}
  709. \item Using command-line options.
  710. \item Using the configuration file: \file{ppc386.cfg}.
  711. \end{itemize}
  712. The compiler first reads the configuration file. Only then the command line
  713. options are checked. This creates the possibility to set some basic options
  714. in the configuration file, and at the same time you can still set some
  715. specific options when compiling some unit or program. First we list the
  716. command line options, and then we explain how to specify the command
  717. line options in the configuration file. When reading this, keep in mind
  718. that the options are case sensitive. While this is customary for \linux, it
  719. isn't under \dos.
  720. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  721. % Using the command-line options
  722. \section{Using the command-line options}
  723. The available options for version 0.99.10 of the compiler are listed by
  724. category (see appendix A for a listing as generated by the compiler):
  725. %
  726. % General options
  727. %
  728. \subsection{General options}
  729. \begin{description}
  730. \item[-h] if you specify this option, the compiler outputs a list of all options,
  731. and exits after that.
  732. \olabel{h}
  733. \item[-?] idem as \var{-h}, waiting after every screenfull for the enter key.
  734. \item[-i] This option tells the compiler to print the copyright information.
  735. \olabel{i} You can give it an option, as \var{-ixxx} where xxx can be one of the
  736. following:
  737. \begin{description}
  738. \item[D] : Returns the compiler date.
  739. \item[V] : Returns the compiler version.
  740. \item[SO] : Returns the compiler OS.
  741. \item[SP] : Returns the compiler processor.
  742. \item[TO] : Returns the target OS.
  743. \item[TP] : Returns the target Processor.
  744. \end{description}
  745. \item[-l] This option tells the compiler to print the \fpc logo on standard
  746. output. It also gives you the \fpc version number.
  747. \olabel{l}
  748. \item [-n] Tells the compiler not to read the configuration file.
  749. \olabel{n}
  750. \end{description}
  751. %
  752. % Options for getting feedback
  753. %
  754. \subsection{Options for getting feedback}
  755. \begin{description}
  756. \item[-vxxx] Be verbose. \var{xxx} is a combination of the following :
  757. \olabel{v}
  758. \begin{itemize}
  759. \item \var{e} : Tells the compiler to show only errors. This option is on by default.
  760. \item \var{i} : Tells the compiler to show some general information.
  761. \item \var{w} : Tells the compiler to issue warnings.
  762. \item \var{n} : Tells the compiler to issue notes.
  763. \item \var{h} : Tells the compiler to issue hints.
  764. \item \var{l} : Tells the compiler to show the line numbers as it processes a
  765. file. Numbers are shown per 100.
  766. \item \var{u} : Tells the compiler to print the names of the files it opens.
  767. \item \var{t} : Tells the compiler to print the names of the files it tries
  768. to open.
  769. \item \var{p} : Tells the compiler to print the names of procedures and
  770. functions as it is processing them.
  771. \item \var{c} : Tells the compiler to warn you when it processes a
  772. conditional.
  773. \item \var{m} : Tells the compiler to write which macros are defined.
  774. \item \var{d} : Tells the compiler to write other debugging info.
  775. \item \var{a} : Tells the compiler to write all possible info. (this is the
  776. same as specifying all options)
  777. \item \var{0} : Tells the compiler to write no messages. This is useful when
  778. you want to override the default setting in the configuration file.
  779. \item \var{b} : Tells the compiler to show all procedure declarations if an
  780. overloaded function error occurs.
  781. \item \var{x} : Tells the compiler to output some executable info (for Win32
  782. platform only).
  783. \item \var{r} : Rhide/GCC compatibility mode: formats the errors
  784. differently, so they are understood by RHIDE.
  785. \end{itemize}
  786. \end{description}
  787. %
  788. % Options concerning files and directories
  789. %
  790. \subsection{Options concerning files and directories}
  791. \begin{description}
  792. \item [-exxx] \file{xxx} specifies the directory where the
  793. compiler can find the executables \file{as} (the assembler) and \file{ld} (the
  794. compiler).
  795. \olabel{e}
  796. \item [-FD] same as \var{-e}.
  797. \item [-Fexxx] This option tells the compiler to write errors, etc. to
  798. the file in \file{xxx}.
  799. \olabel{Fe}
  800. \item [-Fgxxx] (\linux only, obsolete) \file{xxx} specifies the path where the compiler
  801. can find the \gnu C library. This is superseded by the \var{-Fl} option.
  802. \olabel{Fg}
  803. \item [-Fixxx] adds \var{xxx} to the path where the compiler searches for
  804. its include files.
  805. \olabel{Fi}
  806. \item [-Flxxx] Adds \var{xxx} to the library searching path, and is passed
  807. to the linker.
  808. \olabel{Fl}
  809. \item[-FLxxx] (\linux only) Tells the compiler to use \file{xxx} as the
  810. dynamic linker. Default this is \file{/lib/ld-linux.so.2}, or
  811. \file{lib/ld-linux.so.1}, depending on which one is found.
  812. \olabel{FL}
  813. \item[-Foxxx] Adds \file{xxx} to the object file path. This path is used
  814. when looking for files that need to be linked in.
  815. \olabel{Fo}
  816. \item [-Frxxx] \file{xxx} specifies the file which contain the compiler
  817. messages. Default the compiler ahs built-in messages. Specifying this option
  818. will override the default messages.
  819. \olabel{Fr}
  820. \item [-Fuxxx] Idem as \var{-Up}: Add \file{xxx} to the object path.
  821. \olabel{Fu}
  822. \item [-FUxxx] Tells the compiler to write units in directory \var{xxx}
  823. instead of the current directory.
  824. \item [-Ixxx] \olabel{I} Add \file{xxx} to the include file search path.
  825. This path is used when looking for include files.
  826. \item [-P] uses pipes instead of files when assembling. This may speed up
  827. the compiler on \ostwo and \linux. Only with assemblers (such as \gnu
  828. \file{as}) that support piping..
  829. \item [-Upxxx] \olabel{Up} Tells the compiler to add \file{xxx} to the path where to find
  830. units. \\
  831. By default, the compiler only searches for units in the current directory
  832. and the directory where the compiler itself resides. This option tells the
  833. compiler also to look in the directory \file{xxx}.
  834. \end{description}
  835. % Options controlling the kind of output.
  836. \subsection{Options controlling the kind of output.}
  837. for more information on these options, see also \progref
  838. \begin{description}
  839. \item [-a] \olabel{a} Tells the compiler not to delete the assembler file.
  840. This also counts for the (possibly) generated batch script.
  841. \item [-al] \olabel{al} Tells the compiler to include the sourcecode lines
  842. in the assembler file as comments. This feature is still experimental, and
  843. should be used with caution.
  844. \item [-Axxx] \olabel{A}specifies what kind of assembler should be generated . Here
  845. \var{xxx} is one of the following :
  846. \begin{itemize}
  847. \item \textbf{o} : A unix .o (object) file, using \gnu \file{as}.
  848. \item \textbf{nasmcoff} : a coff file using the \file{nasm} assembler.
  849. \item \textbf{nasmelf} : a ELF32 file (\linux only) using the \file{nasm} assembler.
  850. \item \textbf{nasmonj} : a obj file using the \file{nasm} assembler.
  851. \item \textbf{masm} : An obj file using the Microsoft \file{masm} assembler.
  852. \item \textbf{tasm} : An obj file using the Borland \file{tasm} assembler.
  853. \end{itemize}
  854. \item [-CD] Create dynamic library.
  855. \item [-Chxxx] \olabel {Ch} Reserves \var{xxx} bytes heap. \var{xxx} should
  856. be between 1024 and 67107840.
  857. \item [-Ci] \olabel{Ci} Generate Input/Output checking code.
  858. \item [-Cn] \olabel{Cn} Omit the linking stage.
  859. \item [-Co] \olabel{Co} Generate Integer overflow checking code.
  860. \item [-Cr] \olabel{Cr} Generate Range checking code.
  861. \item [-Csxxx] \olabel{Cs} Set stack size to \var{xxx}.
  862. \item [-CS] \olabel{CS} Create static library.
  863. \item [-Ct] \olabel{Ct} generate stack checking code.
  864. \item [-Cx] \olabel{Cx} Use smartlinking when compiling and linking units.
  865. \item [-dxxx] \olabel{d} Define the symbol name \var{xxx}. This can be used
  866. to conditionally compile parts of your code.
  867. \item {-E} \olabel{E} Same as \var{-Cn}.
  868. \item [-g] \olabel{g} Generate debugging information for debugging with
  869. \file{gdb}
  870. \item [-gg] idem as \var{-g}.
  871. \item [-gd] \olabel{gd} generate debugging info for \file{dbx}.
  872. \item [-gh] use the heaptrc unit (see \unitsref).
  873. \item[-Oxxx] \olabel{O} optimize the compiler's output; \var{xxx} can have one
  874. of the following values :
  875. \begin{description}
  876. \item[g] optimize for size, try to generate smaller code.
  877. \item[G] optimize for time, try to generate faster code (default).
  878. \item[r] keep certain variables in registers (experimental, use with
  879. caution).
  880. \item[u] uncertain optimizations
  881. \item[1] Level 1 optimizations (quick optimizations).
  882. \item[2] Level 2 optimizations (\var{-O1} plus some slower optimizations).
  883. \item[3] Level 2 optimizations (\var{-O2} plus \var{-Ou}).
  884. \item[Pn] Specify processor: \var{n} can be one of
  885. \begin{description}
  886. \item[1] optimize for 386/486
  887. \item[2] optimize for Pentium/PentiumMMX (tm)
  888. \item[3] optimizations for PentiumPro/PII/Cyrix 6x86/K6 (tm)
  889. \end{description}
  890. \end{description}
  891. The exact effect of these effects can be found in the \progref.
  892. \item [-oxxx] Tells the compiler to use \var{xxx} as the name of the output
  893. file (executable). Only with programs.
  894. \item [-pg] \olabel{gp} Generate profiler code for \file{gprof}.
  895. \item [-s] \olabel{s} Tells the compiler not to call the assembler and linker.
  896. Instead, the compiler writes a script, \file{PPAS.BAT} under \dos, or
  897. \file{ppas.sh} under \linux, which can then be executed to produce an
  898. executable.
  899. \item[-Txxx] \olabel{T}Specifies the target operating system. \var{xxx} can be one of
  900. the following:
  901. \begin{itemize}
  902. \item \textbf{GO32V1} : \dos and version 1 of the DJ DELORIE extender.
  903. \item \textbf{GO32V2} : \dos and version 2 of the DJ DELORIE extender.
  904. \item \textbf{LINUX} : \linux.
  905. \item \textbf{OS2} : OS/2 (2.x) (this is still under development).
  906. \item \textbf{WIN32} : Windows 32 bit (this is still under development).
  907. \end{itemize}
  908. \item [-uxxx] \olabel{u} undefine the symbol \var{xxx}. This is the opposite
  909. of the \var{-d} option.
  910. \item [-uxxx] \olabel{U} Undefine symbol \var{xxx}.
  911. \item [-Xx] \olabel{X} executable options. This tells the compiler what
  912. kind of executable should be generated. the parameter \var{x}
  913. can be one of the following:
  914. \begin{itemize}
  915. % \item \textbf{e} : (\linux only) Create an \file{ELF} executable (default).
  916. \item \textbf{c} : (\linux only) Link with the C library. You should only use this when
  917. you start to port \fpc to another operating system.
  918. \item \textbf{D} : Link with dynamic libraries (defines the
  919. \var{FPC\_LINK\_DYNAMIC} symbol)
  920. \item \textbf{s} : Strip the symbols from the executable.
  921. \item \textbf{S} : Link with static libraries (defines the
  922. \var{FPC\_LINK\_STATIC} symbol)
  923. \end{itemize}
  924. \end{description}
  925. %
  926. %
  927. % Options concerning the sources (language options)
  928. \subsection{Options concerning the sources (language options)}
  929. for more information on these options, see also \progref
  930. \begin{description}
  931. \item [-Rxxx] \olabel{R} Specifies what assembler you use in your \var{asm} assembler code
  932. blocks. Here \var{xxx} is one of the following:
  933. \begin{description}
  934. \item [att\ ] \var{asm} blocks contain AT\&T assembler.
  935. \item [intel] \var{asm} blocks contain Intel assembler.
  936. \item [direct] \var{asm} blocks should be copied as-is in the assembler
  937. file.
  938. \end{description}
  939. \item [-S2] \olabel{Stwo} Switch on Delphi 2 extensions.
  940. \item [-Sc] \olabel{Sc} Support C-style operators, i.e. \var{*=, +=, /= and
  941. -=}.
  942. \item [-Sd] tells the compiler to dispose asmlists. This uses less memory,
  943. but is slower.
  944. \item [-Se] \olabel{Se} The compiler stops after the first error. Normally,
  945. the compiler tries to continue compiling after an error, until 50 errors are
  946. reached, or a fatal error is reachd, and then it stops. With this switch,
  947. the compiler will stop after the first error.
  948. \item [-Sg] \olabel{Sg} Support the \var{label} and \var{goto} commands.
  949. \item [-Si] \olabel{Si} Support \var{C++} style INLINE.
  950. \item [-Sm] \olabel{Sm} Support C-style macros.
  951. \item [-So] \olabel{So} Try to be Borland TP 7.0 compatible (no function
  952. overloading etc.).
  953. \item [-Sp] \olabel{Sp} Try to be \file{gpc} (\gnu pascal compiler)
  954. compatible.
  955. \item [-Ss] \olabel{Ss} The name of constructors must be \var{init}, and the
  956. name of destructors should be \var{done}.
  957. \item [-St] \olabel{St} Allow the \var{static} keyword in objects.
  958. \item [-Un] \olabel{Un} Do not check the unit name. Normally, the unit name
  959. is the same as the filename. This option allows both to be different.
  960. \item [-Us] \olabel{Us} Compile a system unit. This option causes the
  961. compiler to define only some very basic types.
  962. \end{description}
  963. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  964. % Using the configuration file
  965. \section{Using the configuration file}
  966. \label{se:config_file}
  967. Using the configuration file \file{ppc386.cfg} is an alternative to command
  968. line options. When a configuration file is found, it is read, and the lines
  969. in it are treated like you typed them on the command line. They are treated
  970. before the options that you type on the command line.
  971. You can specify comments in the configuration file with the \var{\#} sign.
  972. Everything from the \var{\#} on will be ignored.
  973. The compiler looks for the \file{ppc386.cfg} file in the following places :
  974. \begin{itemize}
  975. \item Under \linux
  976. \begin{enumerate}
  977. \item The current directory.
  978. \item In your home directory, it looks for \file{.ppc386.cfg}.
  979. \item The directory specified in the environment variable
  980. \var{PPC\_CONFIG\_PATH}, and if it's not set under \file{/etc}.
  981. \end{enumerate}
  982. \item Under all other OSes:
  983. \begin{enumerate}
  984. \item The current directory.
  985. \item If it is set, the directory specified in the environment variable.
  986. \var{PPC\_CONFIG\_PATH}.
  987. \item The directory where the compiler is.
  988. \end{enumerate}
  989. \end{itemize}
  990. When the compiler has finished reading the configuration file, it continues
  991. to treat the command line options.
  992. One of the command-line options allows you to specify a second configuration
  993. file: Specifying \file{@foo} on the command line will open file \file{foo},
  994. and read further options from there. When the compiler has finished reading
  995. this file, it continues to process the command line.
  996. The configuration file allows some kind of preprocessing. It understands the
  997. following directives, which you should place on the first column of a line :
  998. \begin{description}
  999. \item [\#IFDEF]
  1000. \item [\#IFNDEF]
  1001. \item [\#ELSE]
  1002. \item [\#ENDIF]
  1003. \item [\#DEFINE]
  1004. \item [\#UNDEF]
  1005. \item [\#WRITE]
  1006. \item [\#INCLUDE]
  1007. \item [\#SECTION]
  1008. \end{description}
  1009. They work the same way as their \{\$...\} counterparts in Pascal.
  1010. What follows is a description of the different directives.
  1011. \subsection{\#IFDEF}
  1012. Syntax:
  1013. \begin{verbatim}
  1014. #IFDEF name
  1015. \end{verbatim}
  1016. Lines following \var{\#IFDEF} are skipped read if the keyword \var{name}
  1017. following it is not defined.
  1018. They are read until the keywords \var{\#ELSE} or \var{\#ENDIF} are
  1019. encountered, after which normal processing is resumed.
  1020. Example :
  1021. \begin{verbatim}
  1022. #IFDEF VER0_99_5
  1023. -Up/usr/lib/fpc/0.99.5/linuxunits
  1024. #ENDIF
  1025. \end{verbatim}
  1026. In the above example, \file{/usr/lib/fpc/0.99.5/linuxunits} will be added to
  1027. the path if you're compiling with version 0.99.5 of the compiler.
  1028. \subsection{\#IFNDEF}
  1029. Syntax:
  1030. \begin{verbatim}
  1031. #IFNDEF name
  1032. \end{verbatim}
  1033. Lines following \var{\#IFDEF} are skipped read if the keyword \var{name}
  1034. following it is defined.
  1035. They are read until the keywords \var{\#ELSE} or \var{\#ENDIF} are
  1036. encountered, after which normal processing is resumed.
  1037. Example :
  1038. \begin{verbatim}
  1039. #IFNDEF VER0_99_5
  1040. -Up/usr/lib/fpc/0.99.6/linuxunits
  1041. #ENDIF
  1042. \end{verbatim}
  1043. In the above example, \file{/usr/lib/fpc/0.99.6/linuxunits} will be added to
  1044. the path if you're NOT compiling with version 0.99.5 of the compiler.
  1045. \subsection{\#ELSE}
  1046. Syntax:
  1047. \begin{verbatim}
  1048. #ELSE
  1049. \end{verbatim}
  1050. \var{\#ELSE} can be specified after a \var{\#IFDEF} or \var{\#IFNDEF}
  1051. directive as an alternative.
  1052. Lines following \var{\#ELSE} are skipped read if the preceding \var{\#IFDEF}
  1053. \var{\#IFNDEF} was accepted.
  1054. They are skipped until the keyword \var{\#ENDIF} is
  1055. encountered, after which normal processing is resumed.
  1056. Example :
  1057. \begin{verbatim}
  1058. #IFDEF VER0_99_5
  1059. -Up/usr/lib/fpc/0.99.6/linuxunits
  1060. #ELSE
  1061. -Up/usr/lib/fpc/0.99.5/linuxunits
  1062. #ENDIF
  1063. \end{verbatim}
  1064. In the above example, \file{/usr/lib/fpc/0.99.5/linuxunits} will be added to
  1065. the path if you're compiling with version 0.99.5 of the compiler,
  1066. otherwise \file{/usr/lib/fpc/0.99.6/linuxunits} will be added to the path.
  1067. \subsection{\#ENDIF}
  1068. Syntax:
  1069. \begin{verbatim}
  1070. #ENDIF
  1071. \end{verbatim}
  1072. \var{\#ENDIF} marks the end of a block that started with \var{\#IF(N)DEF},
  1073. possibly with an \var{\#ELSE} between it.
  1074. \subsection{\#DEFINE}
  1075. Syntax:
  1076. \begin{verbatim}
  1077. #DEFINE name
  1078. \end{verbatim}
  1079. \var{\#DEFINE} defines a new keyword. This has the same effect as a
  1080. \var{-dname} command-line option.
  1081. \subsection{\#UNDEF}
  1082. Syntax:
  1083. \begin{verbatim}
  1084. #UNDEF name
  1085. \end{verbatim}
  1086. \var{\#UNDEF} un-defines a keyword if it existed.
  1087. This has the same effect as a \var{-uname} command-line option.
  1088. \subsection{\#WRITE}
  1089. Syntax:
  1090. \begin{verbatim}
  1091. #WRITE Message Text
  1092. \end{verbatim}
  1093. \var{\#WRITE} writes \var{Message Text} to the screen.
  1094. This can be useful to display warnings if certain options are set.
  1095. Example:
  1096. \begin{verbatim}
  1097. #IFDEF DEBUG
  1098. #WRITE Setting debugging ON...
  1099. -g
  1100. #ENDIF
  1101. \end{verbatim}
  1102. if \var{DEBUG} is defined, this will produce a line
  1103. \begin{verbatim}
  1104. Setting debugging ON...
  1105. \end{verbatim}
  1106. and will then switch on debugging information in the compiler.
  1107. \subsection{\#INCLUDE}
  1108. Syntax:
  1109. \begin{verbatim}
  1110. #INCLUDE filename
  1111. \end{verbatim}
  1112. \var{\#INCLUDE} instructs the compiler to read the contents of
  1113. \file{filename} before continuing to process the current file.
  1114. This can be useful if you want to have a particular configuration file
  1115. for a project (or, under \linux, in your home directory), but still want to
  1116. have the global options that are set in a global configuration file.
  1117. Example:
  1118. \begin{verbatim}
  1119. #IFDEF LINUX
  1120. #INCLUDE /etc/ppc386.cfg
  1121. #ELSE
  1122. #IFDEF GO32V2
  1123. #INCLUDE c:\pp\bin\ppc386.cfg
  1124. #ENDIF
  1125. #ENDIF
  1126. \end{verbatim}
  1127. This will include \file{/etc/ppc386.cfg} if you're on a linux machine,
  1128. and will include \verb+c:\pp\bin\ppc386.cfg+
  1129. on a dos machine.
  1130. \subsection{\#SECTION}
  1131. Syntax:
  1132. \begin{verbatim}
  1133. #SECTION name
  1134. \end{verbatim}
  1135. The \var{\#SECTION} directive acts as a \var{\#IFDEF} directive, only
  1136. it doesn't require an \var{\#ENDIF} directive. the special name \var{COMMON}
  1137. always exists, i.e. lines following \var{\#SECTION COMMON} are always read.
  1138. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1139. % Porting.
  1140. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1141. \chapter{Porting Turbo Pascal Code}
  1142. \fpc was designed to resemble Turbo Pascal as closely as possible. There
  1143. are, of course, restrictions. Some of these are due to the fact that \fpc is
  1144. a 32-bit compiler. Other restrictions result from the fact that \fpc works
  1145. on more than one operating system.
  1146. In general we can say that if you keep your program code close to ANSI
  1147. Pascal, you will have no problems porting from Turbo Pascal, or even Delphi, to
  1148. \fpc. To a large extent, the constructs defined by Turbo Pascal are
  1149. supported. This is even more so if you use the \var{-So} or \var{-S2}
  1150. switches.
  1151. In the following sections we will list the Turbo Pascal constructs which are
  1152. not supported in \fpc, and we will list in what ways \fpc extends the Turbo
  1153. Pascal language.
  1154. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1155. % Things that will not work
  1156. \section{Things that will not work}
  1157. Here we give a list of things which are defined/allowed in Turbo Pascal, but
  1158. which are not supported by \fpc. Where possible, we indicate the reason.
  1159. \begin{enumerate}
  1160. \item Parameter lists of previously defined functions and procedures must
  1161. match exactly. The reason for this is the function overloading mechanism of
  1162. \fpc. (however, the \var{-So} switch solves this. \seeo{So})
  1163. \item \var {(* ... *)} as comment delimiters are not allowed in versions
  1164. older than 0.9.1. This can easily be remedied with a grown-up editor.
  1165. \item The \var{MEM, MEMW, MEML} and \var{PORT} variables for memory and port
  1166. access are not available. This is due to the operating system. Under
  1167. \dos, the extender unit (\file {GO32.PPU}) implements the mem constuct.
  1168. under \linux, the \file{ports} unit implements such a construct.
  1169. \item \var{PROTECTED, PUBLIC, PUBLISHED, TRY, FINALLY, EXCEPT, RAISE}
  1170. are reserved words. This means you cannot create procedures or variables
  1171. with the same name. While they are not reserved words in Turbo Pascal,
  1172. they are in Delphi. Using the \var{-So} switch will solve this problem if
  1173. you want to compile Turbo Pascal code that uses these words.
  1174. \item The reserved words \var{FAR, NEAR} are ignored. This is
  1175. because \fpc is a 32 bit compiler, so they're obsolete.
  1176. \item \var{INTERRUPT} only will work on a DOS machine.
  1177. \item Boolean expressions are only evaluated until their result is completely
  1178. determined. The rest of the expression will be ignored.
  1179. \item By default the compiler uses \var{AT\&T} assembler syntax.
  1180. This is mainly because \fpc uses \gnu \var{as}. However other assembler
  1181. forms are available, \progref.
  1182. \item Turbo Vision is not available.
  1183. \item The 'overlay' unit is not available. It also isn't necessary, since
  1184. \fpc is a 32 bit compiler, so program size shouldn't be a point.
  1185. \item There are more reserved words. (see appendix \ref{ch:reserved} for a
  1186. list of all reserved words.)
  1187. \item The command-line parameters of the compiler are different.
  1188. \item Compiler switches and directives are mostly the same, but some extra
  1189. exist.
  1190. \item Units are not binary compatible.
  1191. \end{enumerate}
  1192. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1193. % Things which are extra
  1194. \section{Things which are extra}
  1195. Here we give a list of things which are possible in \fpc, but which
  1196. didn't exist in Turbo Pascal or Delphi.
  1197. \begin{enumerate}
  1198. \item There are more reserved words. (see appendix \ref{ch:reserved} for a
  1199. list of all reserved words.)
  1200. \item Functions can also return complex types, such as records and arrays.
  1201. \item You can handle function results in the function itself, as a variable.
  1202. Example
  1203. \begin{verbatim}
  1204. function a : longint;
  1205. begin
  1206. a:=12;
  1207. while a>4 do
  1208. begin
  1209. {...}
  1210. end;
  1211. end;
  1212. \end{verbatim}
  1213. The example above would work with TP, but the compiler would assume
  1214. that the \var{a>4} is a recursive call. To do a recursive call in
  1215. this you must append \var{()} behind the function name:
  1216. \begin{verbatim}
  1217. function a : longint;
  1218. begin
  1219. a:=12;
  1220. { this is the recursive call }
  1221. if a()>4 then
  1222. begin
  1223. {...}
  1224. end;
  1225. end;
  1226. \end{verbatim}
  1227. \item There is partial support of Delphi constructs. (see the \progref for
  1228. more information on this).
  1229. \item The \var{exit} call accepts a return value for functions.
  1230. \begin{verbatim}
  1231. function a : longint;
  1232. begin
  1233. a:=12;
  1234. if a>4 then
  1235. begin
  1236. exit(a*67); {function result upon exit is a*67 }
  1237. end;
  1238. end;
  1239. \end{verbatim}
  1240. \item \fpc supports function overloading. That is, you can define many
  1241. functions with the same name, but with different arguments. For example:
  1242. \begin{verbatim}
  1243. procedure DoSomething (a : longint);
  1244. begin
  1245. {...}
  1246. end;
  1247. procedure DoSomething (a : real);
  1248. begin
  1249. {...}
  1250. end;
  1251. \end{verbatim}
  1252. You can then call procedure \var{DoSomething} with an argument of type
  1253. \var{Longint} or \var{Real}.\\
  1254. This feature has the consequence that a previously declared function must
  1255. always be defined with the header completely the same:
  1256. \begin{verbatim}
  1257. procedure x (v : longint); forward;
  1258. {...}
  1259. procedure x;{ This will overload the previously declared x}
  1260. begin
  1261. {...}
  1262. end;
  1263. \end{verbatim}
  1264. This construction will generate a compiler error, because the compiler
  1265. didn't find a definition of \var{procedure x (v : longint);}. Instead you
  1266. should define your procedure x as:
  1267. \begin{verbatim}
  1268. procedure x (v : longint);
  1269. { This correctly defines the previously declared x}
  1270. begin
  1271. {...}
  1272. end;
  1273. \end{verbatim}
  1274. (The \seeo{So} switch disables overloading. When you use it, the above will
  1275. compile, as in Turbo Pascal.
  1276. \item Operator overloading. \fpc allows to overload operators, i.e. you can
  1277. define e.g. the '+' operator for matrices.
  1278. \item On FAT16 and FAT32 systems, long file names are supported.
  1279. \end{enumerate}
  1280. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1281. % Turbo Pascal compatibility mode
  1282. \section{Turbo Pascal compatibility mode}
  1283. When you compile a program with the \var{-So} switch, the compiler will
  1284. attempt to mimic the Turbo Pascal compiler in the following ways:
  1285. \begin{itemize}
  1286. \item Assigning a procedural variable doesn't require a @ operator. One of
  1287. the differences between Turbo Pascal and \fpc is that the latter requires
  1288. you to specify an address operator when assigning a value to a procedural
  1289. variable. In Turbo Pascal compatibility mode, this is not required.
  1290. \item Procedure overloading is disabled. This means that function header and
  1291. implementation can be different (i.e. the function iplementation doesn't
  1292. need to repeat the function header).
  1293. \item Forward defined procedures don't need the full parameter list when
  1294. they are defined. Due to the procedure overloading feature of \fpc, you must
  1295. always specify the parameter list of a function when you define it, even
  1296. when it was declared earlier with \var{Forward}. In Turbo Pascal
  1297. compatibility mode, there is no function overloading, hence you can omit the
  1298. parameter list:
  1299. \begin{verbatim}
  1300. Procedure a (L : Longint); Forward;
  1301. ...
  1302. Procedure a ; { No need to repeat the (L : Longint) }
  1303. begin
  1304. ...
  1305. end;
  1306. \end{verbatim}
  1307. \item recursive function calls are handled dfferently. Consider the
  1308. following example :
  1309. \begin{verbatim}
  1310. Function expr : Longint;
  1311. begin
  1312. ...
  1313. Expr:=L:
  1314. Writeln (Expr);
  1315. ...
  1316. end;
  1317. \end{verbatim}
  1318. In Turbo Pascal compatibility mode, the function will be called recursively
  1319. when the \var{writeln} statement is processed. In \fpc, the function result
  1320. will be printed. In order to call the function recusively under \fpc, you
  1321. need to implement it as follows :
  1322. \begin{verbatim}
  1323. Function expr : Longint;
  1324. begin
  1325. ...
  1326. Expr:=L:
  1327. Writeln (Expr());
  1328. ...
  1329. end;
  1330. \end{verbatim}
  1331. \item Any text after the final \var{End.} statement is ignored. Normally,
  1332. this text is processed too.
  1333. \item You cannot assign procedural variables to void pointers.
  1334. \item The @ operator is typed when applied on procedures.
  1335. \item You cannot nest comments.
  1336. \end{itemize}
  1337. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1338. % Utilities.
  1339. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1340. \chapter{Utilities and units that come with Free Pascal}
  1341. \label{ch:Utilities}
  1342. Besides the compiler and the Run-Time Library, \fpc comes with some utility
  1343. programs and units. Here we list these programs and units.
  1344. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1345. % Supplied programs
  1346. \section{Supplied programs}
  1347. \subsection{ppudump program}
  1348. \file{ppudump} is a program which shows the contents of a \fpc unit. It
  1349. is distributed with the compiler you can just issue the following command
  1350. \begin{verbatim}
  1351. ppudump [options] foo.ppu
  1352. \end{verbatim}
  1353. to display the contents of the \file{foo.ppu} unit. You can specify multiple
  1354. files on the command line.
  1355. The options can be used to change the verbosity of the display. By default,
  1356. all available information is displayed.
  1357. You can set the verbosity level using the \var{-Vxxx} option.
  1358. Here, \var{xxx} is a combination of the following
  1359. letters:
  1360. \begin{description}
  1361. \item [h:\ ] show header info.
  1362. \item [i:\ ] show interface information.
  1363. \item [m:\ ] show implementation information.
  1364. \item [d:\ ] show only (interface) definitions.
  1365. \item [s:\ ] show only (interface) symbols.
  1366. \item [b:\ ] show browser info.
  1367. \item [a:\ ] show everything (default if no -V option is present).
  1368. \end{description}
  1369. \subsection{Demo programs}
  1370. Also distributed with \fpc comes a series of demonstration programs.
  1371. These programs have no other purpose than demonstrating the capabilities of
  1372. \fpc. They are located in the \file{demo} directory of the sources.
  1373. \subsection{Documentation Example programs}
  1374. All example programs of the documentation are available. Check out the
  1375. directories that end on \file{ex} in the documentation sources. There you
  1376. will find all example sources.
  1377. \subsection{ppumove program}
  1378. \file{ppumove} is a program to make shared or static libraries from
  1379. multiple units. It can be compared with the \file{tpumove} program that
  1380. comes with
  1381. Turbo Pascal.
  1382. It should be distributed in binary form along with the compiler.
  1383. It's usage is very simple:
  1384. \begin{verbatim}
  1385. ppumove [options] unit1.ppu unit2.ppu ... unitn.ppu
  1386. \end{verbatim}
  1387. Where \var{options} is a combination of
  1388. \begin{description}
  1389. \item[-b:\ ] If specified, ppumve will generate a batch file that will
  1390. contain the external linking and archiving commands that must be
  1391. executed. The name of this batch file is \file{pmove.sh} on \linux, and
  1392. \file{pmove.bat} otherwise.
  1393. \item[-d xxx:\ ] If specified, the output files will put in the directory
  1394. \file{xxx}
  1395. \item[-e xxx:\ ] Sets the extension of the moved unit files to \file{xxx}.
  1396. By default, this is \file{.ppl}. You don't have to specify the dot.
  1397. \item[-o xxx:\ ] sets the name of the output file, i.e. the name of the file
  1398. containing all the units. This parameter is mandatory when you use multiple
  1399. files. On \linux, \file{ppumove} will prepend this name with \file{lib} if it isn't
  1400. already there, and will add an extension appropriate to the type of library.
  1401. \item [-q:\ ] Causes \file{ppumove} to operate silently.
  1402. \item [-s:\ ] Tells \file{ppumove} to make a static library instead of a
  1403. dynamic one; By default a dynamic library is made on \linux.
  1404. \item [-w:\ ] Tells ppumove that it is working under \windowsnt. This will
  1405. change the names of te linker and archiving program to \file{ldw} and
  1406. \file{arw}, respectively.
  1407. \item[-h or -?:\ ] will display a short help.
  1408. \end{description}
  1409. The action of the ppumve program is as follows:
  1410. It takes each of the unit files, and modifies it so that the compile will
  1411. know that it should look for the unit code in the library. The new unit
  1412. files will have an extension \file{.ppu}, this can be changed with the
  1413. \var{-e} option. It will then put together all the object files of the units
  1414. into one library, static or dynamic, depending on the presence of the
  1415. \var{-s} option.
  1416. The name of this library must be set with the \var{-o} option.
  1417. If needed, the prefix \file{lib} will be prepended under \linux..
  1418. The extension will be set to \file{.a} for static libraries,
  1419. for shared libraries the extensions are \var{.so} on linux, and \var{.dll}
  1420. under \windowsnt and \ostwo.
  1421. As an example, the following command
  1422. \begin{verbatim}
  1423. ./ppumove -o both -e ppl ppu.ppu timer.ppu
  1424. \end{verbatim}
  1425. under linux, will generate the following output:
  1426. \begin{verbatim}
  1427. PPU-Mover Version 0.99.7
  1428. Copyright (c) 1998 by the Free Pascal Development Team
  1429. Processing ppu.ppu... Done.
  1430. Processing timer.ppu... Done.
  1431. Linking timer.o ppu.o
  1432. Done.
  1433. \end{verbatim}
  1434. And it will produce the following files:
  1435. \begin{enumerate}
  1436. \item \file{libboth.so} : The shared library containing the code from
  1437. \file{ppu.o} and \file{timer.o}. Under \windowsnt, this file would be called
  1438. \file{both.dll}.
  1439. \item \file{timer.ppl} : The unit file that tells the \fpc compiler to look
  1440. for the timer code in the library.
  1441. \item \file{ppu.ppl} : The unit file that tells the \fpc compiler to look
  1442. for the timer code in the library.
  1443. \end{enumerate}
  1444. You could then use or distribute the files \file{libboth.so}, \file{timer.ppl}
  1445. and \file{ppu.ppl}.
  1446. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1447. % Supplied units
  1448. \section{Supplied units}
  1449. Here we list the units that come with the \fpc distribution. Since there is
  1450. a difference in the supplied units per operating system, we list them
  1451. separately per system. They are documented in the \unitsref.
  1452. %
  1453. % Under DOS
  1454. %
  1455. \subsection{Under DOS}
  1456. \begin{itemize}
  1457. \item [strings] This unit provides basic
  1458. string handling routines for the \var{pchar} type, comparable to similar
  1459. routines in standard \var{C} libraries.
  1460. \item [objects] This unit provides basic
  1461. routines for handling objects.
  1462. \item [dos] This unit provides basic routines for
  1463. accessing the operating system \dos. It provides almost the same
  1464. functionality as the Turbo Pascal unit.
  1465. \item [printer] This unit provides all you
  1466. need for rudimentary access to the printer.
  1467. \item [getopts] This unit gives you the
  1468. \gnu \var{getopts} command-line arguments handling mechanism.
  1469. It also supports long options.
  1470. \item [crt] This unit provides basic screen
  1471. handling routines. It provides the same functionality as the Turbo Pascal \var{CRT}
  1472. unit.
  1473. \item [graph] This unit provides basic graphics
  1474. handling, with routines to draw lines on the screen, display texts etc. It
  1475. provides the same functions as the Turbo Pascal unit.
  1476. \item [go32] This unit provides access to possibilities of the \var{GO32}
  1477. \dos extender.
  1478. \item [emu387] This unit provides support for the coprocessor emulator.
  1479. \item [mmx] This unit provides support for \var{mmx} extensions in your
  1480. code.
  1481. \end{itemize}
  1482. %
  1483. % Under Linux
  1484. %
  1485. \subsection{Under Linux}
  1486. \begin{itemize}
  1487. \item [strings] This unit provides basic
  1488. string handling routines for the \var{PChar} type, comparable to similar
  1489. routines in standard \var{C} libraries.
  1490. \item [objects] This unit provides basic
  1491. routines for handling objects.
  1492. \item [crt] This unit provides basic screen
  1493. handling routines. It provides the same functionality Turbo Pascal \var{CRT}
  1494. unit. It works on any terminal which supports the \var{vt100} escape
  1495. sequences.
  1496. \item [dos] This unit provides an emulation of the
  1497. same unit under \dos. It is intended primarily for easy porting of Pascal
  1498. programs from \dos to \linux. For good performance, however, it is
  1499. recommended to use the \var{linux} unit.
  1500. \item [linux] This unit provides access to the
  1501. \linux operating system. It provides most file and I/O handling routines
  1502. that you may need. It implements most of the standard \var{C} library constructs
  1503. that you will find on a Unix system. If you do a lot of disk/file
  1504. operations, the use of this unit is recommended over the one you use under
  1505. Dos.
  1506. \item [printer] This unit provides an
  1507. interface to the standard Unix printing mechanism.
  1508. \item [getopts] This unit gives you the
  1509. \gnu \var{getopts} command-line arguments handling mechanism.
  1510. It also supports long options.
  1511. \item [mmx] This unit provides support for \var{mmx} extensions in your
  1512. code.
  1513. \item [sockets] This unit gives you access to sockets and TCP/IP
  1514. programming.
  1515. \item [graph] Is an implementation of Borlands \file{graph} unit, which
  1516. works on the Linux console. It's implementation is fairly complete, the only
  1517. non-functional things are the fillpatterns and line styles. It uses the
  1518. libvga and libvgagl graphics libraries, so you need these installed for this
  1519. unit to work. Also, programs using this library need to be run as root, or
  1520. setuid root, and hence are a potential security risk.
  1521. \item [ports] This implements the various \var{port[]} constructs. These are
  1522. provided for compatibility only, and it is not recommended to use them
  1523. extensively. Programs using this construct must be run as ruit or setuid
  1524. root, and are a serious security risk on your system.
  1525. \end{itemize}
  1526. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1527. % Debugging
  1528. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1529. \chapter{Debugging your Programs}
  1530. \fpc supports debug information for the \gnu debugger \var{gdb}.
  1531. This chapter describes shortly how to use this feature. It doesn't attempt
  1532. to describe completely the \gnu debugger, however.
  1533. For more information on the workings of the \gnu debugger, see the \var{gdb}
  1534. users' guide.
  1535. \fpc also suports \var{gprof}, the \gnu profiler, see section \ref{se:gprof}
  1536. for more information on profiling.
  1537. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1538. % Compiling your program with debugger support
  1539. \section{Compiling your program with debugger support}
  1540. First of all, you must be sure that the compiler is compiled with debugging
  1541. support. Unfortunately, there is no way to check this at run time, except by
  1542. trying to compile a program with debugging support.
  1543. To compile a program with debugging support, just specify the \var{-g}
  1544. option on the command-line, as follows:
  1545. \begin{verbatim}
  1546. ppc386 -g hello.pp
  1547. \end{verbatim}
  1548. This will generate debugging information in the executable from your
  1549. program. You will notice that the size of the executable increases
  1550. substantially because of this\footnote{A good reason not to include debug
  1551. information in an executable you plan to distribute.}.
  1552. Note that the above will only generate debug information {\var for the code
  1553. that has been generated} when compiling \file{hello.pp}. This means that if
  1554. you used some units (the system unit, for instance) which were not compiled
  1555. with debugging support, no debugging support will be available for the code
  1556. in these units.
  1557. There are 2 solutions for this problem.
  1558. \begin{enumerate}
  1559. \item Recompile all units manually with the \var{-g} option.
  1560. \item Specify the 'build' option (\var{-B}) when compiling with debugging
  1561. support. This will recompile all units, and insert debugging information in
  1562. each of the units.
  1563. \end{enumerate}
  1564. The second option may have undesirable side effects. It may be that some
  1565. units aren't found, or compile incorrectly due to missing conditionals,
  1566. etc..
  1567. If all went well, the executable now contains the necessary information with
  1568. which you can debug it using \gnu \var{gdb}.
  1569. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1570. % Using gdb
  1571. \section{Using \var{gdb} to debug your program}
  1572. To use gdb to debug your program, you can start the debugger, and give it as
  1573. an option the {\em full} name of your program:
  1574. \begin{verbatim}
  1575. gdb hello
  1576. \end{verbatim}
  1577. Or, under \dos :
  1578. \begin{verbatim}
  1579. gdb hello.exe
  1580. \end{verbatim}
  1581. This starts the debugger, and the debugger immediately loads your program
  1582. into memory, but it does not run the program yet. Instead, you are presented
  1583. with the following (more or less) message, followed by the \var{gdb} prompt
  1584. \var{'(gdb)'}:
  1585. \begin{verbatim}
  1586. GDB is free software and you are welcome to distribute copies of it
  1587. under certain conditions; type "show copying" to see the conditions.
  1588. There is absolutely no warranty for GDB; type "show warranty" for details.
  1589. GDB 4.15.1 (i486-slackware-linux),
  1590. Copyright 1995 Free Software Foundation, Inc...
  1591. (gdb)
  1592. \end{verbatim}
  1593. To start the program you can use the \var{run} command. You can optionally
  1594. specify command-line parameters, which will then be fed to your program, for
  1595. example:
  1596. \begin{verbatim}
  1597. (gdb) run -option -anotheroption needed_argument
  1598. \end{verbatim}
  1599. If your program runs without problems, \var{gdb} will inform you of this,
  1600. and return the exit code of your program. If the exit code was zero, then
  1601. the message \var{'Program exited normally'}.
  1602. If something went wrong (a segmentation fault or so), \var{gdb} will stop
  1603. the execution of your program, and inform you of this with an appropriate
  1604. message. You can then use the other \var{gdb} commands to see what happened.
  1605. Alternatively, you can instruct \var{gdb} to stop at a certain point in your
  1606. program, with the \var{break} command.
  1607. Here is a short list of \var{gdb} commands, which you are likely to need when
  1608. debugging your program:
  1609. \begin{description}
  1610. \item [quit\ ] Exits the debugger.
  1611. \item [kill\ ] Stops a running program.
  1612. \item [help\ ] Gives help on all \var{gdb} commands.
  1613. \item [file\ ] Loads a new program into the debugger.
  1614. \item [directory\ ] Add a new directory to the search path for source
  1615. files.\\
  1616. {\em Remark:} My copy of gdb needs '.' to be added explicitly to the search
  1617. path, otherwise it doesn't find the sources.
  1618. \item [list\ ] Lists the program sources per 10 lines. As an option you can
  1619. specify a line number or function name.
  1620. \item [break\ ] Sets a breakpoint at a specified line or function
  1621. \item [awatch\ ] Sets a watch-point for an expression. A watch-point stops
  1622. execution of your program whenever the value of an expression is either
  1623. read or written.
  1624. \end{description}
  1625. for more information, see the \var{gdb} users' guide, or use the \var{'help'}
  1626. function in \var{gdb}.
  1627. The appendix {\ref{ch:GdbIniFile}} contains a sample init file for
  1628. \var{gdb}, which produces good results when debugging \fpc programs.
  1629. It is also possible to use \file{RHIDE}, a text-based IDE that uses gdb.
  1630. There is a version of RHIDE available that can work together with FPC.
  1631. \section{Caveats when debugging with \var{gdb}}
  1632. There are some peculiarities of \fpc which you should be aware of when using
  1633. \var{gdb}. We list the main ones here:
  1634. \begin{enumerate}
  1635. \item \fpc generates information for GDB in uppercare letters. This is a
  1636. consequence of the fact that pascal is a case insensitive language. So, when
  1637. referring to a variable or function, you need to make it's name all
  1638. uppercase.
  1639. As an example, of you want to watch the value of a loop variable
  1640. \var{count}, you should type
  1641. \begin{verbatim}
  1642. watch COUNT
  1643. \end{verbatim}
  1644. Or if you want stop when a certain function (e.g \var{MyFunction}) is called,
  1645. type
  1646. \begin{verbatim}
  1647. break MYFUNCTION
  1648. \end{verbatim}
  1649. \item Line numbers may be off by a little. This is a bug in \fpc and will be
  1650. fixed as soon as possible.
  1651. \item \var{gdb} does not know sets.
  1652. \item \var{gdb} doesn't know strings. Strings are represented in \var{gdb}
  1653. as records with a length field and an array of char contaning the string.
  1654. You can also use the following user function to print strings:
  1655. \begin{verbatim}
  1656. define pst
  1657. set $pos=&$arg0
  1658. set $strlen = {byte}$pos
  1659. print {char}&$arg0.st@($strlen+1)
  1660. end
  1661. document pst
  1662. Print out a Pascal string
  1663. end
  1664. \end{verbatim}
  1665. If you insert it in your \file{gdb.ini} file, you can look at a string with this
  1666. function. There is a sample \file{gdb.ini} in appendix \ref{ch:GdbIniFile}.
  1667. \item Objects are difficult to handle, mainly because \var{gdb} is oriented
  1668. towards C and C++. The workaround implemented in \fpc is that object methods
  1669. are represented as functions, with an extra parameter \var{this} (all
  1670. lowercase !) The name of this function is a concatenation of the object type
  1671. and the function name, separated by two underscore characters.
  1672. For example, the method \var{TPoint.Draw} would be converted to
  1673. \var{TPOINT\_\_DRAW}, and could be stopped at with
  1674. \begin{verbatim}
  1675. break TPOINT__DRAW
  1676. \end{verbatim}
  1677. \item Global overloaded functions confuse \var{gdb} because they have the same
  1678. name. Thus you cannot set a breakpoint at an overloaded function, unless you
  1679. know it's line number, in which case you can set a breakpoint at the
  1680. starting linenumber of the function.
  1681. \end{enumerate}
  1682. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1683. % Using gprof
  1684. \section{Support for \var{gprof}, the \gnu profiler}
  1685. \label{se:gprof}
  1686. You can compile your programs with profiling support. for this, you just
  1687. have to use the compiler switch \var{-pg}. The compiler wil insert the
  1688. necessary stuff for profiling.
  1689. When you have done this, you can run your program uder the gnu profiler,
  1690. \var{gprof}, as follows :
  1691. \begin{verbatim}
  1692. gprog yourexe
  1693. \end{verbatim}
  1694. Where \file{yourexe} is the name of your executable.
  1695. You may want to capture the outpus of the profiler in a file, since it can
  1696. be quite a lot, as follows:
  1697. \begin{verbatim}
  1698. gprog yourexe >gprof.out
  1699. \end{verbatim}
  1700. For more information on the \gnu profiler \var{gprof}, see its manual.
  1701. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1702. % CGI.
  1703. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1704. \chapter{CGI programming in Free Pascal}
  1705. \label{ch:CGIProgramming}
  1706. In these days of heavy WWW traffic on the Internet, CGI scripts have become
  1707. an important topic in computer programming. While CGI programming can be
  1708. done with almost any tool you wish, most languages aren't designed for it.
  1709. Perl may be a notable exception, but perl is an interpreted language, the
  1710. executable is quite big, and hence puts a big load on the server machine.
  1711. Because of its simple, almost intuitive, string handling and its easy syntax,
  1712. Pascal is very well suited for CGI programming. Pascal allows you to quickly
  1713. produce some results, while giving you all the tools you need for more
  1714. complex programming. The basic RTL routines in principle are enough to get
  1715. the job done, but you can create, with relatively little effort, some units
  1716. which can be used as a base for more complex CGI programming.
  1717. That's why, in this chapter, we will discuss the basics of CGI in \fpc.
  1718. In the subsequent, we will assume that the server for which the programs are
  1719. created, are based upon the NCSA \var{httpd} WWW server, as the examples
  1720. will be based upon the NCSA method of CGI programming\footnote{... and it's
  1721. the only WWW-server I have to my disposition at the moment.}.
  1722. They have been tested with the \file{apache} server on \linux, and
  1723. the \file{xitami} server on \windowsnt.
  1724. The two example programs in this chapter have been tested on the command line
  1725. and worked, under the condition that no spaces were present in the name and
  1726. value pairs provided to them.
  1727. There is however, a faster and generally better \file{uncgi} unit available,
  1728. you can find it on the contributed units page of the \fpc web site. It uses
  1729. techniques discussed here, but in a generally more efficient way, and it
  1730. also provides some extra functionality, not discussed here.
  1731. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1732. % Getting your data
  1733. \section{Getting your data}
  1734. Your CGI program must react on data the user has filled in on the form which
  1735. your web-server gave him. The Web server takes the response on the form, and
  1736. feeds it to the CGI script.
  1737. There are essentially two ways of feeding the data to the CGI script. We will
  1738. discuss both.
  1739. %
  1740. %
  1741. % Data coming through standard input.
  1742. \subsection{Data coming through standard input.}
  1743. The first method of getting your data is through standard input. This method
  1744. is invoked when the form uses a form submission method of \var{POST}.
  1745. The web browser sets three environment variables \var{REQUEST\_METHOD},
  1746. \var{CONTENT\_TYPE} and \var{CONTENT\_LENGTH}. It feeds then the results of
  1747. the different fields through standard input to the CGI script.
  1748. All the Pascal program has to do is :
  1749. \begin{itemize}
  1750. \item Check the value of the \var{REQUEST\_METHOD} environment variable. The
  1751. \var{getenv} function will retrieve this value this for you.
  1752. \item Check the value of the \var{CONTENT\_TYPE} environment variable.
  1753. \item Read \var{CONTENT\_LENGTH} characters from standard input. \var{read
  1754. (c)} with \var{c} of type \var{char} will take care of that.
  1755. \end{itemize}
  1756. if you know that the request method will always be \var{POST}, and the
  1757. \var{CONTENT\_TYPE} will be correct, then you can skip the first two steps.
  1758. The third step can be done easier: read characters until you reach the
  1759. end-of-file marker of standard input.
  1760. The following example shows how this can be achieved:
  1761. \begin{verbatim}
  1762. program cgi_post;
  1763. uses dos;
  1764. const max_data = 1000;
  1765. type datarec = record
  1766. name,value : string;
  1767. end;
  1768. var data : array[1..max_data] of datarec;
  1769. i,nrdata : longint;
  1770. c : char;
  1771. literal,aname : boolean;
  1772. begin
  1773. writeln ('Content-type: text/html');
  1774. writeln;
  1775. if getenv('REQUEST_METHOD')<>'POST' then
  1776. begin
  1777. writeln ('This script should be referenced with a METHOD of POST');
  1778. write ('If you don''t understand this, see this ');
  1779. write ('< A HREF="http://www.ncsa.uiuc.edu/SDG/Softare/Mosaic');
  1780. writeln ('/Docs/fill-out-forms/overview.html">forms overview</A>.');
  1781. halt(1);
  1782. end;
  1783. if getenv('CONTENT_TYPE')<>'application/x-www-form-urlencoded' then
  1784. begin
  1785. writeln ('This script can only be used to decode form results');
  1786. halt(1)
  1787. end;
  1788. nrdata:=1;
  1789. aname:=true;
  1790. while not eof(input) do
  1791. begin
  1792. literal:=false;
  1793. read(c);
  1794. if c='\' then
  1795. begin
  1796. literal:=true;
  1797. read(c);
  1798. end;
  1799. if literal or ((c<>'=') and (c<>'&')) then
  1800. with data[nrdata] do
  1801. if aname then name:=name+c else value:=value+c
  1802. else
  1803. begin
  1804. if c='&' then
  1805. begin
  1806. inc (nrdata);
  1807. aname:=true;
  1808. end
  1809. else
  1810. aname:=false;
  1811. end
  1812. end;
  1813. writeln ('<H1>Form Results :</H1>');
  1814. writeln ('You submitted the following name/value pairs :');
  1815. writeln ('<UL>');
  1816. for i:=1 to nrdata do writeln ('<LI> ',data[i].name,' = ',data[i].value);
  1817. writeln ('</UL>');
  1818. end.
  1819. \end{verbatim}
  1820. While this program isn't shorter than the C program provided as an example
  1821. at NCSA, it doesn't need any other units. everythig is done using standard
  1822. Pascal procedures\footnote{actually, this program will give faulty results,
  1823. since spaces in the input are converted to plus signs by the web browser.
  1824. The program doesn't check for this, but that is easy to change.
  1825. The main concern here is to give the working principle.}.
  1826. Note that this program has a limitation: the length of names and values is
  1827. limited to 255 characters. This is due to the fact that strings in Pascal
  1828. have a maximal length of 255. It is of course easy to redefine the
  1829. \var{datarec} record in such a way that longer values are allowed.
  1830. In case you have to read the contents of a \var{TEXTAREA} form element,
  1831. this may be needed.
  1832. % Data passed through an environment variable
  1833. \subsection{Data passed through an environment variable}
  1834. If your form uses the \var{GET} method of passing it's data, the CGI script
  1835. needs to read the \var{QUERY\_STRING} environment variable to get it's data.
  1836. Since this variable can, and probably will, be more than 255 characters long,
  1837. you will not be able to use normal string methods, present in pascal. \fpc
  1838. implements the \var{pchar} type, which is a pointer to a null-terminated
  1839. array of characters.
  1840. And, fortunately, \fpc has a
  1841. \seestrings\ unit, which eases the use of the
  1842. \var{pchar} type.
  1843. The following example illustrates what to do in case of a method of \var{GET}
  1844. \begin{verbatim}
  1845. program cgi_get;
  1846. uses strings,linux;
  1847. const max_data = 1000;
  1848. type datarec = record
  1849. name,value : string;
  1850. end;
  1851. var data : array[1..max_data] of datarec;
  1852. i,nrdata : longint;
  1853. p : PChar;
  1854. literal,aname : boolean;
  1855. begin
  1856. Writeln ('Content-type: text/html');
  1857. Writeln;
  1858. if StrComp(GetEnv('REQUEST_METHOD'),'POST')<>0 then
  1859. begin
  1860. Writeln ('This script should be referenced with a METHOD of GET');
  1861. write ('If you don''t understand this, see this ');
  1862. write ('< A HREF="http://www.ncsa.uiuc.edu/SDG/Softare/Mosaic');
  1863. Writeln ('/Docs/fill-out-forms/overview.html">forms overview</A>.');
  1864. halt(1);
  1865. end;
  1866. p:=GetEnv('QUERY_STRING');
  1867. nrdata:=1;
  1868. aname:=true;
  1869. while p^<>#0 do
  1870. begin
  1871. literal:=false;
  1872. if p^='\' then
  1873. begin
  1874. literal:=true;
  1875. inc(longint(p));
  1876. end;
  1877. if ((p^<>'=') and (p^<>'&')) or literal then
  1878. with data[nrdata] do
  1879. if aname then name:=name+p^ else value:=value+p^
  1880. else
  1881. begin
  1882. if p^='&' then
  1883. begin
  1884. inc (nrdata);
  1885. aname:=true;
  1886. end
  1887. else
  1888. aname:=false;
  1889. end;
  1890. inc(longint(p));
  1891. end;
  1892. Writeln ('<H1>Form Results :</H1>');
  1893. Writeln ('You submitted the following name/value pairs :');
  1894. Writeln ('<UL>');
  1895. for i:=1 to nrdata do writeln ('<LI> ',data[i].name,' = ',data[i].value);
  1896. Writeln ('</UL>');
  1897. end.
  1898. \end{verbatim}
  1899. Although it may not be written in the most elegant way, this program does
  1900. the same thing as the previous one. It also suffers from the same drawback,
  1901. namely the limited length of the \var{value} field of the \var{datarec}.
  1902. This drawback can be remedied by redefining \var{datarec} as follows:
  1903. \begin{verbatim}
  1904. type datarec = record;
  1905. name,value : pchar;
  1906. end;
  1907. \end{verbatim}
  1908. and assigning at run time enough space to keep the contents of the value
  1909. field. This can be done with a
  1910. \begin{verbatim}
  1911. getmem (data[nrdata].value,needed_number_of_bytes);
  1912. \end{verbatim}
  1913. call. After that you can do a
  1914. \begin{verbatim}
  1915. strlcopy (data[nrdata].value,p,needed_number_of_bytes);
  1916. \end{verbatim}
  1917. to copy the data into place.
  1918. You may have noticed the following unorthodox call :
  1919. \begin{verbatim}
  1920. inc(longint(p));
  1921. \end{verbatim}
  1922. \fpc doesn't give you pointer arithmetic as in C. However, \var{longints} and
  1923. \var{pointers} have the same length (namely 4 bytes). Doing a type-cast to a
  1924. \var{longint} allows you to do arithmetic on the \var{pointer}.
  1925. Note however, that this is a non-portable call. This may work on the I386
  1926. processor, but not on a ALPHA processor (where a pointer is 8 bytes long).
  1927. This will be remedied in future releases of \fpc.
  1928. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1929. % Producing output
  1930. \section{Producing output}
  1931. The previous section concentrated mostly on getting input from the web
  1932. server. To send the reply to the server, you don't need to do anything
  1933. special.You just print your data on standard output, and the Web-server will
  1934. intercept this, and send your output to the WWW-client waiting for it.
  1935. You can print anything you want, the only thing you must take care of is
  1936. that you supply a \var{Contents-type} line, followed by an empty line, as
  1937. follows:
  1938. \begin{verbatim}
  1939. Writeln ('Content-type: text/html');
  1940. Writeln;
  1941. { ...start output of the form... }
  1942. \end{verbatim}
  1943. And that's all there is to it !
  1944. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1945. % I'm under Windows, what now ?
  1946. \section{I'm under Windows, what now ?}
  1947. Under Windows the system of writing CGI scripts can be totally different.
  1948. If you use \fpc under Windows then you also should be able to do CGI
  1949. programming, but the above instructions may not work. They are known to work
  1950. for the \file{xitami} server, however.
  1951. If some kind soul is willing to write a section on CGI programming under
  1952. Windows for other servers, I'd be willing to include it here.
  1953. \appendix
  1954. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1955. % APPENDIX A.
  1956. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1957. \chapter{Alphabetical listing of command-line options}
  1958. The following is alphabetical listing of all command-line options, as
  1959. generated by the compiler:
  1960. \begin{verbatim}
  1961. ppc386 [options] <inputfile> [options]
  1962. put + after a boolean switch option to enable it, - to disable it
  1963. -a the compiler doesn't delete the generated assembler file
  1964. -al list sourcecode lines in assembler file
  1965. -B build all modules
  1966. -C code generation options
  1967. -CD create dynamic library
  1968. -Ch<n> <n> bytes heap (between 1023 and 67107840)
  1969. -Ci IO-checking
  1970. -Cn omit linking stage
  1971. -Co check overflow of integer operations
  1972. -Cr range checking
  1973. -Cs<n> set stack size to <n>
  1974. -Ct stack checking
  1975. -CS create static library
  1976. -Cx use smartlinking
  1977. -d<x> defines the symbol <x>
  1978. -e<x> set path to executable
  1979. -E same as -Cn
  1980. -F set file names and paths
  1981. -FD<x> sets the directory where to search for compiler utilities
  1982. -Fe<x> redirect error output to <x>
  1983. -FE<x> set exe/unit output path to <x>
  1984. -Fg<x> same as -Fl
  1985. -Fi<x> adds <x> to include path
  1986. -Fl<x> adds <x> to library path
  1987. -FL<x> uses <x> as dynamic linker
  1988. -Fo<x> adds <x> to object path
  1989. -Fr<x> load error message file <x>
  1990. -Fu<x> adds <x> to unit path
  1991. -FU<x> set unit output path to <x>, overrides -FE
  1992. -g generate debugger information
  1993. -gg use gsym
  1994. -gd use dbx
  1995. -gh use heap trace unit
  1996. -i information
  1997. -iD return compiler date
  1998. -iV return compiler version
  1999. -iSO return source OS
  2000. -iSP return source processor
  2001. -iTO return target OS
  2002. -iTP return target processor
  2003. -I<x> adds <x> to include path
  2004. -k<x> Pass <x> to the linker
  2005. -l write logo
  2006. -n don't read the default config file
  2007. -o<x> change the name of the executable produced to <x>
  2008. -pg generate profile code for gprof
  2009. -P use pipes instead of creating temporary assembler files
  2010. -S syntax options
  2011. -S2 switch some Delphi 2 extensions on
  2012. -Sc supports operators like C (*=,+=,/= and -=)
  2013. -Sd tries to be Delphi compatible
  2014. -Se compiler stops after the first error
  2015. -Sg allow LABEL and GOTO
  2016. -Si support C++ stlyed INLINE
  2017. -Sm support macros like C (global)
  2018. -So tries to be TP/BP 7.0 compatible
  2019. -Sp tries to be gpc compatible
  2020. -Ss constructor name must be init (destructor must be done)
  2021. -St allow static keyword in objects
  2022. -s don't call assembler and linker (only with -a)
  2023. -u<x> undefines the symbol <x>
  2024. -U unit options
  2025. -Un don't check the unit name
  2026. -Up<x> same as -Fu<x>
  2027. -Us compile a system unit
  2028. -v<x> Be verbose. <x> is a combination of the following letters :
  2029. e : Show errors (default) d : Show debug info
  2030. w : Show warnings u : Show unit info
  2031. n : Show notes t : Show tried/used files
  2032. h : Show hints m : Show defined macros
  2033. i : Show general info p : Show compiled procedures
  2034. l : Show linenumbers c : Show conditionals
  2035. a : Show everything 0 : Show nothing (except errors)
  2036. b : Show all procedure r : Rhide/GCC compatibility mode
  2037. declarations if an error x : Executable info (Win32 only)
  2038. occurs
  2039. -X executable options
  2040. -Xc link with the c library
  2041. -XD link with dynamic libraries (defines FPC_LINK_DYNAMIC)
  2042. -Xs strip all symbols from executable
  2043. -XS link with static libraries (defines FPC_LINK_STATIC)
  2044. Processor specific options:
  2045. -A<x> output format
  2046. -Ao coff file using GNU AS
  2047. -Anasmcoff coff file using Nasm
  2048. -Anasmelf elf32 (linux) file using Nasm
  2049. -Anasmobj obj file using Nasm
  2050. -Amasm obj using Masm (Mircosoft)
  2051. -Atasm obj using Tasm (Borland)
  2052. -R<x> assembler reading style
  2053. -Ratt read AT&T style assembler
  2054. -Rintel read Intel style assembler
  2055. -Rdirect copy assembler text directly to assembler file
  2056. -O<x> optimizations
  2057. -Og generate smaller code
  2058. -OG generate faster code (default)
  2059. -Or keep certain variables in registers (still BUGGY!!!)
  2060. -Ou enable uncertain optimizations (see docs)
  2061. -O1 level 1 optimizations (quick optimizations)
  2062. -O2 level 2 optimizations (-O1 + slower optimizations)
  2063. -O3 level 3 optimizations (same as -O2u)
  2064. -Op target processor
  2065. -Op1 set target processor to 386/486
  2066. -Op2 set target processor to Pentium/PentiumMMX (tm)
  2067. -Op3 set target processor to PPro/PII/c6x86/K6 (tm)
  2068. -T<x> Target operating system
  2069. -TGO32V1 version 1 of DJ Delorie DOS extender
  2070. -TGO32V2 version 2 of DJ Delorie DOS extender
  2071. -TLINUX Linux
  2072. -TOS2 OS/2 2.x
  2073. -TWin32 Windows 32 Bit
  2074. -? shows this help
  2075. -h shows this help without waiting
  2076. \end{verbatim}
  2077. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2078. % APPENDIX B.
  2079. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2080. \chapter{Alphabetical list of reserved words}
  2081. \label{ch:reserved}
  2082. \begin{latexonly}
  2083. \begin{multicols}{3}
  2084. \input{reserved.tex}
  2085. \end{multicols}
  2086. \end{latexonly}
  2087. \begin{htmlonly}
  2088. \input{reserved.tex}
  2089. \end{htmlonly}
  2090. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2091. % APPENDIX C.
  2092. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2093. \chapter{Compiler messages}
  2094. \label{ch:ErrorMessages}
  2095. This appendix is meant to list all the compiler messages. The list of
  2096. messages is generated from he compiler source itself, and should be faitly
  2097. complete. At this point, only assembler errors are not in the list.
  2098. % Message file is generated with msg2inc.
  2099. \input {messages.tex}
  2100. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2101. % Assembler reader errors
  2102. \section{Assembler reader errors.}
  2103. This section lists the errors that are generated by the inline assembler reader.
  2104. They are {\em not} the messages of the assembler itself.
  2105. % General assembler errors.
  2106. \subsection{General assembler errors}
  2107. \begin{description}
  2108. \item [Divide by zero in asm evaluator]
  2109. This fatal error is reported when a constant assembler expressions
  2110. does a division by zero.
  2111. \item [Evaluator stack overflow, Evaluator stack underflow]
  2112. These fatal errors are reported when a constant assembler expression
  2113. is too big to evaluate by the constant parser. Try reducing the
  2114. number of terms.
  2115. \item [Invalid numeric format in asm evaluator]
  2116. This fatal error is reported when a non-numeric value is detected
  2117. by the constant parser. Normally this error should never occur.
  2118. \item [Invalid Operator in asm evaluator]
  2119. This fatal error is reported when a mathematical operator is detected
  2120. by the constant parser. Normally this error should never occur.
  2121. \item [Unknown error in asm evaluator]
  2122. This fatal error is reported when an internal error is detected
  2123. by the constant parser. Normally this error should never occur.
  2124. \item [Invalid numeric value]
  2125. This warning is emitted when a conversion from octal,binary or hexadecimal
  2126. to decimal is outside of the supported range.
  2127. \item [Escape sequence ignored]
  2128. This error is emitted when a non ANSI C escape sequence is detected in
  2129. a C string.
  2130. \item [Asm syntax error - Prefix not found]
  2131. This occurs when trying to use a non-valid prefix instruction
  2132. \item [Asm syntax error - Trying to add more than one prefix]
  2133. This occurs when you try to add more than one prefix instruction
  2134. \item [Asm syntax error - Opcode not found]
  2135. You have tried to use an unsupported or unknown opcode
  2136. \item [Constant value out of bounds]
  2137. This error is reported when the constant parser determines that the
  2138. value you are using is out of bounds, either with the opcode or with
  2139. the constant declaration used.
  2140. \item [Non-label pattern contains @]
  2141. This only applied to the m68k and Intel styled assembler, this is reported
  2142. when you try to use a non-label identifier with a '@' prefix.
  2143. \item [Internal error in Findtype()]
  2144. \item [Internal Error in ConcatOpcode()]
  2145. \item [Internal Errror converting binary]
  2146. \item [Internal Errror converting hexadecimal]
  2147. \item [Internal Errror converting octal]
  2148. \item [Internal Error in BuildScaling()]
  2149. \item [Internal Error in BuildConstant()]
  2150. \item [internal error in BuildReference()]
  2151. \item [internal error in HandleExtend()]
  2152. \item [Internal error in ConcatLabeledInstr()]
  2153. \label{InternalError}
  2154. These errors should never occur, if they do then you have found
  2155. a new bug in the assembler parsers. Please contact one of the
  2156. developers.
  2157. \item [Opcode not in table, operands not checked]
  2158. This warning only occurs when compiling the system unit, or related
  2159. files. No checking is performed on the operands of the opcodes.
  2160. \item [@CODE and @DATA not supported]
  2161. This Turbo Pascal construct is not supported.
  2162. \item [SEG and OFFSET not supported]
  2163. This Turbo Pascal construct is not supported.
  2164. \item [Modulo not supported]
  2165. Modulo constant operation is not supported.
  2166. \item [Floating point binary representation ignored]
  2167. \item [Floating point hexadecimal representation ignored]
  2168. \item [Floating point octal representation ignored]
  2169. These warnings occur when a floating point constant are declared in
  2170. a base other then decimal. No conversion can be done on these formats.
  2171. You should use a decimal representation instead.
  2172. \item [Identifier supposed external]
  2173. This warning occurs when a symbol is not found in the symolb table, it
  2174. is therefore considered external.
  2175. \item [Functions with void return value can't return any value in asm code]
  2176. Only routines with a return value can have a return value set.
  2177. \item [Error in binary constant]
  2178. \item [Error in octal constant]
  2179. \item [Error in hexadecimal constant]
  2180. \item [Error in integer constant]
  2181. \label{ErrorConst}
  2182. These errors are reported when you tried using an invalid constant expression,
  2183. or that the value is out of range.
  2184. \item [Invalid labeled opcode]
  2185. \item [Asm syntax error - error in reference]
  2186. \item [Invalid Opcode]
  2187. \item [Invalid combination of opcode and operands]
  2188. \item [Invalid size in reference]
  2189. \item [Invalid middle sized operand]
  2190. \item [Invalid three operand opcode]
  2191. \item [Assembler syntax error]
  2192. \item [Invalid operand type]
  2193. You tried using an invalid combination of opcode and operands, check the syntax
  2194. and if you are sure it is correct, please contact one of the developers.
  2195. \item [Unknown identifier]
  2196. The identifier you are trying to access does not exist, or is not within the
  2197. current scope.
  2198. \item [Trying to define an index register more than once]
  2199. \item [Trying to define a segment register twice]
  2200. \item [Trying to define a base register twice]
  2201. You are trying to define an index/segment register more then once.
  2202. \item [Invalid field specifier]
  2203. The record or object field you are trying to access does not exist, or
  2204. is incorrect.
  2205. \item [Invalid scaling factor]
  2206. \item [Invalid scaling value]
  2207. \item [Scaling value only allowed with index]
  2208. Allowed scaling values are 1,2,4 or 8.
  2209. \item [Cannot use SELF outside a method]
  2210. You are trying to access the SELF identifier for objects outside a method.
  2211. \item [Invalid combination of prefix and opcode]
  2212. This opcode cannot be prefixed by this instruction
  2213. \item [Invalid combination of override and opcode]
  2214. This opcode cannot be overriden by this combination
  2215. \item [Too many operands on line]
  2216. At most three operand instructions exist on the m68k, and i386, you
  2217. are probably trying to use an invalid syntax for this opcode.
  2218. \item [Duplicate local symbol]
  2219. You are trying to redefine a local symbol, such as a local label.
  2220. \item [Unknown label identifer]
  2221. \item [Undefined local symbol]
  2222. \item [local symbol not found inside asm statement]
  2223. This label does not seem to have been defined in the current scope
  2224. \item [Assemble node syntax error]
  2225. \item [Not a directive or local symbol]
  2226. The assembler statement is invalid, or you are not using a recognized
  2227. directive.
  2228. \end{description}
  2229. % I386 specific errors
  2230. \subsection{I386 specific errors}
  2231. \begin{description}
  2232. \item [repeat prefix and a segment override on \var{<=} i386 ...]
  2233. A problem with interrupts and a prefix instruction may occur and may cause
  2234. false results on 386 and earlier computers.
  2235. \item [Fwait can cause emulation problems with emu387]
  2236. This warning is reported when using the FWAIT instruction, it can
  2237. cause emulation problems on systems which use the em387.dxe emulator.
  2238. \item [You need GNU as version >= 2.81 to compile this MMX code]
  2239. MMX assembler code can only be compiled using GAS v2.8.1 or later.
  2240. \item [NEAR ignored]
  2241. \item [FAR ignored]
  2242. \label{FarIgnored}
  2243. \var{NEAR} and \var{FAR} are ignored in the intel assemblers, but are still accepted
  2244. for compatiblity with the 16-bit code model.
  2245. \item [Invalid size for MOVSX/MOVZX]
  2246. \item [16-bit base in 32-bit segment]
  2247. \item [16-bit index in 32-bit segment]
  2248. 16-bit addressing is not supported, you must use 32-bit addressing.
  2249. \item [Constant reference not allowed]
  2250. It is not allowed to try to address a constant memory address in protected
  2251. mode.
  2252. \item [Segment overrides not supported]
  2253. Intel style (eg: rep ds stosb) segment overrides are not support by
  2254. the assembler parser.
  2255. \item [Expressions of the form [sreg:reg...] are currently not supported]
  2256. To access a memory operand in a different segment, you should use the
  2257. sreg:[reg...] snytax instead of [sreg:reg...]
  2258. \item [Size suffix and destination register do not match]
  2259. In intel AT\&T syntax, you are using a register size which does
  2260. not concord with the operand size specified.
  2261. \item [Invalid assembler syntax. No ref with brackets]
  2262. \item [ Trying to use a negative index register ]
  2263. \item [ Local symbols not allowed as references ]
  2264. \item [ Invalid operand in bracket expression ]
  2265. \item [ Invalid symbol name: ]
  2266. \item [ Invalid Reference syntax ]
  2267. \item [ Invalid string as opcode operand: ]
  2268. \item [ Null label references are not allowed ]
  2269. \item [ Using a defined name as a local label ]
  2270. \item [ Invalid constant symbol ]
  2271. \item [ Invalid constant expression ]
  2272. \item [ / at beginning of line not allowed ]
  2273. \item [ NOR not supported ]
  2274. \item [ Invalid floating point register name ]
  2275. \item [ Invalid floating point constant: ]
  2276. \item [ Asm syntax error - Should start with bracket ]
  2277. \item [ Asm syntax error - register: ]
  2278. \item [ Asm syntax error - in opcode operand ]
  2279. \item [ Invalid String expression ]
  2280. \item [ Constant expression out of bounds ]
  2281. \item [ Invalid or missing opcode ]
  2282. \item [ Invalid real constant expression ]
  2283. \item [ Parenthesis are not allowed ]
  2284. \item [ Invalid Reference ]
  2285. \item [ Cannot use \_\_SELF outside a method ]
  2286. \item [ Cannot use \_\_OLDEBP outside a nested procedure ]
  2287. \item [ Invalid segment override expression ]
  2288. \item [ Strings not allowed as constants ]
  2289. \item [ Switching sections is not allowed in an assembler block ]
  2290. \item [ Invalid global definition ]
  2291. \item [ Line separator expected ]
  2292. \item [ Invalid local common definition ]
  2293. \item [ Invalid global common definition ]
  2294. \item [ assembler code not returned to text ]
  2295. \item [ invalid opcode size ]
  2296. \item [ Invalid character: < ]
  2297. \item [ Invalid character: > ]
  2298. \item [ Unsupported opcode ]
  2299. \item [ Invalid suffix for intel assembler ]
  2300. \item [ Extended not supported in this mode ]
  2301. \item [ Comp not supported in this mode ]
  2302. \item [ Invalid Operand: ]
  2303. \item [ Override operator not supported ]
  2304. \end{description}
  2305. % m68k specific errors
  2306. \subsection{m68k specific errors.}
  2307. \begin{description}
  2308. \item [Increment and Decrement mode not allowed together]
  2309. You are trying to use dec/inc mode together.
  2310. \item [Invalid Register list in movem/fmovem]
  2311. The register list is invalid, normally a range of registers should
  2312. be separated by - and individual registers should be separated by
  2313. a slash.
  2314. \item [Invalid Register list for opcode]
  2315. \item [68020+ mode required to assemble]
  2316. \end{description}
  2317. \chapter{Run time errors}
  2318. The \fpc Run-tim library generates the following errors at run-time
  2319. \footnote{The \linux port will generate only a subset of these.}:
  2320. \begin{description}
  2321. \item [1 Invalid function number]
  2322. You tried to call a \dos function which doesn't exist.
  2323. \item [2 File not found]
  2324. You can get this error when you tried to do an operation on a file which
  2325. doesn't exist.
  2326. \item [3 Path not found]
  2327. You can get this error when you tried to do an operation on a file which
  2328. doesn't exist, or when you try to change to, or remove a directory that doesn't exist,
  2329. or try to make a subdirectory of a subdirectory that doesn't exist.
  2330. \item [4 Too many open files]
  2331. When attempting to open a file for reading or writing, you can get this
  2332. error when your program has too many open files.
  2333. \item [5 File access denied]
  2334. You don't have access to the specified file.
  2335. \item [6 Invalid file handle]
  2336. If this happens, the file variable you are using is trashed; it
  2337. indicates that your memory is corrupted.
  2338. \item [12 Invalid file access code]
  2339. This will happen if you do a reset or rewrite of a file when \var{FileMode}
  2340. is invalid.
  2341. \item [15 Invalid drive number]
  2342. The number given to the Getdir function specifies a non-existent disk.
  2343. \item [16 Cannot remove current directory]
  2344. You get this if you try to remove the current diirectory.
  2345. \item [17 Cannot rename across drives]
  2346. You cannot rename a file such that it would end up on another disk or
  2347. partition.
  2348. \item [100 Disk read error]
  2349. \dos only. An error occurred when reading from disk. Typically when you try
  2350. to read past the end of a file.
  2351. \item [101 Disk write error]
  2352. \dos only. Reported when the disk is full, and you're trying to write to it.
  2353. \item [102 File not assigned]
  2354. This is reported by Reset, Rewrite, Append, Rename and Erase, if you call
  2355. them with an unassigne function as a parameter.
  2356. \item [103 File not open]
  2357. Reported by the following functions : Close , Read, Write, Seek,
  2358. EOf, FilePos, FileSize, Flush, BlockRead, and BlockWrite if the file isn't
  2359. open.
  2360. \item [104 File not open for input]
  2361. Reported by Read, BlockRead, Eof, Eoln, SeekEof or SeekEoln if the file
  2362. isn't opened with Reset.
  2363. \item [105 File not open for output]
  2364. Reported by write if a text file isn't opened with Rewrite.
  2365. \item [106 Invalid numeric format]
  2366. Reported when a non-numerice value is read from a text file, when a numeric
  2367. value was expected.
  2368. \item [150 Disk is write-protected]
  2369. (Critical error, \dos only.)
  2370. \item [151 Bad drive request struct length]
  2371. (Critical error, \dos only.)
  2372. \item [152 Drive not ready]
  2373. (Critical error, \dos only.)
  2374. \item [154 CRC error in data]
  2375. (Critical error, \dos only.)
  2376. \item [156 Disk seek error]
  2377. (Critical error, \dos only.)
  2378. \item [157 Unknown media type]
  2379. (Critical error, \dos only.)
  2380. \item [158 Sector Not Found]
  2381. (Critical error, \dos only.)
  2382. \item [159 Printer out of paper]
  2383. (Critical error, \dos only.)
  2384. \item [160 Device write fault]
  2385. (Critical error, \dos only.)
  2386. \item [161 Device read fault]
  2387. (Critical error, \dos only.)
  2388. \item [162 Hardware failure]
  2389. (Critical error, \dos only.)
  2390. \item [200 Division by zero]
  2391. You are dividing a number by zero.
  2392. \item [201 Range check error]
  2393. If you compiled your program with range checking on, then you can get this
  2394. error in the following cases:
  2395. \begin{enumerate}
  2396. \item An array was accessed with an index outside its declared range.
  2397. \item You're trying to assign a value to a variable outside its range (for
  2398. instance a enumerated type).
  2399. \end{enumerate}
  2400. \item [202 Stack overflow error]
  2401. The stack has grown beyond itss maximum size. This error can easily occur if
  2402. you have recursive functions.
  2403. \item [203 Heap overflow error]
  2404. The heap has grown beyond its boundaries, ad you are rying to get more
  2405. memory. Please note that \fpc provides a growing heap, i.e. the heap will
  2406. try to allocate more memory if needed. However, if the heap has reached the
  2407. maximum size allowed by the operating system or hardware, then you will get
  2408. this error.
  2409. \item [204 Invalid pointer operation]
  2410. This you will get if you call dispose or Freemem with an invalid pointer
  2411. (notably, \var{Nil})
  2412. \item [205 Floating point overflow]
  2413. You are trying to use or produce too large real numbers.
  2414. \item [206 Floating point underflow]
  2415. You are trying to use or produce too small real numbers.
  2416. \item [207 Invalid floating point operation]
  2417. Can occur if you try to calculate the square root or logarithm of a negative
  2418. number.
  2419. \item [210 Object not initialized]
  2420. When compiled with range checking on, a program will report this error if
  2421. you call a virtal method without having initialized the VMT.
  2422. \item [211 Call to abstract method]
  2423. Your program tried to execute an abstract virtual method. Abstract methods
  2424. should be overridden, and the overriding method should be called.
  2425. \item [212 Stream registration error]
  2426. This occurs when an invalid type is registered in the objects unit.
  2427. \item [213 Collection index out of range]
  2428. You are trying to access a collection item with an invalid index.
  2429. (objects unit)
  2430. \item [214 Collection overflow error]
  2431. The collection has reached its maximal size, and you are trying to add
  2432. another element. (objects unit)
  2433. \item [216 General Protection fault]
  2434. You are trying to access memory outside your appointed memory.
  2435. \item [217 Unhandled expetion occurred]
  2436. An exception occurred, and there was no exception handler present.
  2437. The \file{sysutils} unit installs a default exception handler which catches
  2438. all excpetions and exits gracefully.
  2439. \end{description}
  2440. \chapter{The Floating Point Coprocessor emulator}
  2441. In this appendix we note some caveats when using the floating point
  2442. emulator on GO32V2 systems. Under GO32V1 systems, all is as described in
  2443. the installation section.
  2444. {\em Q: I don't have an 80387. How do I compile and run floating point
  2445. programs under GO32V2?
  2446. Q: What shall I install on a target machine which lacks hardware
  2447. floating-point support?
  2448. }
  2449. {\em A :}
  2450. Programs which use floating point computations and could be run on
  2451. machines without an 80387 should be allowed to dynamically load the
  2452. \file{emu387.dxe}
  2453. file at run-time if needed. To do this you must link the \var{emu387} unit to your
  2454. exectuable program, for example:
  2455. \begin{verbatim}
  2456. Program MyFloat;
  2457. Uses emu387;
  2458. var
  2459. r: real;
  2460. Begin
  2461. r:=1.0;
  2462. WriteLn(r);
  2463. end.
  2464. \end{verbatim}
  2465. \var{Emu387} takes care of loading the dynamic emulation point library.
  2466. You should always add emulation when you distribute floating-point
  2467. programs.
  2468. A few users reported that the emulation won't work for them unless
  2469. they explicitly tell \var{DJGPP} there is no \var{x87} hardware, like this:
  2470. \begin{verbatim}
  2471. set 387=N
  2472. set emu387=c:/djgpp/bin/emu387.dxe
  2473. \end{verbatim}
  2474. There is an alternative FP emulator called WMEMU. It mimics a real
  2475. coprocessor more closely.
  2476. {\em WARNING:} We strongly suggest that you use WMEMU as FPU emulator, since
  2477. \file{emu387.dxe} does not emulate all the instructions which are used by the
  2478. Run-Time Libary such as \var{FWAIT}.
  2479. {\em Q: I have an 80387 emulator installed in my AUTOEXEC.BAT, but
  2480. DJGPP-compiled floating point programs still doesn't work. Why?
  2481. }
  2482. {\em A :} DJGPP switches the CPU to protected mode, and the information
  2483. needed to emulate the 80387 is different. Not to mention that the
  2484. exceptions never get to the real-mode handler. You must use emulators
  2485. which are designed for DJGPP. Apart of emu387 and WMEMU, the only
  2486. other emulator known to work with DJGPP is Q87 from QuickWare. Q87 is
  2487. shareware and is available from the QuickWare Web site.
  2488. {\em Q: I run DJGPP in an \ostwo DOS box, and I'm told that \ostwo will install
  2489. its own emulator library if the CPU has no FPU, and will transparently
  2490. execute FPU instructions. So why won't DJGPP run floating-point code
  2491. under \ostwo on my machine?
  2492. }
  2493. {\em A} : \ostwo installs an emulator for native \ostwo images, but does not
  2494. provide FPU emulation for DOS sessions.
  2495. \chapter{A sample \file{gdb.ini} file}
  2496. \label{ch:GdbIniFile}
  2497. Here you have a sample \file{gdb.ini} file listing, which gives better
  2498. results when using \var{gdb}. Under \linux you should put this in a
  2499. \file{.gdbinit} file in your home directory or the current directory..
  2500. \begin{verbatim}
  2501. set print demangle off
  2502. set gnutarget auto
  2503. set verbose on
  2504. set complaints 1000
  2505. dir ./rtl/dosv2
  2506. set language c++
  2507. set print vtbl on
  2508. set print object on
  2509. set print sym on
  2510. set print pretty on
  2511. disp /i $eip
  2512. define pst
  2513. set $pos=&$arg0
  2514. set $strlen = {byte}$pos
  2515. print {char}&$arg0.st@($strlen+1)
  2516. end
  2517. document pst
  2518. Print out a pascal string
  2519. end
  2520. \end{verbatim}
  2521. \end{document}