systemh.inc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Run time library.
  4. Copyright (c) 1999-2000 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. Needed switches
  14. ****************************************************************************}
  15. {$I-,Q-,H-,R-,V-}
  16. {$mode objfpc}
  17. { don't use FPU registervariables on the i386 }
  18. {$ifdef i386}
  19. {$maxfpuregisters 0}
  20. {$endif i386}
  21. { needed for insert,delete,readln }
  22. {$P+}
  23. { Stack check gives a note under linux }
  24. {$ifndef unix}
  25. {$S-}
  26. {$endif}
  27. {****************************************************************************
  28. Global Types and Constants
  29. ****************************************************************************}
  30. Type
  31. ShortInt = -128..127;
  32. SmallInt = -32768..32767;
  33. { can't use -2147483648 because of a bug in 1.0.2's val() procedure (JM) }
  34. Longint = +(-2147483647-1)..$7fffffff;
  35. Byte = 0..255;
  36. Word = 0..65535;
  37. DWord = Cardinal;
  38. LongWord = Cardinal;
  39. Integer = SmallInt;
  40. { at least declare Turbo Pascal real types }
  41. {$ifdef i386}
  42. StrLenInt = LongInt;
  43. {$define DEFAULT_EXTENDED}
  44. {$define SUPPORT_SINGLE}
  45. {$define SUPPORT_DOUBLE}
  46. {$define SUPPORT_EXTENDED}
  47. {$define SUPPORT_COMP}
  48. ValSInt = Longint;
  49. ValUInt = Cardinal;
  50. ValReal = Extended;
  51. {$endif}
  52. {$ifdef m68k}
  53. StrLenInt = Longint;
  54. ValSInt = Longint;
  55. ValUInt = Cardinal;
  56. ValReal = Real;
  57. {$define SUPPORT_SINGLE}
  58. {$endif}
  59. { Zero - terminated strings }
  60. PChar = ^Char;
  61. PPChar = ^PChar;
  62. TAnsiChar = Char;
  63. AnsiChar = TAnsiChar;
  64. PAnsiChar = ^TAnsiChar;
  65. PPAnsiChar = ^PAnsiChar;
  66. UCS4Char = Cardinal;
  67. PUCS4Char = ^UCS4Char;
  68. Currency = Int64;
  69. HRESULT = Longint;
  70. TDateTime = Double;
  71. Error = Longint;
  72. PSingle = ^Single;
  73. PDouble = ^Double;
  74. PCurrency = ^Currency;
  75. {$ifdef SUPPORT_COMP}
  76. PComp = ^Comp;
  77. {$endif SUPPORT_COMP}
  78. {$ifdef SUPPORT_EXTENDED}
  79. PExtended = ^Extended;
  80. {$endif SUPPORT_EXTENDED}
  81. PSmallInt = ^Smallint;
  82. PInteger = ^Longint;
  83. PByte = ^Byte;
  84. PWord = ^word;
  85. PDWord = ^DWord;
  86. PLongWord = ^LongWord;
  87. PLongint = ^Longint;
  88. PCardinal = ^Cardinal;
  89. PQWord = ^QWord;
  90. PInt64 = ^Int64;
  91. PPointer = ^Pointer;
  92. PPPointer = ^PPointer;
  93. PBoolean = ^Boolean;
  94. PWordBool = ^WordBool;
  95. PLongBool = ^LongBool;
  96. PShortString = ^ShortString;
  97. PAnsiString = ^AnsiString;
  98. PDate = ^TDateTime;
  99. PError = ^Error;
  100. {$ifdef HASVARIANT}
  101. PVariant = ^Variant;
  102. {$endif HASVARIANT}
  103. {$ifdef HASWIDECHAR}
  104. PWideChar = ^WideChar;
  105. PPWideChar = ^PWideChar;
  106. {$endif HASWIDECHAR}
  107. {$ifdef HASWIDESTRING}
  108. PWideString = ^WideString;
  109. {$endif HASWIDESTRING}
  110. TTextLineBreakStyle = (tlbsLF,tlbsCRLF,tlbsCR);
  111. { procedure type }
  112. TProcedure = Procedure;
  113. const
  114. { Maximum value of the biggest signed and unsigned integer type available}
  115. MaxSIntValue = High(ValSInt);
  116. MaxUIntValue = High(ValUInt);
  117. { max. values for longint and int}
  118. maxLongint = $7fffffff;
  119. maxSmallint = 32767;
  120. const
  121. maxint = maxsmallint;
  122. { Compatibility With TP }
  123. const
  124. { code to use comps in int64mul and div code is commented out! (JM) }
  125. FPUInt64 : boolean = false; { set this to false if you don't want that }
  126. { the fpu does int64*int64 and }
  127. { int64 div int64, if the * is overflow }
  128. { checked, it is done in software }
  129. {$ifdef i386}
  130. Test8086 : byte = 2; { Always i386 or newer }
  131. Test8087 : byte = 3; { Always 387 or newer. Emulated if needed. }
  132. {$endif i386}
  133. {$ifdef m68k}
  134. Test68000 : byte = 0; { Must be determined at startup for both }
  135. Test68881 : byte = 0;
  136. {$endif}
  137. { max level in dumping on error }
  138. Max_Frame_Dump : Word = 8;
  139. { Exit Procedure handling consts and types }
  140. ExitProc : pointer = nil;
  141. Erroraddr: pointer = nil;
  142. Errorcode: Word = 0;
  143. { file input modes }
  144. fmClosed = $D7B0;
  145. fmInput = $D7B1;
  146. fmOutput = $D7B2;
  147. fmInOut = $D7B3;
  148. fmAppend = $D7B4;
  149. Filemode : byte = 2;
  150. CmdLine : PChar = nil;
  151. var
  152. { Standard In- and Output }
  153. Output,
  154. Input,
  155. StdOut,
  156. StdErr : Text;
  157. ExitCode : Word;
  158. StackBottom,
  159. LowestStack,
  160. RandSeed : Cardinal;
  161. { Delphi compatible }
  162. IsLibrary,IsMultiThreaded,IsConsole : boolean;
  163. {$ifdef MT}
  164. ThreadVar
  165. {$else MT}
  166. Var
  167. {$endif MT}
  168. InOutRes : Word;
  169. {****************************************************************************
  170. Processor specific routines
  171. ****************************************************************************}
  172. Procedure Move(const source;var dest;count:Longint);
  173. Procedure FillChar(Var x;count:Longint;Value:Boolean);
  174. Procedure FillChar(Var x;count:Longint;Value:Char);
  175. Procedure FillChar(Var x;count:Longint;Value:Byte);
  176. procedure FillByte(var x;count:longint;value:byte);
  177. Procedure FillWord(Var x;count:Longint;Value:Word);
  178. procedure FillDWord(var x;count:longint;value:DWord);
  179. function IndexChar(const buf;len:longint;b:char):longint;
  180. function IndexByte(const buf;len:longint;b:byte):longint;
  181. function Indexword(const buf;len:longint;b:word):longint;
  182. function IndexDWord(const buf;len:longint;b:DWord):longint;
  183. function CompareChar(const buf1,buf2;len:longint):longint;
  184. function CompareByte(const buf1,buf2;len:longint):longint;
  185. function CompareWord(const buf1,buf2;len:longint):longint;
  186. function CompareDWord(const buf1,buf2;len:longint):longint;
  187. procedure MoveChar0(const buf1;var buf2;len:longint);
  188. function IndexChar0(const buf;len:longint;b:char):longint;
  189. function CompareChar0(const buf1,buf2;len:longint):longint;
  190. {****************************************************************************
  191. Math Routines
  192. ****************************************************************************}
  193. Function lo(w:Word):byte;
  194. Function lo(l:Longint):Word;
  195. Function lo(l:DWord):Word;
  196. Function lo(i:Integer):byte;
  197. Function lo(B: Byte):Byte;
  198. Function hi(w:Word):byte;
  199. Function hi(i:Integer):byte;
  200. Function hi(l:Longint):Word;
  201. Function hi(b : Byte) : Byte;
  202. Function hi(l: DWord): Word;
  203. Function Swap (X:Word):Word;
  204. Function Swap (X:Integer):Integer;
  205. Function Swap (X:Cardinal):Cardinal;
  206. Function Swap (X:LongInt):LongInt;
  207. Function lo(q : QWord) : DWord;
  208. Function lo(i : Int64) : DWord;
  209. Function hi(q : QWord) : DWord;
  210. Function hi(i : Int64) : DWord;
  211. Function Swap (X:QWord):QWord;
  212. Function Swap (X:Int64):Int64;
  213. Function Random(l:cardinal):cardinal;
  214. Function Random(l:longint):longint;
  215. Function Random: extended;
  216. Procedure Randomize;
  217. Function abs(l:Longint):Longint;
  218. Function sqr(l:Longint):Longint;
  219. Function odd(l:Longint):Boolean;
  220. Function odd(l:Cardinal):Boolean;
  221. Function odd(l:Int64):Boolean;
  222. Function odd(l:QWord):Boolean;
  223. { float math routines }
  224. {$I mathh.inc}
  225. {****************************************************************************
  226. Addr/Pointer Handling
  227. ****************************************************************************}
  228. Function ptr(sel,off:Longint):farpointer;
  229. Function Cseg:Word;
  230. Function Dseg:Word;
  231. Function Sseg:Word;
  232. {****************************************************************************
  233. PChar and String Handling
  234. ****************************************************************************}
  235. function strpas(p:pchar):shortstring;
  236. function strlen(p:pchar):longint;
  237. { Shortstring functions }
  238. {$ifndef INTERNSETLENGTH}
  239. Procedure SetLength (Var S:ShortString;len:StrLenInt);
  240. {$endif INTERNSETLENGTH}
  241. Function Copy(const s:shortstring;index:StrLenInt;count:StrLenInt):shortstring;
  242. Procedure Delete(Var s:shortstring;index:StrLenInt;count:StrLenInt);
  243. Procedure Insert(const source:shortstring;Var s:shortstring;index:StrLenInt);
  244. Procedure Insert(source:Char;Var s:shortstring;index:StrLenInt);
  245. Function Pos(const substr:shortstring;const s:shortstring):StrLenInt;
  246. Function Pos(C:Char;const s:shortstring):StrLenInt;
  247. Procedure SetString (Var S : Shortstring; Buf : PChar; Len : Longint);
  248. Procedure SetString (Var S : AnsiString; Buf : PChar; Len : Longint);
  249. Function Length(s:string):byte;
  250. Function upCase(const s:shortstring):shortstring;
  251. Function lowerCase(const s:shortstring):shortstring;
  252. Function Space(b:byte):shortstring;
  253. Function hexStr(Val:Longint;cnt:byte):shortstring;
  254. Function binStr(Val:Longint;cnt:byte):shortstring;
  255. Function hexStr(Val:int64;cnt:byte):shortstring;
  256. Function binStr(Val:int64;cnt:byte):shortstring;
  257. { Char functions }
  258. Function Chr(b:byte):Char;
  259. Function upCase(c:Char):Char;
  260. Function lowerCase(c:Char):Char;
  261. function copy(c:char;index : StrLenInt;count : StrLenInt): shortstring;
  262. function pos(const substr : shortstring;c:char): StrLenInt;
  263. function length(c:char):byte;
  264. {****************************************************************************
  265. AnsiString Handling
  266. ****************************************************************************}
  267. {$ifndef INTERNSETLENGTH}
  268. Procedure SetLength (Var S : AnsiString; l : Longint);
  269. {$endif INTERNSETLENGTH}
  270. Procedure UniqueString (Var S : AnsiString);
  271. Function Length (Const S : AnsiString) : Longint;
  272. Function Copy (Const S : AnsiString; Index,Size : Longint) : AnsiString;
  273. Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : Longint;
  274. Function Pos (c : Char; Const s : AnsiString) : Longint;
  275. Procedure Insert (Const Source : AnsiString; Var S : AnsiString; Index : Longint);
  276. Procedure Delete (Var S : AnsiString; Index,Size: Longint);
  277. Function StringOfChar(c : char;l : longint) : AnsiString;
  278. function upcase(const s : ansistring) : ansistring;
  279. function lowercase(const s : ansistring) : ansistring;
  280. {****************************************************************************
  281. WideString Handling
  282. ****************************************************************************}
  283. {$ifdef HASWIDESTRING}
  284. {$ifndef INTERNSETLENGTH}
  285. Procedure SetLength (Var S : WideString; l : Longint);
  286. {$endif INTERNSETLENGTH}
  287. Procedure UniqueString (Var S : WideString);
  288. Function Length (Const S : WideString) : Longint;
  289. Function Copy (Const S : WideString; Index,Size : Longint) : WideString;
  290. Function Pos (Const Substr : WideString; Const Source : WideString) : Longint;
  291. Function Pos (c : Char; Const s : WideString) : Longint;
  292. Function Pos (c : WideChar; Const s : WideString) : Longint;
  293. Procedure Insert (Const Source : WideString; Var S : WideString; Index : Longint);
  294. Procedure Delete (Var S : WideString; Index,Size: Longint);
  295. {$endif HASWIDESTRING}
  296. {****************************************************************************
  297. Untyped File Management
  298. ****************************************************************************}
  299. Procedure Assign(Var f:File;const Name:string);
  300. Procedure Assign(Var f:File;p:pchar);
  301. Procedure Assign(Var f:File;c:char);
  302. Procedure Rewrite(Var f:File;l:Longint);
  303. Procedure Rewrite(Var f:File);
  304. Procedure Reset(Var f:File;l:Longint);
  305. Procedure Reset(Var f:File);
  306. Procedure Close(Var f:File);
  307. Procedure BlockWrite(Var f:File;Const Buf;Count:Longint;Var Result:Longint);
  308. Procedure BlockWrite(Var f:File;Const Buf;Count:Cardinal;var Result:Cardinal);
  309. Procedure BlockWrite(Var f:File;Const Buf;Count:Word;Var Result:Word);
  310. Procedure BlockWrite(Var f:File;Const Buf;Count:Word;Var Result:Integer);
  311. Procedure BlockWrite(Var f:File;Const Buf;Count:Longint);
  312. Procedure BlockRead(Var f:File;Var Buf;count:Longint;Var Result:Longint);
  313. Procedure BlockRead(Var f:File;Var Buf;count:Cardinal;Var Result:Cardinal);
  314. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Word);
  315. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Integer);
  316. Procedure BlockRead(Var f:File;Var Buf;count:Longint);
  317. Function FilePos(Var f:File):Longint;
  318. Function FileSize(Var f:File):Longint;
  319. Procedure Seek(Var f:File;Pos:Longint);
  320. Function EOF(Var f:File):Boolean;
  321. Procedure Erase(Var f:File);
  322. Procedure Rename(Var f:File;const s:string);
  323. Procedure Rename(Var f:File;p:pchar);
  324. Procedure Rename(Var f:File;c:char);
  325. Procedure Truncate (Var F:File);
  326. {****************************************************************************
  327. Typed File Management
  328. ****************************************************************************}
  329. Procedure Assign(Var f:TypedFile;const Name:string);
  330. Procedure Assign(Var f:TypedFile;p:pchar);
  331. Procedure Assign(Var f:TypedFile;c:char);
  332. Procedure Rewrite(Var f:TypedFile);
  333. Procedure Reset(Var f:TypedFile);
  334. {****************************************************************************
  335. Text File Management
  336. ****************************************************************************}
  337. Procedure Assign(Var t:Text;const s:string);
  338. Procedure Assign(Var t:Text;p:pchar);
  339. Procedure Assign(Var t:Text;c:char);
  340. Procedure Close(Var t:Text);
  341. Procedure Rewrite(Var t:Text);
  342. Procedure Reset(Var t:Text);
  343. Procedure Append(Var t:Text);
  344. Procedure Flush(Var t:Text);
  345. Procedure Erase(Var t:Text);
  346. Procedure Rename(Var t:Text;const s:string);
  347. Procedure Rename(Var t:Text;p:pchar);
  348. Procedure Rename(Var t:Text;c:char);
  349. Function EOF(Var t:Text):Boolean;
  350. Function EOF:Boolean;
  351. Function EOLn(Var t:Text):Boolean;
  352. Function EOLn:Boolean;
  353. Function SeekEOLn (Var t:Text):Boolean;
  354. Function SeekEOF (Var t:Text):Boolean;
  355. Function SeekEOLn:Boolean;
  356. Function SeekEOF:Boolean;
  357. Procedure SetTextBuf(Var f:Text; Var Buf);
  358. Procedure SetTextBuf(Var f:Text; Var Buf; Size:Longint);
  359. {****************************************************************************
  360. Directory Management
  361. ****************************************************************************}
  362. Procedure chdir(const s:string);
  363. Procedure mkdir(const s:string);
  364. Procedure rmdir(const s:string);
  365. Procedure getdir(drivenr:byte;Var dir:shortstring);
  366. Procedure getdir(drivenr:byte;Var dir:ansistring);
  367. {*****************************************************************************
  368. Miscelleaous
  369. *****************************************************************************}
  370. { os independent calls to allow backtraces }
  371. function get_frame:longint;
  372. function get_caller_addr(framebp:longint):longint;
  373. function get_caller_frame(framebp:longint):longint;
  374. Function IOResult:Word;
  375. Function Sptr:Longint;
  376. {*****************************************************************************
  377. Init / Exit / ExitProc
  378. *****************************************************************************}
  379. Function Paramcount:Longint;
  380. Function ParamStr(l:Longint):string;
  381. Procedure Dump_Stack(var f : text;bp:Longint);
  382. Procedure RunError(w:Word);
  383. Procedure RunError;
  384. Procedure halt(errnum:byte);
  385. Procedure AddExitProc(Proc:TProcedure);
  386. Procedure halt;
  387. {*****************************************************************************
  388. Abstract/Assert/Error Handling
  389. *****************************************************************************}
  390. procedure AbstractError;
  391. Function SysBackTraceStr(Addr: Longint): ShortString;
  392. Procedure SysAssert(Const Msg,FName:ShortString;LineNo,ErrorAddr:Longint);
  393. { Error handlers }
  394. Type
  395. TBackTraceStrFunc = Function (Addr: Longint): ShortString;
  396. TErrorProc = Procedure (ErrNo : Longint; Address,Frame : Pointer);
  397. TAbstractErrorProc = Procedure;
  398. TAssertErrorProc = Procedure(const msg,fname:ShortString;lineno,erroraddr:longint);
  399. const
  400. BackTraceStrFunc : TBackTraceStrFunc = @SysBackTraceStr;
  401. ErrorProc : TErrorProc = nil;
  402. AbstractErrorProc : TAbstractErrorProc = nil;
  403. AssertErrorProc : TAssertErrorProc = @SysAssert;
  404. {*****************************************************************************
  405. SetJmp/LongJmp
  406. *****************************************************************************}
  407. {$i setjumph.inc}
  408. {*****************************************************************************
  409. Object Pascal support
  410. *****************************************************************************}
  411. {$i objpash.inc}
  412. {
  413. $Log$
  414. Revision 1.25 2001-07-08 21:00:18 peter
  415. * various widestring updates, it works now mostly without charset
  416. mapping supported
  417. Revision 1.24 2001/06/04 11:43:51 peter
  418. * Formal const to var fixes
  419. * Hexstr(int64) added
  420. Revision 1.23 2001/06/03 20:17:06 peter
  421. * ucs4char added
  422. Revision 1.22 2001/05/16 17:44:25 jonas
  423. + odd() for cardinal, int64 and qword (merged)
  424. Revision 1.21 2001/05/09 19:57:07 peter
  425. *** empty log message ***
  426. Revision 1.20 2001/04/23 18:25:45 peter
  427. * m68k updates
  428. Revision 1.19 2001/04/13 18:06:07 peter
  429. * upcase, lowercase for ansistring
  430. Revision 1.18 2001/03/22 23:26:05 florian
  431. * some new types added like PBoolean
  432. Revision 1.17 2001/03/21 23:29:40 florian
  433. + sLineBreak and misc. stuff for Kylix compatiblity
  434. Revision 1.16 2001/01/24 21:47:18 florian
  435. + more MT stuff added
  436. Revision 1.15 2000/12/16 15:56:19 jonas
  437. - removed all ifdef cardinalmulfix code
  438. Revision 1.14 2000/12/08 14:04:43 jonas
  439. + added pos(char,ansistring), because there is also a pos(char,shortstring)
  440. and without the ansistring version, the shortstring version is always
  441. called when calling pos(char,pchar), even when using $h+ (because the
  442. first parameter matches exactly) (merged)
  443. Revision 1.13 2000/12/07 17:19:47 jonas
  444. * new constant handling: from now on, hex constants >$7fffffff are
  445. parsed as unsigned constants (otherwise, $80000000 got sign extended
  446. and became $ffffffff80000000), all constants in the longint range
  447. become longints, all constants >$7fffffff and <=cardinal($ffffffff)
  448. are cardinals and the rest are int64's.
  449. * added lots of longint typecast to prevent range check errors in the
  450. compiler and rtl
  451. * type casts of symbolic ordinal constants are now preserved
  452. * fixed bug where the original resulttype wasn't restored correctly
  453. after doing a 64bit rangecheck
  454. Revision 1.12 2000/11/13 13:40:04 marco
  455. * Renamefest
  456. Revision 1.11 2000/11/11 16:12:01 peter
  457. * ptr returns farpointer
  458. Revision 1.10 2000/11/06 21:35:59 peter
  459. * removed some warnings
  460. Revision 1.9 2000/11/06 20:34:24 peter
  461. * changed ver1_0 defines to temporary defs
  462. Revision 1.8 2000/10/23 16:15:40 jonas
  463. * renamed strlenint to longint since 1.0 doesn't know that type
  464. Revision 1.7 2000/10/23 14:00:59 florian
  465. * setlength export declaration for 1.0.2 fixed
  466. Revision 1.6 2000/10/21 18:20:17 florian
  467. * a lot of small changes:
  468. - setlength is internal
  469. - win32 graph unit extended
  470. ....
  471. Revision 1.5 2000/08/13 17:55:15 michael
  472. + Added some delphi compatibility types
  473. Revision 1.4 2000/08/08 22:11:45 sg
  474. * Added declarations for WideString utility functions
  475. Revision 1.3 2000/07/14 10:33:10 michael
  476. + Conditionals fixed
  477. Revision 1.2 2000/07/13 11:33:45 michael
  478. + removed logs
  479. }