source: branches/2.20_branch/NewView/StartupUnit.pas@ 443

Last change on this file since 443 was 342, checked in by RBRi, 16 years ago

index is a real object now
support for env variables to make glossary simulation work

  • Property svn:eol-style set to native
File size: 3.5 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
27
28// Given a filename, which may or may not contain a path or extension,
29// finds the actual file. This can involve searching
30// the help and bookshelf paths.
31Function FindHelpFile( FileName: string ): string;
32Procedure PostNewViewTextMessage( Window: HWND;
33 MessageType: ULONG;
34 s: string );
35
36var
37 SharedMemory: TSubAllocatedSharedMemory;
38 GlobalFilelist: TGlobalFilelist;
39
40Implementation
41
42uses
43 Dos,
44 SysUtils,
45 DebugUnit,
46 PMWin,
47 HelpManagerUnit,
48 StringUtilsUnit,
49 FileUtilsUnit;
50
51
52// Given a filename, which may or may not contain a path or extension,
53// finds the actual file. This can involve searching
54// the help and bookshelf paths.
55Function FindHelpFile( FileName: string ): string;
56var
57 AlternativeFileName: string;
58begin
59 Result := '';
60
61 AlternativeFileName := '';
62 if ExtractFileExt( Filename ) = '' then
63 begin
64 Filename := ChangeFileExt( Filename, '.inf' );
65 AlternativeFileName := ChangeFileExt( Filename, '.hlp' );
66 end;
67
68 if ExtractFilePath( FileName ) <> '' then
69 begin
70 // Path specified; just see if it exists
71
72 // expand out relative paths
73 Filename := ExpandFileName( FileName );
74 AlternativeFilename := ExpandFileName( AlternativeFilename );
75
76 if FileExists( Filename ) then
77 Result := Filename
78 else if FileExists( AlternativeFilename ) then
79 Result := AlternativeFilename;
80
81 end
82 else
83 begin
84 // Path not specified; search current
85 if FileExists( ExpandFileName( FileName ) ) then
86 begin
87 Result := ExpandFileName( FileName );
88 exit;
89 end;
90
91 if FileExists( ExpandFileName( AlternativeFilename ) ) then
92 begin
93 Result := ExpandFileName( AlternativeFilename );
94 exit;
95 end;
96
97 // Search help paths
98
99 if not SearchHelpPaths( FileName,
100 Result,
101 false // don't search our app dir
102 ) then
103 begin
104 // Didn't find as specified or as .inf, try .hlp
105 if AlternativeFilename <> '' then
106 begin
107 if not SearchHelpPaths( AlternativeFileName,
108 Result,
109 false // don't search our app dir
110 ) then
111 begin
112 Result := '';
113 end;
114 end;
115 end;
116 end;
117end;
118
119
120function AccessSharedMemory: TSuballocatedSharedMemory;
121begin
122 Result := TSuballocatedSharedMemory.Create( SharedMemName,
123 SharedMemSize,
124 SharedMemReserveSize );
125end;
126
127procedure PostNewViewTextMessage( Window: HWND;
128 MessageType: ULONG;
129 s: string );
130var
131 ps: pchar;
132begin
133 SharedMemory.Allocate( ps, length( s ) + 1 );
134 ps ^ := s;
135 WinPostMsg( Window,
136 MessageType,
137 LONG( ps ),
138 0 );
139end;
140
141
142Initialization
143End.
Note: See TracBrowser for help on using the repository browser.