systemh.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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. Needed switches
  19. ****************************************************************************}
  20. {$I-,Q-,H-,R-,V-}
  21. {$mode objfpc}
  22. { needed for insert,delete,readln }
  23. {$P+}
  24. { Stack check gives a note under linux }
  25. {$ifndef linux}
  26. {$S-}
  27. {$endif}
  28. {****************************************************************************
  29. Global Types and Constants
  30. ****************************************************************************}
  31. Type
  32. Longint = $80000000..$7fffffff; { $8000000 creates a longint overfow !! }
  33. Integer = -32768..32767;
  34. shortint = -128..127;
  35. byte = 0..255;
  36. Word = 0..65535;
  37. { at least declare Turbo Pascal real types }
  38. {$ifdef i386}
  39. StrLenInt = LongInt;
  40. {$define DEFAULT_EXTENDED}
  41. {$define SUPPORT_SINGLE}
  42. {$define SUPPORT_DOUBLE}
  43. {$define SUPPORT_EXTENDED}
  44. {$define SUPPORT_COMP}
  45. { define SUPPORT_FIXED}
  46. ValSInt = Longint;
  47. ValUInt = Cardinal;
  48. ValReal = Extended;
  49. {$endif}
  50. {$ifdef m68k}
  51. StrLenInt = Longint;
  52. ValSInt = Longint;
  53. ValUInt = Cardinal;
  54. ValReal = Real;
  55. {$define SUPPORT_SINGLE}
  56. {$endif}
  57. { some type aliases }
  58. dword = cardinal;
  59. longword = cardinal;
  60. { Zero - terminated strings }
  61. PChar = ^Char;
  62. PPChar = ^PChar;
  63. {$ifdef HASWIDECHAR}
  64. PWideChar = ^WideChar;
  65. {$endif HASWIDECHAR}
  66. { procedure type }
  67. TProcedure = Procedure;
  68. const
  69. { Maximum value of the biggest signed and unsigned integer type available}
  70. MaxSIntValue = High(ValSInt);
  71. MaxUIntValue = High(ValUInt);
  72. { max. values for longint and int}
  73. maxLongint = $7fffffff;
  74. maxint = 32767;
  75. { Compatibility With TP }
  76. {$ifdef i386}
  77. Test8086 : byte = 2; { Always i386 or newer }
  78. Test8087 : byte = 3; { Always 387 or newer. Emulated if needed. }
  79. FPUInt64 : boolean = true; { set this to false if you don't want that }
  80. { the fpu does int64*int64 and }
  81. { int64 div int64, if the * is overflow }
  82. { checked, it is done in software }
  83. {$endif i386}
  84. {$ifdef m68k}
  85. Test68000 : byte = 0; { Must be determined at startup for both }
  86. Test68881 : byte = 0;
  87. {$endif}
  88. { max level in dumping on error }
  89. Max_Frame_Dump : Word = 8;
  90. { Exit Procedure handling consts and types }
  91. ExitProc : pointer = nil;
  92. Erroraddr: pointer = nil;
  93. Errorcode: Word = 0;
  94. { file input modes }
  95. fmClosed = $D7B0;
  96. fmInput = $D7B1;
  97. fmOutput = $D7B2;
  98. fmInOut = $D7B3;
  99. fmAppend = $D7B4;
  100. Filemode : byte = 2;
  101. CmdLine : PChar = nil;
  102. var
  103. { Standard In- and Output }
  104. Output,
  105. Input,
  106. StdOut,
  107. StdErr : Text;
  108. ExitCode,
  109. InOutRes : Word;
  110. StackBottom,
  111. LowestStack,
  112. RandSeed : Cardinal;
  113. {****************************************************************************
  114. Processor specific routines
  115. ****************************************************************************}
  116. Procedure Move(Var source,dest;count:Longint);
  117. Procedure FillChar(Var x;count:Longint;Value:Boolean);
  118. Procedure FillChar(Var x;count:Longint;Value:Char);
  119. Procedure FillChar(Var x;count:Longint;Value:Byte);
  120. {$ifndef RTLLITE}
  121. Procedure FillWord(Var x;count:Longint;Value:Word);
  122. {$endif RTLLITE}
  123. {****************************************************************************
  124. Math Routines
  125. ****************************************************************************}
  126. {$ifndef RTLLITE}
  127. Function lo(w:Word):byte;
  128. Function lo(l:Longint):Word;
  129. Function lo(l:DWord):Word;
  130. Function lo(i:Integer):byte;
  131. Function lo(B: Byte):Byte;
  132. Function hi(w:Word):byte;
  133. Function hi(i:Integer):byte;
  134. Function hi(l:Longint):Word;
  135. Function hi(b : Byte) : Byte;
  136. Function hi(l: DWord): Word;
  137. Function Swap (X:Word):Word;
  138. Function Swap (X:Integer):Integer;
  139. Function Swap (X:Cardinal):Cardinal;
  140. Function Swap (X:LongInt):LongInt;
  141. {$ifdef INT64}
  142. Function lo(q : QWord) : DWord;
  143. Function lo(i : Int64) : DWord;
  144. Function hi(q : QWord) : DWord;
  145. Function hi(i : Int64) : DWord;
  146. Function Swap (X:QWord):QWord;
  147. Function Swap (X:Int64):Int64;
  148. {$endif}
  149. {$endif RTLLITE}
  150. Function Random(l:cardinal):cardinal;
  151. {$ifndef cardinalmulfixed}
  152. Function Random(l:longint):longint;
  153. {$endif cardinalmulfixed}
  154. Function Random: extended;
  155. Procedure Randomize;
  156. Function abs(l:Longint):Longint;
  157. Function sqr(l:Longint):Longint;
  158. Function odd(l:Longint):Boolean;
  159. { float math routines }
  160. {$I mathh.inc}
  161. {****************************************************************************
  162. Addr/Pointer Handling
  163. ****************************************************************************}
  164. {$ifndef RTLLITE}
  165. Function ptr(sel,off:Longint):pointer;
  166. Function Cseg:Word;
  167. Function Dseg:Word;
  168. Function Sseg:Word;
  169. {$endif RTLLITE}
  170. {****************************************************************************
  171. PChar and String Handling
  172. ****************************************************************************}
  173. function strpas(p:pchar):shortstring;
  174. function strlen(p:pchar):longint;
  175. { Shortstring functions }
  176. Function Copy(const s:shortstring;index:StrLenInt;count:StrLenInt):shortstring;
  177. Procedure Delete(Var s:shortstring;index:StrLenInt;count:StrLenInt);
  178. Procedure Insert(const source:shortstring;Var s:shortstring;index:StrLenInt);
  179. Procedure Insert(source:Char;Var s:shortstring;index:StrLenInt);
  180. Function Pos(const substr:shortstring;const s:shortstring):StrLenInt;
  181. Function Pos(C:Char;const s:shortstring):StrLenInt;
  182. Procedure SetLength(var s:shortstring;len:StrLenInt);
  183. Procedure SetString (Var S : Shortstring; Buf : PChar; Len : Longint);
  184. Procedure SetString (Var S : AnsiString; Buf : PChar; Len : Longint);
  185. Function Length(s:string):byte;
  186. Function upCase(const s:shortstring):shortstring;
  187. {$ifndef RTLLITE}
  188. Function lowerCase(const s:shortstring):shortstring;
  189. {$endif}
  190. Function Space(b:byte):shortstring;
  191. {$ifndef RTLLITE}
  192. Function hexStr(Val:Longint;cnt:byte):shortstring;
  193. Function binStr(Val:Longint;cnt:byte):shortstring;
  194. {$endif RTLLITE}
  195. { Char functions }
  196. Function Chr(b:byte):Char;
  197. Function upCase(c:Char):Char;
  198. {$ifndef RTLLITE}
  199. Function lowerCase(c:Char):Char;
  200. {$endif RTLLITE}
  201. function copy(c:char;index : StrLenInt;count : StrLenInt): shortstring;
  202. function pos(const substr : shortstring;c:char): StrLenInt;
  203. function length(c:char):byte;
  204. {****************************************************************************
  205. AnsiString Handling
  206. ****************************************************************************}
  207. Procedure SetLength (Var S : AnsiString; l : Longint);
  208. Procedure UniqueAnsiString (Var S : AnsiString);
  209. Function Length (Const S : AnsiString) : Longint;
  210. Function Copy (Const S : AnsiString; Index,Size : Longint) : AnsiString;
  211. Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : Longint;
  212. Procedure Insert (Const Source : AnsiString; Var S : AnsiString; Index : Longint);
  213. Procedure Delete (Var S : AnsiString; Index,Size: Longint);
  214. Function StringOfChar(c : char;l : longint) : AnsiString;
  215. {****************************************************************************
  216. Untyped File Management
  217. ****************************************************************************}
  218. Procedure Assign(Var f:File;const Name:string);
  219. Procedure Assign(Var f:File;p:pchar);
  220. Procedure Assign(Var f:File;c:char);
  221. Procedure Rewrite(Var f:File;l:Longint);
  222. Procedure Rewrite(Var f:File);
  223. Procedure Reset(Var f:File;l:Longint);
  224. Procedure Reset(Var f:File);
  225. Procedure Close(Var f:File);
  226. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint;Var Result:Longint);
  227. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Word);
  228. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Integer);
  229. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint);
  230. Procedure BlockRead(Var f:File;Var Buf;count:Longint;Var Result:Longint);
  231. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Word);
  232. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Integer);
  233. Procedure BlockRead(Var f:File;Var Buf;count:Longint);
  234. Function FilePos(Var f:File):Longint;
  235. Function FileSize(Var f:File):Longint;
  236. Procedure Seek(Var f:File;Pos:Longint);
  237. Function EOF(Var f:File):Boolean;
  238. Procedure Erase(Var f:File);
  239. Procedure Rename(Var f:File;const s:string);
  240. Procedure Rename(Var f:File;p:pchar);
  241. Procedure Rename(Var f:File;c:char);
  242. Procedure Truncate (Var F:File);
  243. {****************************************************************************
  244. Typed File Management
  245. ****************************************************************************}
  246. Procedure Assign(Var f:TypedFile;const Name:string);
  247. Procedure Assign(Var f:TypedFile;p:pchar);
  248. Procedure Assign(Var f:TypedFile;c:char);
  249. Procedure Rewrite(Var f:TypedFile);
  250. Procedure Reset(Var f:TypedFile);
  251. {****************************************************************************
  252. Text File Management
  253. ****************************************************************************}
  254. Procedure Assign(Var t:Text;const s:string);
  255. Procedure Assign(Var t:Text;p:pchar);
  256. Procedure Assign(Var t:Text;c:char);
  257. Procedure Close(Var t:Text);
  258. Procedure Rewrite(Var t:Text);
  259. Procedure Reset(Var t:Text);
  260. Procedure Append(Var t:Text);
  261. Procedure Flush(Var t:Text);
  262. Procedure Erase(Var t:Text);
  263. Procedure Rename(Var t:Text;const s:string);
  264. Procedure Rename(Var t:Text;p:pchar);
  265. Procedure Rename(Var t:Text;c:char);
  266. Function EOF(Var t:Text):Boolean;
  267. Function EOF:Boolean;
  268. Function EOLn(Var t:Text):Boolean;
  269. Function EOLn:Boolean;
  270. Function SeekEOLn (Var t:Text):Boolean;
  271. Function SeekEOF (Var t:Text):Boolean;
  272. Function SeekEOLn:Boolean;
  273. Function SeekEOF:Boolean;
  274. Procedure SetTextBuf(Var f:Text; Var Buf);
  275. Procedure SetTextBuf(Var f:Text; Var Buf; Size:Longint);
  276. {****************************************************************************
  277. Directory Management
  278. ****************************************************************************}
  279. Procedure chdir(const s:string);
  280. Procedure mkdir(const s:string);
  281. Procedure rmdir(const s:string);
  282. Procedure getdir(drivenr:byte;Var dir:shortstring);
  283. Procedure getdir(drivenr:byte;Var dir:ansistring);
  284. {*****************************************************************************
  285. Miscelleaous
  286. *****************************************************************************}
  287. { os independent calls to allow backtraces }
  288. function get_frame:longint;
  289. function get_caller_addr(framebp:longint):longint;
  290. function get_caller_frame(framebp:longint):longint;
  291. Function IOResult:Word;
  292. Function Sptr:Longint;
  293. {*****************************************************************************
  294. Init / Exit / ExitProc
  295. *****************************************************************************}
  296. Function Paramcount:Longint;
  297. Function ParamStr(l:Longint):string;
  298. {$ifndef RTLLITE}
  299. Procedure Dump_Stack(var f : text;bp:Longint);
  300. {$endif RTLLITE}
  301. Procedure RunError(w:Word);
  302. Procedure RunError;
  303. Procedure halt(errnum:byte);
  304. {$ifndef RTLLITE}
  305. Procedure AddExitProc(Proc:TProcedure);
  306. {$endif RTLLITE}
  307. Procedure halt;
  308. {*****************************************************************************
  309. Abstract/Assert/Error Handling
  310. *****************************************************************************}
  311. procedure AbstractError;
  312. Procedure SysAssert(Const Msg,FName:ShortString;LineNo,ErrorAddr:Longint);
  313. { Error handlers }
  314. Type
  315. TErrorProc = Procedure (ErrNo : Longint; Address : Pointer);
  316. TAbstractErrorProc = Procedure;
  317. TAssertErrorProc = Procedure(const msg,fname:ShortString;lineno,erroraddr:longint);
  318. const
  319. ErrorProc : TErrorProc = nil;
  320. AbstractErrorProc : TAbstractErrorProc = nil;
  321. AssertErrorProc : TAssertErrorProc = @SysAssert;
  322. {*****************************************************************************
  323. SetJmp/LongJmp
  324. *****************************************************************************}
  325. {$i setjumph.inc}
  326. {*****************************************************************************
  327. Object Pascal support
  328. *****************************************************************************}
  329. {$i objpash.inc}
  330. {
  331. $Log$
  332. Revision 1.71 1999-12-18 14:55:05 florian
  333. * very basic widestring support
  334. Revision 1.70 1999/12/12 13:29:34 jonas
  335. * remove "random(longint): longint" if cardinalmulfixed is defined
  336. Revision 1.69 1999/12/01 12:37:13 jonas
  337. + function random(longint): longint
  338. Revision 1.68 1999/11/25 13:34:57 michael
  339. + Added Ansistring setstring call
  340. Revision 1.67 1999/11/20 12:48:09 jonas
  341. * reinstated old random generator, but modified it so the integer
  342. one now has a much longer period
  343. Revision 1.66 1999/11/09 20:14:12 daniel
  344. * Committed new random generator.
  345. Revision 1.65 1999/11/06 14:35:39 peter
  346. * truncated log
  347. Revision 1.64 1999/10/27 14:19:10 florian
  348. + StringOfChar
  349. Revision 1.63 1999/10/26 12:31:00 peter
  350. * *errorproc are not procvars instead of pointers which allows better
  351. error checking for the parameters (shortstring<->ansistring)
  352. Revision 1.62 1999/08/19 11:16:13 peter
  353. * settextbuf size is now longint
  354. Revision 1.61 1999/07/05 20:04:28 peter
  355. * removed temp defines
  356. Revision 1.60 1999/07/03 01:24:21 peter
  357. * $ifdef int64
  358. Revision 1.59 1999/07/02 18:06:43 florian
  359. + qword/int64: lo/hi/swap
  360. Revision 1.58 1999/06/30 22:17:22 florian
  361. + fpuint64 to system unit interface added: if it is true, the rtl
  362. uses the fpu to do int64 operations, if possible
  363. Revision 1.57 1999/05/17 21:52:40 florian
  364. * most of the Object Pascal stuff moved to the system unit
  365. Revision 1.56 1999/05/06 09:05:14 peter
  366. * generic write_float str_float
  367. Revision 1.55 1999/04/17 13:10:26 peter
  368. * addr() internal
  369. Revision 1.54 1999/04/08 15:57:56 peter
  370. + subrange checking for readln()
  371. Revision 1.53 1999/03/16 17:49:37 jonas
  372. * changes for internal Val code (do a "make cycle OPT=-dvalintern" to test)
  373. * in text.inc: changed RTE 106 when read integer values are out of bounds to RTE 201
  374. * in systemh.inc: disabled "support_fixed" for the i386 because it gave internal errors,
  375. Revision 1.52 1999/03/10 22:15:30 florian
  376. + system.cmdline variable for go32v2 and win32 added
  377. Revision 1.51 1999/03/03 15:23:58 michael
  378. + Added setstring for Delphi compatibility
  379. Revision 1.50 1999/02/01 00:05:16 florian
  380. + functions lo/hi for DWord type implemented
  381. Revision 1.49 1999/01/29 09:23:10 pierre
  382. * Fillchar(..,..,boolean) added
  383. Revision 1.48 1999/01/22 12:39:24 pierre
  384. + added text arg for dump_stack
  385. Revision 1.47 1999/01/11 19:26:53 jonas
  386. * made inster(string,string,index) a bit faster
  387. + overloaded insert(char,string,index)
  388. Revision 1.46 1998/12/28 15:50:48 peter
  389. + stdout, which is needed when you write something in the system unit
  390. to the screen. Like the runtime error
  391. Revision 1.45 1998/12/15 22:43:04 peter
  392. * removed temp symbols
  393. }