Last change
on this file since 338 was 17, checked in by RBRi, 19 years ago |
+ Library
|
-
Property svn:eol-style
set to
native
|
File size:
2.5 KB
|
Line | |
---|
1 | Unit ACLVersionUtilityUnit;
|
---|
2 |
|
---|
3 | Interface
|
---|
4 |
|
---|
5 | Uses
|
---|
6 | BseDos;
|
---|
7 |
|
---|
8 | type
|
---|
9 | TVersionsModule = HFILE;
|
---|
10 |
|
---|
11 | function OpenModuleForVersions( const Path: string;
|
---|
12 | var Module: TVersionsModule ): boolean;
|
---|
13 |
|
---|
14 | function GetVersionFromModule( Module: TVersionsModule;
|
---|
15 | var Version: string ): boolean;
|
---|
16 |
|
---|
17 | procedure CloseModuleForVersions( Module: TVersionsModule );
|
---|
18 |
|
---|
19 | Implementation
|
---|
20 |
|
---|
21 | uses
|
---|
22 | OS2Def;
|
---|
23 |
|
---|
24 | function OpenModuleForVersions( const Path: string;
|
---|
25 | var Module: TVersionsModule ): boolean;
|
---|
26 | var
|
---|
27 | ulAction: ULONG;
|
---|
28 | begin
|
---|
29 | Result := DosOpen( Path,
|
---|
30 | Module,
|
---|
31 | ulAction,
|
---|
32 | 0,
|
---|
33 | 0,
|
---|
34 | OPEN_ACTION_FAIL_IF_NEW
|
---|
35 | + OPEN_ACTION_OPEN_IF_EXISTS,
|
---|
36 | OPEN_SHARE_DENYNONE
|
---|
37 | + OPEN_ACCESS_READONLY,
|
---|
38 | nil ) = 0;
|
---|
39 | end;
|
---|
40 |
|
---|
41 | type
|
---|
42 | TMatchState =
|
---|
43 | (
|
---|
44 | msStart1,
|
---|
45 | msStart2,
|
---|
46 | msRead,
|
---|
47 | msEnd1
|
---|
48 | );
|
---|
49 |
|
---|
50 | function GetVersionFromModule( Module: TVersionsModule;
|
---|
51 | var Version: string ): boolean;
|
---|
52 | var
|
---|
53 | cbActual: ULONG;
|
---|
54 | rc: APIRET;
|
---|
55 | c: char;
|
---|
56 | State: TMatchState;
|
---|
57 | MatchCount: longint;
|
---|
58 | Match: boolean;
|
---|
59 | begin
|
---|
60 | Result := false;
|
---|
61 | Version := '';
|
---|
62 | MatchCount := 0;
|
---|
63 | while true do
|
---|
64 | begin
|
---|
65 | rc := DosRead( Module,
|
---|
66 | c,
|
---|
67 | 1,
|
---|
68 | cbActual );
|
---|
69 | if cbActual = 0 then
|
---|
70 | exit; // end of file
|
---|
71 |
|
---|
72 | Match := false;
|
---|
73 | case State of
|
---|
74 | msStart1:
|
---|
75 | if c = '@' then
|
---|
76 | begin
|
---|
77 | Match := true;
|
---|
78 | inc( State );
|
---|
79 | end;
|
---|
80 |
|
---|
81 | msStart2:
|
---|
82 | if c = '$' then
|
---|
83 | begin
|
---|
84 | Match := true;
|
---|
85 | inc( State );
|
---|
86 | end;
|
---|
87 |
|
---|
88 | msRead:
|
---|
89 | begin
|
---|
90 | Match := true;
|
---|
91 | if c = '$' then
|
---|
92 | inc( State )
|
---|
93 | else
|
---|
94 | Version := Version + c;
|
---|
95 | if Length( Version ) >= 100 then
|
---|
96 | Match := false;
|
---|
97 | end;
|
---|
98 |
|
---|
99 | msEnd1:
|
---|
100 | if c = '@' then
|
---|
101 | begin
|
---|
102 | Result := true;
|
---|
103 | exit;
|
---|
104 | end;
|
---|
105 | end;
|
---|
106 |
|
---|
107 | if Match then
|
---|
108 | begin
|
---|
109 | inc( MatchCount )
|
---|
110 | end
|
---|
111 | else
|
---|
112 | begin
|
---|
113 | State := msStart1;
|
---|
114 | if MatchCount > 0 then
|
---|
115 | DosSetFilePtr( Module,
|
---|
116 | - ( MatchCount - 1 ),
|
---|
117 | FILE_CURRENT,
|
---|
118 | cbActual );
|
---|
119 | MatchCount := 0;
|
---|
120 | Version := '';
|
---|
121 | end;
|
---|
122 | end;
|
---|
123 |
|
---|
124 | Version := '';
|
---|
125 | end;
|
---|
126 |
|
---|
127 | procedure CloseModuleForVersions( Module: TVersionsModule );
|
---|
128 | begin
|
---|
129 | DosClose( Module );
|
---|
130 | end;
|
---|
131 |
|
---|
132 | Initialization
|
---|
133 | End.
|
---|
Note:
See
TracBrowser
for help on using the repository browser.