user.tex 138 KB

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