systemh.inc 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  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. {$endif CPUM68K}
  104. {$ifdef CPUPOWERPC}
  105. {$define DEFAULT_DOUBLE}
  106. {$define SUPPORT_SINGLE}
  107. {$define SUPPORT_DOUBLE}
  108. {$define FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE}
  109. ValReal = Double;
  110. { map comp to int64, but this doesn't mean we compile the comp support in! }
  111. Comp = Int64;
  112. PComp = ^Comp;
  113. {$endif CPUPOWERPC}
  114. {$ifdef CPUSPARC}
  115. {$define DEFAULT_DOUBLE}
  116. {$define SUPPORT_SINGLE}
  117. {$define SUPPORT_DOUBLE}
  118. {$define FPC_INCLUDE_SOFTWARE_SHIFT_INT64}
  119. ValReal = Double;
  120. { map comp to int64, but this doesn't mean we compile the comp support in! }
  121. Comp = Int64;
  122. PComp = ^Comp;
  123. {$endif CPUSPARC}
  124. {$ifdef CPUARM}
  125. {$define DEFAULT_DOUBLE}
  126. {$define SUPPORT_SINGLE}
  127. {$define SUPPORT_DOUBLE}
  128. {$define FPC_INCLUDE_SOFTWARE_MOD_DIV}
  129. {$define FPC_INCLUDE_SOFTWARE_SHIFT_INT64}
  130. {$define FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE}
  131. ValReal = Real;
  132. { map comp to int64, but this doesn't mean we compile the comp support in! }
  133. Comp = Int64;
  134. PComp = ^Comp;
  135. {$endif CPUARM}
  136. {$ifdef CPU64}
  137. SizeInt = Int64;
  138. SizeUInt = QWord;
  139. PtrInt = Int64;
  140. PtrUInt = QWord;
  141. ValSInt = int64;
  142. ValUInt = qword;
  143. {$endif CPU64}
  144. {$ifdef CPU32}
  145. SizeInt = Longint;
  146. SizeUInt = DWord;
  147. PtrInt = Longint;
  148. PtrUInt = DWord;
  149. ValSInt = Longint;
  150. ValUInt = Cardinal;
  151. {$endif CPU32}
  152. { Zero - terminated strings }
  153. PChar = ^Char;
  154. PPChar = ^PChar;
  155. { AnsiChar is equivalent of Char, so we need
  156. to use type renamings }
  157. TAnsiChar = Char;
  158. AnsiChar = Char;
  159. PAnsiChar = PChar;
  160. PPAnsiChar = PPChar;
  161. UCS4Char = type LongWord;
  162. PUCS4Char = ^UCS4Char;
  163. TUCS4CharArray = array[0..$effffff] of UCS4Char;
  164. PUCS4CharArray = ^TUCS4CharArray;
  165. {$ifndef VER1_0}
  166. UCS4String = array of UCS4Char;
  167. {$endif VER1_0}
  168. UTF8String = type ansistring;
  169. PUTF8String = ^UTF8String;
  170. {$ifndef HASCURRENCY}
  171. Currency = Int64;
  172. {$endif HASCURRENCY}
  173. HRESULT = type Longint;
  174. TDateTime = type Double;
  175. Error = type Longint;
  176. PSingle = ^Single;
  177. PDouble = ^Double;
  178. PCurrency = ^Currency;
  179. {$ifdef SUPPORT_COMP}
  180. PComp = ^Comp;
  181. {$endif SUPPORT_COMP}
  182. PExtended = ^Extended;
  183. PSmallInt = ^Smallint;
  184. PShortInt = ^Shortint;
  185. PInteger = ^Longint;
  186. PByte = ^Byte;
  187. PWord = ^word;
  188. PDWord = ^DWord;
  189. PLongWord = ^LongWord;
  190. PLongint = ^Longint;
  191. PCardinal = ^Cardinal;
  192. PQWord = ^QWord;
  193. PInt64 = ^Int64;
  194. PPtrInt = ^PtrInt;
  195. PSizeInt = ^SizeInt;
  196. PPointer = ^Pointer;
  197. PPPointer = ^PPointer;
  198. PBoolean = ^Boolean;
  199. PWordBool = ^WordBool;
  200. PLongBool = ^LongBool;
  201. PShortString = ^ShortString;
  202. PAnsiString = ^AnsiString;
  203. PDate = ^TDateTime;
  204. PError = ^Error;
  205. {$ifdef HASVARIANT}
  206. PVariant = ^Variant;
  207. POleVariant = ^OleVariant;
  208. {$endif HASVARIANT}
  209. {$ifdef HASWIDECHAR}
  210. PWideChar = ^WideChar;
  211. PPWideChar = ^PWideChar;
  212. { 1.0.x also has HASWIDECHAR defined, but doesn't support it
  213. fully, setting WChar to Word as fallback (PFV) }
  214. {$ifndef VER1_0}
  215. WChar = Widechar;
  216. {$else}
  217. WChar = Word;
  218. {$endif}
  219. UCS2Char = WideChar;
  220. PUCS2Char = PWideChar;
  221. {$else}
  222. WChar = Word;
  223. {$endif HASWIDECHAR}
  224. {$ifdef HASWIDESTRING}
  225. PWideString = ^WideString;
  226. {$endif HASWIDESTRING}
  227. { Needed for fpc_get_output }
  228. PText = ^Text;
  229. TTextLineBreakStyle = (tlbsLF,tlbsCRLF,tlbsCR);
  230. { procedure type }
  231. TProcedure = Procedure;
  232. const
  233. { Maximum value of the biggest signed and unsigned integer type available}
  234. MaxSIntValue = High(ValSInt);
  235. MaxUIntValue = High(ValUInt);
  236. { max. values for longint and int}
  237. maxLongint = $7fffffff;
  238. maxSmallint = 32767;
  239. maxint = maxsmallint;
  240. type
  241. IntegerArray = array[0..$effffff] of Integer;
  242. PIntegerArray = ^IntegerArray;
  243. PointerArray = array [0..512*1024*1024 - 2] of Pointer;
  244. PPointerArray = ^PointerArray;
  245. {$ifndef VER1_0}
  246. TBoundArray = array of Integer;
  247. {$endif VER1_0}
  248. TPCharArray = packed array[0..(MaxLongint div SizeOf(PChar))-1] of PChar;
  249. PPCharArray = ^TPCharArray;
  250. const
  251. {$ifdef cpui386}
  252. Test8086 : byte = 2; { Always i386 or newer }
  253. Test8087 : byte = 3; { Always 387 or newer. Emulated if needed. }
  254. {$endif cpui386}
  255. {$ifdef cpum68k}
  256. Test68000 : byte = 0; { Must be determined at startup for both }
  257. Test68881 : byte = 0;
  258. {$endif cpum68k}
  259. { max level in dumping on error }
  260. Max_Frame_Dump : Word = 8;
  261. { Exit Procedure handling consts and types }
  262. ExitProc : pointer = nil;
  263. Erroraddr: pointer = nil;
  264. Errorcode: Word = 0;
  265. { file input modes }
  266. fmClosed = $D7B0;
  267. fmInput = $D7B1;
  268. fmOutput = $D7B2;
  269. fmInOut = $D7B3;
  270. fmAppend = $D7B4;
  271. ProcessID: SizeUInt = 1;
  272. Filemode : byte = 2;
  273. CmdLine : PChar = nil;
  274. (* Value should be changed during system initialization as appropriate. *)
  275. { assume that this program will not spawn other threads, when the
  276. first thread is started the following constants need to be filled }
  277. IsMultiThread : boolean = FALSE;
  278. { Indicates if there was an error }
  279. StackError : boolean = FALSE;
  280. var
  281. ExitCode : Word; public name 'operatingsystem_result';
  282. RandSeed : Cardinal;
  283. { Delphi compatibility }
  284. IsLibrary : boolean;
  285. IsConsole : boolean;
  286. { Threading support }
  287. fpc_threadvar_relocate_proc : pointer; public name 'FPC_THREADVAR_RELOCATE';
  288. {$ifdef SUPPORT_THREADVAR}
  289. ThreadVar
  290. {$else SUPPORT_THREADVAR}
  291. Var
  292. {$endif SUPPORT_THREADVAR}
  293. ThreadID : SizeUInt;
  294. { Standard In- and Output }
  295. ErrOutput,
  296. Output,
  297. Input,
  298. StdOut,
  299. StdErr : Text;
  300. InOutRes : Word;
  301. { Stack checking }
  302. StackBottom : Pointer;
  303. StackLength : Cardinal;
  304. {****************************************************************************
  305. Processor specific routines
  306. ****************************************************************************}
  307. {$ifdef FPC_USE_LIBC}
  308. {$ifdef SYSTEMINLINE}
  309. {$define INLINEGENERICS}
  310. {$endif}
  311. {$endif}
  312. Procedure Move(const source;var dest;count:SizeInt);{$ifdef INLINEGENERICS}inline;{$endif}
  313. Procedure FillChar(Var x;count:SizeInt;Value:Boolean);{$ifdef SYSTEMINLINE}inline;{$endif}
  314. Procedure FillChar(Var x;count:SizeInt;Value:Char);{$ifdef SYSTEMINLINE}inline;{$endif}
  315. Procedure FillChar(Var x;count:SizeInt;Value:Byte);{$ifdef INLINEGENERICS}inline;{$endif}
  316. procedure FillByte(var x;count:SizeInt;value:byte);{$ifdef INLINEGENERICS}inline;{$endif}
  317. Procedure FillWord(Var x;count:SizeInt;Value:Word);
  318. procedure FillDWord(var x;count:SizeInt;value:DWord);
  319. function IndexChar(const buf;len:SizeInt;b:char):SizeInt;
  320. function IndexByte(const buf;len:SizeInt;b:byte):SizeInt;{$ifdef INLINEGENERICS}inline;{$endif}
  321. function Indexword(const buf;len:SizeInt;b:word):SizeInt;
  322. function IndexDWord(const buf;len:SizeInt;b:DWord):SizeInt;
  323. function CompareChar(const buf1,buf2;len:SizeInt):SizeInt;
  324. function CompareByte(const buf1,buf2;len:SizeInt):SizeInt;{$ifdef INLINEGENERICS}inline;{$endif}
  325. function CompareWord(const buf1,buf2;len:SizeInt):SizeInt;
  326. function CompareDWord(const buf1,buf2;len:SizeInt):SizeInt;
  327. procedure MoveChar0(const buf1;var buf2;len:SizeInt);
  328. function IndexChar0(const buf;len:SizeInt;b:char):SizeInt;
  329. function CompareChar0(const buf1,buf2;len:SizeInt):SizeInt;{$ifdef INLINEGENERICS}inline;{$endif}
  330. procedure prefetch(const mem);
  331. {****************************************************************************
  332. Math Routines
  333. ****************************************************************************}
  334. Function lo(w:Word):byte;
  335. Function lo(l:Longint):Word;
  336. Function lo(l:DWord):Word;
  337. Function lo(i:Integer):byte;
  338. Function lo(B: Byte):Byte;{$ifdef SYSTEMINLINE}inline;{$endif}
  339. Function hi(w:Word):byte;
  340. Function hi(i:Integer):byte;
  341. Function hi(l:Longint):Word;
  342. Function hi(b : Byte) : Byte;{$ifdef SYSTEMINLINE}inline;{$endif}
  343. Function hi(l: DWord): Word;
  344. Function lo(q : QWord) : DWord;
  345. Function lo(i : Int64) : DWord;
  346. Function hi(q : QWord) : DWord;
  347. Function hi(i : Int64) : DWord;
  348. Function Swap (X:Word):Word;{$ifdef SYSTEMINLINE}inline;{$endif}
  349. Function Swap (X:Integer):Integer;{$ifdef SYSTEMINLINE}inline;{$endif}
  350. Function Swap (X:Cardinal):Cardinal;{$ifdef SYSTEMINLINE}inline;{$endif}
  351. Function Swap (X:LongInt):LongInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  352. Function Swap (X:QWord):QWord;{$ifdef SYSTEMINLINE}inline;{$endif}
  353. Function Swap (X:Int64):Int64;{$ifdef SYSTEMINLINE}inline;{$endif}
  354. Function Align (Addr : PtrInt; Alignment : PtrInt) : PtrInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  355. Function Align (Addr : Pointer; Alignment : PtrInt) : Pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
  356. Function Random(l:longint):longint;
  357. Function Random(l:int64):int64;
  358. Function Random: extended;
  359. Procedure Randomize;
  360. Function abs(l:Longint):Longint;{$ifdef SYSTEMINLINE}inline;{$endif}
  361. Function abs(l:Int64):Int64;{$ifdef SYSTEMINLINE}inline;{$endif}
  362. Function sqr(l:Longint):Longint;{$ifdef SYSTEMINLINE}inline;{$endif}
  363. Function sqr(l:Int64):Int64;{$ifdef SYSTEMINLINE}inline;{$endif}
  364. Function sqr(l:QWord):QWord;{$ifdef SYSTEMINLINE}inline;{$endif}
  365. Function odd(l:Longint):Boolean;{$ifdef SYSTEMINLINE}inline;{$endif}
  366. Function odd(l:Longword):Boolean;{$ifdef SYSTEMINLINE}inline;{$endif}
  367. Function odd(l:Int64):Boolean;{$ifdef SYSTEMINLINE}inline;{$endif}
  368. Function odd(l:QWord):Boolean;{$ifdef SYSTEMINLINE}inline;{$endif}
  369. { float math routines }
  370. {$I mathh.inc}
  371. operator ** (bas,expo : real) e: real;
  372. operator ** (bas,expo : int64) i: int64;
  373. {****************************************************************************
  374. Addr/Pointer Handling
  375. ****************************************************************************}
  376. Function ptr(sel,off:Longint):farpointer;{$ifdef SYSTEMINLINE}inline;{$endif}
  377. Function Cseg:Word;{$ifdef SYSTEMINLINE}inline;{$endif}
  378. Function Dseg:Word;{$ifdef SYSTEMINLINE}inline;{$endif}
  379. Function Sseg:Word;{$ifdef SYSTEMINLINE}inline;{$endif}
  380. {****************************************************************************
  381. PChar and String Handling
  382. ****************************************************************************}
  383. function strpas(p:pchar):shortstring;
  384. function strlen(p:pchar):longint;{$ifdef INLINEGENERICS}inline;{$endif}
  385. { Shortstring functions }
  386. {$ifndef INTERNSETLENGTH}
  387. Procedure SetLength (Var S:ShortString;len:SizeInt);
  388. {$endif INTERNSETLENGTH}
  389. {$ifndef InternCopy}
  390. Function Copy(const s:shortstring;index:SizeInt;count:SizeInt):shortstring;
  391. {$endif interncopy}
  392. Procedure Delete(Var s:shortstring;index:SizeInt;count:SizeInt);
  393. Procedure Insert(const source:shortstring;Var s:shortstring;index:SizeInt);
  394. Procedure Insert(source:Char;Var s:shortstring;index:SizeInt);
  395. Function Pos(const substr:shortstring;const s:shortstring):SizeInt;
  396. Function Pos(C:Char;const s:shortstring):SizeInt;
  397. Procedure SetString (Var S : Shortstring; Buf : PChar; Len : SizeInt);
  398. Procedure SetString (Var S : AnsiString; Buf : PChar; Len : SizeInt);
  399. {$ifndef INTERNLENGTH}
  400. Function Length(s:string):byte;
  401. {$endif INTERNLENGTH}
  402. Function upCase(const s:shortstring):shortstring;
  403. Function lowerCase(const s:shortstring):shortstring; overload;
  404. Function Space(b:byte):shortstring;
  405. Function hexStr(Val:Longint;cnt:byte):shortstring;
  406. Function OctStr(Val:Longint;cnt:byte):shortstring;
  407. Function binStr(Val:Longint;cnt:byte):shortstring;
  408. Function hexStr(Val:int64;cnt:byte):shortstring;
  409. Function OctStr(Val:int64;cnt:byte):shortstring;
  410. Function binStr(Val:int64;cnt:byte):shortstring;
  411. { Char functions }
  412. Function Chr(b:byte):Char;
  413. Function upCase(c:Char):Char;
  414. Function lowerCase(c:Char):Char; overload;
  415. {$ifndef InternCopy}
  416. function copy(c:char;index : SizeInt;count : SizeInt): shortstring;
  417. {$endif interncopy}
  418. function pos(const substr : shortstring;c:char): SizeInt;
  419. {$ifndef INTERNLENGTH}
  420. function length(c:char):byte;
  421. {$endif INTERNLENGTH}
  422. {****************************************************************************
  423. AnsiString Handling
  424. ****************************************************************************}
  425. {$ifndef INTERNSETLENGTH}
  426. Procedure SetLength (Var S : AnsiString; l : SizeInt);
  427. {$endif INTERNSETLENGTH}
  428. Procedure UniqueString (Var S : AnsiString);
  429. {$ifndef INTERNLENGTH}
  430. Function Length (Const S : AnsiString) : SizeInt;
  431. {$endif INTERNLENGTH}
  432. {$ifndef InternCopy}
  433. Function Copy (Const S : AnsiString; Index,Size : SizeInt) : AnsiString;
  434. {$endif interncopy}
  435. Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : SizeInt;
  436. Function Pos (c : Char; Const s : AnsiString) : SizeInt;
  437. Procedure Insert (Const Source : AnsiString; Var S : AnsiString; Index : SizeInt);
  438. Procedure Delete (Var S : AnsiString; Index,Size: SizeInt);
  439. Function StringOfChar(c : char;l : SizeInt) : AnsiString;
  440. function upcase(const s : ansistring) : ansistring;
  441. function lowercase(const s : ansistring) : ansistring;
  442. {****************************************************************************
  443. WideString Handling
  444. ****************************************************************************}
  445. {$ifdef HASWIDESTRING}
  446. {$ifndef INTERNSETLENGTH}
  447. Procedure SetLength (Var S : WideString; l : SizeInt);
  448. {$endif INTERNSETLENGTH}
  449. Procedure UniqueString (Var S : WideString);
  450. {$ifndef INTERNLENGTH}
  451. Function Length (Const S : WideString) : SizeInt;
  452. {$endif INTERNLENGTH}
  453. {$ifndef InternCopy}
  454. Function Copy (Const S : WideString; Index,Size : SizeInt) : WideString;
  455. {$endif interncopy}
  456. Function Pos (Const Substr : WideString; Const Source : WideString) : SizeInt;
  457. Function Pos (c : Char; Const s : WideString) : SizeInt;
  458. Function Pos (c : WideChar; Const s : WideString) : SizeInt;
  459. Procedure Insert (Const Source : WideString; Var S : WideString; Index : SizeInt);
  460. Procedure Delete (Var S : WideString; Index,Size: SizeInt);
  461. Procedure SetString (Var S : WideString; Buf : PWideChar; Len : SizeInt);
  462. Procedure SetString (Var S : WideString; Buf : PChar; Len : SizeInt);
  463. function WideCharToString(S : PWideChar) : AnsiString;
  464. function StringToWideChar(const Src : AnsiString;Dest : PWideChar;DestSize : SizeInt) : PWideChar;
  465. function WideCharLenToString(S : PWideChar;Len : SizeInt) : AnsiString;
  466. procedure WideCharLenToStrVar(Src : PWideChar;Len : SizeInt;var Dest : AnsiString);
  467. procedure WideCharToStrVar(S : PWideChar;var Dest : AnsiString);
  468. Type
  469. TWide2AnsiMove=procedure(source:pwidechar;dest:pchar;len:SizeInt);
  470. TAnsi2WideMove=procedure(source:pchar;dest:pwidechar;len:SizeInt);
  471. TWideStringManager = record
  472. Wide2AnsiMove : TWide2AnsiMove;
  473. Ansi2WideMove : TAnsi2WideMove;
  474. {
  475. UpperUTF8 : procedure(p:PUTF8String);
  476. UpperUCS2 : procedure(p:PUCS2Char);
  477. UpperUCS4 : procedure(p:PUCS4Char);
  478. LowerUTF8 : procedure(p:PUTF8String);
  479. LowerUCS2 : procedure(p:PUCS2Char);
  480. LowerUCS4 : procedure(p:PUCS4Char);
  481. CompUTF8 : function(p1,p2:PUTF8String) : shortint;
  482. CompUCS2 : function(p1,p2:PUCS2Char) : shortint;
  483. CompUCS4 : function(p1,p2:PUC42Char) : shortint;
  484. }
  485. end;
  486. function UnicodeToUtf8(Dest: PChar; Source: PWideChar; MaxBytes: SizeInt): SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  487. function UnicodeToUtf8(Dest: PChar; MaxDestBytes: SizeUInt; Source: PWideChar; SourceChars: SizeUInt): SizeUInt;
  488. function Utf8ToUnicode(Dest: PWideChar; Source: PChar; MaxChars: SizeInt): SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  489. function Utf8ToUnicode(Dest: PWideChar; MaxDestChars: SizeUInt; Source: PChar; SourceBytes: SizeUInt): SizeUInt;
  490. function UTF8Encode(const s : WideString) : UTF8String;
  491. function UTF8Decode(const s : UTF8String): WideString;
  492. function AnsiToUtf8(const s : ansistring): UTF8String;{$ifdef SYSTEMINLINE}inline;{$endif}
  493. function Utf8ToAnsi(const s : UTF8String) : ansistring;{$ifdef SYSTEMINLINE}inline;{$endif}
  494. Procedure GetWideStringManager (Var Manager : TWideStringManager);
  495. Procedure SetWideStringManager (Const New : TWideStringManager);
  496. Procedure SetWideStringManager (Const New : TWideStringManager; Var Old: TWideStringManager);
  497. {$endif HASWIDESTRING}
  498. {****************************************************************************
  499. Untyped File Management
  500. ****************************************************************************}
  501. Procedure Assign(Var f:File;const Name:string);
  502. Procedure Assign(Var f:File;p:pchar);
  503. Procedure Assign(Var f:File;c:char);
  504. Procedure Rewrite(Var f:File;l:Longint);
  505. Procedure Rewrite(Var f:File);
  506. Procedure Reset(Var f:File;l:Longint);
  507. Procedure Reset(Var f:File);
  508. Procedure Close(Var f:File);
  509. Procedure BlockWrite(Var f:File;Const Buf;Count:Longint;Var Result:Longint);
  510. Procedure BlockWrite(Var f:File;Const Buf;Count:Cardinal;var Result:Cardinal);
  511. Procedure BlockWrite(Var f:File;Const Buf;Count:Word;Var Result:Word);
  512. Procedure BlockWrite(Var f:File;Const Buf;Count:Word;Var Result:Integer);
  513. Procedure BlockWrite(Var f:File;Const Buf;Count:Longint);
  514. Procedure BlockRead(Var f:File;Var Buf;count:Longint;Var Result:Longint);
  515. Procedure BlockRead(Var f:File;Var Buf;count:Cardinal;Var Result:Cardinal);
  516. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Word);
  517. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Integer);
  518. Procedure BlockRead(Var f:File;Var Buf;count:Longint);
  519. Function FilePos(Var f:File):Longint;
  520. Function FileSize(Var f:File):Longint;
  521. Procedure Seek(Var f:File;Pos:Longint);
  522. Function EOF(Var f:File):Boolean;
  523. Procedure Erase(Var f:File);
  524. Procedure Rename(Var f:File;const s:string);
  525. Procedure Rename(Var f:File;p:pchar);
  526. Procedure Rename(Var f:File;c:char);
  527. Procedure Truncate (Var F:File);
  528. {****************************************************************************
  529. Typed File Management
  530. ****************************************************************************}
  531. Procedure Assign(Var f:TypedFile;const Name:string);
  532. Procedure Assign(Var f:TypedFile;p:pchar);
  533. Procedure Assign(Var f:TypedFile;c:char);
  534. Procedure Rewrite(Var f:TypedFile);
  535. Procedure Reset(Var f:TypedFile);
  536. {****************************************************************************
  537. Text File Management
  538. ****************************************************************************}
  539. Procedure Assign(Var t:Text;const s:string);
  540. Procedure Assign(Var t:Text;p:pchar);
  541. Procedure Assign(Var t:Text;c:char);
  542. Procedure Close(Var t:Text);
  543. Procedure Rewrite(Var t:Text);
  544. Procedure Reset(Var t:Text);
  545. Procedure Append(Var t:Text);
  546. Procedure Flush(Var t:Text);
  547. Procedure Erase(Var t:Text);
  548. Procedure Rename(Var t:Text;const s:string);
  549. Procedure Rename(Var t:Text;p:pchar);
  550. Procedure Rename(Var t:Text;c:char);
  551. Function EOF(Var t:Text):Boolean;
  552. Function EOF:Boolean;
  553. Function EOLn(Var t:Text):Boolean;
  554. Function EOLn:Boolean;
  555. Function SeekEOLn (Var t:Text):Boolean;
  556. Function SeekEOF (Var t:Text):Boolean;
  557. Function SeekEOLn:Boolean;
  558. Function SeekEOF:Boolean;
  559. Procedure SetTextBuf(Var f:Text; Var Buf);
  560. Procedure SetTextBuf(Var f:Text; Var Buf; Size:Longint);
  561. Procedure SetTextLineEnding(Var f:Text; Ending:string);
  562. {****************************************************************************
  563. Directory Management
  564. ****************************************************************************}
  565. Procedure chdir(const s:string);
  566. Procedure mkdir(const s:string);
  567. Procedure rmdir(const s:string);
  568. Procedure getdir(drivenr:byte;Var dir:shortstring);
  569. Procedure getdir(drivenr:byte;Var dir:ansistring);
  570. {*****************************************************************************
  571. Miscellaneous
  572. *****************************************************************************}
  573. { os independent calls to allow backtraces }
  574. function get_frame:pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
  575. function get_caller_addr(framebp:pointer):pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
  576. function get_caller_frame(framebp:pointer):pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
  577. Function IOResult:Word;{$ifdef SYSTEMINLINE}inline;{$endif}
  578. Function Sptr:Pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
  579. {*****************************************************************************
  580. Init / Exit / ExitProc
  581. *****************************************************************************}
  582. Function Paramcount:Longint;
  583. Function ParamStr(l:Longint):string;
  584. Procedure Dump_Stack(var f : text;bp:pointer);
  585. Procedure RunError(w:Word);
  586. Procedure RunError;{$ifdef SYSTEMINLINE}inline;{$endif}
  587. Procedure halt(errnum:byte);
  588. Procedure AddExitProc(Proc:TProcedure);
  589. Procedure halt;{$ifdef SYSTEMINLINE}inline;{$endif}
  590. { Need to be exported for threads unit }
  591. Procedure SysInitExceptions;
  592. procedure SysInitStdIO;
  593. Procedure SysResetFPU;{$ifdef SYSTEMINLINE}inline;{$endif}
  594. {*****************************************************************************
  595. Abstract/Assert/Error Handling
  596. *****************************************************************************}
  597. function ArrayStringToPPchar(const S:Array of AnsiString;reserveentries:Longint):ppchar; // const ?
  598. Function StringToPPChar(Var S:AnsiString;ReserveEntries:integer):ppchar;
  599. Function StringToPPChar(S: PChar;ReserveEntries:integer):ppchar;
  600. procedure AbstractError;
  601. Function SysBackTraceStr(Addr:Pointer): ShortString;
  602. Procedure SysAssert(Const Msg,FName:ShortString;LineNo:Longint;ErrorAddr:Pointer);
  603. { Error handlers }
  604. Type
  605. TBackTraceStrFunc = Function (Addr: Pointer): ShortString;
  606. TErrorProc = Procedure (ErrNo : Longint; Address,Frame : Pointer);
  607. TAbstractErrorProc = Procedure;
  608. TAssertErrorProc = Procedure(const msg,fname:ShortString;lineno:longint;erroraddr:pointer);
  609. const
  610. BackTraceStrFunc : TBackTraceStrFunc = @SysBackTraceStr;
  611. ErrorProc : TErrorProc = nil;
  612. AbstractErrorProc : TAbstractErrorProc = nil;
  613. AssertErrorProc : TAssertErrorProc = @SysAssert;
  614. {*****************************************************************************
  615. SetJmp/LongJmp
  616. *****************************************************************************}
  617. {$i setjumph.inc}
  618. {*****************************************************************************
  619. Object Pascal support
  620. *****************************************************************************}
  621. {$i objpash.inc}
  622. {*****************************************************************************
  623. Variant support
  624. *****************************************************************************}
  625. {$ifdef HASVARIANT}
  626. {$i varianth.inc}
  627. {$endif HASVARIANT}
  628. {*****************************************************************************
  629. Internal helper routines support
  630. *****************************************************************************}
  631. {$i dynarrh.inc}
  632. {$i compproc.inc}
  633. {
  634. $Log$
  635. Revision 1.107 2004-11-09 23:10:22 peter
  636. * use helper call to retrieve address of input/output to reduce
  637. code that is generated in the main program for loading the
  638. threadvar
  639. Revision 1.106 2004/11/04 09:32:31 peter
  640. ErrOutput added
  641. Revision 1.105 2004/10/30 20:49:10 marco
  642. * arraytostring added
  643. Revision 1.104 2004/10/14 17:39:33 florian
  644. + added system.align
  645. + threadvars are now aligned
  646. Revision 1.103 2004/10/09 21:00:46 jonas
  647. + cgenmath with libc math functions. Faster than the routines in genmath
  648. and also have full double support (exp() only has support for values in
  649. the single range in genmath, for example). Used in FPC_USE_LIBC is
  650. defined
  651. * several fixes to allow compilation with -dHASINLINE, but internalerrors
  652. because of missing support for inlining assembler code
  653. Revision 1.102 2004/09/22 05:56:11 hajny
  654. * compilation fix
  655. Revision 1.101 2004/09/21 23:43:26 hajny
  656. * SetTextLineEnding implemented, FileRec.Name position alignment for CPU64
  657. Revision 1.100 2004/09/21 15:04:22 peter
  658. * AnsiChar is equivalent of Char, use only type renamings
  659. Revision 1.99 2004/08/29 10:23:12 peter
  660. no message
  661. Revision 1.98 2004/07/18 20:21:44 florian
  662. + several unicode (to/from utf-8 conversion) stuff added
  663. * some longint -> SizeInt changes
  664. Revision 1.97 2004/07/07 15:15:40 daniel
  665. * Add inline directive to sysresetfpu
  666. Revision 1.96 2004/07/03 21:50:31 daniel
  667. * Modified bootstrap code so separate prt0.as/prt0_10.as files are no
  668. longer necessary
  669. Revision 1.95 2004/06/11 19:21:53 florian
  670. * fixed wrong commit
  671. Revision 1.94 2004/06/11 13:45:33 florian
  672. * fixed arm system unit compilation
  673. Revision 1.93 2004/05/30 16:51:38 peter
  674. * sparc need software shl shr
  675. Revision 1.92 2004/05/05 21:26:34 florian
  676. * some m68k and amiga related stuff fixed
  677. Revision 1.91 2004/05/01 23:55:18 peter
  678. * replace strlenint with sizeint
  679. Revision 1.90 2004/05/01 20:52:50 peter
  680. * ValSInt fixed for 64 bit
  681. Revision 1.89 2004/04/29 18:59:43 peter
  682. * str() helpers now also use valint/valuint
  683. * int64/qword helpers disabled for cpu64
  684. Revision 1.88 2004/04/22 17:10:38 peter
  685. * random(int64) added
  686. Revision 1.87 2004/03/23 22:35:45 peter
  687. * new compiler has smallint,longint,word internal defined
  688. Revision 1.86 2004/02/20 22:15:16 florian
  689. + x86_64 dependend sysutils part added
  690. * some 64 bit adaptions
  691. Revision 1.85 2004/02/20 11:01:20 daniel
  692. * Applied
  693. Revision 1.84 2004/02/02 20:39:27 florian
  694. + added prefetch(const mem)
  695. Revision 1.83 2004/01/26 11:48:24 florian
  696. * compilation on arm fixed
  697. Revision 1.82 2004/01/20 23:13:53 hajny
  698. * ExecuteProcess fixes, ProcessID and ThreadID added
  699. Revision 1.81 2003/12/29 19:24:12 florian
  700. + introduced PtrInt and PtrUInt
  701. * made strscan 64 bit safe
  702. Revision 1.80 2003/11/29 17:27:05 michael
  703. + Added overloaded version of SetWideStringManager without old parameter
  704. Revision 1.79 2003/11/28 20:36:13 michael
  705. + Added WideStringManager
  706. Revision 1.78 2003/11/15 19:01:27 florian
  707. * fixed rtl to work with the integrated fpc ppc assembler reader
  708. Revision 1.77 2003/11/03 09:42:28 marco
  709. * Peter's Cardinal<->Longint fixes patch
  710. Revision 1.76 2003/10/17 20:52:12 olle
  711. * Changed m68k to cpum68k, i386 to cpui386
  712. Revision 1.75 2003/10/16 15:43:13 peter
  713. * THandle is platform dependent
  714. Revision 1.74 2003/10/08 16:24:47 florian
  715. * fixed some variant issues
  716. * improved type declarations
  717. Revision 1.72 2003/09/04 16:07:31 florian
  718. * fixed qword_to_double conversion on powerpc
  719. Revision 1.71 2003/09/03 14:09:37 florian
  720. * arm fixes to the common rtl code
  721. * some generic math code fixed
  722. * ...
  723. Revision 1.70 2003/09/01 20:47:23 peter
  724. * pcomp added for sparc
  725. Revision 1.69 2003/05/01 08:05:23 florian
  726. * started to make the rtl 64 bit save by introducing SizeInt and SizeUInt (similar to size_t of C)
  727. Revision 1.68 2003/04/30 16:36:39 florian
  728. + support for generic pchar routines added
  729. + some basic rtl stuff for x86-64 added
  730. Revision 1.67 2003/04/25 21:09:44 peter
  731. * remove dos lf
  732. Revision 1.66 2003/04/23 22:46:41 florian
  733. + powerpc defines now pcomp as well
  734. Revision 1.65 2003/04/01 15:36:31 peter
  735. * make HResult unique type
  736. Revision 1.64 2003/03/17 14:30:11 peter
  737. * changed address parameter/return values to pointer instead
  738. of longint
  739. Revision 1.63 2003/01/13 14:37:11 florian
  740. * cpu defines fixed
  741. * ... = type ...; stuff reactived, should work now with 1.1
  742. Revision 1.62 2002/12/21 17:20:27 florian
  743. + some types for D6 compatibility added
  744. Revision 1.61 2002/12/15 22:33:12 peter
  745. * SetString(WideString,[PChar|PWideChar],Len) added
  746. Revision 1.60 2002/11/16 20:12:22 florian
  747. + sparc types added
  748. + UTF*/UCS* types added
  749. Revision 1.59 2002/10/14 19:39:17 peter
  750. * threads unit added for thread support
  751. Revision 1.58 2002/10/06 13:56:47 carl
  752. - remove stack checking for every target in system unit
  753. Revision 1.57 2002/10/02 18:21:51 peter
  754. * Copy() changed to internal function calling compilerprocs
  755. * FPC_SHORTSTR_COPY renamed to FPC_SHORTSTR_ASSIGN because of the
  756. new copy functions
  757. Revision 1.56 2002/09/28 21:18:02 florian
  758. * map comp to int64 for the powerpc
  759. Revision 1.55 2002/09/26 21:50:37 florian
  760. + some WideString<->AnsiString conversion functions added
  761. Revision 1.54 2002/09/07 21:20:50 carl
  762. * cardinal -> longword
  763. - remove FPUInt64 variable
  764. Revision 1.53 2002/09/07 15:07:46 peter
  765. * old logs removed and tabs fixed
  766. Revision 1.52 2002/08/19 19:34:02 peter
  767. * SYSTEMINLINE define that will add inline directives for small
  768. functions and wrappers. This will be defined automaticly when
  769. the compiler defines the HASINLINE directive
  770. Revision 1.51 2002/08/06 20:53:38 michael
  771. + Added support for octal strings (using &)
  772. Revision 1.50 2002/07/26 22:46:06 florian
  773. * interface of system unit for Linux/PowerPC compiles
  774. Revision 1.49 2002/07/26 21:29:03 florian
  775. + powerpc type support
  776. Revision 1.48 2002/07/04 20:40:09 florian
  777. + some x86-64 support added
  778. Revision 1.47 2002/07/01 16:29:05 peter
  779. * sLineBreak changed to normal constant like Kylix
  780. Revision 1.46 2002/06/02 10:49:30 marco
  781. * Renamefest supports_double for FreeBSD too
  782. Revision 1.45 2002/04/21 15:51:51 carl
  783. * StackError is now a typed constant
  784. + $S can be used under unix
  785. Revision 1.44 2002/04/12 17:35:24 carl
  786. - removed unused variable
  787. Revision 1.43 2002/01/25 17:41:05 peter
  788. * moved array types to objpas unit
  789. Revision 1.42 2002/01/25 17:39:35 peter
  790. * array types added
  791. Revision 1.41 2002/01/24 18:27:06 peter
  792. * lowercase() overloaded
  793. Revision 1.40 2002/01/24 12:33:53 jonas
  794. * adapted ranges of native types to int64 (e.g. high cardinal is no
  795. longer longint($ffffffff), but just $fffffff in psystem)
  796. * small additional fix in 64bit rangecheck code generation for 32 bit
  797. processors
  798. * adaption of ranges required the matching talgorithm used for selecting
  799. which overloaded procedure to call to be adapted. It should now always
  800. select the closest match for ordinal parameters.
  801. + inttostr(qword) in sysstr.inc/sysstrh.inc
  802. + abs(int64), sqr(int64), sqr(qword) in systemh.inc/generic.inc (previous
  803. fixes were required to be able to add them)
  804. * is_in_limit() moved from ncal to types unit, should always be used
  805. instead of direct comparisons of low/high values of orddefs because
  806. qword is a special case
  807. }