histlist.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. { $Id$ }
  2. {********[ SOURCE FILE OF GRAPHICAL FREE VISION ]**********}
  3. { }
  4. { System independent GRAPHICAL clone of HISTLIST.PAS }
  5. { }
  6. { Interface Copyright (c) 1992 Borland International }
  7. { }
  8. { Copyright (c) 1996, 1997, 1998, 1999 by Leon de Boer }
  9. { [email protected] - primary e-mail address }
  10. { [email protected] - backup e-mail address }
  11. { }
  12. {****************[ THIS CODE IS FREEWARE ]*****************}
  13. { }
  14. { This sourcecode is released for the purpose to }
  15. { promote the pascal language on all platforms. You may }
  16. { redistribute it and/or modify with the following }
  17. { DISCLAIMER. }
  18. { }
  19. { This SOURCE CODE is distributed "AS IS" WITHOUT }
  20. { WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR }
  21. { ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. }
  22. { }
  23. {*****************[ SUPPORTED PLATFORMS ]******************}
  24. { 16 and 32 Bit compilers }
  25. { DOS - Turbo Pascal 7.0 + (16 Bit) }
  26. { DPMI - Turbo Pascal 7.0 + (16 Bit) }
  27. { - FPC 0.9912+ (GO32V2) (32 Bit) }
  28. { WINDOWS - Turbo Pascal 7.0 + (16 Bit) }
  29. { - Delphi 1.0+ (16 Bit) }
  30. { WIN95/NT - Delphi 2.0+ (32 Bit) }
  31. { - Virtual Pascal 2.0+ (32 Bit) }
  32. { - Speedsoft Sybil 2.0+ (32 Bit) }
  33. { - FPC 0.9912+ (32 Bit) }
  34. { OS2 - Virtual Pascal 1.0+ (32 Bit) }
  35. { }
  36. {******************[ REVISION HISTORY ]********************}
  37. { Version Date Fix }
  38. { ------- --------- --------------------------------- }
  39. { 1.00 11 Nov 96 First DOS/DPMI platform release. }
  40. { 1.10 13 Jul 97 Windows platform code added. }
  41. { 1.20 29 Aug 97 Platform.inc sort added. }
  42. { 1.30 13 Oct 97 Delphi 2 32 bit code added. }
  43. { 1.40 05 May 98 Virtual pascal 2.0 code added. }
  44. { 1.50 30 Sep 99 Complete recheck preformed }
  45. { 1.51 03 Nov 99 FPC windows support added }
  46. {**********************************************************}
  47. UNIT HistList;
  48. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  49. INTERFACE
  50. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  51. {====Include file to sort compiler platform out =====================}
  52. {$I Platform.inc}
  53. {====================================================================}
  54. {==== Compiler directives ===========================================}
  55. {$IFNDEF PPC_FPC}{ FPC doesn't support these switches }
  56. {$F-} { Short calls are okay }
  57. {$A+} { Word Align Data }
  58. {$B-} { Allow short circuit boolean evaluations }
  59. {$O+} { This unit may be overlaid }
  60. {$G+} { 286 Code optimization - if you're on an 8088 get a real computer }
  61. {$P-} { Normal string variables }
  62. {$N-} { No 80x87 code generation }
  63. {$E+} { Emulation is on }
  64. {$ENDIF}
  65. {$X+} { Extended syntax is ok }
  66. {$R-} { Disable range checking }
  67. {$S-} { Disable Stack Checking }
  68. {$I-} { Disable IO Checking }
  69. {$Q-} { Disable Overflow Checking }
  70. {$V-} { Turn off strict VAR strings }
  71. {====================================================================}
  72. USES FVCommon, Objects; { Standard GFV units }
  73. {***************************************************************************}
  74. { INTERFACE ROUTINES }
  75. {***************************************************************************}
  76. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  77. { HISTORY SYSTEM CONTROL ROUTINES }
  78. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  79. {-InitHistory--------------------------------------------------------
  80. Initializes the history system usually called from Application.Init
  81. 30Sep99 LdB
  82. ---------------------------------------------------------------------}
  83. PROCEDURE InitHistory;
  84. {-DoneHistory--------------------------------------------------------
  85. Destroys the history system usually called from Application.Done
  86. 30Sep99 LdB
  87. ---------------------------------------------------------------------}
  88. PROCEDURE DoneHistory;
  89. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  90. { HISTORY ITEM ROUTINES }
  91. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  92. {-HistoryCount-------------------------------------------------------
  93. Returns the number of strings in the history list with ID number Id.
  94. 30Sep99 LdB
  95. ---------------------------------------------------------------------}
  96. FUNCTION HistoryCount (Id: Byte): Word;
  97. {-HistoryStr---------------------------------------------------------
  98. Returns the Index'th string in the history list with ID number Id.
  99. 30Sep99 LdB
  100. ---------------------------------------------------------------------}
  101. FUNCTION HistoryStr (Id: Byte; Index: Sw_Integer): String;
  102. {-ClearHistory-------------------------------------------------------
  103. Removes all strings from all history lists.
  104. 30Sep99 LdB
  105. ---------------------------------------------------------------------}
  106. PROCEDURE ClearHistory;
  107. {-HistoryAdd---------------------------------------------------------
  108. Adds the string Str to the history list indicated by Id.
  109. 30Sep99 LdB
  110. ---------------------------------------------------------------------}
  111. PROCEDURE HistoryAdd (Id: Byte; Const Str: String);
  112. function HistoryRemove(Id: Byte; Index: Sw_Integer): boolean;
  113. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  114. { HISTORY STREAM STORAGE AND RETREIVAL ROUTINES }
  115. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  116. {-LoadHistory--------------------------------------------------------
  117. Reads the application's history block from the stream S by reading the
  118. size of the block, then the block itself. Sets HistoryUsed to the end
  119. of the block read. Use LoadHistory to restore a history block saved
  120. with StoreHistory
  121. 30Sep99 LdB
  122. ---------------------------------------------------------------------}
  123. PROCEDURE LoadHistory (Var S: TStream);
  124. {-StoreHistory--------------------------------------------------------
  125. Writes the currently used portion of the history block to the stream
  126. S, first writing the length of the block then the block itself. Use
  127. the LoadHistory procedure to restore the history block.
  128. 30Sep99 LdB
  129. ---------------------------------------------------------------------}
  130. PROCEDURE StoreHistory (Var S: TStream);
  131. {***************************************************************************}
  132. { INITIALIZED PUBLIC VARIABLES }
  133. {***************************************************************************}
  134. {---------------------------------------------------------------------------}
  135. { INITIALIZED DOS/DPMI/WIN/NT/OS2 VARIABLES }
  136. {---------------------------------------------------------------------------}
  137. CONST
  138. HistorySize: Word = 64*1024; { Maximum history size }
  139. HistoryUsed: LongInt = 0; { History used }
  140. HistoryBlock: Pointer = Nil; { Storage block }
  141. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  142. IMPLEMENTATION
  143. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  144. {***************************************************************************}
  145. { PRIVATE RECORD DEFINITIONS }
  146. {***************************************************************************}
  147. {---------------------------------------------------------------------------}
  148. { THistRec RECORD DEFINITION }
  149. {---------------------------------------------------------------------------}
  150. TYPE
  151. THistRec =
  152. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  153. PACKED
  154. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  155. RECORD
  156. Zero: byte; { Start marker }
  157. Id : byte; { History id }
  158. Str : String; { History string }
  159. END;
  160. PHistRec = ^THistRec; { History record ptr }
  161. {***************************************************************************}
  162. { UNINITIALIZED PRIVATE VARIABLES }
  163. {***************************************************************************}
  164. {---------------------------------------------------------------------------}
  165. { UNINITIALIZED DOS/DPMI/WIN/NT/OS2 VARIABLES }
  166. {---------------------------------------------------------------------------}
  167. VAR
  168. CurId: Byte; { Current history id }
  169. CurString: PString; { Current string }
  170. {***************************************************************************}
  171. { PRIVATE UNIT ROUTINES }
  172. {***************************************************************************}
  173. {---------------------------------------------------------------------------}
  174. { StartId -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  175. {---------------------------------------------------------------------------}
  176. PROCEDURE StartId (Id: Byte);
  177. BEGIN
  178. CurId := Id; { Set current id }
  179. CurString := HistoryBlock; { Set current string }
  180. END;
  181. {---------------------------------------------------------------------------}
  182. { DeleteString -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  183. {---------------------------------------------------------------------------}
  184. PROCEDURE DeleteString;
  185. VAR Len: Sw_Integer; P, P2: PChar;
  186. BEGIN
  187. P := PChar(CurString); { Current string }
  188. P2 := PChar(CurString); { Current string }
  189. Len := PByte(P2)^+3; { Length of data }
  190. Dec(P, 2); { Correct position }
  191. Inc(P2, PByte(P2)^+1); { Next hist record }
  192. { Shuffle history }
  193. Move(P2^, P^, cardinal(HistoryBlock) + HistoryUsed - cardinal(P2) );
  194. Dec(HistoryUsed, Len); { Adjust history used }
  195. END;
  196. {---------------------------------------------------------------------------}
  197. { AdvanceStringPtr -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  198. {---------------------------------------------------------------------------}
  199. PROCEDURE AdvanceStringPtr;
  200. VAR P: PHistRec;
  201. BEGIN
  202. While (CurString <> Nil) Do Begin
  203. If (cardinal(CurString) >= cardinal(HistoryBlock) + HistoryUsed) Then Begin{ Last string check }
  204. CurString := Nil; { Clear current string }
  205. Exit; { Now exit }
  206. End;
  207. Inc(PChar(CurString), PByte(CurString)^+1); { Move to next string }
  208. If (cardinal(CurString) >= cardinal(HistoryBlock) + HistoryUsed) Then Begin{ Last string check }
  209. CurString := Nil; { Clear current string }
  210. Exit; { Now exit }
  211. End;
  212. P := PHistRec(CurString); { Transfer record ptr }
  213. Inc(PChar(CurString), 2); { Move to string }
  214. if (P^.Zero<>0) then
  215. RunError(215);
  216. If (P^.Id = CurId) Then Exit; { Found the string }
  217. End;
  218. END;
  219. {---------------------------------------------------------------------------}
  220. { InsertString -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  221. {---------------------------------------------------------------------------}
  222. PROCEDURE InsertString (Id: Byte; Const Str: String);
  223. VAR P1, P2: PChar;
  224. P : PHistRec;
  225. BEGIN
  226. while (HistoryUsed+Length(Str)+3>HistorySize) do
  227. begin
  228. P:=PHistRec(HistoryBlock);
  229. while Pointer(P)<Pointer(HistoryBlock)+HistorySize do
  230. begin
  231. if Pointer(P)+Length(P^.Str)+6+Length(Str) >
  232. Pointer(HistoryBlock)+HistorySize then
  233. begin
  234. HistoryUsed:=HistoryUsed-(Length(P^.Str)+3);
  235. FillChar(P^,Pointer(HistoryBlock)+HistorySize-Pointer(P),#0);
  236. break;
  237. end;
  238. P:=PHistRec(Pointer(P)+Length(P^.Str)+3);
  239. end;
  240. end;
  241. P1 := PChar(HistoryBlock)+1; { First history record }
  242. P2 := P1+Length(Str)+3; { History record after }
  243. Move(P1^, P2^, HistoryUsed - 1); { Shuffle history data }
  244. PHistRec(P1)^.Zero := 0; { Set marker byte }
  245. PHistRec(P1)^.Id := Id; { Set history id }
  246. {$IFDEF PPC_DELPHI3} { DELPHI3+ COMPILER }
  247. Move(Str[1], PHistRec(P1)^.Str[1], Length(Str)); { Set history string }
  248. SetLength(PHistRec(P1)^.Str, Length(Str)); { Set string length }
  249. {$ELSE} { OTHER COMPILERS }
  250. Move(Str[0], PHistRec(P1)^.Str, Length(Str)+1); { Set history string }
  251. {$ENDIF}
  252. Inc(HistoryUsed, Length(Str)+3); { Inc history used }
  253. END;
  254. {***************************************************************************}
  255. { INTERFACE ROUTINES }
  256. {***************************************************************************}
  257. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  258. { HISTORY SYSTEM CONTROL ROUTINES }
  259. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  260. {---------------------------------------------------------------------------}
  261. { InitHistory -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  262. {---------------------------------------------------------------------------}
  263. PROCEDURE InitHistory;
  264. BEGIN
  265. GetMem(HistoryBlock, HistorySize); { Allocate block }
  266. ClearHistory; { Clear the history }
  267. END;
  268. {---------------------------------------------------------------------------}
  269. { DoneHistory -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  270. {---------------------------------------------------------------------------}
  271. PROCEDURE DoneHistory;
  272. BEGIN
  273. If (HistoryBlock <> Nil) Then { History block valid }
  274. FreeMem(HistoryBlock, HistorySize); { Release history block }
  275. END;
  276. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  277. { HISTORY ITEM ROUTINES }
  278. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  279. {---------------------------------------------------------------------------}
  280. { HistoryCount -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  281. {---------------------------------------------------------------------------}
  282. FUNCTION HistoryCount(Id: Byte): Word;
  283. VAR Count: Word;
  284. BEGIN
  285. StartId(Id); { Set to first record }
  286. Count := 0; { Clear count }
  287. If (HistoryBlock <> Nil) Then Begin { History initalized }
  288. AdvanceStringPtr; { Move to first string }
  289. While (CurString <> Nil) Do Begin
  290. Inc(Count); { Add one to count }
  291. AdvanceStringPtr; { Move to next string }
  292. End;
  293. End;
  294. HistoryCount := Count; { Return history count }
  295. END;
  296. {---------------------------------------------------------------------------}
  297. { HistoryStr -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  298. {---------------------------------------------------------------------------}
  299. FUNCTION HistoryStr(Id: Byte; Index: Sw_Integer): String;
  300. VAR I: Sw_Integer;
  301. BEGIN
  302. StartId(Id); { Set to first record }
  303. If (HistoryBlock <> Nil) Then Begin { History initalized }
  304. For I := 0 To Index Do AdvanceStringPtr; { Find indexed string }
  305. If (CurString <> Nil) Then
  306. HistoryStr := CurString^ Else { Return string }
  307. HistoryStr := ''; { Index not found }
  308. End Else HistoryStr := ''; { History uninitialized }
  309. END;
  310. {---------------------------------------------------------------------------}
  311. { ClearHistory -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  312. {---------------------------------------------------------------------------}
  313. PROCEDURE ClearHistory;
  314. BEGIN
  315. If (HistoryBlock <> Nil) Then Begin { History initiated }
  316. PChar(HistoryBlock)^ := #0; { Clear first byte }
  317. HistoryUsed := 1; { Set position }
  318. End;
  319. END;
  320. {---------------------------------------------------------------------------}
  321. { HistoryAdd -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  322. {---------------------------------------------------------------------------}
  323. PROCEDURE HistoryAdd (Id: Byte; Const Str: String);
  324. BEGIN
  325. If (Str = '') Then Exit; { Empty string exit }
  326. If (HistoryBlock = Nil) Then Exit; { History uninitialized }
  327. StartId(Id); { Set current data }
  328. AdvanceStringPtr; { Find the string }
  329. While (CurString <> nil) Do Begin
  330. If (Str = CurString^) Then DeleteString; { Delete duplicates }
  331. AdvanceStringPtr; { Find next string }
  332. End;
  333. InsertString(Id, Str); { Add new history item }
  334. END;
  335. function HistoryRemove(Id: Byte; Index: Sw_Integer): boolean;
  336. var
  337. I: Sw_Integer;
  338. begin
  339. StartId(Id);
  340. for I := 0 to Index do
  341. AdvanceStringPtr; { Find the string }
  342. if CurString <> nil then
  343. begin
  344. DeleteString;
  345. HistoryRemove:=true;
  346. end
  347. else
  348. HistoryRemove:=false;
  349. end;
  350. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  351. { HISTORY STREAM STORAGE AND RETREIVAL ROUTINES }
  352. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  353. {---------------------------------------------------------------------------}
  354. { LoadHistory -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  355. {---------------------------------------------------------------------------}
  356. PROCEDURE LoadHistory (Var S: TStream);
  357. VAR Size: sw_Word;
  358. BEGIN
  359. S.Read(Size, sizeof(Size)); { Read history size }
  360. If (HistoryBlock <> Nil) Then Begin { History initialized }
  361. If (Size <= HistorySize) Then Begin
  362. S.Read(HistoryBlock^, Size); { Read the history }
  363. HistoryUsed := Size; { History used }
  364. End Else S.Seek(S.GetPos + Size); { Move stream position }
  365. End Else S.Seek(S.GetPos + Size); { Move stream position }
  366. END;
  367. {---------------------------------------------------------------------------}
  368. { StoreHistory -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  369. {---------------------------------------------------------------------------}
  370. PROCEDURE StoreHistory (Var S: TStream);
  371. VAR Size: sw_Word;
  372. BEGIN
  373. If (HistoryBlock = Nil) Then Size := 0 Else { No history data }
  374. Size := HistoryUsed; { Size of history data }
  375. S.Write(Size, sizeof(Size)); { Write history size }
  376. If (Size > 0) Then S.Write(HistoryBlock^, Size); { Write history data }
  377. END;
  378. END.
  379. {
  380. $Log$
  381. Revision 1.11 2004-11-03 20:51:36 florian
  382. * fixed problems on targets requiring proper alignment
  383. Revision 1.10 2002/10/17 11:24:16 pierre
  384. * Clean up the Load/Store routines so they are endian independent
  385. Revision 1.9 2002/09/07 15:06:37 peter
  386. * old logs removed and tabs fixed
  387. Revision 1.8 2002/06/10 11:51:08 pierre
  388. * render history load/store compatible with older fvnew lib
  389. Revision 1.7 2002/06/03 20:07:44 pierre
  390. * DeleteString was moving to much memory
  391. Revision 1.6 2002/05/24 09:30:33 pierre
  392. * fix bug with HistoryUsed, now is really a used size
  393. }