systemh.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Run time library.
  4. Copyright (c) 1993,97 by the Free Pascal development team
  5. See the File COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {*****************************************************************************
  12. This File contains the OS independent declarations of the system unit
  13. Possible defines:
  14. -----------------
  15. RTLLITE Create a somewhat smaller RTL
  16. *****************************************************************************}
  17. {****************************************************************************
  18. Support for multiple compiler versions
  19. ****************************************************************************}
  20. {$i version.inc}
  21. {****************************************************************************
  22. Global Types and Constants
  23. ****************************************************************************}
  24. Type
  25. Longint = $80000000..$7fffffff;
  26. Integer = -32768..32767;
  27. shortint = -128..127;
  28. byte = 0..255;
  29. Word = 0..65535;
  30. { at least declare Turbo Pascal real types }
  31. {$ifdef i386}
  32. {$ifndef VER0_99_5}
  33. {$ifndef VER0_99_6}
  34. {$define DEFAULT_EXTENDED}
  35. {$endif}
  36. {$endif}
  37. {$define SUPPORT_EXTENDED}
  38. {$define SUPPORT_COMP}
  39. {$define SUPPORT_SINGLE}
  40. {$define SUPPORT_FIXED}
  41. Double = real;
  42. {$ifdef DEFAULT_EXTENDED}
  43. ValReal = Extended;
  44. {$else}
  45. ValReal = Double;
  46. {$endif}
  47. {$endif}
  48. {$ifdef m68k}
  49. StrLenInt = Integer;
  50. ValReal = Real;
  51. {$ifdef USEANSISTRINGS}
  52. {$error StrLenInt must be a longint if ansi strings are used}
  53. {$endif}
  54. {$endif}
  55. {$ifdef i386}
  56. StrLenInt = LongInt;
  57. {$endif}
  58. { some type aliases }
  59. dword = cardinal;
  60. longword = cardinal;
  61. { Zero - terminated strings }
  62. PChar = ^Char;
  63. PPChar = ^PChar;
  64. { procedure type }
  65. TProcedure = Procedure;
  66. const
  67. { max. values for longint and int}
  68. maxLongint = $7fffffff;
  69. maxint = 32767;
  70. { Compatibility With TP }
  71. {$ifdef i386}
  72. Test8086 : byte = 2; { Always i386 or newer }
  73. Test8087 : byte = 3; { Always 387 or newer. Emulated if needed. }
  74. {$endif i386}
  75. {$ifdef m68k}
  76. Test68000 : byte = 0; { Must be determined at startup for both }
  77. Test68881 : byte = 0;
  78. {$endif}
  79. { max level in dumping on error }
  80. Max_Frame_Dump : Word = 8;
  81. { Exit Procedure handling consts and types }
  82. ExitProc : pointer=nil;
  83. Erroraddr: pointer = nil;
  84. Errorcode: Word = 0;
  85. { file input modes }
  86. fmClosed = $D7B0;
  87. fmInput = $D7B1;
  88. fmOutput = $D7B2;
  89. fmInOut = $D7B3;
  90. fmAppend = $D7B4;
  91. Filemode : byte = 2;
  92. Type TErrorProc = Procedure (ErrNo : Longint; Address : Pointer);
  93. var
  94. { Standard In- and Output }
  95. Output,
  96. Input,
  97. StdErr : Text;
  98. ExitCode,
  99. InOutRes : Word;
  100. StackBottom,
  101. LowestStack,
  102. RandSeed : Longint;
  103. Const
  104. ErrorProc : Pointer = nil;
  105. {****************************************************************************
  106. Processor specific routines
  107. ****************************************************************************}
  108. Procedure Move(Var source,dest;count:Longint);
  109. Procedure FillChar(Var x;count:Longint;Value:Char);
  110. Procedure FillChar(Var x;count:Longint;Value:byte);
  111. {$ifndef RTLLITE}
  112. Procedure FillWord(Var x;count:Longint;Value:Word);
  113. {$endif RTLLITE}
  114. {****************************************************************************
  115. Math Routines
  116. ****************************************************************************}
  117. {$ifndef RTLLITE}
  118. Function lo(w:Word):byte;
  119. Function lo(l:Longint):Word;
  120. Function lo(i:Integer):byte;
  121. Function lo(B: Byte):Byte;
  122. Function hi(w:Word):byte;
  123. Function hi(i:Integer):byte;
  124. Function hi(l:Longint):Word;
  125. Function Hi(B : Byte): byte;
  126. Function Swap (X:Word):Word;
  127. Function Swap (X:Integer):Integer;
  128. Function Swap (X:Cardinal):Cardinal;
  129. Function Swap (X:Longint):Longint;
  130. {$ifdef VER0_99_5}
  131. Procedure Inc(Var i:cardinal);
  132. Procedure Inc(Var i:Longint);
  133. Procedure Inc(Var i:Integer);
  134. Procedure Inc(Var i:Word);
  135. Procedure Inc(Var i:shortint);
  136. Procedure Inc(Var i:byte);
  137. Procedure Inc(Var c:Char);
  138. Procedure Inc(Var p:PChar);
  139. Procedure Dec(Var i:cardinal);
  140. Procedure Dec(Var i:Longint);
  141. Procedure Dec(Var i:Integer);
  142. Procedure Dec(Var i:Word);
  143. Procedure Dec(Var i:shortint);
  144. Procedure Dec(Var i:byte);
  145. Procedure Dec(Var c:Char);
  146. Procedure Dec(Var p:PChar);
  147. Procedure Dec(Var i:cardinal;a:Longint);
  148. Procedure Inc(Var i:cardinal;a:Longint);
  149. Procedure Dec(Var i:Longint;a:Longint);
  150. Procedure Inc(Var i:Longint;a:Longint);
  151. Procedure Dec(Var i:Word;a:Longint);
  152. Procedure Inc(Var i:Word;a:Longint);
  153. Procedure Dec(Var i:Integer;a:Longint);
  154. Procedure Inc(Var i:Integer;a:Longint);
  155. Procedure Dec(Var i:byte;a:Longint);
  156. Procedure Inc(Var i:byte;a:Longint);
  157. Procedure Dec(Var i:shortint;a:Longint);
  158. Procedure Inc(Var i:shortint;a:Longint);
  159. Procedure Dec(Var c:Char;a:Longint);
  160. Procedure Inc(Var c:Char;a:Longint);
  161. Procedure Dec(Var p:PChar;a:Longint);
  162. Procedure Inc(Var p:PChar;a:Longint);
  163. {$endif VER0_99_5}
  164. {$endif RTLLITE}
  165. Function Chr(b:byte):Char;
  166. Function Length(s:string):byte;
  167. Function Random(l:Longint):Longint;
  168. Function Random:real;
  169. Procedure Randomize;
  170. Function abs(l:Longint):Longint;
  171. Function sqr(l:Longint):Longint;
  172. Function odd(l:Longint):Boolean;
  173. { float mathe routines }
  174. {$I mathh.inc}
  175. {****************************************************************************
  176. Memory management
  177. ****************************************************************************}
  178. Procedure getmem(Var p:pointer;Size:Longint);
  179. Procedure freemem(Var p:pointer;Size:Longint);
  180. Function memavail:Longint;
  181. Function maxavail:Longint;
  182. {$ifndef RTLLITE}
  183. Function ptr(sel,off:Longint):pointer;
  184. Function Addr (Var X):pointer;
  185. Function Cseg:Word;
  186. Function Dseg:Word;
  187. Function Sseg:Word;
  188. {$endif RTLLITE}
  189. {****************************************************************************
  190. PChar Handling
  191. ****************************************************************************}
  192. function strpas(p:pchar):string;
  193. function strlen(p:pchar):longint;
  194. Function Copy(const s:string;index:StrLenInt;count:StrLenInt):string;
  195. Procedure Delete(Var s:string;index:StrLenInt;count:StrLenInt);
  196. Procedure Insert(const source:string;Var s:string;index:StrLenInt);
  197. Function Pos(const substr:string;const s:string):byte;
  198. Function Pos(C:Char;const s:string):byte;
  199. Function upCase(c:Char):Char;
  200. Function upCase(const s:string):string;
  201. {$ifndef RTLLITE}
  202. Function lowerCase(c:Char):Char;
  203. Function lowerCase(const s:string):string;
  204. Function hexStr(Val:Longint;cnt:byte):string;
  205. Function binStr(Val:Longint;cnt:byte):string;
  206. {$endif RTLLITE}
  207. Function Space(b:byte):string;
  208. Procedure Val(const s:string;Var l:Longint;Var code:Word);
  209. Procedure Val(const s:string;Var l:Longint;Var code:Integer);
  210. Procedure Val(const s:string;Var l:Longint);
  211. Procedure Val(const s:string;Var b:byte;Var code:Word);
  212. Procedure Val(const s:string;Var b:byte;Var code:Integer);
  213. Procedure Val(const s:string;Var b:byte);
  214. Procedure Val(const s:string;Var b:shortint;Var code:Word);
  215. Procedure Val(const s:string;Var b:shortint;Var code:Integer);
  216. Procedure Val(const s:string;Var b:shortint);
  217. Procedure Val(const s:string;Var b:Word;Var code:Word);
  218. Procedure Val(const s:string;Var b:Word;Var code:Integer);
  219. Procedure Val(const s:string;Var b:Word);
  220. Procedure Val(const s:string;Var b:Integer;Var code:Word);
  221. Procedure Val(const s:string;Var b:Integer;Var code:Integer);
  222. Procedure Val(const s:string;Var b:Integer);
  223. Procedure Val(const s:string;Var v:cardinal;Var code:Word);
  224. Procedure Val(const s:string;Var v:cardinal;Var code:Integer);
  225. Procedure Val(const s:string;Var v:cardinal);
  226. Procedure Val(const s:string;Var d:ValReal;Var code:Word);
  227. Procedure Val(const s:string;Var d:ValReal;Var code:Integer);
  228. Procedure Val(const s:string;Var d:ValReal);
  229. {$ifdef SUPPORT_SINGLE}
  230. Procedure Val(const s:string;Var d:single;Var code:Word);
  231. Procedure Val(const s:string;Var d:single;Var code:Integer);
  232. Procedure Val(const s:string;Var d:single);
  233. {$endif SUPPORT_SINGLE}
  234. {$ifdef SUPPORT_COMP}
  235. Procedure Val(const s:string;Var d:comp;Var code:Word);
  236. Procedure Val(const s:string;Var d:comp;Var code:Integer);
  237. Procedure Val(const s:string;Var d:comp);
  238. {$endif SUPPORT_COMP}
  239. {$ifdef DEFAULT_EXTENDED}
  240. Procedure Val(const s:string;Var d:Real;Var code:Word);
  241. Procedure Val(const s:string;Var d:Real;Var code:Integer);
  242. Procedure Val(const s:string;Var d:Real);
  243. {$else DEFAULT_EXTENDED}
  244. {$ifdef SUPPORT_EXTENDED}
  245. Procedure Val(const s:string;Var d:Extended;Var code:Word);
  246. Procedure Val(const s:string;Var d:Extended;Var code:Integer);
  247. Procedure Val(const s:string;Var d:Extended);
  248. {$endif}
  249. {$endif DEFAULT_EXTENDED}
  250. {****************************************************************************
  251. AnsiString Handling
  252. ****************************************************************************}
  253. {$ifdef UseAnsiStrings }
  254. Procedure SetLength (Var S : AnsiString; l : Longint);
  255. Procedure UniqueAnsiString (Var S : AnsiString);
  256. Function Length (Var S : AnsiString) : Longint;
  257. Function Copy (Var S : AnsiString; Index,Size : Longint) : AnsiString;
  258. Function Pos (Var Substr : AnsiString; Var Source : AnsiString) : Longint;
  259. Procedure Insert (Var Source : AnsiString; Var S : AnsiString; Index : Longint);
  260. Procedure Delete (Var S : AnsiString; Index,Size: Longint);
  261. Procedure Val (Var S : AnsiString; var R : real; Var Code : Integer);
  262. {
  263. Procedure Val (Const S : AnsiString; var D : Double; Var Code : Integer);
  264. }
  265. Procedure Val (Var S : AnsiString; var E : Extended; Code : Integer);
  266. Procedure Val (Var S : AnsiString; var C : Cardinal; Code : Integer);
  267. Procedure Val (Var S : AnsiString; var L : Longint; Var Code : Integer);
  268. Procedure Val (Var S : AnsiString; var W : Word; Var Code : Integer);
  269. Procedure Val (Var S : AnsiString; var I : Integer; Var Code : Integer);
  270. Procedure Val (Var S : AnsiString; var B : Byte; Var Code : Integer);
  271. Procedure Val (Var S : AnsiString; var SI : ShortInt; Var Code : Integer);
  272. {
  273. Procedure Str (Const R : Real;Len, fr : longint; Var S : AnsiString);
  274. Procedure Str (Const D : Double;Len,fr : longint; Var S : AnsiString);
  275. Procedure Str (Const E : Extended;Len,fr : longint; Var S : AnsiString);
  276. Procedure Str (Const C : Cardinal;len : Longint; Var S : AnsiString);
  277. Procedure Str (Const L : LongInt;len : longint; Var S : AnsiString);
  278. Procedure Str (Const W : Word;len : longint; Var S : AnsiString);
  279. Procedure Str (Const I : Integer;len : Longint; Var S : AnsiString);
  280. Procedure Str (Const B : Byte; Len : longint; Var S : AnsiString);
  281. Procedure Str (Const SI : ShortInt; Len : longint; Var S : AnsiString);
  282. }
  283. {$endif}
  284. {****************************************************************************
  285. Untyped File Management
  286. ****************************************************************************}
  287. Procedure Assign(Var f:File;const Name:string);
  288. Procedure Assign(Var f:File;p:pchar);
  289. Procedure Assign(Var f:File;c:char);
  290. Procedure Rewrite(Var f:File;l:Word);
  291. Procedure Rewrite(Var f:File);
  292. Procedure Reset(Var f:File;l:Word);
  293. Procedure Reset(Var f:File);
  294. Procedure Close(Var f:File);
  295. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint;Var Result:Longint);
  296. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Word);
  297. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Integer);
  298. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint);
  299. Procedure BlockRead(Var f:File;Var Buf;count:Longint;Var Result:Longint);
  300. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Word);
  301. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Integer);
  302. Procedure BlockRead(Var f:File;Var Buf;count:Longint);
  303. Function FilePos(Var f:File):Longint;
  304. Function FileSize(Var f:File):Longint;
  305. Procedure Seek(Var f:File;Pos:Longint);
  306. Function EOF(Var f:File):Boolean;
  307. Procedure Erase(Var f:File);
  308. Procedure Rename(Var f:File;const s:string);
  309. Procedure Rename(Var f:File;p:pchar);
  310. Procedure Rename(Var f:File;c:char);
  311. Procedure Truncate (Var F:File);
  312. {****************************************************************************
  313. Typed File Management
  314. ****************************************************************************}
  315. Procedure Assign(Var f:TypedFile;const Name:string);
  316. Procedure Assign(Var f:TypedFile;p:pchar);
  317. Procedure Assign(Var f:TypedFile;c:char);
  318. Procedure Rewrite(Var f:TypedFile);
  319. Procedure Reset(Var f:TypedFile);
  320. {****************************************************************************
  321. Text File Management
  322. ****************************************************************************}
  323. Procedure Assign(Var t:Text;const s:string);
  324. Procedure Assign(Var t:Text;p:pchar);
  325. Procedure Assign(Var t:Text;c:char);
  326. Procedure Close(Var t:Text);
  327. Procedure Rewrite(Var t:Text);
  328. Procedure Reset(Var t:Text);
  329. Procedure Append(Var t:Text);
  330. Procedure Flush(Var t:Text);
  331. Procedure Erase(Var t:Text);
  332. Procedure Rename(Var t:Text;const s:string);
  333. Procedure Rename(Var t:Text;p:pchar);
  334. Procedure Rename(Var t:Text;c:char);
  335. Function EOF(Var t:Text):Boolean;
  336. Function EOF:Boolean;
  337. Function EOLn(Var t:Text):Boolean;
  338. Function EOLn:Boolean;
  339. Function SeekEOLn (Var F:Text):Boolean;
  340. Function SeekEOF (Var F:Text):Boolean;
  341. Function SeekEOLn:Boolean;
  342. Function SeekEOF:Boolean;
  343. Procedure SetTextBuf(Var f:Text; Var Buf);
  344. Procedure SetTextBuf(Var f:Text; Var Buf; Size:Word);
  345. {****************************************************************************
  346. Directory Management
  347. ****************************************************************************}
  348. Procedure chdir(const s:string);
  349. Procedure mkdir(const s:string);
  350. Procedure rmdir(const s:string);
  351. Procedure getdir(drivenr:byte;Var dir:string);
  352. {*****************************************************************************
  353. Miscelleaous
  354. *****************************************************************************}
  355. Function IOResult:Word;
  356. Function Sptr:Longint;
  357. {*****************************************************************************
  358. Init / Exit / ExitProc
  359. *****************************************************************************}
  360. Function Paramcount:Longint;
  361. Function ParamStr(l:Longint):string;
  362. {$ifndef RTLLITE}
  363. Procedure Dump_Stack(bp:Longint);
  364. {$endif RTLLITE}
  365. Procedure RunError(w:Word);
  366. Procedure RunError;
  367. Procedure halt(errnum:byte);
  368. {$ifndef RTLLITE}
  369. Procedure AddExitProc(Proc:TProcedure);
  370. {$endif RTLLITE}
  371. Procedure halt;
  372. {*****************************************************************************
  373. SetJmp/LongJmp
  374. *****************************************************************************}
  375. {$i setjumph.inc}
  376. {
  377. $Log$
  378. Revision 1.24 1998-08-11 21:39:08 peter
  379. * splitted default_extended from support_extended
  380. Revision 1.23 1998/08/11 00:05:27 peter
  381. * $ifdef ver0_99_5 updates
  382. Revision 1.22 1998/08/08 12:28:14 florian
  383. * a lot small fixes to the extended data type work
  384. Revision 1.21 1998/07/30 13:26:17 michael
  385. + Added support for ErrorProc variable. All internal functions are required
  386. to call HandleError instead of runerror from now on.
  387. This is necessary for exception support.
  388. Revision 1.20 1998/07/28 20:37:47 michael
  389. + added setjmp/longjmp and exception support
  390. Revision 1.19 1998/07/20 23:36:57 michael
  391. changes for ansistrings
  392. Revision 1.18 1998/07/18 17:14:24 florian
  393. * strlenint type implemented
  394. Revision 1.17 1998/07/10 11:02:39 peter
  395. * support_fixed, becuase fixed is not 100% yet for the m68k
  396. Revision 1.16 1998/07/02 12:13:18 carl
  397. * No SINGLE type for m68k or other non-intel processors!
  398. Revision 1.15 1998/07/01 14:43:46 carl
  399. - max_frame_dump reduced to 8, 20 is too much!
  400. Revision 1.14 1998/06/25 14:04:26 peter
  401. + internal inc/dec
  402. Revision 1.13 1998/06/25 09:44:21 daniel
  403. + RTLLITE directive to compile minimal RTL.
  404. Revision 1.12 1998/06/15 15:16:27 daniel
  405. * RTLLITE conditional added to produce smaller RTL
  406. Revision 1.11 1998/06/08 12:38:23 michael
  407. Implemented rtti, inserted ansistrings again
  408. Revision 1.10 1998/06/04 23:46:02 peter
  409. * comp,extended are only i386 added support_comp,support_extended
  410. Revision 1.9 1998/06/04 08:26:03 pierre
  411. * boolean internal definition again (needed to compile
  412. older RTL's)
  413. Revision 1.8 1998/06/03 23:39:53 peter
  414. + boolean=bytebool
  415. Revision 1.7 1998/05/22 12:34:11 peter
  416. * fixed the optimizes of daniel
  417. Revision 1.6 1998/05/21 19:31:00 peter
  418. * objects compiles for linux
  419. + assign(pchar), assign(char), rename(pchar), rename(char)
  420. * fixed read_text_as_array
  421. + read_text_as_pchar which was not yet in the rtl
  422. Revision 1.5 1998/05/12 10:42:45 peter
  423. * moved getopts to inc/, all supported OS's need argc,argv exported
  424. + strpas, strlen are now exported in the systemunit
  425. * removed logs
  426. * removed $ifdef ver_above
  427. Revision 1.4 1998/04/16 12:30:47 peter
  428. + inc(pchar), dec(pchar), incc(pchar,a),dec(pchar,a)
  429. }