source: trunk/NewView/StartupUnit.pas@ 61

Last change on this file since 61 was 61, checked in by RBRi, 19 years ago

another refactoring step for cleaning up the command line handling

  • Property svn:eol-style set to native
File size: 4.8 KB
Line 
1Unit StartupUnit;
2
3// NewView - a new OS/2 Help Viewer
4// Copyright 2003 Aaron Lawrence (aaronl at consultant dot com)
5// This software is released under the Gnu Public License - see readme.txt
6
7// Code related to startup and finding help files.
8// Shared between NewView.exe and ViewStub.exe
9
10Interface
11
12uses
13 OS2Def,
14 Classes,
15 GlobalFilelistUnit,
16 SharedMemoryUnit,
17 CmdLineParameterUnit;
18
19const
20 OWN_HELP_MARKER = '[NVHELP]';
21
22
23function AccessSharedMemory: TSuballocatedSharedMemory;
24
25// Look for any items that are actually specifiying environment
26// variables, and expand them to the contents of the variables
27Procedure TranslateIPFEnvironmentVars( Items: TStrings;
28 ExpandedItems: TStrings );
29
30// Given a filename, which may or may not contain a path or extension,
31// finds the actual file. This can involve searching
32// the help and bookshelf paths.
33Function FindHelpFile( FileName: string ): string;
34Procedure PostNewViewTextMessage( Window: HWND;
35 MessageType: ULONG;
36 s: string );
37
38var
39 SharedMemory: TSubAllocatedSharedMemory;
40 GlobalFilelist: TGlobalFilelist;
41
42Implementation
43
44uses
45 Dos,
46 SysUtils,
47 DebugUnit,
48 PMWin,
49 ACLStringUtility,
50 ACLFileUtility,
51 HelpManagerUnit;
52
53// Look for any items that are actually specifiying environment
54// variables, and expand them to the contents of the variables
55Procedure TranslateIPFEnvironmentVars( Items: TStrings;
56 ExpandedItems: TStrings );
57var
58 i: longint;
59 Item: string;
60 EnvironmentVarValue: string;
61begin
62 LogEvent(LogStartup, 'Translating environment vars' );
63 for i := 0 to Items.Count - 1 do
64 begin
65 Item := Items[ i ];
66
67 Item := StrUnQuote( Item ); // remove single quotes
68 Item := StrUnDoubleQuote( Item ); // remove double quotes
69
70 LogEvent(LogStartup, ' Item: ' + Item );
71 EnvironmentVarValue := GetEnv( Uppercase( Item ) );
72 if DosError = 0 then
73 begin
74 // environment var exists - use it's value
75 LogEvent(LogStartup, ' Translated: ' + EnvironmentVarValue );
76 while EnvironmentVarValue <> '' do
77 begin
78 Item := ExtractNextValue( EnvironmentVarValue, '+' );
79 ExpandedItems.Add( Item );
80 end;
81 end
82 else
83 begin
84 // not an environment var
85 ExpandedItems.Add( Item );
86 end;
87 end;
88end;
89
90// Given a filename, which may or may not contain a path or extension,
91// finds the actual file. This can involve searching
92// the help and bookshelf paths.
93Function FindHelpFile( FileName: string ): string;
94var
95 AlternativeFileName: string;
96begin
97 if FileName = OWN_HELP_MARKER then
98 begin
99 Result := GetOwnHelpFileName;
100 exit;
101 end;
102
103 Result := '';
104
105 AlternativeFileName := '';
106 if ExtractFileExt( Filename ) = '' then
107 begin
108 Filename := ChangeFileExt( Filename, '.inf' );
109 AlternativeFileName := ChangeFileExt( Filename, '.hlp' );
110 end;
111
112 if ExtractFilePath( FileName ) <> '' then
113 begin
114 // Path specified; just see if it exists
115
116 // expand out relative paths
117 Filename := ExpandFileName( FileName );
118 AlternativeFilename := ExpandFileName( AlternativeFilename );
119
120 if FileExists( Filename ) then
121 Result := Filename
122 else if FileExists( AlternativeFilename ) then
123 Result := AlternativeFilename;
124
125 end
126 else
127 begin
128 // Path not specified; search current
129 if FileExists( ExpandFileName( FileName ) ) then
130 begin
131 Result := ExpandFileName( FileName );
132 exit;
133 end;
134
135 if FileExists( ExpandFileName( AlternativeFilename ) ) then
136 begin
137 Result := ExpandFileName( AlternativeFilename );
138 exit;
139 end;
140
141 // Search help paths
142
143 if not SearchHelpPaths( FileName,
144 Result,
145 false // don't search our app dir
146 ) then
147 begin
148 // Didn't find as specified or as .inf, try .hlp
149 if AlternativeFilename <> '' then
150 begin
151 if not SearchHelpPaths( AlternativeFileName,
152 Result,
153 false // don't search our app dir
154 ) then
155 begin
156 Result := '';
157 end;
158 end;
159 end;
160 end;
161end;
162
163
164function AccessSharedMemory: TSuballocatedSharedMemory;
165begin
166 Result := TSuballocatedSharedMemory.Create( SharedMemName,
167 SharedMemSize,
168 SharedMemReserveSize );
169end;
170
171procedure PostNewViewTextMessage( Window: HWND;
172 MessageType: ULONG;
173 s: string );
174var
175 ps: pchar;
176begin
177 SharedMemory.Allocate( ps, length( s ) + 1 );
178 ps ^ := s;
179 WinPostMsg( Window,
180 MessageType,
181 LONG( ps ),
182 0 );
183end;
184
185
186Initialization
187End.
Note: See TracBrowser for help on using the repository browser.