user.tex 133 KB

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