systemh.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  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. {$ifdef i386}
  121. Test8086 : byte = 2; { Always i386 or newer }
  122. Test8087 : byte = 3; { Always 387 or newer. Emulated if needed. }
  123. { code to use comps in int64mul and div code is commented out! (JM) }
  124. FPUInt64 : boolean = false; { set this to false if you don't want that }
  125. { the fpu does int64*int64 and }
  126. { int64 div int64, if the * is overflow }
  127. { checked, it is done in software }
  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. { float math routines }
  217. {$I mathh.inc}
  218. {****************************************************************************
  219. Addr/Pointer Handling
  220. ****************************************************************************}
  221. Function ptr(sel,off:Longint):farpointer;
  222. Function Cseg:Word;
  223. Function Dseg:Word;
  224. Function Sseg:Word;
  225. {****************************************************************************
  226. PChar and String Handling
  227. ****************************************************************************}
  228. function strpas(p:pchar):shortstring;
  229. function strlen(p:pchar):longint;
  230. { Shortstring functions }
  231. {$ifndef INTERNSETLENGTH}
  232. Procedure SetLength (Var S:ShortString;len:StrLenInt);
  233. {$endif INTERNSETLENGTH}
  234. Function Copy(const s:shortstring;index:StrLenInt;count:StrLenInt):shortstring;
  235. Procedure Delete(Var s:shortstring;index:StrLenInt;count:StrLenInt);
  236. Procedure Insert(const source:shortstring;Var s:shortstring;index:StrLenInt);
  237. Procedure Insert(source:Char;Var s:shortstring;index:StrLenInt);
  238. Function Pos(const substr:shortstring;const s:shortstring):StrLenInt;
  239. Function Pos(C:Char;const s:shortstring):StrLenInt;
  240. Procedure SetString (Var S : Shortstring; Buf : PChar; Len : Longint);
  241. Procedure SetString (Var S : AnsiString; Buf : PChar; Len : Longint);
  242. Function Length(s:string):byte;
  243. Function upCase(const s:shortstring):shortstring;
  244. Function lowerCase(const s:shortstring):shortstring;
  245. Function Space(b:byte):shortstring;
  246. Function hexStr(Val:Longint;cnt:byte):shortstring;
  247. Function binStr(Val:Longint;cnt:byte):shortstring;
  248. { Char functions }
  249. Function Chr(b:byte):Char;
  250. Function upCase(c:Char):Char;
  251. Function lowerCase(c:Char):Char;
  252. function copy(c:char;index : StrLenInt;count : StrLenInt): shortstring;
  253. function pos(const substr : shortstring;c:char): StrLenInt;
  254. function length(c:char):byte;
  255. {****************************************************************************
  256. AnsiString Handling
  257. ****************************************************************************}
  258. {$ifndef INTERNSETLENGTH}
  259. Procedure SetLength (Var S : AnsiString; l : Longint);
  260. {$endif INTERNSETLENGTH}
  261. Procedure UniqueString (Var S : AnsiString);
  262. Function Length (Const S : AnsiString) : Longint;
  263. Function Copy (Const S : AnsiString; Index,Size : Longint) : AnsiString;
  264. Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : Longint;
  265. Function Pos (c : Char; Const s : AnsiString) : Longint;
  266. Procedure Insert (Const Source : AnsiString; Var S : AnsiString; Index : Longint);
  267. Procedure Delete (Var S : AnsiString; Index,Size: Longint);
  268. Function StringOfChar(c : char;l : longint) : AnsiString;
  269. function upcase(const s : ansistring) : ansistring;
  270. function lowercase(const s : ansistring) : ansistring;
  271. {****************************************************************************
  272. WideString Handling
  273. ****************************************************************************}
  274. {$ifdef haswidechar}
  275. {$ifndef INTERNSETLENGTH}
  276. Procedure SetLength (Var S : WideString; l : Longint);
  277. {$endif INTERNSETLENGTH}
  278. Procedure UniqueString (Var S : WideString);
  279. Function Length (Const S : WideString) : Longint;
  280. Function Copy (Const S : WideString; Index,Size : Longint) : WideString;
  281. Function Pos (Const Substr : WideString; Const Source : WideString) : Longint;
  282. Procedure Insert (Const Source : WideString; Var S : WideString; Index : Longint);
  283. Procedure Delete (Var S : WideString; Index,Size: Longint);
  284. {$endif haswidechar}
  285. {****************************************************************************
  286. Untyped File Management
  287. ****************************************************************************}
  288. Procedure Assign(Var f:File;const Name:string);
  289. Procedure Assign(Var f:File;p:pchar);
  290. Procedure Assign(Var f:File;c:char);
  291. Procedure Rewrite(Var f:File;l:Longint);
  292. Procedure Rewrite(Var f:File);
  293. Procedure Reset(Var f:File;l:Longint);
  294. Procedure Reset(Var f:File);
  295. Procedure Close(Var f:File);
  296. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint;Var Result:Longint);
  297. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Word);
  298. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Integer);
  299. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint);
  300. Procedure BlockRead(Var f:File;Var Buf;count:Longint;Var Result:Longint);
  301. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Word);
  302. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Integer);
  303. Procedure BlockRead(Var f:File;Var Buf;count:Longint);
  304. Function FilePos(Var f:File):Longint;
  305. Function FileSize(Var f:File):Longint;
  306. Procedure Seek(Var f:File;Pos:Longint);
  307. Function EOF(Var f:File):Boolean;
  308. Procedure Erase(Var f:File);
  309. Procedure Rename(Var f:File;const s:string);
  310. Procedure Rename(Var f:File;p:pchar);
  311. Procedure Rename(Var f:File;c:char);
  312. Procedure Truncate (Var F:File);
  313. {****************************************************************************
  314. Typed File Management
  315. ****************************************************************************}
  316. Procedure Assign(Var f:TypedFile;const Name:string);
  317. Procedure Assign(Var f:TypedFile;p:pchar);
  318. Procedure Assign(Var f:TypedFile;c:char);
  319. Procedure Rewrite(Var f:TypedFile);
  320. Procedure Reset(Var f:TypedFile);
  321. {****************************************************************************
  322. Text File Management
  323. ****************************************************************************}
  324. Procedure Assign(Var t:Text;const s:string);
  325. Procedure Assign(Var t:Text;p:pchar);
  326. Procedure Assign(Var t:Text;c:char);
  327. Procedure Close(Var t:Text);
  328. Procedure Rewrite(Var t:Text);
  329. Procedure Reset(Var t:Text);
  330. Procedure Append(Var t:Text);
  331. Procedure Flush(Var t:Text);
  332. Procedure Erase(Var t:Text);
  333. Procedure Rename(Var t:Text;const s:string);
  334. Procedure Rename(Var t:Text;p:pchar);
  335. Procedure Rename(Var t:Text;c:char);
  336. Function EOF(Var t:Text):Boolean;
  337. Function EOF:Boolean;
  338. Function EOLn(Var t:Text):Boolean;
  339. Function EOLn:Boolean;
  340. Function SeekEOLn (Var t:Text):Boolean;
  341. Function SeekEOF (Var t:Text):Boolean;
  342. Function SeekEOLn:Boolean;
  343. Function SeekEOF:Boolean;
  344. Procedure SetTextBuf(Var f:Text; Var Buf);
  345. Procedure SetTextBuf(Var f:Text; Var Buf; Size:Longint);
  346. {****************************************************************************
  347. Directory Management
  348. ****************************************************************************}
  349. Procedure chdir(const s:string);
  350. Procedure mkdir(const s:string);
  351. Procedure rmdir(const s:string);
  352. Procedure getdir(drivenr:byte;Var dir:shortstring);
  353. Procedure getdir(drivenr:byte;Var dir:ansistring);
  354. {*****************************************************************************
  355. Miscelleaous
  356. *****************************************************************************}
  357. { os independent calls to allow backtraces }
  358. function get_frame:longint;
  359. function get_caller_addr(framebp:longint):longint;
  360. function get_caller_frame(framebp:longint):longint;
  361. Function IOResult:Word;
  362. Function Sptr:Longint;
  363. {*****************************************************************************
  364. Init / Exit / ExitProc
  365. *****************************************************************************}
  366. Function Paramcount:Longint;
  367. Function ParamStr(l:Longint):string;
  368. Procedure Dump_Stack(var f : text;bp:Longint);
  369. Procedure RunError(w:Word);
  370. Procedure RunError;
  371. Procedure halt(errnum:byte);
  372. Procedure AddExitProc(Proc:TProcedure);
  373. Procedure halt;
  374. {*****************************************************************************
  375. Abstract/Assert/Error Handling
  376. *****************************************************************************}
  377. procedure AbstractError;
  378. Function SysBackTraceStr(Addr: Longint): ShortString;
  379. Procedure SysAssert(Const Msg,FName:ShortString;LineNo,ErrorAddr:Longint);
  380. { Error handlers }
  381. Type
  382. TBackTraceStrFunc = Function (Addr: Longint): ShortString;
  383. TErrorProc = Procedure (ErrNo : Longint; Address,Frame : Pointer);
  384. TAbstractErrorProc = Procedure;
  385. TAssertErrorProc = Procedure(const msg,fname:ShortString;lineno,erroraddr:longint);
  386. const
  387. BackTraceStrFunc : TBackTraceStrFunc = @SysBackTraceStr;
  388. ErrorProc : TErrorProc = nil;
  389. AbstractErrorProc : TAbstractErrorProc = nil;
  390. AssertErrorProc : TAssertErrorProc = @SysAssert;
  391. {*****************************************************************************
  392. SetJmp/LongJmp
  393. *****************************************************************************}
  394. {$i setjumph.inc}
  395. {*****************************************************************************
  396. Object Pascal support
  397. *****************************************************************************}
  398. {$i objpash.inc}
  399. {
  400. $Log$
  401. Revision 1.19 2001-04-13 18:06:07 peter
  402. * upcase, lowercase for ansistring
  403. Revision 1.18 2001/03/22 23:26:05 florian
  404. * some new types added like PBoolean
  405. Revision 1.17 2001/03/21 23:29:40 florian
  406. + sLineBreak and misc. stuff for Kylix compatiblity
  407. Revision 1.16 2001/01/24 21:47:18 florian
  408. + more MT stuff added
  409. Revision 1.15 2000/12/16 15:56:19 jonas
  410. - removed all ifdef cardinalmulfix code
  411. Revision 1.14 2000/12/08 14:04:43 jonas
  412. + added pos(char,ansistring), because there is also a pos(char,shortstring)
  413. and without the ansistring version, the shortstring version is always
  414. called when calling pos(char,pchar), even when using $h+ (because the
  415. first parameter matches exactly) (merged)
  416. Revision 1.13 2000/12/07 17:19:47 jonas
  417. * new constant handling: from now on, hex constants >$7fffffff are
  418. parsed as unsigned constants (otherwise, $80000000 got sign extended
  419. and became $ffffffff80000000), all constants in the longint range
  420. become longints, all constants >$7fffffff and <=cardinal($ffffffff)
  421. are cardinals and the rest are int64's.
  422. * added lots of longint typecast to prevent range check errors in the
  423. compiler and rtl
  424. * type casts of symbolic ordinal constants are now preserved
  425. * fixed bug where the original resulttype wasn't restored correctly
  426. after doing a 64bit rangecheck
  427. Revision 1.12 2000/11/13 13:40:04 marco
  428. * Renamefest
  429. Revision 1.11 2000/11/11 16:12:01 peter
  430. * ptr returns farpointer
  431. Revision 1.10 2000/11/06 21:35:59 peter
  432. * removed some warnings
  433. Revision 1.9 2000/11/06 20:34:24 peter
  434. * changed ver1_0 defines to temporary defs
  435. Revision 1.8 2000/10/23 16:15:40 jonas
  436. * renamed strlenint to longint since 1.0 doesn't know that type
  437. Revision 1.7 2000/10/23 14:00:59 florian
  438. * setlength export declaration for 1.0.2 fixed
  439. Revision 1.6 2000/10/21 18:20:17 florian
  440. * a lot of small changes:
  441. - setlength is internal
  442. - win32 graph unit extended
  443. ....
  444. Revision 1.5 2000/08/13 17:55:15 michael
  445. + Added some delphi compatibility types
  446. Revision 1.4 2000/08/08 22:11:45 sg
  447. * Added declarations for WideString utility functions
  448. Revision 1.3 2000/07/14 10:33:10 michael
  449. + Conditionals fixed
  450. Revision 1.2 2000/07/13 11:33:45 michael
  451. + removed logs
  452. }