source: trunk/NewView/StartupUnit.pas@ 259

Last change on this file since 259 was 259, checked in by RBRi, 18 years ago

support -i option

  • Property svn:eol-style set to native
File size: 4.7 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 HELP_FILE_DELIMITER = '+';
22
23
24function AccessSharedMemory: TSuballocatedSharedMemory;
25
26// Look for any items that are actually specifiying environment
27// variables, and expand them to the contents of the variables
28Procedure TranslateIPFEnvironmentVars(const Items: TStrings; 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 HelpManagerUnit,
50 StringUtilsUnit,
51 FileUtilsUnit;
52
53// Look for any items that are actually specifiying environment
54// variables, and expand them to the contents of the variables
55Procedure TranslateIPFEnvironmentVars(const Items: TStrings; ExpandedItems: TStrings );
56var
57 i : longint;
58 tmpItem: string;
59 tmpEnvironmentVarValue: string;
60begin
61 LogEvent(LogStartup, 'Translating environment vars' );
62 for i := 0 to Items.Count - 1 do
63 begin
64 tmpItem := Items[i];
65
66 tmpItem := StrTrimChars(tmpItem, [StrSingleQuote]); // remove single quotes
67 tmpItem := StrTrimChars(tmpItem, [StrDoubleQuote]); // remove double quotes
68
69 LogEvent(LogStartup, ' Checking for environment var: ' + tmpItem );
70 tmpEnvironmentVarValue := GetEnv( Uppercase( tmpItem ) );
71 if DosError = 0 then
72 begin
73 // environment var exists - use it's value
74 LogEvent(LogStartup, ' Environment var found; translated to: ' + tmpEnvironmentVarValue);
75 StrExtractStrings(ExpandedItems, tmpEnvironmentVarValue, [HELP_FILE_DELIMITER], #0);
76 end
77 else
78 begin
79 // not an environment var
80 ExpandedItems.Add(tmpItem);
81 end;
82 end;
83end;
84
85// Given a filename, which may or may not contain a path or extension,
86// finds the actual file. This can involve searching
87// the help and bookshelf paths.
88Function FindHelpFile( FileName: string ): string;
89var
90 AlternativeFileName: string;
91begin
92 Result := '';
93
94 AlternativeFileName := '';
95 if ExtractFileExt( Filename ) = '' then
96 begin
97 Filename := ChangeFileExt( Filename, '.inf' );
98 AlternativeFileName := ChangeFileExt( Filename, '.hlp' );
99 end;
100
101 if ExtractFilePath( FileName ) <> '' then
102 begin
103 // Path specified; just see if it exists
104
105 // expand out relative paths
106 Filename := ExpandFileName( FileName );
107 AlternativeFilename := ExpandFileName( AlternativeFilename );
108
109 if FileExists( Filename ) then
110 Result := Filename
111 else if FileExists( AlternativeFilename ) then
112 Result := AlternativeFilename;
113
114 end
115 else
116 begin
117 // Path not specified; search current
118 if FileExists( ExpandFileName( FileName ) ) then
119 begin
120 Result := ExpandFileName( FileName );
121 exit;
122 end;
123
124 if FileExists( ExpandFileName( AlternativeFilename ) ) then
125 begin
126 Result := ExpandFileName( AlternativeFilename );
127 exit;
128 end;
129
130 // Search help paths
131
132 if not SearchHelpPaths( FileName,
133 Result,
134 false // don't search our app dir
135 ) then
136 begin
137 // Didn't find as specified or as .inf, try .hlp
138 if AlternativeFilename <> '' then
139 begin
140 if not SearchHelpPaths( AlternativeFileName,
141 Result,
142 false // don't search our app dir
143 ) then
144 begin
145 Result := '';
146 end;
147 end;
148 end;
149 end;
150end;
151
152
153function AccessSharedMemory: TSuballocatedSharedMemory;
154begin
155 Result := TSuballocatedSharedMemory.Create( SharedMemName,
156 SharedMemSize,
157 SharedMemReserveSize );
158end;
159
160procedure PostNewViewTextMessage( Window: HWND;
161 MessageType: ULONG;
162 s: string );
163var
164 ps: pchar;
165begin
166 SharedMemory.Allocate( ps, length( s ) + 1 );
167 ps ^ := s;
168 WinPostMsg( Window,
169 MessageType,
170 LONG( ps ),
171 0 );
172end;
173
174
175Initialization
176End.
Note: See TracBrowser for help on using the repository browser.