user.tex 134 KB

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