systemh.inc 33 KB

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