remove OSF1 support
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / main.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: main.C /main/25 1996/11/22 11:02:05 rcs $ */
24 /*
25  * (c) Copyright 1996 Digital Equipment Corporation.
26  * (c) Copyright 1996 Hewlett-Packard Company.
27  * (c) Copyright 1996 International Business Machines Corp.
28  * (c) Copyright 1996 Sun Microsystems, Inc.
29  * (c) Copyright 1996 Novell, Inc. 
30  * (c) Copyright 1994, 1995, 1996 FUJITSU LIMITED.
31  * (c) Copyright 1996 Hitachi.
32  */
33 /*
34  * Copyright (c) 1993 HAL Computer Systems International, Ltd.
35  * All rights reserved.  Unpublished -- rights reserved under
36  * the Copyright Laws of the United States.  USE OF A COPYRIGHT
37  * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
38  * OR DISCLOSURE.
39  * 
40  * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
41  * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
42  * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
43  * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
44  * INTERNATIONAL, LTD.
45  * 
46  *                         RESTRICTED RIGHTS LEGEND
47  * Use, duplication, or disclosure by the Government is subject
48  * to the restrictions as set forth in subparagraph (c)(l)(ii)
49  * of the Rights in Technical Data and Computer Software clause
50  * at DFARS 252.227-7013.
51  *
52  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
53  *                  1315 Dell Avenue
54  *                  Campbell, CA  95008
55  * 
56  */
57
58 # include "UAS.hh"
59
60 #include <locale.h>
61 #ifdef SVR4
62 #include <libintl.h>
63 #endif
64
65 #if defined(sparc) && defined(MAP_ZERO)
66 #include <sys/mman.h>
67 #include <fcntl.h>
68 #endif
69
70 #define C_WindowSystem
71 #define L_Other
72
73 #define C_MessageMgr
74 #define C_InputMgrX
75 #define C_LibraryMgr
76 #define C_EnvMgr
77 #ifdef UseSessionMgmt
78 #define C_SessionMgr
79 #endif
80 #ifdef UseTooltalk
81 #define C_TtIpcMgr
82 #endif
83 #define L_Managers
84
85 #define C_UrlAgent
86 #define L_Agents
87
88 #include "Prelude.h"
89
90 #include "Managers/CatMgr.hh"
91
92 #include "Exceptions.hh"
93 #include "utility/mmdb_exception.h"
94
95 #ifdef MONITOR
96 extern "C" {
97   extern void monitor(int);
98   int quantify_clear_data(void);
99 }  
100 #endif
101 extern "C" {
102   int quantify_clear_data(void);
103 }  
104
105
106 #ifdef UseSessionMgmt
107 // Background task to explicitly save the initial session state.
108 // Need this work proc to run last on startup.
109 //
110 Boolean
111 SetSession_wp( XtPointer /*fiddler_on_the_roof*/ )
112 {
113   session().set() ;                     // explicitly save the state
114   return (Boolean)True ;                // must always return True
115 }
116
117 // Background task to check for and restore any prior session state
118 //
119 Boolean
120 RestoreSession_wp( XtPointer /*fiddler_on_the_roof*/ )
121 {
122   session().restore() ;                 // check for saved state & process
123   return (Boolean)True ;                // must always return True
124 }
125 #endif
126
127
128 #ifdef UseTooltalk
129 // Background task to initialize with tooltalk.
130 // Do before initial session state saved.
131 //
132 Boolean
133 SetTooltalk_wp( XtPointer /*fiddler_on_the_roof*/ )
134 {
135   if( !env().secondary() )
136             tt_manager().establish_server();
137   return (Boolean)True ;                // must always return True
138 }
139 #endif
140
141
142 // Background task to launch explicit section requests at startup
143 //
144 Boolean
145 DisplayNode_wp( XtPointer locator )
146 {
147   UrlAgent::document( (char *)locator, 1 );     // arg2 = force new window
148   delete [] (char *)locator;
149
150   return (Boolean)True ;                        // must always return True
151 }
152
153 // this series will window-stack multiple documents with the
154 // first in the list displayed last, and thus on top
155 //
156 void
157 DisplayDocList( UAS_List<UAS_String> docs )
158 {
159     UAS_String  doc_locator, start_doc, end_doc ;
160     char *document;
161     char *temp;
162
163 #ifdef UseSessionMgmt
164   if( docs.length() != 0 )
165   {
166     // the presumption for now is that any special session state
167     // info will exist only if there were node display windows... 
168     XtAppAddWorkProc( window_system().app_context(),
169                       RestoreSession_wp, (char *)NULL ) ;
170   }
171 #endif
172
173   // set up to display the documents
174
175   for (unsigned int i = 0; i < docs.length(); i++)
176   {
177     (*(docs[i])).split( '-', start_doc, end_doc ) ;
178     doc_locator = start_doc.length() ? start_doc : end_doc ;
179
180     // only print cares about a range of locators;
181     // for display, just do the first locator if a range
182
183     // allocate memory for a normal c string to pass
184     // through to the work proc
185
186     int len = doc_locator.length();
187     document = new char[len + 1];
188     temp = (char *)doc_locator;
189     *((char *) memcpy(document, temp, len) + len) = '\0';
190
191     XtAppAddWorkProc( window_system().app_context(),
192                       DisplayNode_wp, document) ;
193   }
194 }
195
196
197 // PrintNode_wp
198 //
199 // Background task to launch explicit section requests at startup
200 //
201 Boolean
202 PrintNode_wp( XtPointer locator )
203 {
204   UrlAgent::print_document( (char *)locator);
205   delete [] (char *)locator;
206   return (Boolean)True ;                        // must always return True
207 }
208
209
210 // PrintDocList will print a list of sections
211
212 void
213 PrintDocList( UAS_List<UAS_String> docs )
214 {
215     UAS_String  doc_locator, start_doc, end_doc ;
216     char *document;
217     char *temp;
218     
219     for (unsigned int i = 0; i < docs.length(); i++)
220     {
221         (*(docs[i])).split( '-', start_doc, end_doc ) ;
222         doc_locator = start_doc.length() ? start_doc : end_doc ;
223         
224         // only print cares about a range of locators;
225         int len = doc_locator.length();
226         document = new char[len + 1];
227         temp = (char *)doc_locator;
228         *((char *) memcpy(document, temp, len) + len) = '\0';
229                 
230         // ... needs expansion of range here if present ...
231         XtAppAddWorkProc( window_system().app_context(),
232                           PrintNode_wp, document ) ;
233     }
234 }
235
236 int
237 main(int argc, char **argv)
238 {
239     INIT_EXCEPTIONS();
240     
241 #if defined(sparc) && defined(MAP_ZERO)
242     // to permit dtsearch to access address zero 
243     mmap(NULL, 0x1000, PROT_READ, MAP_PRIVATE | MAP_FIXED,
244          open("/dev/zero", O_RDONLY), 0);
245 #endif
246     
247 #ifdef MONITOR
248     monitor(0);
249 #endif
250     
251     WindowSystem window_system (argc, argv);
252     CatMgr msg_catalog_mgr;
253     InputMgrX input_manager;
254     if (env().init(argc, argv) < 0)
255         exit(1);
256     
257     mtry
258     {
259         
260         // don't set up for session management or tooltalk if
261         // invoked for print only
262         if (!window_system.videoShell()->print_only) {
263 #ifdef UseSessionMgmt
264             // set session state register to occur after startup has settled
265             XtAppAddWorkProc( window_system.app_context(),
266                               SetSession_wp, (char *)NULL ) ;
267 #endif
268 #ifdef UseTooltalk
269             XtAppAddWorkProc( window_system.app_context(),
270                               SetTooltalk_wp, (char *)NULL ) ;
271 #endif
272         }
273         
274         // set up to process any explicit section display requests for
275         // startup. If print only, print specified sections.
276         UAS_List<UAS_String>env_sections( env().sections() );
277
278         if (window_system.videoShell()->print_only) {
279             PrintDocList( env_sections );
280         }
281         else {
282             DisplayDocList( env_sections );
283         }
284         
285         // request immediate loading of any/all infolibs specified
286         UAS_List<UAS_String>env_infolibs( env().infolibs() );
287         library_mgr().init( env_infolibs );
288         
289         window_system.run();
290     }
291     mcatch (Exception &, e)
292     {
293         char buffer[256];
294         snprintf (buffer, sizeof(buffer),
295                  "Internal Error: Exception got away.\nFile: %s, Line: %d",
296 #ifdef C_API
297                  e.file(), e.line());
298 #else
299                  __FILE__, __LINE__);
300 #endif
301         message_mgr().error_dialog (buffer);
302         exit (1);
303     }
304     end_try;
305     
306     return (0);
307 }
308
309 #ifdef hpux
310
311 extern "C" {
312 void DosClose () { cerr << "DosClose\n"; }
313 void DosWrite () { cerr << "DosWrite\n"; }
314 void DosPeekNmPipe () { cerr << "DosPeekNmPipe\n"; }
315 void DosDisconnectNmPipe () { cerr << "DosDisconnectNmPipe\n"; }
316 void DosMakeNmPipe () { cerr << "DosMakeNmPipe\n"; }
317 void DosConnectNmPipe () { cerr << "DosConnectNmPipe\n"; }
318 void DosRead () { cerr << "DosRead\n"; }
319 }
320
321 #endif