dos.tex 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  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. \chapter{The DOS unit.}
  22. \FPCexampledir{dosex}
  23. This chapter describes the \var{DOS} unit for Free pascal, both under
  24. \dos, \ostwo, \windows and \linux.
  25. The unit was first written for \dos by Florian kl\"ampfl. It was ported to
  26. \linux by Mark May\footnote{Current e-mail address \textsf{[email protected]}},
  27. and enhanced by Micha\"el Van Canneyt.
  28. Under non-\dos systems, some of the functionality is lost, as it is either impossible
  29. or meaningless to implement it. Other than that, the functionality for all
  30. operating systems is the same.
  31. This chapter is divided in three sections:
  32. \begin{itemize}
  33. \item The first section lists the pre-defined constants, types and variables.
  34. \item The second section gives an overview of all functions available,
  35. grouped by category.
  36. \item The third section describes the functions which appear in the
  37. interface part of the DOS unit.
  38. \end{itemize}
  39. \section{Types, Variables, Constants}
  40. \subsection {Constants}
  41. The DOS unit implements the following constants:
  42. \begin{verbatim}
  43. {Bitmasks for CPU Flags}
  44. fcarry = $0001;
  45. fparity = $0004;
  46. fauxiliary = $0010;
  47. fzero = $0040;
  48. fsign = $0080;
  49. foverflow = $0800;
  50. {Bitmasks for file attribute}
  51. readonly = $01;
  52. hidden = $02;
  53. sysfile = $04;
  54. volumeid = $08;
  55. directory = $10;
  56. archive = $20;
  57. anyfile = $3F;
  58. fmclosed = $D7B0;
  59. fminput = $D7B1;
  60. fmoutput = $D7B2;
  61. fminout = $D7B3;
  62. \end{verbatim}
  63. \subsection{Types}
  64. The following string types are defined for easy handling of
  65. filenames :
  66. \begin{verbatim}
  67. ComStr = String[255]; { For command-lines }
  68. PathStr = String[255]; { For full path for file names }
  69. DirStr = String[255]; { For Directory and (DOS) drive string }
  70. NameStr = String[255]; { For Name of file }
  71. ExtStr = String[255]; { For Extension of file }
  72. \end{verbatim}
  73. \begin{verbatim}
  74. SearchRec = Packed Record
  75. Fill : array[1..21] of byte;
  76. { Fill replaced with declarations below, for Linux}
  77. Attr : Byte; {attribute of found file}
  78. Time : LongInt; {last modify date of found file}
  79. Size : LongInt; {file size of found file}
  80. Reserved : Word; {future use}
  81. Name : String[255]; {name of found file}
  82. SearchSpec: String[255]; {search pattern}
  83. NamePos: Word; {end of path, start of name position}
  84. End;
  85. \end{verbatim}
  86. Under \linux, the \var{Fill} array is replaced with the following:
  87. \begin{verbatim}
  88. SearchNum: LongInt; {to track which search this is}
  89. SearchPos: LongInt; {directory position}
  90. DirPtr: LongInt; {directory pointer for reading directory}
  91. SearchType: Byte; {0=normal, 1=open will close}
  92. SearchAttr: Byte; {attribute we are searching for}
  93. Fill: Array[1..07] of Byte; {future use}
  94. \end{verbatim}
  95. This is because the searching meachanism on Unix systems is substantially
  96. different from \dos's, and the calls have to be mimicked.
  97. \begin{verbatim}
  98. const
  99. filerecnamelength = 255;
  100. type
  101. FileRec = Packed Record
  102. Handle,
  103. Mode,
  104. RecSize : longint;
  105. _private : array[1..32] of byte;
  106. UserData : array[1..16] of byte;
  107. name : array[0..filerecnamelength] of char;
  108. End;
  109. \end{verbatim}
  110. \var{FileRec} is used for internal representation of typed and untyped files.
  111. Text files are handled by the following types :
  112. \begin{verbatim}
  113. const
  114. TextRecNameLength = 256;
  115. TextRecBufSize = 256;
  116. type
  117. TextBuf = array[0..TextRecBufSize-1] of char;
  118. TextRec = Packed Record
  119. Handle,
  120. Mode,
  121. bufsize,
  122. _private,
  123. bufpos,
  124. bufend : longint;
  125. bufptr : ^textbuf;
  126. openfunc,
  127. inoutfunc,
  128. flushfunc,
  129. closefunc : pointer;
  130. UserData : array[1..16] of byte;
  131. name : array[0..textrecnamelength-1] of char;
  132. buffer : textbuf;
  133. End;
  134. \end{verbatim}
  135. Remark that this is not binary compatible with the Turbo Pascal definition
  136. of \var{TextRec}, since the sizes of the different fields are different.
  137. \begin{verbatim}
  138. Registers = record
  139. case i : integer of
  140. 0 : (ax,f1,bx,f2,cx,f3,dx,f4,bp,f5,si,
  141. f51,di,f6,ds,f7,es,f8,flags,fs,gs : word);
  142. 1 : (al,ah,f9,f10,bl,bh,f11,f12,
  143. cl,ch,f13,f14,dl,dh : byte);
  144. 2 : (eax, ebx, ecx, edx, ebp, esi, edi : longint);
  145. End;
  146. \end{verbatim}
  147. The \var{registers} type is used in the \var{MSDos} call.
  148. \begin{verbatim}
  149. DateTime = record
  150. Year: Word;
  151. Month: Word;
  152. Day: Word;
  153. Hour: Word;
  154. Min: Word;
  155. Sec: word;
  156. End;
  157. \end{verbatim}
  158. The \var{DateTime} type is used in \seep{PackTime} and \seep{UnPackTime} for
  159. setting/reading file times with \seep{GetFTime} and \seep{SetFTime}.
  160. \subsection{Variables}
  161. \begin{verbatim}
  162. DosError : integer;
  163. \end{verbatim}
  164. The \var{DosError} variable is used by the procedures in the \dos unit to
  165. report errors. It can have the following values :
  166. \begin{center}
  167. \begin{tabular}{cl}
  168. 2 & File not found. \\
  169. 3 & path not found. \\
  170. 5 & Access denied. \\
  171. 6 & Invalid handle. \\
  172. 8 & Not enough memory. \\
  173. 10 & Invalid environment. \\
  174. 11 & Invalid format. \\
  175. 18 & No more files.
  176. \end{tabular}
  177. \end{center}
  178. Other values are possible, but are not documented.
  179. %\begin{verbatim}
  180. % drivestr : array [0..26] of pchar;
  181. %\end{verbatim}
  182. %This variable is defined in the \linux version of the \dos unit. It is used
  183. %in the \seef{DiskFree} and \seef{DiskSize} calls.
  184. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  185. % Functions and procedures by category
  186. \section{Function list by category}
  187. What follows is a listing of the available functions, grouped by category.
  188. For each function there is a reference to the page where you can find the
  189. function.
  190. \subsection{File handling}
  191. Routines to handle files on disk.
  192. \begin{funclist}
  193. \funcrefl{FExpand}{Dos:FExpand}{Expand filename to full path}
  194. \procref{FindClose}{Close finfirst/findnext session}
  195. \procref{FindFirst}{Start find of file}
  196. \procref{FindNext}{Find next file}
  197. \funcrefl{FSearch}{Dos:FSearch}{Search for file in a path}
  198. \procref{FSplit}{Split filename in parts}
  199. \procref{GetFAttr}{Return file attributes}
  200. \procref{GetFTime}{Return file time}
  201. \funcref{GetLongName}{Convert short filename to long filename}
  202. \funcref{GetShortName}{Convert long filename to short filename}
  203. \procref{SetFAttr}{Set file attributes}
  204. \procref{SetFTime}{Set file time}
  205. \end{funclist}
  206. \subsection{Directory and disk handling}
  207. Routines to handle disk information.
  208. \begin{funclist}
  209. \procref{AddDisk}{Add disk to list of disks}
  210. \funcref{DiskFree}{Return size of free disk space}
  211. \funcref{DiskSize}{Return total disk size}
  212. \end{funclist}
  213. \subsection{Process handling}
  214. Functions to handle process information and starting new processes.
  215. \begin{funclist}
  216. \funcref{DosExitCode}{Exit code of last executed program}
  217. \funcref{EnvCount}{Return number of environment variables}
  218. \funcref{EnvStr}{Return environment string pair}
  219. \procref{Exec}{Execute program}
  220. \funcrefl{GetEnv}{Dos:GetEnv}{Return specified environment string}
  221. \end{funclist}
  222. \subsection{System information}
  223. Functions for retrieving and setting general system information such as date
  224. and time.
  225. \begin{funclist}
  226. \funcref{DosVersion}{Get OS version}
  227. \procref{GetCBreak}{Get setting of control-break handling flag}
  228. \procrefl{GetDate}{Dos:GetDate}{Get system date}
  229. \procref{GetIntVec}{Get interrupt vector status}
  230. \procrefl{GetTime}{Dos:GetTime}{Get system time}
  231. \procref{GetVerify}{Get verify flag}
  232. \procref{Intr}{Execute an interrupt}
  233. \procref{Keep}{Keep process in memory and exit}
  234. \procref{MSDos}{Execute MS-dos function call}
  235. \procref{PackTime}{Pack time for file time}
  236. \procref{SetCBreak}{Set control-break handling flag}
  237. \procref{SetDate}{Set system date}
  238. \procref{SetIntVec}{Set interrupt vectors}
  239. \procref{SetTime}{Set system time}
  240. \procref{SetVerify}{Set verify flag}
  241. \procref{SwapVectors}{Swap interrupt vectors}
  242. \procref{UnPackTime}{Unpack file time}
  243. \end{funclist}
  244. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  245. % Functions and procedures
  246. \section{Functions and Procedures}
  247. \begin{procedure}{AddDisk}
  248. \Declaration
  249. Procedure AddDisk (Const S : String);
  250. \Description
  251. \var{AddDisk} adds a filename \var{S} to the internal list of disks. It is
  252. implemented for \linux only.
  253. This list is used to determine which disks to use in the \seef{DiskFree}
  254. and \seef{DiskSize} calls.
  255. The \seef{DiskFree} and \seef{DiskSize} functions need a file on the
  256. specified drive, since this is required for the \var{statfs} system call.
  257. The names are added sequentially. The dos
  258. initialization code presets the first three disks to:
  259. \begin{itemize}
  260. \item \var{'.'} for the current drive,
  261. \item \var{'/fd0/.'} for the first floppy-drive.
  262. \item \var{'/fd1/.'} for the second floppy-drive.
  263. \item \var{'/'} for the first hard disk.
  264. \end{itemize}
  265. The first call to \var{AddDisk} will therefore add a name for the second
  266. harddisk, The second call for the third drive, and so on until 23 drives
  267. have been added (corresponding to drives \var{'D:'} to \var{'Z:'})
  268. \Errors
  269. None
  270. \SeeAlso
  271. \seef{DiskFree}, \seef{DiskSize}
  272. \end{procedure}
  273. \begin{function}{DiskFree}
  274. \Declaration
  275. Function DiskFree (Drive: byte) : Int64;
  276. \Description
  277. \var{DiskFree} returns the number of free bytes on a disk. The parameter
  278. \var{Drive} indicates which disk should be checked. This parameter is 1 for
  279. floppy \var{a:}, 2 for floppy \var{b:}, etc. A value of 0 returns the free
  280. space on the current drive.
  281. Typically, the free space is the size of a disk block, multiplied by the
  282. number of free blocks on the disk.
  283. \textbf{For \linux only:}\\
  284. The \var{diskfree} and \var{disksize} functions need a file on the
  285. specified drive, since this is required for the \var{statfs} system call.
  286. These filenames are set in the initialization of the dos unit, and have
  287. been preset to :
  288. \begin{itemize}
  289. \item \var{'.'} for the current drive,
  290. \item \var{'/fd0/.'} for the first floppy-drive.
  291. \item \var{'/fd1/.'} for the second floppy-drive.
  292. \item \var{'/'} for the first hard disk.
  293. \end{itemize}
  294. There is room for 1-26 drives. You can add a drive with the
  295. \seep{AddDisk} procedure.
  296. These settings can be coded in \var{dos.pp}, in the initialization part.
  297. \Errors
  298. -1 when a failure occurs, or an invalid \var{drivenr} is given.
  299. \SeeAlso
  300. \seef{DiskSize}, \seep{AddDisk}
  301. \end{function}
  302. \FPCexample{ex6}
  303. \begin{function}{DiskSize}
  304. \Declaration
  305. Function DiskSize (Drive: byte) : Int64;
  306. \Description
  307. \var{DiskSize} returns the total size (in bytes) of a disk. The parameter
  308. \var{Drive} indicates which disk should be checked. This parameter is 1 for
  309. floppy \var{a:}, 2 for floppy \var{b:}, etc. A value of 0 returns the size
  310. of the current drive.
  311. \textbf{For \linux only:}\\
  312. The \var{diskfree} and \var{disksize} functions need a file on the specified drive, since this
  313. is required for the \var{statfs} system call.
  314. These filenames are set in the initialization of the dos unit, and have
  315. been preset to :
  316. \begin{itemize}
  317. \item \var{'.'} for the current drive,
  318. \item \var{'/fd0/.'} for the first floppy-drive.
  319. \item \var{'/fd1/.'} for the second floppy-drive.
  320. \item \var{'/'} for the first hard disk.
  321. \end{itemize}
  322. There is room for 1-26 drives. You can add a drive with the
  323. \seep{AddDisk} procedure.
  324. These settings can be coded in \var{dos.pp}, in the initialization part.
  325. \Errors
  326. -1 when a failure occurs, or an invalid drive number is given.
  327. \SeeAlso
  328. \seef{DiskFree}, \seep{AddDisk}
  329. \end{function}
  330. For an example, see \seef{DiskFree}.
  331. \begin{function}{DosExitCode}
  332. \Declaration
  333. Function DosExitCode : Word;
  334. \Description
  335. \var{DosExitCode} contains (in the low byte) the exit-code of a program
  336. executed with the \var{Exec} call.
  337. \Errors
  338. None.
  339. \SeeAlso
  340. \seep{Exec}
  341. \end{function}
  342. \FPCexample{ex5}
  343. \begin{function}{DosVersion}
  344. \Declaration
  345. Function DosVersion : Word;
  346. \Description
  347. \var{DosVersion} returns the \dos version number. On \linux systems, it
  348. returns the Linux version (The first 2 numbers, e.g Linux version 2.1.76 will
  349. give you DosVersion 2.1)
  350. \Errors
  351. None.
  352. \SeeAlso
  353. \end{function}
  354. \FPCexample{ex1}
  355. \begin{function}{EnvCount}
  356. \Declaration
  357. Function EnvCount : longint;\Description
  358. \var{EnvCount} returns the number of environment variables.
  359. \Errors
  360. None.
  361. \SeeAlso
  362. \seef{EnvStr}, \seef{Dos:GetEnv}
  363. \end{function}
  364. \begin{function}{EnvStr}
  365. \Declaration
  366. Function EnvStr (Index: integer) : string;\Description
  367. \var{EnvStr} returns the \var{Index}-th \var{Name=Value} pair from the list
  368. of environment variables.
  369. The index of the first pair is zero.
  370. \Errors
  371. The length is limited to 255 characters. This may cause problems under
  372. \linux. The \linux unit solves this problem.
  373. \SeeAlso
  374. \seef{EnvCount}, \seef{Dos:GetEnv}
  375. \end{function}
  376. \FPCexample{ex13}
  377. \begin{procedure}{Exec}
  378. \Declaration
  379. Procedure Exec (const Path: pathstr; const ComLine: comstr);
  380. \Description
  381. \var{Exec} executes the program in \var{Path}, with the options given by
  382. \var{ComLine}.
  383. After the program has terminated, the procedure returns. The Exit value of
  384. the program can be consulted with the \var{DosExitCode} function.
  385. \Errors
  386. Errors are reported in \var{DosError}.
  387. \SeeAlso
  388. \seef{DosExitCode}
  389. \end{procedure}
  390. For an example, see \seef{DosExitCode}
  391. \begin{functionl}{FExpand}{Dos:FExpand}
  392. \Declaration
  393. Function FExpand (const path: pathstr) : pathstr;
  394. \Description
  395. \var{FExpand} takes its argument and expands it to a complete filename, i.e.
  396. a filename starting from the root directory of the current drive, prepended
  397. with the drive-letter (under \dos).
  398. The resulting name is converted to uppercase on \dos systems. Under \linux,
  399. the name is left as it is. (filenames are case sensitive under Unix)
  400. \Errors
  401. \seep{FSplit}
  402. \SeeAlso
  403. \lstinputlisting{dosex/ex5.pp}
  404. \end{functionl}
  405. \begin{procedure}{FindClose}
  406. \Declaration
  407. Procedure FindClose (Var F: SearchRec);
  408. \Description
  409. \textbf{\linux, \windows and \ostwo wonly}
  410. \var{FindClose} frees any resources associated with the search record
  411. \var{F}.
  412. Under \linux, \windows and \ostwo the \var{findfirst/findnext} calls have
  413. to be mimicked. This call is needed to free any internal resources allocated
  414. by the \seef{FindFirst} or \seef{FindNext} calls.
  415. E.g. on \linux, an internal table of file descriptors is kept.
  416. When using different \var{searchrecs} at the same time,
  417. the system may run out of file descriptors for directories.
  418. The \linux implementation of the \dos unit therefore keeps a table of open
  419. directories, and when the table is full, closes one of the directories, and
  420. reopens another. This system is adequate but slow if you use a lot of
  421. \var{searchrecs}.
  422. So, to speed up the findfirst/findnext system, the \var{FindClose} call was
  423. implemented. When you don't need a \var{searchrec} any more, you can tell
  424. this to the \dos unit by issuing a \var{FindClose} call. The directory
  425. which is kept open for this \var{searchrec} is then closed, and the table slot
  426. freed.
  427. It is recommended to use the \linux call \var{Glob} when looking for files
  428. on \linux.
  429. \Errors
  430. None.
  431. \SeeAlso
  432. \seef{Glob}.
  433. \end{procedure}
  434. \begin{procedure}{FindFirst}
  435. \Declaration
  436. Procedure FindFirst (const Path: pathstr; Attr: word; var F: SearchRec);
  437. \Description
  438. \var{FindFirst} searches the file specified in \var{Path}, checks the
  439. atrributes specified in \var{Attr}. It returns a \var{SearchRec} record for
  440. further searching in \var{F}.
  441. \var{Path} can contain the wildcard characters \var{?} (matches any single
  442. character) and \var{*} (matches 0 ore more arbitrary characters). In this
  443. case \var{FindFirst} will return the first file which matches the specified
  444. criteria.
  445. If \var{DosError} is different from zero, no file(s) matching the criteria
  446. was(were) found.
  447. On \ostwo, you cannot issue two different \var{FindFirst} calls. That is,
  448. you must close any previous search operation with \seep{FindClose} before
  449. starting a new one. Failure to do so will end in a Run-Time Error 6
  450. (Invalid file handle)
  451. Also, on \ostwo, the boolean variable \var{FileNameCaseSensitive} indicates
  452. whether searches are conducted case-sensitive or not. By default, searches
  453. are not case sensitive. If the varieble is set to \var{True}, searches on
  454. \ostwo are case sensistive.
  455. \Errors
  456. Errors are reported in DosError.
  457. \SeeAlso
  458. \seep{FindNext},
  459. \seep{FindClose}
  460. \end{procedure}
  461. \FPCexample{ex7}
  462. \begin{procedure}{FindNext}
  463. \Declaration
  464. Procedure FindNext (var f: searchRec);
  465. \Description
  466. \var{FindNext} takes as an argument a \var{SearchRec} from a previous
  467. \var{FindNext} call, or a \var{FindFirst} call, and tries to find another
  468. file which matches the criteria, specified in the \var{FindFirst} call.
  469. If \var{DosError} is different from zero, no more files matching the
  470. criteria were found.
  471. \Errors
  472. \var{DosError} is used to report errors.
  473. \SeeAlso
  474. \seep{FindFirst}, \seep{FindClose}
  475. \end{procedure}
  476. For an example, see \seep{FindFirst}.
  477. \begin{functionl}{FSearch}{Dos:FSearch}
  478. \Declaration
  479. Function FSearch (Path: pathstr; DirList: string) : pathstr;
  480. \Description
  481. \var{FSearch} searches the file \var{Path} in all directories listed in
  482. \var{DirList}. The full name of the found file is returned.
  483. \var{DirList} must be a list of directories, separated by semi-colons (or
  484. colons under \linux).
  485. When no file is found, an empty string is returned.
  486. \Errors
  487. None.
  488. \SeeAlso
  489. \seefl{FExpand}{Dos:FExpand}
  490. \end{functionl}
  491. \FPCexample{ex10}
  492. \begin{procedure}{FSplit}
  493. \Declaration
  494. Procedure FSplit (path: pathstr; \\ var dir: dirstr; var name: namestr;
  495. var ext: extstr);
  496. \Description
  497. \var{FSplit} splits a full file name into 3 parts : A \var{Path}, a
  498. \var{Name} and an extension (in \var{ext}.)
  499. The extension is taken to be all letters after the {\em last} dot (.). For
  500. \dos, however, an exception is made when \var{LFNSupport=False}, then
  501. the extension is defined as all characters after the {\em first} dot.
  502. \Errors
  503. None.
  504. \SeeAlso
  505. \seefl{FSearch}{Dos:FSearch}
  506. \end{procedure}
  507. \FPCexample{ex12}
  508. \begin{procedure}{GetCBreak}
  509. \Declaration
  510. Procedure GetCBreak (var breakvalue: boolean);
  511. \Description
  512. \var{GetCBreak} gets the status of CTRL-Break checking under \dos.
  513. When \var{BreakValue} is \var{false}, then \dos only checks for the
  514. CTRL-Break key-press when I/O is performed. When it is set to \var{True},
  515. then a check is done at every system call.
  516. \Errors
  517. Under Linux, this exists but is
  518. not implemented, i.e. the call does nothing.
  519. \SeeAlso
  520. \seep{SetCBreak}
  521. \end{procedure}
  522. \begin{procedurel}{GetDate}{Dos:GetDate}
  523. \Declaration
  524. Procedure GetDate (var year, month, mday, wday: word);\Description
  525. \var{GetDate} returns the system's date. \var{Year} is a number in the range
  526. 1980..2099.\var{mday} is the day of the month,
  527. \var{wday} is the day of the week, starting with Sunday as day 0.
  528. \Errors
  529. None.
  530. \SeeAlso
  531. \seepl{GetTime}{Dos:GetTime},\seep{SetDate}
  532. \end{procedurel}
  533. \FPCexample{ex2}
  534. \begin{functionl}{GetEnv}{Dos:GetEnv}
  535. \Declaration
  536. Function GetEnv (EnvVar: String) : String;
  537. \Description
  538. \var{Getenv} returns the value of the environment variable \var{EnvVar}.
  539. Under \linux, case is important when looking for \var{EnvVar}.
  540. When there is no environment variable \var{EnvVar} defined, an empty
  541. string is returned.
  542. \Errors
  543. None.
  544. \SeeAlso
  545. \seef{EnvCount}, \seef{EnvStr}
  546. \end{functionl}
  547. \FPCexample{ex14}
  548. \begin{procedure}{GetFAttr}
  549. \Declaration
  550. Procedure GetFAttr (var F; var Attr: word);
  551. \Description
  552. \var{GetFAttr} returns the file attributes of the file-variable \var{f}.
  553. \var{F} can be a untyped or typed file, or of type \var{Text}. \var{f} must
  554. have been assigned, but not opened. The attributes can be examined with the
  555. following constants :
  556. \begin{itemize}
  557. \item \var{ReadOnly = 01h}
  558. \item \var{Hidden = 02h}
  559. \item \var{SysFile = 04h}
  560. \item \var{VolumeId = 08h}
  561. \item \var{Directory = 10h}
  562. \item \var{Archive = 20h}
  563. \end{itemize}
  564. Under \linux, supported attributes are:
  565. \begin{itemize}
  566. \item \var{Directory}
  567. \item \var{ReadOnly} if the current process doesn't have access to the file.
  568. \item \var{Hidden} for files whose name starts with a dot \var{('.')}.
  569. \end{itemize}
  570. \Errors
  571. Errors are reported in \var{DosError}
  572. \SeeAlso
  573. \seep{SetFAttr}
  574. \end{procedure}
  575. \FPCexample{ex8}
  576. \begin{procedure}{GetFTime}
  577. \Declaration
  578. Procedure GetFTime (var F; var Time: longint);
  579. \Description
  580. \var{GetFTime} returns the modification time of a file.
  581. This time is encoded and must be decoded with \var{UnPackTime}.
  582. \var{F} must be a file type, which has been assigned, and
  583. opened.
  584. \Errors
  585. Errors are reported in \var{DosError}
  586. \SeeAlso
  587. \seep{SetFTime}, \seep{PackTime},\seep{UnPackTime}
  588. \end{procedure}
  589. \FPCexample{ex9}
  590. \begin{procedure}{GetIntVec}
  591. \Declaration
  592. Procedure GetIntVec (IntNo: byte; var Vector: pointer);
  593. \Description
  594. \var{GetIntVec} returns the address of interrupt vector
  595. \var{IntNo}.
  596. \Errors
  597. Under non- \dos operating systems, this call does nothing.
  598. \SeeAlso
  599. \seep{SetIntVec}
  600. \end{procedure}
  601. \begin{function}{GetLongName}
  602. \Declaration
  603. function GetLongName(var p : String) : boolean;\Description
  604. This function is only implemented in the GO32V2 version of \fpc.
  605. \var{GetLongName} changes the filename \var{p} to a long filename
  606. if the \dos call to do this is successful. The resulting string
  607. is the long file name corresponding to the short filename \var{p}.
  608. The function returns \var{True} if the \dos call was successful,
  609. \var{False} otherwise.
  610. This function should only be necessary when using the DOS extender
  611. under Windows 95 and higher.
  612. \Errors
  613. If the \dos call was not succesfull, \var{False} is returned.
  614. \SeeAlso
  615. \seef{GetShortName}
  616. \end{function}
  617. \begin{function}{GetShortName}
  618. \Declaration
  619. function GetShortName(var p : String) : boolean;\Description
  620. This function is only implemented in the GO32V2 version of \fpc.
  621. \var{GetShortName} changes the filename \var{p} to a short filename
  622. if the \dos call to do this is successful. The resulting string
  623. is the short file name corresponding to the long filename \var{p}.
  624. The function returns \var{True} if the \dos call was successful,
  625. \var{False} otherwise.
  626. This function should only be necessary when using the DOS extender
  627. under Windows 95 and higher.
  628. \Errors
  629. If the \dos call was not successful, \var{False} is returned.
  630. \SeeAlso
  631. \seef{GetLongName}
  632. \end{function}
  633. \begin{procedurel}{GetTime}{Dos:GetTime}
  634. \Declaration
  635. Procedure GetTime (var hour, minute, second, sec100: word);
  636. \Description
  637. \var{GetTime} returns the system's time. \var{Hour} is a on a 24-hour time
  638. scale. \var{sec100} is in hundredth of a
  639. second.
  640. \Errors
  641. None.
  642. \SeeAlso
  643. \seepl{GetDate}{Dos:GetDate},
  644. \seep{SetTime}
  645. \end{procedurel}
  646. \FPCexample{ex3}
  647. \begin{procedure}{GetVerify}
  648. \Declaration
  649. Procedure GetVerify (var verify: boolean);
  650. \Description
  651. \var{GetVerify} returns the status of the verify flag under \dos. When
  652. \var{Verify} is \var{True}, then \dos checks data which are written to disk,
  653. by reading them after writing. If \var{Verify} is \var{False}, then data
  654. written to disk are not verified.
  655. \Errors
  656. Under \linux, Verify is always
  657. \var{True}.
  658. \SeeAlso
  659. \seep{SetVerify}
  660. \end{procedure}
  661. \begin{procedure}{Intr}
  662. \Declaration
  663. Procedure Intr (IntNo: byte; var Regs: registers);
  664. \Description
  665. \var{Intr} executes a software interrupt number \var{IntNo} (must be between
  666. 0 and 255), with processor registers set to \var{Regs}. After the interrupt call
  667. returned, the processor registers are saved in \var{Regs}.
  668. \Errors
  669. Under \linux this call does nothing, because interrupts are managed by the
  670. kernel. The only allowed interrupt is 80h, the Linux kernel entry interrupt.
  671. \SeeAlso
  672. \seep{MSDos}, see the \linux unit.
  673. \end{procedure}
  674. \begin{procedure}{Keep}
  675. \Declaration
  676. Procedure Keep (ExitCode: word);
  677. \Description
  678. \var{Keep} terminates the program, but stays in memory. This is used for TSR
  679. (Terminate Stay Resident) programs which catch some interrupt.
  680. \var{ExitCode} is the same parameter as the \var{Halt} function takes.
  681. \Errors
  682. Under non-\dos operating systems, this call does nothing.
  683. \SeeAlso
  684. \seem{Halt}{}
  685. \end{procedure}
  686. \begin{procedure}{MSDos}
  687. \Declaration
  688. Procedure MSDos (var regs: registers);
  689. \Description
  690. \var{MSDos} executes an MS-\dos call (int 21h). This is the same as doing a
  691. \var{Intr} call with an interrupt number of 21h.
  692. \Errors
  693. None.
  694. \SeeAlso
  695. \seep{Intr}
  696. \end{procedure}
  697. \begin{procedure}{PackTime}
  698. \Declaration
  699. Procedure PackTime (var T: datetime; var P: longint);
  700. \Description
  701. \var{UnPackTime} converts the date and time specified in \var{T}
  702. to a packed-time format which can be fed to \var{SetFTime}.
  703. \Errors
  704. None.
  705. \SeeAlso
  706. \seep{SetFTime}, \seep{FindFirst}, \seep{FindNext}, \seep{UnPackTime}
  707. \end{procedure}
  708. \FPCexample{ex4}
  709. \begin{procedure}{SetCBreak}
  710. \Declaration
  711. Procedure SetCBreak (breakvalue: boolean);
  712. \Description
  713. \var{SetCBreak} sets the status of CTRL-Break checking under \dos.
  714. When \var{BreakValue} is \var{false}, then \dos only checks for the
  715. CTRL-Break key-press when I/O is performed. When it is set to \var{True},
  716. then a check is done at every system call.
  717. \Errors
  718. Under Linux, this call exists
  719. but is not implemented, i.e. it does nothing.
  720. \SeeAlso
  721. \seep{GetCBreak}
  722. \end{procedure}
  723. \begin{procedure}{SetDate}
  724. \Declaration
  725. Procedure SetDate (year,month,day: word);
  726. \Description
  727. \var{SetDate} sets the system's internal date. \var{Year} is a number
  728. between 1980 and 2099.
  729. \Errors
  730. On a \linux machine, this is not implemented (allthough a procedure
  731. exists, it just doesn't do anything. The setting of the date is a
  732. root-only privilege, and is hence not implemented.
  733. \SeeAlso
  734. \seep{Dos:GetDate},
  735. \seep{SetTime}
  736. \end{procedure}
  737. \begin{procedure}{SetFAttr}
  738. \Declaration
  739. Procedure SetFAttr (var F; Attr: word);
  740. \Description
  741. \var{SetFAttr} sets the file attributes of the file-variable \var{F}.
  742. \var{F} can be a untyped or typed file, or of type \var{Text}. \var{F} must
  743. have been assigned, but not opened. The attributes can be a sum of the
  744. following constants:
  745. \begin{itemize}
  746. \item \var{ReadOnly = 01h}
  747. \item \var{Hidden = 02h}
  748. \item \var{SysFile = 04h}
  749. \item \var{VolumeId = 08h}
  750. \item \var{Directory = 10h}
  751. \item \var{Archive = 20h}
  752. \item \var{AnyFile = 3fh}
  753. \end{itemize}
  754. \Errors
  755. Errors are reported in \var{DosError}.
  756. Under \linux the call exists, but is not implemented, i.e. it does nothing.
  757. \SeeAlso
  758. \seep{GetFAttr}
  759. \end{procedure}
  760. \begin{procedure}{SetFTime}
  761. \Declaration
  762. Procedure SetFTime (var F; Time: longint);
  763. \Description
  764. \var{SetFTime} sets the modification time of a file,
  765. this time is encoded and must be encoded with \var{PackTime}.
  766. \var{F} must be a file type, which has been assigned, and
  767. opened.
  768. \Errors
  769. Errors are reported in \var{DosError}
  770. \SeeAlso
  771. \seep{GetFTime}, \seep{PackTime},\seep{UnPackTime}
  772. \end{procedure}
  773. \begin{procedure}{SetIntVec}
  774. \Declaration
  775. Procedure SetIntVec (IntNo: byte; Vector: pointer);
  776. \Description
  777. \var{SetIntVec} sets interrupt vector \var{IntNo} to \var{Vector}.
  778. \var{Vector} should point to an interrupt procedure.
  779. \Errors
  780. Under non- \dos operating systems, this call does nothing.
  781. \SeeAlso
  782. \seep{GetIntVec}
  783. \end{procedure}
  784. \begin{procedure}{SetTime}
  785. \Declaration
  786. Procedure SetTime (hour,minute,second,sec100: word);
  787. \Description
  788. \var{SetTime} sets the system's internal clock. The \var{Hour} parameter is
  789. on a 24-hour time scale.
  790. \Errors
  791. this call exists, but is not implemented on \linux,
  792. as setting the time is a root-only privilege.
  793. \SeeAlso
  794. \seep{Dos:GetTime}, \seep{SetDate}
  795. \end{procedure}
  796. \begin{procedure}{SetVerify}
  797. \Declaration
  798. Procedure SetVerify (verify: boolean);
  799. \Description
  800. \var{SetVerify} sets the status of the verify flag under \dos. When
  801. \var{Verify} is \var{True}, then \dos checks data which are written to disk,
  802. by reading them after writing. If \var{Verify} is \var{False}, then data
  803. written to disk are not verified.
  804. \Errors
  805. Under \linux, Verify is always
  806. \var{True}.
  807. \SeeAlso
  808. \seep{SetVerify}
  809. \end{procedure}
  810. \begin{procedure}{SwapVectors}
  811. \Declaration
  812. Procedure SwapVectors ;
  813. \Description
  814. \var{SwapVectors} swaps the contents of the internal table of interrupt
  815. vectors with the current contents of the interrupt vectors.
  816. This is called typically in before and after an \var{Exec} call.
  817. \Errors
  818. Under \linux this call does nothing, as the interrupt vectors are
  819. managed by the kernel.
  820. \SeeAlso
  821. \seep{Exec}, \seep{SetIntVec}
  822. \end{procedure}
  823. \begin{procedure}{UnPackTime}
  824. \Declaration
  825. Procedure UnPackTime (p: longint; var T: datetime);
  826. \Description
  827. \var{UnPackTime} converts the file-modification time in \var{p}
  828. to a \var{DateTime} record. The file-modification time can be
  829. returned by \var{GetFTime}, \var{FindFirst} or \var{FindNext} calls.
  830. \Errors
  831. None.
  832. \SeeAlso
  833. \seep{GetFTime}, \seep{FindFirst}, \seep{FindNext}, \seep{PackTime}
  834. \end{procedure}
  835. For an example, see \seep{PackTime}.