user.tex 130 KB

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