histlist.inc 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. {********[ SOURCE FILE OF GRAPHICAL FREE VISION ]**********}
  2. { }
  3. { System independent GRAPHICAL clone of HISTLIST.PAS }
  4. { }
  5. { Interface Copyright (c) 1992 Borland International }
  6. { }
  7. { Copyright (c) 1996, 1997, 1998, 1999 by Leon de Boer }
  8. { [email protected] - primary e-mail address }
  9. { [email protected] - backup e-mail address }
  10. { }
  11. {****************[ THIS CODE IS FREEWARE ]*****************}
  12. { }
  13. { This sourcecode is released for the purpose to }
  14. { promote the pascal language on all platforms. You may }
  15. { redistribute it and/or modify with the following }
  16. { DISCLAIMER. }
  17. { }
  18. { This SOURCE CODE is distributed "AS IS" WITHOUT }
  19. { WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR }
  20. { ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. }
  21. { }
  22. {*****************[ SUPPORTED PLATFORMS ]******************}
  23. { 16 and 32 Bit compilers }
  24. { DOS - Turbo Pascal 7.0 + (16 Bit) }
  25. { DPMI - Turbo Pascal 7.0 + (16 Bit) }
  26. { - FPC 0.9912+ (GO32V2) (32 Bit) }
  27. { WINDOWS - Turbo Pascal 7.0 + (16 Bit) }
  28. { - Delphi 1.0+ (16 Bit) }
  29. { WIN95/NT - Delphi 2.0+ (32 Bit) }
  30. { - Virtual Pascal 2.0+ (32 Bit) }
  31. { - Speedsoft Sybil 2.0+ (32 Bit) }
  32. { - FPC 0.9912+ (32 Bit) }
  33. { OS2 - Virtual Pascal 1.0+ (32 Bit) }
  34. { }
  35. {******************[ REVISION HISTORY ]********************}
  36. { Version Date Fix }
  37. { ------- --------- --------------------------------- }
  38. { 1.00 11 Nov 96 First DOS/DPMI platform release. }
  39. { 1.10 13 Jul 97 Windows platform code added. }
  40. { 1.20 29 Aug 97 Platform.inc sort added. }
  41. { 1.30 13 Oct 97 Delphi 2 32 bit code added. }
  42. { 1.40 05 May 98 Virtual pascal 2.0 code added. }
  43. { 1.50 30 Sep 99 Complete recheck preformed }
  44. { 1.51 03 Nov 99 FPC windows support added }
  45. {**********************************************************}
  46. {$IFNDEF FPC_DOTTEDUNITS}
  47. {$ifdef FV_UNICODE}
  48. UNIT UHistList;
  49. {$else FV_UNICODE}
  50. UNIT HistList;
  51. {$endif FV_UNICODE}
  52. {$ENDIF FPC_DOTTEDUNITS}
  53. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  54. INTERFACE
  55. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  56. {====Include file to sort compiler platform out =====================}
  57. {$I platform.inc}
  58. {====================================================================}
  59. {==== Compiler directives ===========================================}
  60. {$IFNDEF PPC_FPC}{ FPC doesn't support these switches }
  61. {$F-} { Short calls are okay }
  62. {$A+} { Word Align Data }
  63. {$B-} { Allow short circuit boolean evaluations }
  64. {$O+} { This unit may be overlaid }
  65. {$G+} { 286 Code optimization - if you're on an 8088 get a real computer }
  66. {$P-} { Normal string variables }
  67. {$N-} { No 80x87 code generation }
  68. {$E+} { Emulation is on }
  69. {$ENDIF}
  70. {$X+} { Extended syntax is ok }
  71. {$R-} { Disable range checking }
  72. {$S-} { Disable Stack Checking }
  73. {$I-} { Disable IO Checking }
  74. {$Q-} { Disable Overflow Checking }
  75. {$V-} { Turn off strict VAR strings }
  76. {====================================================================}
  77. {$IFDEF FPC_DOTTEDUNITS}
  78. USES
  79. {$ifdef FV_UNICODE}
  80. FreeVision.Ufvcommon,
  81. {$else FV_UNICODE}
  82. FreeVision.Fvcommon,
  83. {$endif FV_UNICODE}
  84. System.Objects; { Standard GFV units }
  85. {$ELSE FPC_DOTTEDUNITS}
  86. USES
  87. {$ifdef FV_UNICODE}
  88. UFVCommon,
  89. {$else FV_UNICODE}
  90. FVCommon,
  91. {$endif FV_UNICODE}
  92. Objects; { Standard GFV units }
  93. {$ENDIF FPC_DOTTEDUNITS}
  94. {***************************************************************************}
  95. { INTERFACE ROUTINES }
  96. {***************************************************************************}
  97. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  98. { HISTORY SYSTEM CONTROL ROUTINES }
  99. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  100. {-InitHistory--------------------------------------------------------
  101. Initializes the history system usually called from Application.Init
  102. 30Sep99 LdB
  103. ---------------------------------------------------------------------}
  104. PROCEDURE InitHistory;
  105. {-DoneHistory--------------------------------------------------------
  106. Destroys the history system usually called from Application.Done
  107. 30Sep99 LdB
  108. ---------------------------------------------------------------------}
  109. PROCEDURE DoneHistory;
  110. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  111. { HISTORY ITEM ROUTINES }
  112. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  113. {-HistoryCount-------------------------------------------------------
  114. Returns the number of strings in the history list with ID number Id.
  115. 30Sep99 LdB
  116. ---------------------------------------------------------------------}
  117. FUNCTION HistoryCount (Id: Byte): Word;
  118. {-HistoryStr---------------------------------------------------------
  119. Returns the Index'th string in the history list with ID number Id.
  120. 30Sep99 LdB
  121. ---------------------------------------------------------------------}
  122. FUNCTION HistoryStr (Id: Byte; Index: Sw_Integer): Sw_String;
  123. {-ClearHistory-------------------------------------------------------
  124. Removes all strings from all history lists.
  125. 30Sep99 LdB
  126. ---------------------------------------------------------------------}
  127. PROCEDURE ClearHistory;
  128. {-HistoryAdd---------------------------------------------------------
  129. Adds the string Str to the history list indicated by Id.
  130. 30Sep99 LdB
  131. ---------------------------------------------------------------------}
  132. PROCEDURE HistoryAdd (Id: Byte; Const Str: Sw_String);
  133. function HistoryRemove(Id: Byte; Index: Sw_Integer): boolean;
  134. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  135. { HISTORY STREAM STORAGE AND RETREIVAL ROUTINES }
  136. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  137. {-LoadHistory--------------------------------------------------------
  138. Reads the application's history block from the stream S by reading the
  139. size of the block, then the block itself. Sets HistoryUsed to the end
  140. of the block read. Use LoadHistory to restore a history block saved
  141. with StoreHistory
  142. 30Sep99 LdB
  143. ---------------------------------------------------------------------}
  144. PROCEDURE LoadHistory (Var S: TStream);
  145. {-StoreHistory--------------------------------------------------------
  146. Writes the currently used portion of the history block to the stream
  147. S, first writing the length of the block then the block itself. Use
  148. the LoadHistory procedure to restore the history block.
  149. 30Sep99 LdB
  150. ---------------------------------------------------------------------}
  151. PROCEDURE StoreHistory (Var S: TStream);
  152. {***************************************************************************}
  153. { INITIALIZED PUBLIC VARIABLES }
  154. {***************************************************************************}
  155. {---------------------------------------------------------------------------}
  156. { INITIALIZED DOS/DPMI/WIN/NT/OS2 VARIABLES }
  157. {---------------------------------------------------------------------------}
  158. CONST
  159. HistorySize: sw_integer = 64*1024; { Maximum history size }
  160. HistoryUsed: sw_integer = 0; { History used }
  161. HistoryBlock: Pointer = Nil; { Storage block }
  162. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  163. IMPLEMENTATION
  164. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  165. {***************************************************************************}
  166. { PRIVATE RECORD DEFINITIONS }
  167. {***************************************************************************}
  168. {---------------------------------------------------------------------------}
  169. { THistRec RECORD DEFINITION
  170. Zero 1 byte, start marker
  171. Id 1 byte, History id
  172. $ifdef FV_UNICODE
  173. <utf8string> uleb128 length+utf8 string data
  174. $else FV_UNICODE
  175. <shortstring> 1 byte length+string data, Contents
  176. $endif FV_UNICODE
  177. }
  178. {***************************************************************************}
  179. { UNINITIALIZED PRIVATE VARIABLES }
  180. {***************************************************************************}
  181. {---------------------------------------------------------------------------}
  182. { UNINITIALIZED DOS/DPMI/WIN/NT/OS2 VARIABLES }
  183. {---------------------------------------------------------------------------}
  184. VAR
  185. CurId: Byte; { Current history id }
  186. {$ifdef FV_UNICODE}
  187. CurString: Pointer; { Current string }
  188. {$else FV_UNICODE}
  189. CurString: PString; { Current string }
  190. {$endif FV_UNICODE}
  191. {***************************************************************************}
  192. { PRIVATE UNIT ROUTINES }
  193. {***************************************************************************}
  194. {---------------------------------------------------------------------------}
  195. { StartId -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  196. {---------------------------------------------------------------------------}
  197. PROCEDURE StartId (Id: Byte);
  198. BEGIN
  199. CurId := Id; { Set current id }
  200. CurString := HistoryBlock; { Set current string }
  201. END;
  202. {$ifdef FV_UNICODE}
  203. {---------------------------------------------------------------------------}
  204. { DecodeSizeUInt }
  205. {---------------------------------------------------------------------------}
  206. FUNCTION DecodeSizeUInt(var P: PByte): SizeUInt;
  207. VAR Shift: Byte;
  208. BEGIN
  209. Shift := 0;
  210. Result := 0;
  211. repeat
  212. Result := Result or ((P^ and 127) shl Shift);
  213. Inc(Shift, 7);
  214. Inc(P);
  215. until ((P-1)^ and 128) = 0;
  216. END;
  217. { stored string length (including size bytes) }
  218. FUNCTION StoredStringSize(P: PByte): SizeUInt;
  219. VAR Len: SizeUInt; OrigP: PByte;
  220. BEGIN
  221. OrigP := P;
  222. Len := DecodeSizeUInt(P);
  223. Result := Len + (P - OrigP);
  224. END;
  225. {---------------------------------------------------------------------------}
  226. { EncodeSizeUInt }
  227. {---------------------------------------------------------------------------}
  228. PROCEDURE EncodeSizeUInt(var P: PByte; V: SizeUInt);
  229. BEGIN
  230. repeat
  231. P^ := V and 127;
  232. V := V shr 7;
  233. if V <> 0 then
  234. P^ := P^ or 128;
  235. Inc(P);
  236. until V = 0;
  237. END;
  238. {---------------------------------------------------------------------------}
  239. { EncodedSizeLengthInBytes }
  240. {---------------------------------------------------------------------------}
  241. FUNCTION EncodedSizeLengthInBytes(V: SizeUInt): Integer;
  242. BEGIN
  243. if V < (1 shl 7) then
  244. Result := 1
  245. else if V < (1 shl (2*7)) then
  246. Result := 2
  247. else if V < (1 shl (3*7)) then
  248. Result := 3
  249. else if V < (1 shl (4*7)) then
  250. Result := 4
  251. else if V < (1 shl (5*7)) then
  252. Result := 5
  253. else if V < (1 shl (6*7)) then
  254. Result := 6
  255. else if V < (1 shl (7*7)) then
  256. Result := 7
  257. else if V < (1 shl (8*7)) then
  258. Result := 8
  259. else if V < (1 shl (9*7)) then
  260. Result := 9
  261. else
  262. Result := 10;
  263. END;
  264. {$endif FV_UNICODE}
  265. {---------------------------------------------------------------------------}
  266. { DeleteString -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  267. {---------------------------------------------------------------------------}
  268. {$ifdef FV_UNICODE}
  269. PROCEDURE DeleteString;
  270. VAR Len: SizeUInt; P, P2: Pointer;
  271. BEGIN
  272. P := CurString; { Current string }
  273. P2 := CurString; { Current string }
  274. Len := DecodeSizeUInt(P2); { Length of string }
  275. Dec(P, 2); { Correct position }
  276. Inc(P2, Len); { Next hist record }
  277. { Shuffle history }
  278. Move(P2^, P^, Pointer(HistoryBlock) + HistoryUsed - Pointer(P2) );
  279. Dec(HistoryUsed, P2-P); { Adjust history used }
  280. END;
  281. {$else FV_UNICODE}
  282. PROCEDURE DeleteString;
  283. VAR Len: Sw_Integer; P, P2: PAnsiChar;
  284. BEGIN
  285. P := PAnsiChar(CurString); { Current string }
  286. P2 := PAnsiChar(CurString); { Current string }
  287. Len := PByte(P2)^+3; { Length of data }
  288. Dec(P, 2); { Correct position }
  289. Inc(P2, PByte(P2)^+1); { Next hist record }
  290. { Shuffle history }
  291. Move(P2^, P^, Pointer(HistoryBlock) + HistoryUsed - Pointer(P2) );
  292. Dec(HistoryUsed, Len); { Adjust history used }
  293. END;
  294. {$endif FV_UNICODE}
  295. {---------------------------------------------------------------------------}
  296. { AdvanceStringPtr -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  297. {---------------------------------------------------------------------------}
  298. PROCEDURE AdvanceStringPtr;
  299. VAR P: PAnsiChar;
  300. {$ifdef FV_UNICODE}
  301. Len: SizeUInt;
  302. {$endif FV_UNICODE}
  303. BEGIN
  304. While (CurString <> Nil) Do Begin
  305. If (Pointer(CurString) >= Pointer(HistoryBlock) + HistoryUsed) Then Begin{ Last string check }
  306. CurString := Nil; { Clear current string }
  307. Exit; { Now exit }
  308. End;
  309. {$ifdef FV_UNICODE}
  310. Len := DecodeSizeUInt(CurString);
  311. Inc(CurString, Len); { Move to next string }
  312. {$else FV_UNICODE}
  313. Inc(PAnsiChar(CurString), PByte(CurString)^+1); { Move to next string }
  314. {$endif FV_UNICODE}
  315. If (Pointer(CurString) >= Pointer(HistoryBlock) + HistoryUsed) Then Begin{ Last string check }
  316. CurString := Nil; { Clear current string }
  317. Exit; { Now exit }
  318. End;
  319. P := PAnsiChar(CurString); { Transfer record ptr }
  320. Inc(PAnsiChar(CurString), 2); { Move to string }
  321. if (P^<>#0) then
  322. RunError(215);
  323. Inc(P);
  324. If (P^ = Chr(CurId)) Then Exit; { Found the string }
  325. End;
  326. END;
  327. {---------------------------------------------------------------------------}
  328. { InsertString -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  329. {---------------------------------------------------------------------------}
  330. {$ifdef FV_UNICODE}
  331. PROCEDURE InsertString (Id: Byte; Const Str: UnicodeString);
  332. VAR P, P1, P2: PByte; StrU8: UTF8String;
  333. Len: SizeUInt;
  334. BEGIN
  335. StrU8 := Str;
  336. while (HistoryUsed+Length(StrU8)+EncodedSizeLengthInBytes(Length(StrU8))+2>HistorySize) do
  337. begin
  338. P:=HistoryBlock;
  339. while Pointer(P)<Pointer(HistoryBlock)+HistorySize do
  340. begin
  341. if Pointer(P)+StoredStringSize(P+2)+4+Length(StrU8)+EncodedSizeLengthInBytes(Length(StrU8)) >
  342. Pointer(HistoryBlock)+HistorySize then
  343. begin
  344. Dec(HistoryUsed,Length(PShortString(P+2)^)+3);
  345. FillChar(P^,Pointer(HistoryBlock)+HistorySize-Pointer(P),#0);
  346. break;
  347. end;
  348. Inc(P, 2);
  349. Len:=DecodeSizeUInt(P);
  350. Inc(P,Len);
  351. end;
  352. end;
  353. P1 := HistoryBlock+1; { First history record }
  354. P2 := P1+Length(StrU8)+EncodedSizeLengthInBytes(Length(StrU8))+2; { History record after }
  355. Move(P1^, P2^, HistoryUsed - 1); { Shuffle history data }
  356. P1^:=0; { Set marker byte }
  357. Inc(P1);
  358. P1^:=Id; { Set history id }
  359. Inc(P1);
  360. EncodeSizeUInt(P1, Length(StrU8));
  361. Move(StrU8[1], P1^, Length(StrU8)); { Set history string }
  362. Inc(HistoryUsed, Length(StrU8)+EncodedSizeLengthInBytes(Length(StrU8))+2); { Inc history used }
  363. END;
  364. {$else FV_UNICODE}
  365. PROCEDURE InsertString (Id: Byte; Const Str: String);
  366. VAR P, P1, P2: PAnsiChar;
  367. BEGIN
  368. while (HistoryUsed+Length(Str)+3>HistorySize) do
  369. begin
  370. P:=PAnsiChar(HistoryBlock);
  371. while Pointer(P)<Pointer(HistoryBlock)+HistorySize do
  372. begin
  373. if Pointer(P)+Length(PShortString(P+2)^)+6+Length(Str) >
  374. Pointer(HistoryBlock)+HistorySize then
  375. begin
  376. Dec(HistoryUsed,Length(PShortString(P+2)^)+3);
  377. FillChar(P^,Pointer(HistoryBlock)+HistorySize-Pointer(P),#0);
  378. break;
  379. end;
  380. Inc(P,Length(PShortString(P+2)^)+3);
  381. end;
  382. end;
  383. P1 := PAnsiChar(HistoryBlock)+1; { First history record }
  384. P2 := P1+Length(Str)+3; { History record after }
  385. Move(P1^, P2^, HistoryUsed - 1); { Shuffle history data }
  386. P1^:=#0; { Set marker byte }
  387. Inc(P1);
  388. P1^:=Chr(Id); { Set history id }
  389. Inc(P1);
  390. Move(Str[0], P1^, Length(Str)+1); { Set history string }
  391. Inc(HistoryUsed, Length(Str)+3); { Inc history used }
  392. END;
  393. {$endif FV_UNICODE}
  394. {***************************************************************************}
  395. { INTERFACE ROUTINES }
  396. {***************************************************************************}
  397. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  398. { HISTORY SYSTEM CONTROL ROUTINES }
  399. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  400. {---------------------------------------------------------------------------}
  401. { InitHistory -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  402. {---------------------------------------------------------------------------}
  403. PROCEDURE InitHistory;
  404. BEGIN
  405. if HistorySize>0 then
  406. GetMem(HistoryBlock, HistorySize); { Allocate block }
  407. ClearHistory; { Clear the history }
  408. END;
  409. {---------------------------------------------------------------------------}
  410. { DoneHistory -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  411. {---------------------------------------------------------------------------}
  412. PROCEDURE DoneHistory;
  413. BEGIN
  414. If (HistoryBlock <> Nil) Then { History block valid }
  415. begin
  416. FreeMem(HistoryBlock); { Release history block }
  417. HistoryBlock:=nil;
  418. end;
  419. END;
  420. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  421. { HISTORY ITEM ROUTINES }
  422. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  423. {---------------------------------------------------------------------------}
  424. { HistoryCount -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  425. {---------------------------------------------------------------------------}
  426. FUNCTION HistoryCount(Id: Byte): Word;
  427. VAR Count: Word;
  428. BEGIN
  429. StartId(Id); { Set to first record }
  430. Count := 0; { Clear count }
  431. If (HistoryBlock <> Nil) Then Begin { History initalized }
  432. AdvanceStringPtr; { Move to first string }
  433. While (CurString <> Nil) Do Begin
  434. Inc(Count); { Add one to count }
  435. AdvanceStringPtr; { Move to next string }
  436. End;
  437. End;
  438. HistoryCount := Count; { Return history count }
  439. END;
  440. {---------------------------------------------------------------------------}
  441. { HistoryStr -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  442. {---------------------------------------------------------------------------}
  443. FUNCTION HistoryStr(Id: Byte; Index: Sw_Integer): Sw_String;
  444. VAR I: Sw_Integer;
  445. {$ifdef FV_UNICODE}
  446. TmpP: Pointer;
  447. StrU8: UTF8String;
  448. {$endif FV_UNICODE}
  449. BEGIN
  450. StartId(Id); { Set to first record }
  451. If (HistoryBlock <> Nil) Then Begin { History initalized }
  452. For I := 0 To Index Do AdvanceStringPtr; { Find indexed string }
  453. If (CurString <> Nil) Then Begin
  454. {$ifdef FV_UNICODE}
  455. TmpP := CurString;
  456. SetLength(StrU8, DecodeSizeUInt(TmpP));
  457. Move(TmpP^, StrU8[1], Length(StrU8));
  458. HistoryStr := StrU8;
  459. {$else FV_UNICODE}
  460. HistoryStr := CurString^ { Return string }
  461. {$endif FV_UNICODE}
  462. End Else
  463. HistoryStr := ''; { Index not found }
  464. End Else HistoryStr := ''; { History uninitialized }
  465. END;
  466. {---------------------------------------------------------------------------}
  467. { ClearHistory -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  468. {---------------------------------------------------------------------------}
  469. PROCEDURE ClearHistory;
  470. BEGIN
  471. If (HistoryBlock <> Nil) Then Begin { History initiated }
  472. PAnsiChar(HistoryBlock)^ := #0; { Clear first byte }
  473. HistoryUsed := 1; { Set position }
  474. End;
  475. END;
  476. {---------------------------------------------------------------------------}
  477. { HistoryAdd -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  478. {---------------------------------------------------------------------------}
  479. PROCEDURE HistoryAdd (Id: Byte; Const Str: Sw_String);
  480. {$ifdef FV_UNICODE}
  481. VAR StrU8: UTF8String; TmpP: PByte; TmpLen: SizeUInt;
  482. {$endif FV_UNICODE}
  483. BEGIN
  484. If (Str = '') Then Exit; { Empty string exit }
  485. If (HistoryBlock = Nil) Then Exit; { History uninitialized }
  486. {$ifdef FV_UNICODE}
  487. StrU8:=Str;
  488. {$endif FV_UNICODE}
  489. StartId(Id); { Set current data }
  490. AdvanceStringPtr; { Find the string }
  491. While (CurString <> nil) Do Begin
  492. {$ifdef FV_UNICODE}
  493. TmpP := CurString;
  494. TmpLen := DecodeSizeUInt(TmpP);
  495. If (TmpLen=Length(StrU8)) and (CompareByte(TmpP^, StrU8[1], TmpLen)=0) then
  496. DeleteString; { Delete duplicates }
  497. {$else FV_UNICODE}
  498. If (Str = CurString^) Then DeleteString; { Delete duplicates }
  499. {$endif FV_UNICODE}
  500. AdvanceStringPtr; { Find next string }
  501. End;
  502. InsertString(Id, Str); { Add new history item }
  503. END;
  504. function HistoryRemove(Id: Byte; Index: Sw_Integer): boolean;
  505. var
  506. I: Sw_Integer;
  507. begin
  508. StartId(Id);
  509. for I := 0 to Index do
  510. AdvanceStringPtr; { Find the string }
  511. if CurString <> nil then
  512. begin
  513. DeleteString;
  514. HistoryRemove:=true;
  515. end
  516. else
  517. HistoryRemove:=false;
  518. end;
  519. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  520. { HISTORY STREAM STORAGE AND RETREIVAL ROUTINES }
  521. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  522. {---------------------------------------------------------------------------}
  523. { LoadHistory -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  524. {---------------------------------------------------------------------------}
  525. PROCEDURE LoadHistory (Var S: TStream);
  526. VAR Size: sw_integer;
  527. BEGIN
  528. S.Read(Size, sizeof(Size)); { Read history size }
  529. If (HistoryBlock <> Nil) Then Begin { History initialized }
  530. If (Size <= HistorySize) Then Begin
  531. S.Read(HistoryBlock^, Size); { Read the history }
  532. HistoryUsed := Size; { History used }
  533. End Else S.Seek(S.GetPos + Size); { Move stream position }
  534. End Else S.Seek(S.GetPos + Size); { Move stream position }
  535. END;
  536. {---------------------------------------------------------------------------}
  537. { StoreHistory -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  538. {---------------------------------------------------------------------------}
  539. PROCEDURE StoreHistory (Var S: TStream);
  540. VAR Size: sw_integer;
  541. BEGIN
  542. If (HistoryBlock = Nil) Then Size := 0 Else { No history data }
  543. Size := HistoryUsed; { Size of history data }
  544. S.Write(Size, sizeof(Size)); { Write history size }
  545. If (Size > 0) Then S.Write(HistoryBlock^, Size); { Write history data }
  546. END;
  547. END.