user.tex 150 KB

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