2
0

user.tex 138 KB

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