systemh.inc 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  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. { Using inlining for small system functions/wrappers }
  18. {$ifdef HASINLINE}
  19. {$inline on}
  20. {$define SYSTEMINLINE}
  21. {$endif}
  22. { Use threadvars when the compiler supports it }
  23. {$ifdef HASTHREADVAR}
  24. {$define SUPPORT_THREADVAR}
  25. {$endif HASTHREADVAR}
  26. { don't use FPU registervariables on the i386 }
  27. {$ifdef CPUI386}
  28. {$maxfpuregisters 0}
  29. {$endif CPUI386}
  30. { the assembler helpers need this }
  31. {$ifdef POWERPC}
  32. {$goto+}
  33. {$endif POWERPC}
  34. { needed for insert,delete,readln }
  35. {$P+}
  36. { stack checking always disabled
  37. for system unit. This is because
  38. the startup code might not
  39. have been called yet when we
  40. get a stack error, this will
  41. cause big crashes
  42. }
  43. {$S-}
  44. {****************************************************************************
  45. Global Types and Constants
  46. ****************************************************************************}
  47. Type
  48. {$Ifdef HAS_INTERNAL_INTTYPES}
  49. { The compiler has all integer types defined internally. Here
  50. we define only aliases }
  51. DWord = LongWord;
  52. Cardinal = LongWord;
  53. Integer = SmallInt;
  54. {$else HAS_INTERNAL_INTTYPES}
  55. ShortInt = -128..127;
  56. SmallInt = -32768..32767;
  57. { can't use -2147483648 because of a bug in 1.0.2's val() procedure (JM) }
  58. Longint = +(-2147483647-1)..$7fffffff;
  59. Byte = 0..255;
  60. Word = 0..65535;
  61. {$ifndef ver1_0}
  62. DWord = LongWord;
  63. Cardinal = LongWord;
  64. {$else}
  65. Longword = cardinal;
  66. Dword = cardinal;
  67. {$endif}
  68. Integer = SmallInt;
  69. {$endif HAS_INTERNAL_INTTYPES}
  70. {$ifdef CPUI386}
  71. { for bootstrapping with 1.0.x }
  72. {$define CPU32}
  73. {$define DEFAULT_EXTENDED}
  74. {$define SUPPORT_SINGLE}
  75. {$define SUPPORT_DOUBLE}
  76. {$define SUPPORT_EXTENDED}
  77. {$define SUPPORT_COMP}
  78. ValReal = Extended;
  79. {$endif CPUI386}
  80. {$ifdef CPUX86_64}
  81. {$define DEFAULT_EXTENDED}
  82. {$define SUPPORT_SINGLE}
  83. {$define SUPPORT_DOUBLE}
  84. {$define SUPPORT_EXTENDED}
  85. {$define SUPPORT_COMP}
  86. ValReal = Extended;
  87. {$endif CPUX86_64}
  88. {$ifdef CPUM68K}
  89. ValReal = Real;
  90. {$define SUPPORT_SINGLE}
  91. {$IFDEF Unix}
  92. { Linux FPU emulator will be used }
  93. {$define SUPPORT_DOUBLE}
  94. {$ENDIF}
  95. {$IFOPT E-}
  96. { If not compiling with emulation }
  97. { then support double type. }
  98. {$define SUPPORT_DOUBLE}
  99. {$ENDIF}
  100. { Comp type does not exist on fpu }
  101. Comp = int64;
  102. PComp = ^Comp;
  103. {$ifdef FPC_HASNOFARPOINTER}
  104. FarPointer = Pointer;
  105. {$endif FPC_HASNOFARPOINTER}
  106. {$endif CPUM68K}
  107. {$ifdef CPUPOWERPC}
  108. {$define DEFAULT_DOUBLE}
  109. {$define SUPPORT_SINGLE}
  110. {$define SUPPORT_DOUBLE}
  111. {$define FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE}
  112. ValReal = Double;
  113. { map comp to int64, but this doesn't mean we compile the comp support in! }
  114. Comp = Int64;
  115. PComp = ^Comp;
  116. {$ifdef FPC_HASNOFARPOINTER}
  117. FarPointer = Pointer;
  118. {$endif FPC_HASNOFARPOINTER}
  119. {$endif CPUPOWERPC}
  120. {$ifdef CPUSPARC}
  121. {$define DEFAULT_DOUBLE}
  122. {$define SUPPORT_SINGLE}
  123. {$define SUPPORT_DOUBLE}
  124. {$define FPC_INCLUDE_SOFTWARE_SHIFT_INT64}
  125. ValReal = Double;
  126. { map comp to int64, but this doesn't mean we compile the comp support in! }
  127. Comp = Int64;
  128. PComp = ^Comp;
  129. {$ifdef FPC_HASNOFARPOINTER}
  130. FarPointer = Pointer;
  131. {$endif FPC_HASNOFARPOINTER}
  132. {$endif CPUSPARC}
  133. {$ifdef CPUARM}
  134. {$define DEFAULT_DOUBLE}
  135. {$define SUPPORT_SINGLE}
  136. {$define SUPPORT_DOUBLE}
  137. {$define FPC_INCLUDE_SOFTWARE_MOD_DIV}
  138. {$define FPC_INCLUDE_SOFTWARE_SHIFT_INT64}
  139. {$define FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE}
  140. ValReal = Real;
  141. { map comp to int64, but this doesn't mean we compile the comp support in! }
  142. Comp = Int64;
  143. PComp = ^Comp;
  144. {$ifdef FPC_HASNOFARPOINTER}
  145. FarPointer = Pointer;
  146. {$endif FPC_HASNOFARPOINTER}
  147. {$endif CPUARM}
  148. {$ifdef CPU64}
  149. SizeInt = Int64;
  150. SizeUInt = QWord;
  151. PtrInt = Int64;
  152. PtrUInt = QWord;
  153. ValSInt = int64;
  154. ValUInt = qword;
  155. {$endif CPU64}
  156. {$ifdef CPU32}
  157. SizeInt = Longint;
  158. SizeUInt = DWord;
  159. PtrInt = Longint;
  160. PtrUInt = DWord;
  161. ValSInt = Longint;
  162. ValUInt = Cardinal;
  163. {$endif CPU32}
  164. { Zero - terminated strings }
  165. PChar = ^Char;
  166. PPChar = ^PChar;
  167. { AnsiChar is equivalent of Char, so we need
  168. to use type renamings }
  169. TAnsiChar = Char;
  170. AnsiChar = Char;
  171. PAnsiChar = PChar;
  172. PPAnsiChar = PPChar;
  173. UCS4Char = type LongWord;
  174. PUCS4Char = ^UCS4Char;
  175. TUCS4CharArray = array[0..$effffff] of UCS4Char;
  176. PUCS4CharArray = ^TUCS4CharArray;
  177. {$ifndef VER1_0}
  178. UCS4String = array of UCS4Char;
  179. {$endif VER1_0}
  180. UTF8String = type ansistring;
  181. PUTF8String = ^UTF8String;
  182. {$ifndef HASCURRENCY}
  183. Currency = Int64;
  184. {$endif HASCURRENCY}
  185. HRESULT = type Longint;
  186. TDateTime = type Double;
  187. Error = type Longint;
  188. PSingle = ^Single;
  189. PDouble = ^Double;
  190. PCurrency = ^Currency;
  191. {$ifdef SUPPORT_COMP}
  192. PComp = ^Comp;
  193. {$endif SUPPORT_COMP}
  194. PExtended = ^Extended;
  195. PSmallInt = ^Smallint;
  196. PShortInt = ^Shortint;
  197. PInteger = ^Integer;
  198. PByte = ^Byte;
  199. PWord = ^word;
  200. PDWord = ^DWord;
  201. PLongWord = ^LongWord;
  202. PLongint = ^Longint;
  203. PCardinal = ^Cardinal;
  204. PQWord = ^QWord;
  205. PInt64 = ^Int64;
  206. PPtrInt = ^PtrInt;
  207. PSizeInt = ^SizeInt;
  208. PPointer = ^Pointer;
  209. PPPointer = ^PPointer;
  210. PBoolean = ^Boolean;
  211. PWordBool = ^WordBool;
  212. PLongBool = ^LongBool;
  213. PShortString = ^ShortString;
  214. PAnsiString = ^AnsiString;
  215. PDate = ^TDateTime;
  216. PError = ^Error;
  217. {$ifdef HASVARIANT}
  218. PVariant = ^Variant;
  219. POleVariant = ^OleVariant;
  220. {$endif HASVARIANT}
  221. {$ifdef HASWIDECHAR}
  222. PWideChar = ^WideChar;
  223. PPWideChar = ^PWideChar;
  224. { 1.0.x also has HASWIDECHAR defined, but doesn't support it
  225. fully, setting WChar to Word as fallback (PFV) }
  226. {$ifndef VER1_0}
  227. WChar = Widechar;
  228. {$else}
  229. WChar = Word;
  230. {$endif}
  231. UCS2Char = WideChar;
  232. PUCS2Char = PWideChar;
  233. {$else}
  234. WChar = Word;
  235. {$endif HASWIDECHAR}
  236. {$ifdef HASWIDESTRING}
  237. PWideString = ^WideString;
  238. {$endif HASWIDESTRING}
  239. { Needed for fpc_get_output }
  240. PText = ^Text;
  241. TTextLineBreakStyle = (tlbsLF,tlbsCRLF,tlbsCR);
  242. { procedure type }
  243. TProcedure = Procedure;
  244. { platform dependent types }
  245. {$i sysosh.inc}
  246. const
  247. { Maximum value of the biggest signed and unsigned integer type available}
  248. MaxSIntValue = High(ValSInt);
  249. MaxUIntValue = High(ValUInt);
  250. { max. values for longint and int}
  251. maxLongint = $7fffffff;
  252. maxSmallint = 32767;
  253. maxint = maxsmallint;
  254. type
  255. IntegerArray = array[0..$effffff] of Integer;
  256. PIntegerArray = ^IntegerArray;
  257. PointerArray = array [0..512*1024*1024 - 2] of Pointer;
  258. PPointerArray = ^PointerArray;
  259. {$ifndef VER1_0}
  260. TBoundArray = array of Integer;
  261. {$endif VER1_0}
  262. TPCharArray = packed array[0..(MaxLongint div SizeOf(PChar))-1] of PChar;
  263. PPCharArray = ^TPCharArray;
  264. const
  265. {$ifdef cpui386}
  266. Test8086 : byte = 2; { Always i386 or newer }
  267. Test8087 : byte = 3; { Always 387 or newer. Emulated if needed. }
  268. {$endif cpui386}
  269. {$ifdef cpum68k}
  270. Test68000 : byte = 0; { Must be determined at startup for both }
  271. Test68881 : byte = 0;
  272. {$endif cpum68k}
  273. { max level in dumping on error }
  274. Max_Frame_Dump : Word = 8;
  275. { Exit Procedure handling consts and types }
  276. ExitProc : pointer = nil;
  277. Erroraddr: pointer = nil;
  278. Errorcode: Word = 0;
  279. { file input modes }
  280. fmClosed = $D7B0;
  281. fmInput = $D7B1;
  282. fmOutput = $D7B2;
  283. fmInOut = $D7B3;
  284. fmAppend = $D7B4;
  285. Filemode : byte = 2;
  286. CmdLine : PChar = nil;
  287. (* Value should be changed during system initialization as appropriate. *)
  288. { assume that this program will not spawn other threads, when the
  289. first thread is started the following constants need to be filled }
  290. IsMultiThread : boolean = FALSE;
  291. { set to true, if a threading helper is used before a thread
  292. manager has been installed }
  293. ThreadingAlreadyUsed : boolean = FALSE;
  294. { Indicates if there was an error }
  295. StackError : boolean = FALSE;
  296. InitProc : Pointer = nil;
  297. var
  298. ExitCode : Word; public name 'operatingsystem_result';
  299. RandSeed : Cardinal;
  300. { Delphi compatibility }
  301. IsLibrary : boolean;
  302. IsConsole : boolean;
  303. { Threading support }
  304. fpc_threadvar_relocate_proc : pointer; public name 'FPC_THREADVAR_RELOCATE';
  305. {$ifdef SUPPORT_THREADVAR}
  306. ThreadVar
  307. {$else SUPPORT_THREADVAR}
  308. Var
  309. {$endif SUPPORT_THREADVAR}
  310. ThreadID : SizeUInt;
  311. { Standard In- and Output }
  312. ErrOutput,
  313. Output,
  314. Input,
  315. StdOut,
  316. StdErr : Text;
  317. InOutRes : Word;
  318. { Stack checking }
  319. StackBottom : Pointer;
  320. StackLength : Cardinal;
  321. { Numbers for routines that have compiler magic }
  322. {$I innr.inc}
  323. {****************************************************************************
  324. Processor specific routines
  325. ****************************************************************************}
  326. {$ifdef FPC_USE_LIBC}
  327. {$ifdef SYSTEMINLINE}
  328. {$define INLINEGENERICS}
  329. {$endif}
  330. {$endif}
  331. Procedure Move(const source;var dest;count:SizeInt);{$ifdef INLINEGENERICS}inline;{$endif}
  332. Procedure FillChar(Var x;count:SizeInt;Value:Boolean);{$ifdef SYSTEMINLINE}inline;{$endif}
  333. Procedure FillChar(Var x;count:SizeInt;Value:Char);{$ifdef SYSTEMINLINE}inline;{$endif}
  334. Procedure FillChar(Var x;count:SizeInt;Value:Byte);{$ifdef INLINEGENERICS}inline;{$endif}
  335. procedure FillByte(var x;count:SizeInt;value:byte);{$ifdef INLINEGENERICS}inline;{$endif}
  336. Procedure FillWord(Var x;count:SizeInt;Value:Word);
  337. procedure FillDWord(var x;count:SizeInt;value:DWord);
  338. function IndexChar(const buf;len:SizeInt;b:char):SizeInt;
  339. function IndexByte(const buf;len:SizeInt;b:byte):SizeInt;{$ifdef INLINEGENERICS}inline;{$endif}
  340. function Indexword(const buf;len:SizeInt;b:word):SizeInt;
  341. function IndexDWord(const buf;len:SizeInt;b:DWord):SizeInt;
  342. function CompareChar(const buf1,buf2;len:SizeInt):SizeInt;
  343. function CompareByte(const buf1,buf2;len:SizeInt):SizeInt;{$ifdef INLINEGENERICS}inline;{$endif}
  344. function CompareWord(const buf1,buf2;len:SizeInt):SizeInt;
  345. function CompareDWord(const buf1,buf2;len:SizeInt):SizeInt;
  346. procedure MoveChar0(const buf1;var buf2;len:SizeInt);
  347. function IndexChar0(const buf;len:SizeInt;b:char):SizeInt;
  348. function CompareChar0(const buf1,buf2;len:SizeInt):SizeInt;{$ifdef INLINEGENERICS}inline;{$endif}
  349. procedure prefetch(const mem);{$ifdef INTERNCONSTINTF}[internproc:fpc_in_prefetch_var];{$endif}
  350. {****************************************************************************
  351. Math Routines
  352. ****************************************************************************}
  353. Function lo(B: Byte):Byte;{$ifdef SYSTEMINLINE}inline;{$endif}
  354. Function hi(b : Byte) : Byte;{$ifdef SYSTEMINLINE}inline;{$endif}
  355. Function lo(i : Integer) : byte; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_lo_Word];{$endif}
  356. Function lo(w : Word) : byte; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_lo_Word];{$endif}
  357. Function lo(l : Longint) : Word; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_lo_long];{$endif}
  358. Function lo(l : DWord) : Word; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_lo_long];{$endif}
  359. Function lo(i : Int64) : DWord; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_lo_qword];{$endif}
  360. Function lo(q : QWord) : DWord; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_lo_qword];{$endif}
  361. Function hi(i : Integer) : byte; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_hi_Word];{$endif}
  362. Function hi(w : Word) : byte; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_hi_Word];{$endif}
  363. Function hi(l : Longint) : Word; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_hi_long];{$endif}
  364. Function hi(l : DWord) : Word; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_hi_long];{$endif}
  365. Function hi(i : Int64) : DWord; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_hi_qword];{$endif}
  366. Function hi(q : QWord) : DWord; {$ifdef INTERNCONSTINTF}[INTERNPROC: fpc_in_hi_qword];{$endif}
  367. Function swap (X : Word) : Word;{$ifdef SYSTEMINLINE}inline;{$endif}{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_swap_word];{$endif}
  368. Function Swap (X : Integer) : Integer;{$ifdef SYSTEMINLINE}inline;{$endif}{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_swap_word];{$endif}
  369. Function swap (X : Longint) : Longint;{$ifdef SYSTEMINLINE}inline;{$endif}{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_swap_long];{$endif}
  370. Function Swap (X : Cardinal) : Cardinal;{$ifdef SYSTEMINLINE}inline;{$endif}{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_swap_long];{$endif}
  371. Function Swap (X : QWord) : QWord;{$ifdef SYSTEMINLINE}inline;{$endif}{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_swap_qword];{$endif}
  372. Function swap (X : Int64) : Int64;{$ifdef SYSTEMINLINE}inline;{$endif}{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_swap_qword];{$endif}
  373. Function Align (Addr : PtrInt; Alignment : PtrInt) : PtrInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  374. Function Align (Addr : Pointer; Alignment : PtrInt) : Pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
  375. Function Random(l:longint):longint;
  376. Function Random(l:int64):int64;
  377. Function Random: extended;
  378. Procedure Randomize;
  379. Function abs(l:Longint):Longint;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_abs];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  380. Function abs(l:Int64):Int64;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_abs];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  381. Function sqr(l:Longint):Longint;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_sqr];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  382. Function sqr(l:Int64):Int64;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_sqr];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  383. Function sqr(l:QWord):QWord;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_sqr];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  384. Function odd(l:Longint):Boolean;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_odd];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  385. Function odd(l:Longword):Boolean;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_odd];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  386. Function odd(l:Int64):Boolean;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_odd];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  387. Function odd(l:QWord):Boolean;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_odd];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  388. { float math routines }
  389. {$I mathh.inc}
  390. {****************************************************************************
  391. Addr/Pointer Handling
  392. ****************************************************************************}
  393. Function ptr(sel,off:Longint):farpointer;{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_ptr];{$endif}{$ifdef SYSTEMINLINE}inline;{$endif}
  394. Function Cseg:Word;{$ifdef SYSTEMINLINE}inline;{$endif}
  395. Function Dseg:Word;{$ifdef SYSTEMINLINE}inline;{$endif}
  396. Function Sseg:Word;{$ifdef SYSTEMINLINE}inline;{$endif}
  397. {****************************************************************************
  398. PChar and String Handling
  399. ****************************************************************************}
  400. function strpas(p:pchar):shortstring;external name 'FPC_PCHAR_TO_SHORTSTR';
  401. function strlen(p:pchar):longint;external name 'FPC_PCHAR_LENGTH';
  402. { Shortstring functions }
  403. {$ifndef INTERNSETLENGTH}
  404. Procedure SetLength (Var S:ShortString;len:SizeInt);
  405. {$endif INTERNSETLENGTH}
  406. {$ifndef InternCopy}
  407. Function Copy(const s:shortstring;index:SizeInt;count:SizeInt):shortstring;
  408. {$endif interncopy}
  409. Procedure Delete(Var s:shortstring;index:SizeInt;count:SizeInt);
  410. Procedure Insert(const source:shortstring;Var s:shortstring;index:SizeInt);
  411. Procedure Insert(source:Char;Var s:shortstring;index:SizeInt);
  412. Function Pos(const substr:shortstring;const s:shortstring):SizeInt;
  413. Function Pos(C:Char;const s:shortstring):SizeInt;
  414. Procedure SetString (Var S : Shortstring; Buf : PChar; Len : SizeInt);
  415. Procedure SetString (Var S : AnsiString; Buf : PChar; Len : SizeInt);
  416. {$ifndef INTERNLENGTH}
  417. Function Length(s:string):byte;
  418. {$endif INTERNLENGTH}
  419. Function upCase(const s:shortstring):shortstring;
  420. Function lowerCase(const s:shortstring):shortstring; overload;
  421. Function Space(b:byte):shortstring;
  422. Function hexStr(Val:Longint;cnt:byte):shortstring;
  423. Function OctStr(Val:Longint;cnt:byte):shortstring;
  424. Function binStr(Val:Longint;cnt:byte):shortstring;
  425. Function hexStr(Val:int64;cnt:byte):shortstring;
  426. Function OctStr(Val:int64;cnt:byte):shortstring;
  427. Function binStr(Val:int64;cnt:byte):shortstring;
  428. Function hexStr(Val:Pointer):shortstring;
  429. { Char functions }
  430. {$ifdef INTERNCONSTINTF}
  431. Function chr(b : byte) : Char; [INTERNPROC: fpc_in_chr_byte];
  432. {$else}
  433. Function Chr(b:byte):Char;
  434. {$endif}
  435. Function upCase(c:Char):Char;
  436. Function lowerCase(c:Char):Char; overload;
  437. {$ifndef InternCopy}
  438. function copy(c:char;index : SizeInt;count : SizeInt): shortstring;
  439. {$endif interncopy}
  440. function pos(const substr : shortstring;c:char): SizeInt;
  441. {$ifndef INTERNLENGTH}
  442. function length(c:char):byte;
  443. {$endif INTERNLENGTH}
  444. {****************************************************************************
  445. AnsiString Handling
  446. ****************************************************************************}
  447. {$ifndef INTERNSETLENGTH}
  448. Procedure SetLength (Var S : AnsiString; l : SizeInt);
  449. {$endif INTERNSETLENGTH}
  450. Procedure UniqueString(Var S : AnsiString);external name 'FPC_ANSISTR_UNIQUE';
  451. {$ifndef INTERNLENGTH}
  452. Function Length (Const S : AnsiString) : SizeInt;
  453. {$endif INTERNLENGTH}
  454. {$ifndef InternCopy}
  455. Function Copy (Const S : AnsiString; Index,Size : SizeInt) : AnsiString;
  456. {$endif interncopy}
  457. Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : SizeInt;
  458. Function Pos (c : Char; Const s : AnsiString) : SizeInt;
  459. Procedure Insert (Const Source : AnsiString; Var S : AnsiString; Index : SizeInt);
  460. Procedure Delete (Var S : AnsiString; Index,Size: SizeInt);
  461. Function StringOfChar(c : char;l : SizeInt) : AnsiString;
  462. function upcase(const s : ansistring) : ansistring;
  463. function lowercase(const s : ansistring) : ansistring;
  464. {****************************************************************************
  465. WideString Handling
  466. ****************************************************************************}
  467. {$ifdef HASWIDESTRING}
  468. {$i wstringh.inc}
  469. {$endif HASWIDESTRING}
  470. {****************************************************************************
  471. Untyped File Management
  472. ****************************************************************************}
  473. Procedure Assign(Var f:File;const Name:string);
  474. Procedure Assign(Var f:File;p:pchar);
  475. Procedure Assign(Var f:File;c:char);
  476. Procedure Rewrite(Var f:File;l:Longint);
  477. Procedure Rewrite(Var f:File);
  478. Procedure Reset(Var f:File;l:Longint);
  479. Procedure Reset(Var f:File);
  480. Procedure Close(Var f:File);
  481. Procedure BlockWrite(Var f:File;Const Buf;Count:Longint;Var Result:Longint);
  482. Procedure BlockWrite(Var f:File;Const Buf;Count:Cardinal;var Result:Cardinal);
  483. Procedure BlockWrite(Var f:File;Const Buf;Count:Word;Var Result:Word);
  484. Procedure BlockWrite(Var f:File;Const Buf;Count:Word;Var Result:Integer);
  485. Procedure BlockWrite(Var f:File;Const Buf;Count:Longint);
  486. Procedure BlockRead(Var f:File;Var Buf;count:Longint;Var Result:Longint);
  487. Procedure BlockRead(Var f:File;Var Buf;count:Cardinal;Var Result:Cardinal);
  488. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Word);
  489. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Integer);
  490. Procedure BlockRead(Var f:File;Var Buf;count:Longint);
  491. Function FilePos(Var f:File):Longint;
  492. Function FileSize(Var f:File):Longint;
  493. Procedure Seek(Var f:File;Pos:Longint);
  494. Function EOF(Var f:File):Boolean;
  495. Procedure Erase(Var f:File);
  496. Procedure Rename(Var f:File;const s:string);
  497. Procedure Rename(Var f:File;p:pchar);
  498. Procedure Rename(Var f:File;c:char);
  499. Procedure Truncate (Var F:File);
  500. {****************************************************************************
  501. Typed File Management
  502. ****************************************************************************}
  503. Procedure Assign(Var f:TypedFile;const Name:string);
  504. Procedure Assign(Var f:TypedFile;p:pchar);
  505. Procedure Assign(Var f:TypedFile;c:char);
  506. {$ifdef INTERNCONSTINTF}
  507. Procedure Reset(var f : TypedFile); [INTERNPROC: fpc_in_Reset_TypedFile];
  508. Procedure Rewrite(var f : TypedFile); [INTERNPROC: fpc_in_Rewrite_TypedFile];
  509. {$else}
  510. Procedure Rewrite(Var f:TypedFile);
  511. Procedure Reset(Var f:TypedFile);
  512. {$endif}
  513. {****************************************************************************
  514. Text File Management
  515. ****************************************************************************}
  516. Procedure Assign(Var t:Text;const s:string);
  517. Procedure Assign(Var t:Text;p:pchar);
  518. Procedure Assign(Var t:Text;c:char);
  519. Procedure Close(Var t:Text);
  520. Procedure Rewrite(Var t:Text);
  521. Procedure Reset(Var t:Text);
  522. Procedure Append(Var t:Text);
  523. Procedure Flush(Var t:Text);
  524. Procedure Erase(Var t:Text);
  525. Procedure Rename(Var t:Text;const s:string);
  526. Procedure Rename(Var t:Text;p:pchar);
  527. Procedure Rename(Var t:Text;c:char);
  528. Function EOF(Var t:Text):Boolean;
  529. Function EOF:Boolean;
  530. Function EOLn(Var t:Text):Boolean;
  531. Function EOLn:Boolean;
  532. Function SeekEOLn (Var t:Text):Boolean;
  533. Function SeekEOF (Var t:Text):Boolean;
  534. Function SeekEOLn:Boolean;
  535. Function SeekEOF:Boolean;
  536. Procedure SetTextBuf(Var f:Text; Var Buf);{$ifdef INTERNCONSTINTF}[INTERNPROC:fpc_in_settextbuf_file_x];{$endif}
  537. Procedure SetTextBuf(Var f:Text; Var Buf; Size:Longint);
  538. Procedure SetTextLineEnding(Var f:Text; Ending:string);
  539. {****************************************************************************
  540. Directory Management
  541. ****************************************************************************}
  542. Procedure chdir(const s:string);
  543. Procedure mkdir(const s:string);
  544. Procedure rmdir(const s:string);
  545. Procedure getdir(drivenr:byte;Var dir:shortstring);
  546. Procedure getdir(drivenr:byte;Var dir:ansistring);
  547. {*****************************************************************************
  548. Miscellaneous
  549. *****************************************************************************}
  550. { os independent calls to allow backtraces }
  551. function get_frame:pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
  552. function get_caller_addr(framebp:pointer):pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
  553. function get_caller_frame(framebp:pointer):pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
  554. Function IOResult:Word;{$ifdef SYSTEMINLINE}inline;{$endif}
  555. Function Sptr:Pointer;{$ifdef SYSTEMINLINE}inline;{$endif}{$ifdef INTERNCONSTINTF}[internconst:fpc_in_const_ptr];{$endif}
  556. Function GetProcessID:SizeUInt;
  557. Function GetThreadID:SizeUInt;
  558. {*****************************************************************************
  559. Init / Exit / ExitProc
  560. *****************************************************************************}
  561. Function Paramcount:Longint;
  562. Function ParamStr(l:Longint):string;
  563. Procedure Dump_Stack(var f : text;bp:pointer);
  564. Procedure RunError(w:Word);
  565. Procedure RunError;{$ifdef SYSTEMINLINE}inline;{$endif}
  566. Procedure halt(errnum:byte);
  567. Procedure AddExitProc(Proc:TProcedure);
  568. Procedure halt;{$ifdef SYSTEMINLINE}inline;{$endif}
  569. { Need to be exported for threads unit }
  570. Procedure SysInitExceptions;
  571. procedure SysInitStdIO;
  572. Procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
  573. {*****************************************************************************
  574. Abstract/Assert/Error Handling
  575. *****************************************************************************}
  576. function ArrayStringToPPchar(const S:Array of AnsiString;reserveentries:Longint):ppchar; // const ?
  577. Function StringToPPChar(Var S:AnsiString;ReserveEntries:integer):ppchar;
  578. Function StringToPPChar(S: PChar;ReserveEntries:integer):ppchar;
  579. procedure AbstractError;external name 'FPC_ABSTRACTERROR';
  580. Function SysBackTraceStr(Addr:Pointer): ShortString;
  581. Procedure SysAssert(Const Msg,FName:ShortString;LineNo:Longint;ErrorAddr:Pointer);
  582. { Error handlers }
  583. Type
  584. TBackTraceStrFunc = Function (Addr: Pointer): ShortString;
  585. TErrorProc = Procedure (ErrNo : Longint; Address,Frame : Pointer);
  586. TAbstractErrorProc = Procedure;
  587. TAssertErrorProc = Procedure(const msg,fname:ShortString;lineno:longint;erroraddr:pointer);
  588. const
  589. BackTraceStrFunc : TBackTraceStrFunc = @SysBackTraceStr;
  590. ErrorProc : TErrorProc = nil;
  591. AbstractErrorProc : TAbstractErrorProc = nil;
  592. AssertErrorProc : TAssertErrorProc = @SysAssert;
  593. {*****************************************************************************
  594. SetJmp/LongJmp
  595. *****************************************************************************}
  596. {$i setjumph.inc}
  597. {*****************************************************************************
  598. Object Pascal support
  599. *****************************************************************************}
  600. {$i objpash.inc}
  601. {*****************************************************************************
  602. Variant support
  603. *****************************************************************************}
  604. {$ifdef HASVARIANT}
  605. {$i varianth.inc}
  606. {$endif HASVARIANT}
  607. {*****************************************************************************
  608. Internal helper routines support
  609. *****************************************************************************}
  610. {$i dynarrh.inc}
  611. {$i compproc.inc}
  612. {*****************************************************************************
  613. Heap
  614. *****************************************************************************}
  615. {$i heaph.inc}
  616. {*****************************************************************************
  617. Thread support
  618. *****************************************************************************}
  619. { Generic threadmanager }
  620. {$i threadh.inc}
  621. {*****************************************************************************
  622. FPDoc phony declarations.
  623. *****************************************************************************}
  624. {$ifdef fpdocsystem}
  625. {$i system.fpd}
  626. {$endif}
  627. {
  628. $Log$
  629. Revision 1.122 2005-04-03 19:29:28 florian
  630. * proper error message if the cthreads unit is included too late
  631. uses clause
  632. Revision 1.121 2005/02/25 12:34:46 peter
  633. * added HexStr(Pointer)
  634. Revision 1.120 2005/02/14 17:13:29 peter
  635. * truncate log
  636. Revision 1.119 2005/02/08 20:25:28 florian
  637. - killed power from system unit
  638. * move operator ** to math unit
  639. Revision 1.118 2005/02/06 20:37:31 florian
  640. * InitProc gets an inital value
  641. Revision 1.117 2005/02/06 20:35:54 florian
  642. + InitProc
  643. Revision 1.116 2005/02/06 11:20:52 peter
  644. * threading in system unit
  645. * removed systhrds unit
  646. Revision 1.115 2005/02/05 10:47:38 florian
  647. * fixed previous commit
  648. Revision 1.114 2005/02/05 10:07:21 florian
  649. * map farpointer to pointer on platforms not having farpointers
  650. Revision 1.113 2005/02/01 20:22:49 florian
  651. * improved widestring infrastructure manager
  652. Revision 1.112 2005/01/24 18:03:19 peter
  653. * pinteger in non-delphi/objfpc mode is psmallint
  654. }