user.tex 151 KB

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