XlationSvc: remove a "'" added in previous spelling commit that causes warnings
[oweals/cde.git] / cde / lib / DtSvc / DtUtil2 / Info.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: Info.c /main/1 1996/03/25 19:10:11 barstow $
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 1996 FUJITSU LIMITED.
31  * (c) Copyright 1996 Hitachi.
32  *
33  * This file contains the main program for: dtinfo_start
34  */
35
36 #include <stdlib.h>
37 #include <sys/param.h>          /* MAXHOSTNAMELEN */
38 #include <Tt/tt_c.h>
39 #include <Dt/Info.h>
40 #include <Dt/Connect.h>
41
42 /*
43  * External declaration for Xegethostname
44  */
45 extern int Xegetshorthostname (char * hostname, unsigned int size);
46
47
48 /*
49  * Static variables
50  */
51 static const char       * DTINFOLIBDEFAULT_NAME = "DTINFOLIBDEFAULT";
52
53 static const char       * DTINFOLIBDEFAULT_DEFAULT = "cde";
54
55 static const char       * SHOW_INFO_OP_NAME = "DtInfo_ShowInfoAtLoc";
56
57 static const char       * SHOW_INFO_DEFAULT_ACTION = "DtInfoStartAtLoc";
58
59 static const char       * LOCALE_NAME = "LANG";
60
61 static const char       * DEFAULT_LOCALE = "C";
62
63 static const char       * STRING_ARG_TYPE = "string";
64
65
66 /*
67  * Forward declarations for static functions
68  */
69 static DtInfoShowStatus ConnectToMessageServer ();
70
71
72 /*
73  * Public functions
74  */
75 DtInfoShowStatus
76 DtInfoShowTopic (
77         const char              * info_lib,     /* the InfoLib */
78         const char              * locator)      /* the generalized locator
79                                                    format */
80 {
81         Tt_message              message;
82         Tt_status               status;
83         DtInfoShowStatus        ret_val;
84         const char              * file = info_lib;
85         const char              * locale;
86         char                    host[MAXHOSTNAMELEN];
87
88         /*
89          * Check the arguments
90          */
91         if (!locator)
92                 return (DtINFO_SHOW_BAD_LOCATOR);
93
94         if ((ret_val = ConnectToMessageServer ()) != DtINFO_SHOW_OK)
95                 return (ret_val);
96
97         if (!file) {
98                 if ((file = getenv (DTINFOLIBDEFAULT_NAME)) == NULL)
99                         file = DTINFOLIBDEFAULT_DEFAULT;
100         }
101
102         if ((locale = getenv (LOCALE_NAME)) == NULL)
103                 locale = DEFAULT_LOCALE;
104
105         message = tt_message_create ();
106         status = tt_ptr_error (message);
107         if (status != TT_OK)
108                 return (DtINFO_SHOW_MSG_CREATE_FAIL);
109
110         /*
111          * Initialize message
112          */
113         tt_message_class_set    (message, TT_REQUEST);
114         tt_message_scope_set    (message, TT_SESSION);
115         tt_message_address_set  (message, TT_PROCEDURE);
116         tt_message_session_set  (message, tt_default_session());
117         tt_message_op_set       (message, SHOW_INFO_OP_NAME);
118         tt_message_file_set     (message, info_lib);
119
120         /*
121          * Add the arguments
122          */
123         tt_message_arg_add (message, TT_IN, STRING_ARG_TYPE, 
124                             SHOW_INFO_DEFAULT_ACTION);
125
126         if ((Xegetshorthostname (host, MAXHOSTNAMELEN)) != 0)
127                 tt_message_arg_add (message, TT_IN, STRING_ARG_TYPE, NULL);
128         else
129                 tt_message_arg_add (message, TT_IN, STRING_ARG_TYPE, host);
130
131         tt_message_arg_add (message, TT_IN, STRING_ARG_TYPE, locale);
132         tt_message_arg_add (message, TT_IN, STRING_ARG_TYPE, locator);
133
134         /*
135          * Send it
136          */
137         status = tt_message_send (message);
138         if (status != TT_OK)
139                 return (DtINFO_SHOW_MSG_SEND_FAIL);
140
141         return (DtINFO_SHOW_OK);
142 }
143
144
145 static DtInfoShowStatus
146 ConnectToMessageServer ()
147 {
148         char                    * procid;
149         Tt_status               status;
150
151         procid = tt_default_procid ();
152         status = tt_ptr_error (procid);
153         if (status == TT_OK) {
154                 tt_free (procid);
155         }
156
157         if ((status == TT_ERR_NOMP) || (status == TT_ERR_PROCID)) {
158                 procid = tt_open ();
159                 status = tt_ptr_error (procid);
160                 if (status != TT_OK) {
161                         return (DtINFO_SHOW_TT_OPEN_FAIL);
162                 }
163         }
164
165         return (DtINFO_SHOW_OK);
166 }