user.tex 134 KB

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