user.tex 109 KB

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