histlist.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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 = 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 = PACKED RECORD
  152. Zero: byte; { Start marker }
  153. Id : byte; { History id }
  154. Str : String; { History string }
  155. END;
  156. PHistRec = ^THistRec; { History record ptr }
  157. {***************************************************************************}
  158. { UNINITIALIZED PRIVATE VARIABLES }
  159. {***************************************************************************}
  160. {---------------------------------------------------------------------------}
  161. { UNINITIALIZED DOS/DPMI/WIN/NT/OS2 VARIABLES }
  162. {---------------------------------------------------------------------------}
  163. VAR
  164. CurId: Byte; { Current history id }
  165. CurString: PString; { Current string }
  166. {***************************************************************************}
  167. { PRIVATE UNIT ROUTINES }
  168. {***************************************************************************}
  169. {---------------------------------------------------------------------------}
  170. { StartId -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  171. {---------------------------------------------------------------------------}
  172. PROCEDURE StartId (Id: Byte);
  173. BEGIN
  174. CurId := Id; { Set current id }
  175. CurString := HistoryBlock; { Set current string }
  176. END;
  177. {---------------------------------------------------------------------------}
  178. { DeleteString -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  179. {---------------------------------------------------------------------------}
  180. PROCEDURE DeleteString;
  181. VAR Len: Sw_Integer; P, P2: PChar;
  182. BEGIN
  183. P := PChar(CurString); { Current string }
  184. P2 := PChar(CurString); { Current string }
  185. Len := PByte(P2)^+3; { Length of data }
  186. Dec(P, 2); { Correct position }
  187. Inc(P2, PByte(P2)^+1); { Next hist record }
  188. { Shuffle history }
  189. Move(P2^, P^, cardinal(HistoryBlock) + HistoryUsed - cardinal(P2) );
  190. Dec(HistoryUsed, Len); { Adjust history used }
  191. END;
  192. {---------------------------------------------------------------------------}
  193. { AdvanceStringPtr -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  194. {---------------------------------------------------------------------------}
  195. PROCEDURE AdvanceStringPtr;
  196. VAR P: PHistRec;
  197. BEGIN
  198. While (CurString <> Nil) Do Begin
  199. If (cardinal(CurString) >= cardinal(HistoryBlock) + HistoryUsed) Then Begin{ Last string check }
  200. CurString := Nil; { Clear current string }
  201. Exit; { Now exit }
  202. End;
  203. Inc(PChar(CurString), PByte(CurString)^+1); { Move to next string }
  204. If (cardinal(CurString) >= cardinal(HistoryBlock) + HistoryUsed) Then Begin{ Last string check }
  205. CurString := Nil; { Clear current string }
  206. Exit; { Now exit }
  207. End;
  208. P := PHistRec(CurString); { Transfer record ptr }
  209. Inc(PChar(CurString), 2); { Move to string }
  210. if (P^.Zero<>0) then
  211. RunError(215);
  212. If (P^.Id = CurId) Then Exit; { Found the string }
  213. End;
  214. END;
  215. {---------------------------------------------------------------------------}
  216. { InsertString -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  217. {---------------------------------------------------------------------------}
  218. PROCEDURE InsertString (Id: Byte; Const Str: String);
  219. VAR P1, P2: PChar;
  220. P : PHistRec;
  221. BEGIN
  222. while (HistoryUsed+Length(Str)+3>HistorySize) do
  223. begin
  224. P:=PHistRec(HistoryBlock);
  225. while Pointer(P)<Pointer(HistoryBlock)+HistorySize do
  226. begin
  227. if Pointer(P)+Length(P^.Str)+6+Length(Str) >
  228. Pointer(HistoryBlock)+HistorySize then
  229. begin
  230. HistoryUsed:=HistoryUsed-(Length(P^.Str)+3);
  231. FillChar(P^,Pointer(HistoryBlock)+HistorySize-Pointer(P),#0);
  232. break;
  233. end;
  234. P:=PHistRec(Pointer(P)+Length(P^.Str)+3);
  235. end;
  236. end;
  237. P1 := PChar(HistoryBlock)+1; { First history record }
  238. P2 := P1+Length(Str)+3; { History record after }
  239. Move(P1^, P2^, HistoryUsed - 1); { Shuffle history data }
  240. PHistRec(P1)^.Zero := 0; { Set marker byte }
  241. PHistRec(P1)^.Id := Id; { Set history id }
  242. {$IFDEF PPC_DELPHI3} { DELPHI3+ COMPILER }
  243. Move(Str[1], PHistRec(P1)^.Str[1], Length(Str)); { Set history string }
  244. SetLength(PHistRec(P1)^.Str, Length(Str)); { Set string length }
  245. {$ELSE} { OTHER COMPILERS }
  246. Move(Str[0], PHistRec(P1)^.Str, Length(Str)+1); { Set history string }
  247. {$ENDIF}
  248. Inc(HistoryUsed, Length(Str)+3); { Inc history used }
  249. END;
  250. {***************************************************************************}
  251. { INTERFACE ROUTINES }
  252. {***************************************************************************}
  253. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  254. { HISTORY SYSTEM CONTROL ROUTINES }
  255. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  256. {---------------------------------------------------------------------------}
  257. { InitHistory -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  258. {---------------------------------------------------------------------------}
  259. PROCEDURE InitHistory;
  260. BEGIN
  261. GetMem(HistoryBlock, HistorySize); { Allocate block }
  262. ClearHistory; { Clear the history }
  263. END;
  264. {---------------------------------------------------------------------------}
  265. { DoneHistory -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  266. {---------------------------------------------------------------------------}
  267. PROCEDURE DoneHistory;
  268. BEGIN
  269. If (HistoryBlock <> Nil) Then { History block valid }
  270. FreeMem(HistoryBlock, HistorySize); { Release history block }
  271. END;
  272. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  273. { HISTORY ITEM ROUTINES }
  274. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  275. {---------------------------------------------------------------------------}
  276. { HistoryCount -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  277. {---------------------------------------------------------------------------}
  278. FUNCTION HistoryCount(Id: Byte): Word;
  279. VAR Count: Word;
  280. BEGIN
  281. StartId(Id); { Set to first record }
  282. Count := 0; { Clear count }
  283. If (HistoryBlock <> Nil) Then Begin { History initalized }
  284. AdvanceStringPtr; { Move to first string }
  285. While (CurString <> Nil) Do Begin
  286. Inc(Count); { Add one to count }
  287. AdvanceStringPtr; { Move to next string }
  288. End;
  289. End;
  290. HistoryCount := Count; { Return history count }
  291. END;
  292. {---------------------------------------------------------------------------}
  293. { HistoryStr -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  294. {---------------------------------------------------------------------------}
  295. FUNCTION HistoryStr(Id: Byte; Index: Sw_Integer): String;
  296. VAR I: Sw_Integer;
  297. BEGIN
  298. StartId(Id); { Set to first record }
  299. If (HistoryBlock <> Nil) Then Begin { History initalized }
  300. For I := 0 To Index Do AdvanceStringPtr; { Find indexed string }
  301. If (CurString <> Nil) Then
  302. HistoryStr := CurString^ Else { Return string }
  303. HistoryStr := ''; { Index not found }
  304. End Else HistoryStr := ''; { History uninitialized }
  305. END;
  306. {---------------------------------------------------------------------------}
  307. { ClearHistory -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  308. {---------------------------------------------------------------------------}
  309. PROCEDURE ClearHistory;
  310. BEGIN
  311. If (HistoryBlock <> Nil) Then Begin { History initiated }
  312. PChar(HistoryBlock)^ := #0; { Clear first byte }
  313. HistoryUsed := 1; { Set position }
  314. End;
  315. END;
  316. {---------------------------------------------------------------------------}
  317. { HistoryAdd -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  318. {---------------------------------------------------------------------------}
  319. PROCEDURE HistoryAdd (Id: Byte; Const Str: String);
  320. BEGIN
  321. If (Str = '') Then Exit; { Empty string exit }
  322. If (HistoryBlock = Nil) Then Exit; { History uninitialized }
  323. StartId(Id); { Set current data }
  324. AdvanceStringPtr; { Find the string }
  325. While (CurString <> nil) Do Begin
  326. If (Str = CurString^) Then DeleteString; { Delete duplicates }
  327. AdvanceStringPtr; { Find next string }
  328. End;
  329. InsertString(Id, Str); { Add new history item }
  330. END;
  331. function HistoryRemove(Id: Byte; Index: Sw_Integer): boolean;
  332. var
  333. I: Sw_Integer;
  334. begin
  335. StartId(Id);
  336. for I := 0 to Index do
  337. AdvanceStringPtr; { Find the string }
  338. if CurString <> nil then
  339. begin
  340. DeleteString;
  341. HistoryRemove:=true;
  342. end
  343. else
  344. HistoryRemove:=false;
  345. end;
  346. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  347. { HISTORY STREAM STORAGE AND RETREIVAL ROUTINES }
  348. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  349. {---------------------------------------------------------------------------}
  350. { LoadHistory -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  351. {---------------------------------------------------------------------------}
  352. PROCEDURE LoadHistory (Var S: TStream);
  353. VAR Size: sw_Word;
  354. BEGIN
  355. S.Read(Size, sizeof(Size)); { Read history size }
  356. If (HistoryBlock <> Nil) Then Begin { History initialized }
  357. If (Size <= HistorySize) Then Begin
  358. S.Read(HistoryBlock^, Size); { Read the history }
  359. HistoryUsed := Size; { History used }
  360. End Else S.Seek(S.GetPos + Size); { Move stream position }
  361. End Else S.Seek(S.GetPos + Size); { Move stream position }
  362. END;
  363. {---------------------------------------------------------------------------}
  364. { StoreHistory -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  365. {---------------------------------------------------------------------------}
  366. PROCEDURE StoreHistory (Var S: TStream);
  367. VAR Size: sw_Word;
  368. BEGIN
  369. If (HistoryBlock = Nil) Then Size := 0 Else { No history data }
  370. Size := HistoryUsed; { Size of history data }
  371. S.Write(Size, sizeof(Size)); { Write history size }
  372. If (Size > 0) Then S.Write(HistoryBlock^, Size); { Write history data }
  373. END;
  374. END.
  375. {
  376. $Log$
  377. Revision 1.10 2002-10-17 11:24:16 pierre
  378. * Clean up the Load/Store routines so they are endian independent
  379. Revision 1.9 2002/09/07 15:06:37 peter
  380. * old logs removed and tabs fixed
  381. Revision 1.8 2002/06/10 11:51:08 pierre
  382. * render history load/store compatible with older fvnew lib
  383. Revision 1.7 2002/06/03 20:07:44 pierre
  384. * DeleteString was moving to much memory
  385. Revision 1.6 2002/05/24 09:30:33 pierre
  386. * fix bug with HistoryUsed, now is really a used size
  387. }