user.tex 134 KB

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