systemh.inc 18 KB

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