systemh.inc 15 KB

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