systemh.inc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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. This File contains the OS independent declarations of the system unit
  6. See the File COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {
  13. Supported conditionnals:
  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. {$Q-}
  26. { $8000000 creates a longint overfow !! }
  27. Longint = $80000000..$7fffffff;
  28. Integer = -32768..32767;
  29. shortint = -128..127;
  30. byte = 0..255;
  31. Word = 0..65535;
  32. { at least declare Turbo Pascal real types }
  33. {$ifdef i386}
  34. StrLenInt = LongInt;
  35. {$define DEFAULT_EXTENDED}
  36. {$define SUPPORT_EXTENDED}
  37. {$define SUPPORT_COMP}
  38. {$define SUPPORT_SINGLE}
  39. {$define SUPPORT_FIXED}
  40. Double = real;
  41. {$ifdef DEFAULT_EXTENDED}
  42. ValReal = Extended;
  43. {$else}
  44. ValReal = Double;
  45. {$endif}
  46. {$endif}
  47. {$ifdef m68k}
  48. StrLenInt = Integer;
  49. ValReal = Real;
  50. {$ifdef USEANSISTRINGS}
  51. {$error StrLenInt must be a longint if ansi strings are used}
  52. {$endif}
  53. {$endif}
  54. { some type aliases }
  55. dword = cardinal;
  56. longword = cardinal;
  57. {$ifndef useansistrings}
  58. shortstring = string;
  59. {$endif}
  60. { Zero - terminated strings }
  61. PChar = ^Char;
  62. PPChar = ^PChar;
  63. { procedure type }
  64. TProcedure = Procedure;
  65. const
  66. { max. values for longint and int}
  67. maxLongint = $7fffffff;
  68. maxint = 32767;
  69. { Compatibility With TP }
  70. {$ifdef i386}
  71. Test8086 : byte = 2; { Always i386 or newer }
  72. Test8087 : byte = 3; { Always 387 or newer. Emulated if needed. }
  73. {$endif i386}
  74. {$ifdef m68k}
  75. Test68000 : byte = 0; { Must be determined at startup for both }
  76. Test68881 : byte = 0;
  77. {$endif}
  78. { max level in dumping on error }
  79. Max_Frame_Dump : Word = 8;
  80. { Exit Procedure handling consts and types }
  81. ExitProc : pointer = nil;
  82. Erroraddr: pointer = nil;
  83. Errorcode: Word = 0;
  84. { file input modes }
  85. fmClosed = $D7B0;
  86. fmInput = $D7B1;
  87. fmOutput = $D7B2;
  88. fmInOut = $D7B3;
  89. fmAppend = $D7B4;
  90. Filemode : byte = 2;
  91. Type
  92. 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. { Error handlers }
  104. ErrorProc : Pointer;
  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. {$endif RTLLITE}
  131. Function Chr(b:byte):Char;
  132. Function Length(s:string):byte;
  133. Function Random(l:Longint):Longint;
  134. Function Random:real;
  135. Procedure Randomize;
  136. Function abs(l:Longint):Longint;
  137. Function sqr(l:Longint):Longint;
  138. Function odd(l:Longint):Boolean;
  139. { float math routines }
  140. {$I mathh.inc}
  141. {****************************************************************************
  142. Addr/Pointer Handling
  143. ****************************************************************************}
  144. {$ifndef RTLLITE}
  145. Function ptr(sel,off:Longint):pointer;
  146. Function Addr (Var X):pointer;
  147. Function Cseg:Word;
  148. Function Dseg:Word;
  149. Function Sseg:Word;
  150. {$endif RTLLITE}
  151. {****************************************************************************
  152. PChar and String Handling
  153. ****************************************************************************}
  154. function strpas(p:pchar):shortstring;
  155. function strlen(p:pchar):longint;
  156. { Shortstring functions }
  157. Function Copy(const s:shortstring;index:StrLenInt;count:StrLenInt):shortstring;
  158. Procedure Delete(Var s:shortstring;index:StrLenInt;count:StrLenInt);
  159. Procedure Insert(const source:shortstring;Var s:shortstring;index:StrLenInt);
  160. Function Pos(const substr:shortstring;const s:shortstring):StrLenInt;
  161. Function Pos(C:Char;const s:shortstring):StrLenInt;
  162. Procedure SetLength(var s:shortstring;len:StrLenInt);
  163. { Char functions to overcome overloading problem with ansistrings }
  164. function copy(c:char;index : StrLenInt;count : StrLenInt): shortstring;
  165. function pos(const substr : shortstring;c:char): StrLenInt;
  166. function length(c:char):byte;
  167. Function upCase(const s:shortstring):shortstring;
  168. Function upCase(c:Char):Char;
  169. {$ifndef RTLLITE}
  170. Function lowerCase(c:Char):Char;
  171. Function lowerCase(const s:shortstring):shortstring;
  172. Function hexStr(Val:Longint;cnt:byte):shortstring;
  173. Function binStr(Val:Longint;cnt:byte):shortstring;
  174. {$endif RTLLITE}
  175. Function Space(b:byte):shortstring;
  176. Procedure Val(const s:shortstring;Var l:Longint;Var code:Word);
  177. Procedure Val(const s:shortstring;Var l:Longint;Var code:Integer);
  178. Procedure Val(const s:shortstring;Var l:Longint;Var code:Longint);
  179. Procedure Val(const s:shortstring;Var l:Longint);
  180. Procedure Val(const s:shortstring;Var b:byte;Var code:Word);
  181. Procedure Val(const s:shortstring;Var b:byte;Var code:Integer);
  182. Procedure Val(const s:shortstring;Var b:byte;Var code:Longint);
  183. Procedure Val(const s:shortstring;Var b:byte);
  184. Procedure Val(const s:shortstring;Var b:shortint;Var code:Word);
  185. Procedure Val(const s:shortstring;Var b:shortint;Var code:Integer);
  186. Procedure Val(const s:shortstring;Var b:shortint;Var code:Longint);
  187. Procedure Val(const s:shortstring;Var b:shortint);
  188. Procedure Val(const s:shortstring;Var b:Word;Var code:Word);
  189. Procedure Val(const s:shortstring;Var b:Word;Var code:Integer);
  190. Procedure Val(const s:shortstring;Var b:Word;Var code:Longint);
  191. Procedure Val(const s:shortstring;Var b:Word);
  192. Procedure Val(const s:shortstring;Var b:Integer;Var code:Word);
  193. Procedure Val(const s:shortstring;Var b:Integer;Var code:Integer);
  194. Procedure Val(const s:shortstring;Var b:Integer;Var code:Longint);
  195. Procedure Val(const s:shortstring;Var b:Integer);
  196. Procedure Val(const s:shortstring;Var v:cardinal;Var code:Word);
  197. Procedure Val(const s:shortstring;Var v:cardinal;Var code:Integer);
  198. Procedure Val(const s:shortstring;Var v:cardinal;Var code:Longint);
  199. Procedure Val(const s:shortstring;Var v:cardinal);
  200. Procedure Val(const s:shortstring;Var d:ValReal;Var code:Word);
  201. Procedure Val(const s:shortstring;Var d:ValReal;Var code:Integer);
  202. Procedure Val(const s:shortstring;Var d:ValReal;Var code:Longint);
  203. Procedure Val(const s:shortstring;Var d:ValReal);
  204. {$ifdef SUPPORT_SINGLE}
  205. Procedure Val(const s:shortstring;Var d:single;Var code:Word);
  206. Procedure Val(const s:shortstring;Var d:single;Var code:Integer);
  207. Procedure Val(const s:shortstring;Var d:single;Var code:Longint);
  208. Procedure Val(const s:shortstring;Var d:single);
  209. {$endif SUPPORT_SINGLE}
  210. {$ifdef SUPPORT_COMP}
  211. Procedure Val(const s:shortstring;Var d:comp;Var code:Word);
  212. Procedure Val(const s:shortstring;Var d:comp;Var code:Integer);
  213. Procedure Val(const s:shortstring;Var d:comp;Var code:Longint);
  214. Procedure Val(const s:shortstring;Var d:comp);
  215. {$endif SUPPORT_COMP}
  216. {$ifdef SUPPORT_FIXED}
  217. Procedure Val(const s:shortstring;Var d:fixed;Var code:Word);
  218. Procedure Val(const s:shortstring;Var d:fixed;Var code:Integer);
  219. Procedure Val(const s:shortstring;Var d:fixed;Var code:Longint);
  220. Procedure Val(const s:shortstring;Var d:fixed);
  221. {$endif SUPPORT_FIXED}
  222. {$ifdef DEFAULT_EXTENDED}
  223. Procedure Val(const s:shortstring;Var d:Real;Var code:Word);
  224. Procedure Val(const s:shortstring;Var d:Real;Var code:Integer);
  225. Procedure Val(const s:shortstring;Var d:Real;Var code:Longint);
  226. Procedure Val(const s:shortstring;Var d:Real);
  227. {$else DEFAULT_EXTENDED}
  228. {$ifdef SUPPORT_EXTENDED}
  229. Procedure Val(const s:shortstring;Var d:Extended;Var code:Word);
  230. Procedure Val(const s:shortstring;Var d:Extended;Var code:Integer);
  231. Procedure Val(const s:shortstring;Var d:Extended;Var code:Longint);
  232. Procedure Val(const s:shortstring;Var d:Extended);
  233. {$endif}
  234. {$endif DEFAULT_EXTENDED}
  235. {****************************************************************************
  236. AnsiString Handling
  237. ****************************************************************************}
  238. Procedure SetLength (Var S : AnsiString; l : Longint);
  239. Procedure UniqueAnsiString (Var S : AnsiString);
  240. Function Length (Const S : AnsiString) : Longint;
  241. Function Copy (Const S : AnsiString; Index,Size : Longint) : AnsiString;
  242. Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : Longint;
  243. Procedure Insert (Const Source : AnsiString; Var S : AnsiString; Index : Longint);
  244. Procedure Delete (Var S : AnsiString; Index,Size: Longint);
  245. Procedure Val (Const S : AnsiString; var R : real; Var Code : Integer);
  246. {
  247. Procedure Val (Const S : AnsiString; var D : Double; Var Code : Integer);
  248. }
  249. Procedure Val (Const S : AnsiString; var E : Extended; Code : Integer);
  250. Procedure Val (Const S : AnsiString; var C : Cardinal; Code : Integer);
  251. Procedure Val (Const S : AnsiString; var L : Longint; Var Code : Integer);
  252. Procedure Val (Const S : AnsiString; var W : Word; Var Code : Integer);
  253. Procedure Val (Const S : AnsiString; var I : Integer; Var Code : Integer);
  254. Procedure Val (Const S : AnsiString; var B : Byte; Var Code : Integer);
  255. Procedure Val (Const S : AnsiString; var SI : ShortInt; Var Code : Integer);
  256. {
  257. Procedure Str (Const R : Real;Len, fr : longint; Var S : AnsiString);
  258. Procedure Str (Const D : Double;Len,fr : longint; Var S : AnsiString);
  259. Procedure Str (Const E : Extended;Len,fr : longint; Var S : AnsiString);
  260. Procedure Str (Const C : Cardinal;len : Longint; Var S : AnsiString);
  261. Procedure Str (Const L : LongInt;len : longint; Var S : AnsiString);
  262. Procedure Str (Const W : Word;len : longint; Var S : AnsiString);
  263. Procedure Str (Const I : Integer;len : Longint; Var S : AnsiString);
  264. Procedure Str (Const B : Byte; Len : longint; Var S : AnsiString);
  265. Procedure Str (Const SI : ShortInt; Len : longint; Var S : AnsiString);
  266. }
  267. {****************************************************************************
  268. Untyped File Management
  269. ****************************************************************************}
  270. Procedure Assign(Var f:File;const Name:string);
  271. Procedure Assign(Var f:File;p:pchar);
  272. Procedure Assign(Var f:File;c:char);
  273. Procedure Rewrite(Var f:File;l:Longint);
  274. Procedure Rewrite(Var f:File);
  275. Procedure Reset(Var f:File;l:Longint);
  276. Procedure Reset(Var f:File);
  277. Procedure Close(Var f:File);
  278. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint;Var Result:Longint);
  279. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Word);
  280. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Integer);
  281. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint);
  282. Procedure BlockRead(Var f:File;Var Buf;count:Longint;Var Result:Longint);
  283. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Word);
  284. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Integer);
  285. Procedure BlockRead(Var f:File;Var Buf;count:Longint);
  286. Function FilePos(Var f:File):Longint;
  287. Function FileSize(Var f:File):Longint;
  288. Procedure Seek(Var f:File;Pos:Longint);
  289. Function EOF(Var f:File):Boolean;
  290. Procedure Erase(Var f:File);
  291. Procedure Rename(Var f:File;const s:string);
  292. Procedure Rename(Var f:File;p:pchar);
  293. Procedure Rename(Var f:File;c:char);
  294. Procedure Truncate (Var F:File);
  295. {****************************************************************************
  296. Typed File Management
  297. ****************************************************************************}
  298. Procedure Assign(Var f:TypedFile;const Name:string);
  299. Procedure Assign(Var f:TypedFile;p:pchar);
  300. Procedure Assign(Var f:TypedFile;c:char);
  301. Procedure Rewrite(Var f:TypedFile);
  302. Procedure Reset(Var f:TypedFile);
  303. {****************************************************************************
  304. Text File Management
  305. ****************************************************************************}
  306. Procedure Assign(Var t:Text;const s:string);
  307. Procedure Assign(Var t:Text;p:pchar);
  308. Procedure Assign(Var t:Text;c:char);
  309. Procedure Close(Var t:Text);
  310. Procedure Rewrite(Var t:Text);
  311. Procedure Reset(Var t:Text);
  312. Procedure Append(Var t:Text);
  313. Procedure Flush(Var t:Text);
  314. Procedure Erase(Var t:Text);
  315. Procedure Rename(Var t:Text;const s:string);
  316. Procedure Rename(Var t:Text;p:pchar);
  317. Procedure Rename(Var t:Text;c:char);
  318. Function EOF(Var t:Text):Boolean;
  319. Function EOF:Boolean;
  320. Function EOLn(Var t:Text):Boolean;
  321. Function EOLn:Boolean;
  322. Function SeekEOLn (Var t:Text):Boolean;
  323. Function SeekEOF (Var t:Text):Boolean;
  324. Function SeekEOLn:Boolean;
  325. Function SeekEOF:Boolean;
  326. Procedure SetTextBuf(Var f:Text; Var Buf);
  327. Procedure SetTextBuf(Var f:Text; Var Buf; Size:Word);
  328. {****************************************************************************
  329. Directory Management
  330. ****************************************************************************}
  331. Procedure chdir(const s:string);
  332. Procedure mkdir(const s:string);
  333. Procedure rmdir(const s:string);
  334. Procedure getdir(drivenr:byte;Var dir:string);
  335. {*****************************************************************************
  336. Miscelleaous
  337. *****************************************************************************}
  338. { os independent calls to allow backtraces }
  339. function get_frame:longint;
  340. function get_caller_addr(framebp:longint):longint;
  341. function get_caller_frame(framebp:longint):longint;
  342. Function IOResult:Word;
  343. Function Sptr:Longint;
  344. {*****************************************************************************
  345. Init / Exit / ExitProc
  346. *****************************************************************************}
  347. Function Paramcount:Longint;
  348. Function ParamStr(l:Longint):string;
  349. {$ifndef RTLLITE}
  350. Procedure Dump_Stack(bp:Longint);
  351. {$endif RTLLITE}
  352. Procedure RunError(w:Word);
  353. Procedure RunError;
  354. Procedure halt(errnum:byte);
  355. {$ifndef RTLLITE}
  356. Procedure AddExitProc(Proc:TProcedure);
  357. {$endif RTLLITE}
  358. Procedure halt;
  359. {*****************************************************************************
  360. Abstract/Assert
  361. *****************************************************************************}
  362. procedure AbstractError;
  363. Procedure SysAssert(Const Msg,FName:string;LineNo,ErrorAddr:Longint);
  364. const
  365. AssertErrorProc : Pointer=@SysAssert;
  366. AbstractErrorProc : Pointer=nil;
  367. {*****************************************************************************
  368. SetJmp/LongJmp
  369. *****************************************************************************}
  370. {$i setjumph.inc}
  371. {
  372. $Log$
  373. Revision 1.40 1998-11-05 10:29:37 pierre
  374. * fix for length(char) in const expressions
  375. Revision 1.39 1998/11/04 20:34:01 michael
  376. + Removed ifdef useansistrings
  377. Revision 1.38 1998/11/04 10:20:51 peter
  378. * ansistring fixes
  379. Revision 1.37 1998/10/10 15:28:47 peter
  380. + read single,fixed
  381. + val with code:longint
  382. + val for fixed
  383. Revision 1.36 1998/10/05 17:22:54 pierre
  384. * avoid overflow on $8000000 with $Q-
  385. Revision 1.35 1998/10/05 12:32:52 peter
  386. + assert() support
  387. Revision 1.34 1998/10/01 14:54:48 peter
  388. * export also stackframe functions
  389. Revision 1.33 1998/09/28 14:02:33 michael
  390. + AnsiString changes
  391. Revision 1.32 1998/09/22 15:30:55 peter
  392. * shortstring=string type added
  393. Revision 1.31 1998/09/20 17:49:09 florian
  394. * some ansistring fixes
  395. Revision 1.30 1998/09/17 16:34:17 peter
  396. * new eof,eoln,seekeoln,seekeof
  397. * speed upgrade for read_string
  398. * inoutres 104/105 updates for read_* and write_*
  399. Revision 1.29 1998/09/16 13:08:04 michael
  400. Added AbstractErrorHandler
  401. Revision 1.28 1998/09/14 10:48:22 peter
  402. * FPC_ names
  403. * Heap manager is now system independent
  404. Revision 1.27 1998/09/08 15:03:28 peter
  405. * moved getmem/freemem/memavail/maxavail to heaph.inc
  406. Revision 1.26 1998/09/04 18:16:14 peter
  407. * uniform filerec/textrec (with recsize:longint and name:0..255)
  408. Revision 1.25 1998/09/01 17:36:22 peter
  409. + internconst
  410. Revision 1.24 1998/08/11 21:39:08 peter
  411. * splitted default_extended from support_extended
  412. Revision 1.23 1998/08/11 00:05:27 peter
  413. * $ifdef ver0_99_5 updates
  414. Revision 1.22 1998/08/08 12:28:14 florian
  415. * a lot small fixes to the extended data type work
  416. Revision 1.21 1998/07/30 13:26:17 michael
  417. + Added support for ErrorProc variable. All internal functions are required
  418. to call HandleError instead of runerror from now on.
  419. This is necessary for exception support.
  420. Revision 1.20 1998/07/28 20:37:47 michael
  421. + added setjmp/longjmp and exception support
  422. Revision 1.19 1998/07/20 23:36:57 michael
  423. changes for ansistrings
  424. Revision 1.18 1998/07/18 17:14:24 florian
  425. * strlenint type implemented
  426. Revision 1.17 1998/07/10 11:02:39 peter
  427. * support_fixed, becuase fixed is not 100% yet for the m68k
  428. Revision 1.16 1998/07/02 12:13:18 carl
  429. * No SINGLE type for m68k or other non-intel processors!
  430. Revision 1.15 1998/07/01 14:43:46 carl
  431. - max_frame_dump reduced to 8, 20 is too much!
  432. Revision 1.14 1998/06/25 14:04:26 peter
  433. + internal inc/dec
  434. Revision 1.13 1998/06/25 09:44:21 daniel
  435. + RTLLITE directive to compile minimal RTL.
  436. Revision 1.12 1998/06/15 15:16:27 daniel
  437. * RTLLITE conditional added to produce smaller RTL
  438. Revision 1.11 1998/06/08 12:38:23 michael
  439. Implemented rtti, inserted ansistrings again
  440. Revision 1.10 1998/06/04 23:46:02 peter
  441. * comp,extended are only i386 added support_comp,support_extended
  442. Revision 1.9 1998/06/04 08:26:03 pierre
  443. * boolean internal definition again (needed to compile
  444. older RTL's)
  445. Revision 1.8 1998/06/03 23:39:53 peter
  446. + boolean=bytebool
  447. Revision 1.7 1998/05/22 12:34:11 peter
  448. * fixed the optimizes of daniel
  449. Revision 1.6 1998/05/21 19:31:00 peter
  450. * objects compiles for linux
  451. + assign(pchar), assign(char), rename(pchar), rename(char)
  452. * fixed read_text_as_array
  453. + read_text_as_pchar which was not yet in the rtl
  454. Revision 1.5 1998/05/12 10:42:45 peter
  455. * moved getopts to inc/, all supported OS's need argc,argv exported
  456. + strpas, strlen are now exported in the systemunit
  457. * removed logs
  458. * removed $ifdef ver_above
  459. Revision 1.4 1998/04/16 12:30:47 peter
  460. + inc(pchar), dec(pchar), incc(pchar,a),dec(pchar,a)
  461. }