systemh.inc 19 KB

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