user.tex 136 KB

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