wutils.pas 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit WUtils;
  12. interface
  13. {$ifndef FPC}
  14. {$define TPUNIXLF}
  15. {$endif}
  16. uses
  17. {$ifdef win32}
  18. windows,
  19. {$endif win32}
  20. {$ifdef netwlibc}
  21. libc,
  22. {$else}
  23. {$ifdef netware}
  24. nwserv,
  25. {$endif}
  26. {$endif}
  27. {$ifdef Unix}
  28. {$ifdef VER1_0}
  29. linux,
  30. {$else}
  31. baseunix,
  32. unix,
  33. {$endif}
  34. {$endif Unix}
  35. Dos,Objects;
  36. const
  37. kbCtrlGrayPlus = $9000;
  38. kbCtrlGrayMinus = $8e00;
  39. kbCtrlGrayMul = $9600;
  40. TempFirstChar = {$ifndef Unix}'~'{$else}'_'{$endif};
  41. TempExt = '.tmp';
  42. TempNameLen = 8;
  43. EOL : String[2] = {$ifdef Unix}#10;{$else}#13#10;{$endif}
  44. type
  45. PByteArray = ^TByteArray;
  46. TByteArray = array[0..MaxBytes] of byte;
  47. PNoDisposeCollection = ^TNoDisposeCollection;
  48. TNoDisposeCollection = object(TCollection)
  49. procedure FreeItem(Item: Pointer); virtual;
  50. end;
  51. PUnsortedStringCollection = ^TUnsortedStringCollection;
  52. TUnsortedStringCollection = object(TCollection)
  53. constructor CreateFrom(ALines: PUnsortedStringCollection);
  54. procedure Assign(ALines: PUnsortedStringCollection);
  55. function At(Index: Sw_Integer): PString;
  56. procedure FreeItem(Item: Pointer); virtual;
  57. function GetItem(var S: TStream): Pointer; virtual;
  58. procedure PutItem(var S: TStream; Item: Pointer); virtual;
  59. procedure InsertStr(const S: string);
  60. end;
  61. PNulStream = ^TNulStream;
  62. TNulStream = object(TStream)
  63. constructor Init;
  64. function GetPos: Longint; virtual;
  65. function GetSize: Longint; virtual;
  66. procedure Read(var Buf; Count: Word); virtual;
  67. procedure Seek(Pos: Longint); virtual;
  68. procedure Write(var Buf; Count: Word); virtual;
  69. end;
  70. PSubStream = ^TSubStream;
  71. TSubStream = object(TStream)
  72. constructor Init(AStream: PStream; AStartPos, ASize: longint);
  73. function GetPos: Longint; virtual;
  74. function GetSize: Longint; virtual;
  75. procedure Read(var Buf; Count: Word); virtual;
  76. procedure Seek(Pos: Longint); virtual;
  77. procedure Write(var Buf; Count: Word); virtual;
  78. private
  79. StartPos: longint;
  80. S : PStream;
  81. end;
  82. PFastBufStream = ^TFastBufStream;
  83. TFastBufStream = object(TBufStream)
  84. constructor Init (FileName: FNameStr; Mode, Size: Word);
  85. procedure Seek(Pos: Longint); virtual;
  86. procedure Readline(var s:string;var linecomplete,hasCR : boolean);
  87. private
  88. BasePos: longint;
  89. end;
  90. PTextCollection = ^TTextCollection;
  91. TTextCollection = object(TStringCollection)
  92. function LookUp(const S: string; var Idx: sw_integer): string;
  93. function Compare(Key1, Key2: Pointer): sw_Integer; virtual;
  94. end;
  95. PIntCollection = ^TIntCollection;
  96. TIntCollection = object(TSortedCollection)
  97. function Compare(Key1, Key2: Pointer): sw_Integer; virtual;
  98. procedure FreeItem(Item: Pointer); virtual;
  99. procedure Add(Item: ptrint);
  100. function Contains(Item: ptrint): boolean;
  101. function AtInt(Index: sw_integer): ptrint;
  102. end;
  103. {$ifdef TPUNIXLF}
  104. procedure readln(var t:text;var s:string);
  105. {$endif}
  106. procedure ReadlnFromStream(Stream: PStream; var s:string;var linecomplete,hasCR : boolean);
  107. function eofstream(s: pstream): boolean;
  108. function Min(A,B: longint): longint;
  109. function Max(A,B: longint): longint;
  110. function CharStr(C: char; Count: integer): string;
  111. function UpcaseStr(const S: string): string;
  112. function LowCase(C: char): char;
  113. function LowcaseStr(S: string): string;
  114. function RExpand(const S: string; MinLen: byte): string;
  115. function LExpand(const S: string; MinLen: byte): string;
  116. function LTrim(const S: string): string;
  117. function RTrim(const S: string): string;
  118. function Trim(const S: string): string;
  119. function IntToStr(L: longint): string;
  120. function IntToStrL(L: longint; MinLen: sw_integer): string;
  121. function IntToStrZ(L: longint; MinLen: sw_integer): string;
  122. function StrToInt(const S: string): longint;
  123. function StrToCard(const S: string): cardinal;
  124. function FloatToStr(D: Double; Decimals: byte): string;
  125. function FloatToStrL(D: Double; Decimals: byte; MinLen: byte): string;
  126. function HexToInt(S: string): longint;
  127. function HexToCard(S: string): cardinal;
  128. function IntToHex(L: longint; MinLen: integer): string;
  129. function GetStr(P: PString): string;
  130. function GetPChar(P: PChar): string;
  131. function BoolToStr(B: boolean; const TrueS, FalseS: string): string;
  132. function LExtendString(S: string; MinLen: byte): string;
  133. function DirOf(const S: string): string;
  134. function ExtOf(const S: string): string;
  135. function NameOf(const S: string): string;
  136. function NameAndExtOf(const S: string): string;
  137. function DirAndNameOf(const S: string): string;
  138. { return Dos GetFTime value or -1 if the file does not exist }
  139. function GetFileTime(const FileName: string): longint;
  140. { copied from compiler global unit }
  141. function GetShortName(const n:string):string;
  142. function GetLongName(const n:string):string;
  143. function TrimEndSlash(const Path: string): string;
  144. function CompleteDir(const Path: string): string;
  145. function GetCurDir: string;
  146. function OptimizePath(Path: string; MaxLen: integer): string;
  147. function CompareText(S1, S2: string): integer;
  148. function ExistsDir(const DirName: string): boolean;
  149. function ExistsFile(const FileName: string): boolean;
  150. function SizeOfFile(const FileName: string): longint;
  151. function DeleteFile(const FileName: string): integer;
  152. function CopyFile(const SrcFileName, DestFileName: string): boolean;
  153. function GenTempFileName: string;
  154. function FormatPath(Path: string): string;
  155. function CompletePath(const Base, InComplete: string): string;
  156. function CompleteURL(const Base, URLRef: string): string;
  157. function EatIO: integer;
  158. function Now: longint;
  159. function FormatDateTimeL(L: longint; const Format: string): string;
  160. function FormatDateTime(const D: DateTime; const Format: string): string;
  161. {$ifdef TP}
  162. function StrPas(C: PChar): string;
  163. {$endif}
  164. function MemToStr(var B; Count: byte): string;
  165. procedure StrToMem(S: string; var B);
  166. procedure GiveUpTimeSlice;
  167. const LastStrToIntResult : integer = 0;
  168. LastHexToIntResult : integer = 0;
  169. LastStrToCardResult : integer = 0;
  170. LastHexToCardResult : integer = 0;
  171. DirSep : char = {$ifdef Unix}'/'{$else}'\'{$endif};
  172. UseOldBufStreamMethod : boolean = false;
  173. procedure RegisterWUtils;
  174. implementation
  175. uses
  176. {$IFDEF OS2}
  177. DosCalls,
  178. {$ENDIF OS2}
  179. Strings;
  180. {$ifndef NOOBJREG}
  181. const
  182. SpaceStr = ' '+
  183. ' '+
  184. ' '+
  185. ' ' ;
  186. RUnsortedStringCollection: TStreamRec = (
  187. ObjType: 22500;
  188. VmtLink: Ofs(TypeOf(TUnsortedStringCollection)^);
  189. Load: @TUnsortedStringCollection.Load;
  190. Store: @TUnsortedStringCollection.Store
  191. );
  192. {$endif}
  193. {$ifdef TPUNIXLF}
  194. procedure readln(var t:text;var s:string);
  195. var
  196. c : char;
  197. i : longint;
  198. begin
  199. if TextRec(t).UserData[1]=2 then
  200. system.readln(t,s)
  201. else
  202. begin
  203. c:=#0;
  204. i:=0;
  205. while (not eof(t)) and (c<>#10) and (i<High(S)) do
  206. begin
  207. read(t,c);
  208. if c<>#10 then
  209. begin
  210. inc(i);
  211. s[i]:=c;
  212. end;
  213. end;
  214. if (i>0) and (s[i]=#13) then
  215. begin
  216. dec(i);
  217. TextRec(t).UserData[1]:=2;
  218. end;
  219. s[0]:=chr(i);
  220. end;
  221. end;
  222. {$endif}
  223. function eofstream(s: pstream): boolean;
  224. begin
  225. eofstream:=(s^.getpos>=s^.getsize);
  226. end;
  227. procedure ReadlnFromStream(Stream: PStream; var S:string;var linecomplete,hasCR : boolean);
  228. var
  229. c : char;
  230. i,pos : longint;
  231. begin
  232. linecomplete:=false;
  233. c:=#0;
  234. i:=0;
  235. { this created problems for lines longer than 255 characters
  236. now those lines are cutted into pieces without warning PM }
  237. { changed implicit 255 to High(S), so it will be automatically extended
  238. when longstrings eventually become default - Gabor }
  239. while (not eofstream(stream)) and (c<>#10) and (i<High(S)) do
  240. begin
  241. stream^.read(c,sizeof(c));
  242. if c<>#10 then
  243. begin
  244. inc(i);
  245. s[i]:=c;
  246. end;
  247. end;
  248. { if there was a CR LF then remove the CR Dos newline style }
  249. if (i>0) and (s[i]=#13) then
  250. begin
  251. dec(i);
  252. end;
  253. if (c=#13) and (not eofstream(stream)) then
  254. stream^.read(c,sizeof(c));
  255. if (i=High(S)) and not eofstream(stream) then
  256. begin
  257. pos:=stream^.getpos;
  258. stream^.read(c,sizeof(c));
  259. if (c=#13) and not eofstream(stream) then
  260. stream^.read(c,sizeof(c));
  261. if c<>#10 then
  262. stream^.seek(pos);
  263. end;
  264. if (c=#10) or eofstream(stream) then
  265. linecomplete:=true;
  266. if (c=#10) then
  267. hasCR:=true;
  268. s[0]:=chr(i);
  269. end;
  270. {$ifdef TP}
  271. { TP's own StrPas() is buggy, because it causes GPF with strings longer than
  272. 255 chars }
  273. function StrPas(C: PChar): string;
  274. var S: string;
  275. I: longint;
  276. begin
  277. if Assigned(C)=false then
  278. S:=''
  279. else
  280. begin
  281. I:=StrLen(C); if I>High(S) then I:=High(S);
  282. S[0]:=chr(I); Move(C^,S[1],I);
  283. end;
  284. StrPas:=S;
  285. end;
  286. {$endif}
  287. function MemToStr(var B; Count: byte): string;
  288. var S: string;
  289. begin
  290. S[0]:=chr(Count);
  291. if Count>0 then Move(B,S[1],Count);
  292. MemToStr:=S;
  293. end;
  294. procedure StrToMem(S: string; var B);
  295. begin
  296. if length(S)>0 then Move(S[1],B,length(S));
  297. end;
  298. function Max(A,B: longint): longint;
  299. begin
  300. if A>B then Max:=A else Max:=B;
  301. end;
  302. function Min(A,B: longint): longint;
  303. begin
  304. if A<B then Min:=A else Min:=B;
  305. end;
  306. function CharStr(C: char; Count: integer): string;
  307. {$ifndef FPC}
  308. var S: string;
  309. {$endif}
  310. begin
  311. if Count<=0 then
  312. begin
  313. CharStr:='';
  314. exit;
  315. end
  316. else if Count>255 then
  317. Count:=255;
  318. {$ifdef FPC}
  319. CharStr[0]:=chr(Count);
  320. FillChar(CharStr[1],Count,C);
  321. {$else}
  322. S[0]:=chr(Count);
  323. FillChar(S[1],Count,C);
  324. CharStr:=S;
  325. {$endif}
  326. end;
  327. function UpcaseStr(const S: string): string;
  328. var
  329. I: Longint;
  330. begin
  331. for I:=1 to length(S) do
  332. if S[I] in ['a'..'z'] then
  333. UpCaseStr[I]:=chr(ord(S[I])-32)
  334. else
  335. UpCaseStr[I]:=S[I];
  336. UpcaseStr[0]:=S[0];
  337. end;
  338. function RExpand(const S: string; MinLen: byte): string;
  339. begin
  340. if length(S)<MinLen then
  341. RExpand:=S+CharStr(' ',MinLen-length(S))
  342. else
  343. RExpand:=S;
  344. end;
  345. function LExpand(const S: string; MinLen: byte): string;
  346. begin
  347. if length(S)<MinLen then
  348. LExpand:=CharStr(' ',MinLen-length(S))+S
  349. else
  350. LExpand:=S;
  351. end;
  352. function LTrim(const S: string): string;
  353. var
  354. i : longint;
  355. begin
  356. i:=1;
  357. while (i<length(s)) and (s[i]=' ') do
  358. inc(i);
  359. LTrim:=Copy(s,i,High(S));
  360. end;
  361. function RTrim(const S: string): string;
  362. var
  363. i : longint;
  364. begin
  365. i:=length(s);
  366. while (i>0) and (s[i]=' ') do
  367. dec(i);
  368. RTrim:=Copy(s,1,i);
  369. end;
  370. function Trim(const S: string): string;
  371. var
  372. i,j : longint;
  373. begin
  374. i:=1;
  375. while (i<length(s)) and (s[i]=' ') do
  376. inc(i);
  377. j:=length(s);
  378. while (j>0) and (s[j]=' ') do
  379. dec(j);
  380. Trim:=Copy(S,i,j-i+1);
  381. end;
  382. function IntToStr(L: longint): string;
  383. var S: string;
  384. begin
  385. Str(L,S);
  386. IntToStr:=S;
  387. end;
  388. function IntToStrL(L: longint; MinLen: sw_integer): string;
  389. begin
  390. IntToStrL:=LExpand(IntToStr(L),MinLen);
  391. end;
  392. function IntToStrZ(L: longint; MinLen: sw_integer): string;
  393. var S: string;
  394. begin
  395. S:=IntToStr(L);
  396. if length(S)<MinLen then
  397. S:=CharStr('0',MinLen-length(S))+S;
  398. IntToStrZ:=S;
  399. end;
  400. function StrToInt(const S: string): longint;
  401. var L: longint;
  402. C: integer;
  403. begin
  404. Val(S,L,C); if C<>0 then L:=-1;
  405. LastStrToIntResult:=C;
  406. StrToInt:=L;
  407. end;
  408. function StrToCard(const S: string): cardinal;
  409. var L: cardinal;
  410. C: integer;
  411. begin
  412. Val(S,L,C); if C<>0 then L:=$ffffffff;
  413. LastStrToCardResult:=C;
  414. StrToCard:=L;
  415. end;
  416. function HexToInt(S: string): longint;
  417. var L,I: longint;
  418. C: char;
  419. const HexNums: string[16] = '0123456789ABCDEF';
  420. begin
  421. S:=Trim(S); L:=0; I:=1; LastHexToIntResult:=0;
  422. while (I<=length(S)) and (LastHexToIntResult=0) do
  423. begin
  424. C:=Upcase(S[I]);
  425. if C in['0'..'9','A'..'F'] then
  426. begin
  427. L:=L*16+(Pos(C,HexNums)-1);
  428. end else LastHexToIntResult:=I;
  429. Inc(I);
  430. end;
  431. HexToInt:=L;
  432. end;
  433. function HexToCard(S: string): cardinal;
  434. var L,I: cardinal;
  435. C: char;
  436. const HexNums: string[16] = '0123456789ABCDEF';
  437. begin
  438. S:=Trim(S); L:=0; I:=1; LastHexToCardResult:=0;
  439. while (I<=length(S)) and (LastHexToCardResult=0) do
  440. begin
  441. C:=Upcase(S[I]);
  442. if C in['0'..'9','A'..'F'] then
  443. begin
  444. L:=L*16+(Pos(C,HexNums)-1);
  445. end else LastHexToCardResult:=I;
  446. Inc(I);
  447. end;
  448. HexToCard:=L;
  449. end;
  450. function IntToHex(L: longint; MinLen: integer): string;
  451. const HexNums : string[16] = '0123456789ABCDEF';
  452. var S: string;
  453. R: real;
  454. function DivF(Mit,Mivel: real): longint;
  455. begin
  456. DivF:=trunc(Mit/Mivel);
  457. end;
  458. function ModF(Mit,Mivel: real): longint;
  459. begin
  460. ModF:=trunc(Mit-DivF(Mit,Mivel)*Mivel);
  461. end;
  462. begin
  463. S:='';
  464. R:=L; if R<0 then begin R:=R+2147483647+2147483647+2; end;
  465. repeat
  466. Insert(HexNums[ModF(R,16)+1],S,1);
  467. R:=DivF(R,16);
  468. until R=0;
  469. while length(S)<MinLen do
  470. Insert('0',S,1);
  471. IntToHex:=S;
  472. end;
  473. function FloatToStr(D: Double; Decimals: byte): string;
  474. var S: string;
  475. L: byte;
  476. begin
  477. Str(D:0:Decimals,S);
  478. if length(S)>0 then
  479. while (S[1]=' ') do Delete(S,1,1);
  480. FloatToStr:=S;
  481. end;
  482. function FloatToStrL(D: Double; Decimals: byte; MinLen: byte): string;
  483. begin
  484. FloatToStrL:=LExtendString(FloatToStr(D,Decimals),MinLen);
  485. end;
  486. function LExtendString(S: string; MinLen: byte): string;
  487. begin
  488. LExtendString:=copy(SpaceStr,1,MinLen-length(S))+S;
  489. end;
  490. function GetStr(P: PString): string;
  491. begin
  492. if P=nil then GetStr:='' else GetStr:=P^;
  493. end;
  494. function GetPChar(P: PChar): string;
  495. begin
  496. if P=nil then GetPChar:='' else GetPChar:=StrPas(P);
  497. end;
  498. function DirOf(const S: string): string;
  499. var D: DirStr; E: ExtStr; N: NameStr;
  500. begin
  501. FSplit(S,D,N,E);
  502. if (D<>'') and (D[Length(D)]<>DirSep) then
  503. DirOf:=D+DirSep
  504. else
  505. DirOf:=D;
  506. end;
  507. function ExtOf(const S: string): string;
  508. var D: DirStr; E: ExtStr; N: NameStr;
  509. begin
  510. FSplit(S,D,N,E);
  511. ExtOf:=E;
  512. end;
  513. function NameOf(const S: string): string;
  514. var D: DirStr; E: ExtStr; N: NameStr;
  515. begin
  516. FSplit(S,D,N,E);
  517. NameOf:=N;
  518. end;
  519. function NameAndExtOf(const S: string): string;
  520. var D: DirStr; E: ExtStr; N: NameStr;
  521. begin
  522. FSplit(S,D,N,E);
  523. NameAndExtOf:=N+E;
  524. end;
  525. function DirAndNameOf(const S: string): string;
  526. var D: DirStr; E: ExtStr; N: NameStr;
  527. begin
  528. FSplit(S,D,N,E);
  529. DirAndNameOf:=D+N;
  530. end;
  531. { return Dos GetFTime value or -1 if the file does not exist }
  532. function GetFileTime(const FileName: string): longint;
  533. var T: longint;
  534. f: file;
  535. FM: integer;
  536. begin
  537. if FileName='' then
  538. T:=-1
  539. else
  540. begin
  541. FM:=FileMode; FileMode:=0;
  542. EatIO; Dos.DosError:=0;
  543. Assign(f,FileName);
  544. {$I-}
  545. Reset(f);
  546. if InOutRes=0 then
  547. begin
  548. GetFTime(f,T);
  549. Close(f);
  550. end;
  551. {$I+}
  552. if (EatIO<>0) or (Dos.DosError<>0) then T:=-1;
  553. FileMode:=FM;
  554. end;
  555. GetFileTime:=T;
  556. end;
  557. function GetShortName(const n:string):string;
  558. {$ifdef win32}
  559. var
  560. hs,hs2 : string;
  561. i : longint;
  562. {$endif}
  563. {$ifdef go32v2}
  564. var
  565. hs : string;
  566. {$endif}
  567. begin
  568. GetShortName:=n;
  569. {$ifdef win32}
  570. hs:=n+#0;
  571. i:=Windows.GetShortPathName(@hs[1],@hs2[1],high(hs2));
  572. if (i>0) and (i<=high(hs2)) then
  573. begin
  574. hs2[0]:=chr(strlen(@hs2[1]));
  575. GetShortName:=hs2;
  576. end;
  577. {$endif}
  578. {$ifdef go32v2}
  579. hs:=n;
  580. if Dos.GetShortName(hs) then
  581. GetShortName:=hs;
  582. {$endif}
  583. end;
  584. function GetLongName(const n:string):string;
  585. {$ifdef win32}
  586. var
  587. hs : string;
  588. hs2 : Array [0..255] of char;
  589. i : longint;
  590. j : pchar;
  591. {$endif}
  592. {$ifdef go32v2}
  593. var
  594. hs : string;
  595. {$endif}
  596. begin
  597. GetLongName:=n;
  598. {$ifdef win32}
  599. hs:=n+#0;
  600. i:=Windows.GetFullPathName(@hs[1],256,hs2,j);
  601. if (i>0) and (i<=high(hs)) then
  602. begin
  603. hs:=strpas(hs2);
  604. GetLongName:=hs;
  605. end;
  606. {$endif}
  607. {$ifdef go32v2}
  608. hs:=n;
  609. if Dos.GetLongName(hs) then
  610. GetLongName:=hs;
  611. {$endif}
  612. end;
  613. function EatIO: integer;
  614. begin
  615. EatIO:=IOResult;
  616. end;
  617. function LowCase(C: char): char;
  618. begin
  619. if ('A'<=C) and (C<='Z') then C:=chr(ord(C)+32);
  620. LowCase:=C;
  621. end;
  622. function LowcaseStr(S: string): string;
  623. var I: Longint;
  624. begin
  625. for I:=1 to length(S) do
  626. S[I]:=Lowcase(S[I]);
  627. LowcaseStr:=S;
  628. end;
  629. function BoolToStr(B: boolean; const TrueS, FalseS: string): string;
  630. begin
  631. if B then BoolToStr:=TrueS else BoolToStr:=FalseS;
  632. end;
  633. procedure TNoDisposeCollection.FreeItem(Item: Pointer);
  634. begin
  635. { don't do anything here }
  636. end;
  637. constructor TUnsortedStringCollection.CreateFrom(ALines: PUnsortedStringCollection);
  638. begin
  639. if Assigned(ALines)=false then Fail;
  640. inherited Init(ALines^.Count,ALines^.Count div 10);
  641. Assign(ALines);
  642. end;
  643. procedure TUnsortedStringCollection.Assign(ALines: PUnsortedStringCollection);
  644. procedure AddIt(P: PString); {$ifndef FPC}far;{$endif}
  645. begin
  646. Insert(NewStr(GetStr(P)));
  647. end;
  648. begin
  649. FreeAll;
  650. if Assigned(ALines) then
  651. ALines^.ForEach(@AddIt);
  652. end;
  653. procedure TUnsortedStringCollection.InsertStr(const S: string);
  654. begin
  655. Insert(NewStr(S));
  656. end;
  657. function TUnsortedStringCollection.At(Index: Sw_Integer): PString;
  658. begin
  659. At:=inherited At(Index);
  660. end;
  661. procedure TUnsortedStringCollection.FreeItem(Item: Pointer);
  662. begin
  663. if Item<>nil then DisposeStr(Item);
  664. end;
  665. function TUnsortedStringCollection.GetItem(var S: TStream): Pointer;
  666. begin
  667. GetItem:=S.ReadStr;
  668. end;
  669. procedure TUnsortedStringCollection.PutItem(var S: TStream; Item: Pointer);
  670. begin
  671. S.WriteStr(Item);
  672. end;
  673. function TIntCollection.Contains(Item: ptrint): boolean;
  674. var Index: sw_integer;
  675. begin
  676. Contains:=Search(pointer(Item),Index);
  677. end;
  678. function TIntCollection.AtInt(Index: sw_integer): ptrint;
  679. begin
  680. AtInt:=longint(At(Index));
  681. end;
  682. procedure TIntCollection.Add(Item: ptrint);
  683. begin
  684. Insert(pointer(Item));
  685. end;
  686. function TIntCollection.Compare(Key1, Key2: Pointer): sw_Integer;
  687. var K1: longint absolute Key1;
  688. K2: longint absolute Key2;
  689. R: integer;
  690. begin
  691. if K1<K2 then R:=-1 else
  692. if K1>K2 then R:= 1 else
  693. R:=0;
  694. Compare:=R;
  695. end;
  696. procedure TIntCollection.FreeItem(Item: Pointer);
  697. begin
  698. { do nothing here }
  699. end;
  700. constructor TNulStream.Init;
  701. begin
  702. inherited Init;
  703. Position:=0;
  704. end;
  705. function TNulStream.GetPos: Longint;
  706. begin
  707. GetPos:=Position;
  708. end;
  709. function TNulStream.GetSize: Longint;
  710. begin
  711. GetSize:=Position;
  712. end;
  713. procedure TNulStream.Read(var Buf; Count: Word);
  714. begin
  715. Error(stReadError,0);
  716. end;
  717. procedure TNulStream.Seek(Pos: Longint);
  718. begin
  719. if Pos<=Position then
  720. Position:=Pos;
  721. end;
  722. procedure TNulStream.Write(var Buf; Count: Word);
  723. begin
  724. Inc(Position,Count);
  725. end;
  726. constructor TSubStream.Init(AStream: PStream; AStartPos, ASize: longint);
  727. begin
  728. inherited Init;
  729. if Assigned(AStream)=false then Fail;
  730. S:=AStream; StartPos:=AStartPos; StreamSize:=ASize;
  731. Seek(0);
  732. end;
  733. function TSubStream.GetPos: Longint;
  734. var Pos: longint;
  735. begin
  736. Pos:=S^.GetPos; Dec(Pos,StartPos);
  737. GetPos:=Pos;
  738. end;
  739. function TSubStream.GetSize: Longint;
  740. begin
  741. GetSize:=StreamSize;
  742. end;
  743. procedure TSubStream.Read(var Buf; Count: Word);
  744. var Pos: longint;
  745. RCount: word;
  746. begin
  747. Pos:=GetPos;
  748. if Pos+Count>StreamSize then RCount:=StreamSize-Pos else RCount:=Count;
  749. S^.Read(Buf,RCount);
  750. if RCount<Count then
  751. Error(stReadError,0);
  752. end;
  753. procedure TSubStream.Seek(Pos: Longint);
  754. var RPos: longint;
  755. begin
  756. if (Pos<=StreamSize) then RPos:=Pos else RPos:=StreamSize;
  757. S^.Seek(StartPos+RPos);
  758. end;
  759. procedure TSubStream.Write(var Buf; Count: Word);
  760. begin
  761. S^.Write(Buf,Count);
  762. end;
  763. constructor TFastBufStream.Init (FileName: FNameStr; Mode, Size: Word);
  764. begin
  765. Inherited Init(FileName,Mode,Size);
  766. BasePos:=0;
  767. end;
  768. procedure TFastBufStream.Seek(Pos: Longint);
  769. var RelOfs: longint;
  770. begin
  771. RelOfs:=Pos-BasePos;
  772. if (RelOfs<0) or (RelOfs>=BufEnd) or (BufEnd=0) then
  773. begin
  774. inherited Seek(Pos);
  775. BasePos:=Pos-BufPtr;
  776. end
  777. else
  778. begin
  779. BufPtr:=RelOfs;
  780. Position:=Pos;
  781. end;
  782. end;
  783. procedure TFastBufStream.Readline(var s:string;var linecomplete,hasCR : boolean);
  784. var
  785. c : char;
  786. i,pos,StartPos : longint;
  787. charsInS : boolean;
  788. begin
  789. linecomplete:=false;
  790. c:=#0;
  791. i:=0;
  792. { this created problems for lines longer than 255 characters
  793. now those lines are cutted into pieces without warning PM }
  794. { changed implicit 255 to High(S), so it will be automatically extended
  795. when longstrings eventually become default - Gabor }
  796. if (bufend-bufptr>=High(S)) and (getpos+High(S)<getsize) then
  797. begin
  798. StartPos:=GetPos;
  799. //read(S[1],High(S));
  800. system.move(buffer^[bufptr],S[1],High(S));
  801. charsInS:=true;
  802. end
  803. else
  804. CharsInS:=false;
  805. while (CharsInS or not (getpos>=getsize)) and
  806. (c<>#10) and (i<High(S)) do
  807. begin
  808. if CharsInS then
  809. c:=s[i+1]
  810. else
  811. read(c,sizeof(c));
  812. if c<>#10 then
  813. begin
  814. inc(i);
  815. if not CharsInS then
  816. s[i]:=c;
  817. end;
  818. end;
  819. if CharsInS then
  820. begin
  821. if c=#10 then
  822. Seek(StartPos+i+1)
  823. else
  824. Seek(StartPos+i);
  825. end;
  826. { if there was a CR LF then remove the CR Dos newline style }
  827. if (i>0) and (s[i]=#13) then
  828. begin
  829. dec(i);
  830. end;
  831. if (c=#13) and (not (getpos>=getsize)) then
  832. begin
  833. read(c,sizeof(c));
  834. end;
  835. if (i=High(S)) and not (getpos>=getsize) then
  836. begin
  837. pos:=getpos;
  838. read(c,sizeof(c));
  839. if (c=#13) and not (getpos>=getsize) then
  840. read(c,sizeof(c));
  841. if c<>#10 then
  842. seek(pos);
  843. end;
  844. if (c=#10) or (getpos>=getsize) then
  845. linecomplete:=true;
  846. if (c=#10) then
  847. hasCR:=true;
  848. s[0]:=chr(i);
  849. end;
  850. function TTextCollection.Compare(Key1, Key2: Pointer): Sw_Integer;
  851. var K1: PString absolute Key1;
  852. K2: PString absolute Key2;
  853. R: Sw_integer;
  854. S1,S2: string;
  855. begin
  856. S1:=UpCaseStr(K1^);
  857. S2:=UpCaseStr(K2^);
  858. if S1<S2 then R:=-1 else
  859. if S1>S2 then R:=1 else
  860. R:=0;
  861. Compare:=R;
  862. end;
  863. function TTextCollection.LookUp(const S: string; var Idx: sw_integer): string;
  864. var OLI,ORI,Left,Right,Mid: integer;
  865. {LeftP,RightP,}MidP: PString;
  866. {LeftS,}MidS{,RightS}: string;
  867. FoundS: string;
  868. UpS : string;
  869. begin
  870. Idx:=-1; FoundS:='';
  871. Left:=0; Right:=Count-1;
  872. UpS:=UpCaseStr(S);
  873. while Left<=Right do
  874. begin
  875. OLI:=Left; ORI:=Right;
  876. Mid:=Left+(Right-Left) div 2;
  877. MidP:=At(Mid);
  878. MidS:=UpCaseStr(MidP^);
  879. if copy(MidS,1,length(UpS))=UpS then
  880. begin
  881. Idx:=Mid; FoundS:=GetStr(MidP);
  882. { exit immediately if exact match PM }
  883. If Length(MidS)=Length(UpS) then
  884. break;
  885. end;
  886. if UpS<MidS then
  887. Right:=Mid
  888. else
  889. Left:=Mid;
  890. if (OLI=Left) and (ORI=Right) then
  891. begin
  892. if (Left<Right) then
  893. Left:=Right
  894. else
  895. Break;
  896. end;
  897. end;
  898. LookUp:=FoundS;
  899. end;
  900. function TrimEndSlash(const Path: string): string;
  901. var S: string;
  902. begin
  903. S:=Path;
  904. if (length(S)>0) and (S<>DirSep) and (copy(S,length(S),1)=DirSep) and
  905. (S[length(S)-1]<>':') then
  906. S:=copy(S,1,length(S)-1);
  907. TrimEndSlash:=S;
  908. end;
  909. function CompareText(S1, S2: string): integer;
  910. var R: integer;
  911. begin
  912. S1:=UpcaseStr(S1); S2:=UpcaseStr(S2);
  913. if S1<S2 then R:=-1 else
  914. if S1>S2 then R:= 1 else
  915. R:=0;
  916. CompareText:=R;
  917. end;
  918. function FormatPath(Path: string): string;
  919. var P: sw_integer;
  920. SC: char;
  921. begin
  922. if ord(DirSep)=ord('/') then
  923. SC:='\'
  924. else
  925. SC:='/';
  926. repeat
  927. P:=Pos(SC,Path);
  928. if P>0 then Path[P]:=DirSep;
  929. until P=0;
  930. FormatPath:=Path;
  931. end;
  932. function CompletePath(const Base, InComplete: string): string;
  933. var Drv,BDrv: string[40]; D,BD: DirStr; N,BN: NameStr; E,BE: ExtStr;
  934. P: sw_integer;
  935. Complete: string;
  936. begin
  937. Complete:=FormatPath(InComplete);
  938. FSplit(FormatPath(InComplete),D,N,E);
  939. P:=Pos(':',D); if P=0 then Drv:='' else begin Drv:=copy(D,1,P); Delete(D,1,P); end;
  940. FSplit(FormatPath(Base),BD,BN,BE);
  941. P:=Pos(':',BD); if P=0 then BDrv:='' else begin BDrv:=copy(BD,1,P); Delete(BD,1,P); end;
  942. if copy(D,1,1)<>DirSep then
  943. Complete:=BD+D+N+E;
  944. if Drv='' then
  945. Complete:=BDrv+Complete;
  946. Complete:=FExpand(Complete);
  947. CompletePath:=Complete;
  948. end;
  949. function CompleteURL(const Base, URLRef: string): string;
  950. var P: integer;
  951. Drive: string[20];
  952. IsComplete: boolean;
  953. S: string;
  954. Ref: string;
  955. Bookmark: string;
  956. begin
  957. IsComplete:=false; Ref:=URLRef;
  958. P:=Pos(':',Ref);
  959. if P=0 then Drive:='' else Drive:=UpcaseStr(copy(Ref,1,P-1));
  960. if Drive<>'' then
  961. if (Drive='MAILTO') or (Drive='FTP') or (Drive='HTTP') or
  962. (Drive='GOPHER') or (Drive='FILE') then
  963. IsComplete:=true;
  964. if IsComplete then S:=Ref else
  965. begin
  966. P:=Pos('#',Ref);
  967. if P=0 then
  968. Bookmark:=''
  969. else
  970. begin
  971. Bookmark:=copy(Ref,P+1,length(Ref));
  972. Ref:=copy(Ref,1,P-1);
  973. end;
  974. S:=CompletePath(Base,Ref);
  975. if Bookmark<>'' then
  976. S:=S+'#'+Bookmark;
  977. end;
  978. CompleteURL:=S;
  979. end;
  980. function OptimizePath(Path: string; MaxLen: integer): string;
  981. var i : integer;
  982. BackSlashs : array[1..20] of integer;
  983. BSCount : integer;
  984. Jobbra : boolean;
  985. Jobb, Bal : byte;
  986. Hiba : boolean;
  987. begin
  988. if length(Path)>MaxLen then
  989. begin
  990. BSCount:=0; Jobbra:=true;
  991. for i:=1 to length(Path) do if Path[i]=DirSep then
  992. begin
  993. Inc(BSCount);
  994. BackSlashs[BSCount]:=i;
  995. end;
  996. i:=BSCount div 2;
  997. Hiba:=false;
  998. Bal:=i; Jobb:=i+1;
  999. case i of 0 : ;
  1000. 1 : Path:=copy(Path, 1, BackSlashs[1])+'..'+
  1001. copy(Path, BackSlashs[2], length(Path));
  1002. else begin
  1003. while (BackSlashs[Bal]+(length(Path)-BackSlashs[Jobb]) >=
  1004. MaxLen) and not Hiba do
  1005. begin
  1006. if Jobbra then begin
  1007. if Jobb<BSCount then inc(Jobb)
  1008. else Hiba:=true;
  1009. Jobbra:=false;
  1010. end
  1011. else begin
  1012. if Bal>1 then dec(Bal)
  1013. else Hiba:=true;
  1014. Jobbra:=true;
  1015. end;
  1016. end;
  1017. Path:=copy(Path, 1, BackSlashs[Bal])+'..'+
  1018. copy(Path, BackSlashs[Jobb], length(Path));
  1019. end;
  1020. end;
  1021. end;
  1022. if length(Path)>MaxLen then
  1023. begin
  1024. i:=Pos('\..\',Path);
  1025. if i>0 then Path:=copy(Path,1,i-1)+'..'+copy(Path,i+length('\..\'),length(Path));
  1026. end;
  1027. OptimizePath:=Path;
  1028. end;
  1029. function Now: longint;
  1030. var D: DateTime;
  1031. W: word;
  1032. L: longint;
  1033. begin
  1034. FillChar(D,sizeof(D),0);
  1035. GetDate(D.Year,D.Month,D.Day,W);
  1036. GetTime(D.Hour,D.Min,D.Sec,W);
  1037. PackTime(D,L);
  1038. Now:=L;
  1039. end;
  1040. function FormatDateTimeL(L: longint; const Format: string): string;
  1041. var D: DateTime;
  1042. begin
  1043. UnpackTime(L,D);
  1044. FormatDateTimeL:=FormatDateTime(D,Format);
  1045. end;
  1046. function FormatDateTime(const D: DateTime; const Format: string): string;
  1047. var I: sw_integer;
  1048. CurCharStart: sw_integer;
  1049. CurChar: char;
  1050. CurCharCount: integer;
  1051. DateS: string;
  1052. C: char;
  1053. procedure FlushChars;
  1054. var S: string;
  1055. I: sw_integer;
  1056. begin
  1057. S:='';
  1058. for I:=1 to CurCharCount do
  1059. S:=S+CurChar;
  1060. case CurChar of
  1061. 'y' : S:=IntToStrL(D.Year,length(S));
  1062. 'm' : S:=IntToStrZ(D.Month,length(S));
  1063. 'd' : S:=IntToStrZ(D.Day,length(S));
  1064. 'h' : S:=IntToStrZ(D.Hour,length(S));
  1065. 'n' : S:=IntToStrZ(D.Min,length(S));
  1066. 's' : S:=IntToStrZ(D.Sec,length(S));
  1067. end;
  1068. DateS:=DateS+S;
  1069. end;
  1070. begin
  1071. DateS:='';
  1072. CurCharStart:=-1; CurCharCount:=0; CurChar:=#0;
  1073. for I:=1 to length(Format) do
  1074. begin
  1075. C:=Format[I];
  1076. if (C<>CurChar) or (CurCharStart=-1) then
  1077. begin
  1078. if CurCharStart<>-1 then FlushChars;
  1079. CurCharCount:=1; CurCharStart:=I;
  1080. end
  1081. else
  1082. Inc(CurCharCount);
  1083. CurChar:=C;
  1084. end;
  1085. FlushChars;
  1086. FormatDateTime:=DateS;
  1087. end;
  1088. function DeleteFile(const FileName: string): integer;
  1089. var f: file;
  1090. begin
  1091. {$I-}
  1092. Assign(f,FileName);
  1093. Erase(f);
  1094. DeleteFile:=EatIO;
  1095. {$I+}
  1096. end;
  1097. function ExistsFile(const FileName: string): boolean;
  1098. var
  1099. Dir : SearchRec;
  1100. begin
  1101. Dos.FindFirst(FileName,Archive+ReadOnly,Dir);
  1102. ExistsFile:=(Dos.DosError=0);
  1103. {$ifdef FPC}
  1104. Dos.FindClose(Dir);
  1105. {$endif def FPC}
  1106. end;
  1107. { returns zero for empty and non existant files }
  1108. function SizeOfFile(const FileName: string): longint;
  1109. var
  1110. Dir : SearchRec;
  1111. begin
  1112. Dos.FindFirst(FileName,Archive+ReadOnly,Dir);
  1113. if (Dos.DosError=0) then
  1114. SizeOfFile:=Dir.Size
  1115. else
  1116. SizeOfFile:=0;
  1117. {$ifdef FPC}
  1118. Dos.FindClose(Dir);
  1119. {$endif def FPC}
  1120. end;
  1121. function ExistsDir(const DirName: string): boolean;
  1122. var
  1123. Dir : SearchRec;
  1124. begin
  1125. Dos.FindFirst(TrimEndSlash(DirName),Directory,Dir);
  1126. { if a file is found it is also reported
  1127. at least for some Dos version
  1128. so we need to check the attributes PM }
  1129. ExistsDir:=(Dos.DosError=0) and ((Dir.attr and Directory) <> 0);
  1130. {$ifdef FPC}
  1131. Dos.FindClose(Dir);
  1132. {$endif def FPC}
  1133. end;
  1134. function CompleteDir(const Path: string): string;
  1135. begin
  1136. { keep c: untouched PM }
  1137. if (Path<>'') and (Path[Length(Path)]<>DirSep) and
  1138. (Path[Length(Path)]<>':') then
  1139. CompleteDir:=Path+DirSep
  1140. else
  1141. CompleteDir:=Path;
  1142. end;
  1143. function GetCurDir: string;
  1144. var S: string;
  1145. begin
  1146. GetDir(0,S);
  1147. if copy(S,length(S),1)<>DirSep then S:=S+DirSep;
  1148. GetCurDir:=S;
  1149. end;
  1150. function GenTempFileName: string;
  1151. var Dir: string;
  1152. Name: string;
  1153. I: integer;
  1154. OK: boolean;
  1155. Path: string;
  1156. begin
  1157. Dir:=GetEnv('TEMP');
  1158. if Dir='' then Dir:=GetEnv('TMP');
  1159. if (Dir<>'') then if not ExistsDir(Dir) then Dir:='';
  1160. if Dir='' then Dir:=GetCurDir;
  1161. repeat
  1162. Name:=TempFirstChar;
  1163. for I:=2 to TempNameLen do
  1164. Name:=Name+chr(ord('a')+random(ord('z')-ord('a')+1));
  1165. Name:=Name+TempExt;
  1166. Path:=CompleteDir(Dir)+Name;
  1167. OK:=not ExistsFile(Path);
  1168. until OK;
  1169. GenTempFileName:=Path;
  1170. end;
  1171. function CopyFile(const SrcFileName, DestFileName: string): boolean;
  1172. var SrcF,DestF: PBufStream;
  1173. OK: boolean;
  1174. begin
  1175. SrcF:=nil; DestF:=nil;
  1176. New(SrcF, Init(SrcFileName,stOpenRead,4096));
  1177. OK:=Assigned(SrcF) and (SrcF^.Status=stOK);
  1178. if OK then
  1179. begin
  1180. New(DestF, Init(DestFileName,stCreate,1024));
  1181. OK:=Assigned(DestF) and (DestF^.Status=stOK);
  1182. end;
  1183. if OK then DestF^.CopyFrom(SrcF^,SrcF^.GetSize);
  1184. if Assigned(DestF) then Dispose(DestF, Done);
  1185. if Assigned(SrcF) then Dispose(SrcF, Done);
  1186. CopyFile:=OK;
  1187. end;
  1188. procedure GiveUpTimeSlice;
  1189. {$ifdef GO32V2}{$define DOS}{$endif}
  1190. {$ifdef TP}{$define DOS}{$endif}
  1191. {$ifdef DOS}
  1192. var r: registers;
  1193. begin
  1194. Intr ($28, R); (* This is supported everywhere. *)
  1195. r.ax:=$1680;
  1196. intr($2f,r);
  1197. end;
  1198. {$endif}
  1199. {$ifdef Unix}
  1200. var
  1201. req,rem : timespec;
  1202. begin
  1203. req.tv_sec:=0;
  1204. req.tv_nsec:=10000000;{ 10 ms }
  1205. {$ifdef ver1_0}nanosleep(req,rem){$else}fpnanosleep(@req,@rem){$endif};
  1206. end;
  1207. {$endif}
  1208. {$IFDEF OS2}
  1209. begin
  1210. DosSleep (5);
  1211. end;
  1212. {$ENDIF}
  1213. {$ifdef Win32}
  1214. begin
  1215. { if the return value of this call is non zero then
  1216. it means that a ReadFileEx or WriteFileEx have completed
  1217. unused for now ! }
  1218. { wait for 10 ms }
  1219. if SleepEx(10,true)=WAIT_IO_COMPLETION then
  1220. begin
  1221. { here we should handle the completion of the routines
  1222. if we use them }
  1223. end;
  1224. end;
  1225. {$endif}
  1226. {$undef DOS}
  1227. {$ifdef netwlibc} {$define netware} {$endif}
  1228. {$ifdef netware}
  1229. begin
  1230. Delay (10);
  1231. end;
  1232. {$endif}
  1233. procedure RegisterWUtils;
  1234. begin
  1235. {$ifndef NOOBJREG}
  1236. RegisterType(RUnsortedStringCollection);
  1237. {$endif}
  1238. end;
  1239. BEGIN
  1240. Randomize;
  1241. END.
  1242. {
  1243. $Log$
  1244. Revision 1.20 2004-12-19 20:31:16 hajny
  1245. * GiveUpTimeSlice for Dos improved for better cooperation with some TSRs on plain DOS
  1246. Revision 1.19 2004/12/19 13:55:42 florian
  1247. * x86_64 compilation fixed
  1248. Revision 1.18 2004/09/16 22:08:13 armin
  1249. * added target netwlibc
  1250. Revision 1.17 2003/09/27 14:03:45 peter
  1251. * fixed for unix
  1252. Revision 1.16 2002/09/11 12:10:03 pierre
  1253. * fix bug in new readline method on line overflow
  1254. Revision 1.15 2002/09/11 08:30:38 pierre
  1255. * avoid a lot of useless calls in readline method
  1256. Revision 1.14 2002/09/10 12:19:14 pierre
  1257. * use faster method for loading files by default
  1258. Revision 1.13 2002/09/09 06:58:27 pierre
  1259. + FastBufStream.readline method added
  1260. Revision 1.12 2002/09/07 15:40:50 peter
  1261. * old logs removed and tabs fixed
  1262. Revision 1.11 2002/09/06 09:53:53 pierre
  1263. * explicitly set BasePos to zero in TFastBufStream constructor
  1264. Revision 1.10 2002/08/29 07:59:46 pierre
  1265. CVS: Enter log comment for commit
  1266. + SizeOfFile function added
  1267. Revision 1.9 2002/05/13 13:44:33 peter
  1268. * fixed range error
  1269. Revision 1.8 2002/04/02 13:23:02 pierre
  1270. + HextToCard StrToCard new functions
  1271. Revision 1.7 2002/03/22 16:43:27 pierre
  1272. * avoid that constructor is proposed for code complete if const is given
  1273. Revision 1.6 2002/03/20 13:48:31 pierre
  1274. * avoid stack corruption in CharStr if count > 255
  1275. }