Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / lib / tttk / tttkutils.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 librararies 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 //%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                  
24 //%%  (c) Copyright 1993, 1994 International Business Machines Corp.    
25 //%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                   
26 //%%  (c) Copyright 1993, 1994 Novell, Inc.                             
27 //%%  $XConsortium: tttkutils.C /main/4 1996/02/27 16:06:59 drk $                                                       
28 /*
29  * @(#)tttkutils.C      1.3 93/09/07
30  *
31  * Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
32  */
33 #include <stdio.h>
34 #include <string.h>
35 #include <unistd.h>
36 #include "api/c/tt_c.h"
37 #include "util/tt_port.h"
38 #include "api/c/api_api.h"
39 #include "tttk/tttk.h"
40 #include "tttk/tttkutils.h"
41
42 char _TttkKeys[ _TttkNumKeys ] = { 0 };
43
44 // Array of supported desktop messages
45
46 const char *TtDtOps[] = {
47         "TtDtOpNone",
48         "Created",
49         "Deleted",
50         "Do_Command",
51         "Set_Environment",
52         "Get_Environment",
53         "Set_Geometry",
54         "Get_Geometry",
55         "Set_Iconified",
56         "Get_Iconified",
57         "Set_Locale",
58         "Get_Locale",
59         "Set_Mapped",
60         "Get_Mapped",
61         "Modified",
62         "Reverted",
63         "Get_Modified",
64         "Moved",
65         "Pause",
66         "Resume",
67         "Quit",
68         "Raise",
69         "Lower",
70         "Save",
71         "Revert",
72         "Saved",
73         "Set_Situation",
74         "Get_Situation",
75         "Signal",
76         "Started",
77         "Stopped",
78         "Status",
79         "Get_Status",
80         "Get_Sysinfo",
81         "Set_XInfo",
82         "Get_XInfo",
83         "Abstract",
84         "Deposit",
85         "Display",
86         "Edit",
87         "Edit",
88         "Interpret",
89         "Print",
90         "Translate",
91         "Mail",
92         "Mail",
93         "Mail",
94         "Instantiate"
95 };
96
97 Tt_callback_action
98 _ttDtCallbackAction(
99         Tt_message msg
100 )
101 {
102         Tt_status status = tt_ptr_error( msg );
103         if ((status != TT_OK) || (msg == 0)) {
104                 return TT_CALLBACK_PROCESSED;
105         } else {
106                 return TT_CALLBACK_CONTINUE;
107         }
108 }
109
110 void
111 _ttDtPrint(
112         const char     *whence,
113         const char     *msg
114 )
115 {
116         _tt_syslog( 0, LOG_ERR, "%s: %s", whence, msg );
117 }
118
119 void
120 _ttDtPrintStatus(
121         const char     *whence,
122         const char     *expr,
123         Tt_status       status
124 )
125 {
126         _tt_syslog( 0, LOG_ERR, "%s: %s: %s\n",
127                     whence, expr, tt_status_message( status ));
128 }
129
130 void
131 _ttDtPrintInt(
132         const char     *whence,
133         const char     *expr,
134         int             n
135 )
136 {
137         _tt_syslog( 0, LOG_ERR, "%s: %s: %d\n", whence, expr, n );
138 }
139
140 void
141 _ttDtPError(
142         const char     *whence,
143         const char     *msg
144 )
145 {
146         _tt_syslog( 0, LOG_ERR, "%s: %s: %m", whence, msg );
147 }
148
149 Tttk_op
150 tttk_string_op(
151         const char *s
152 )
153 {
154         if (s == 0) return TTDT_OP_NONE;
155         for (int op = TTDT_OP_NONE; op < TTDT_OP_LAST; op++) {
156                 const char *opStr = _ttDtOp( (Tttk_op)op );
157                 if (opStr == 0) {
158                         continue;
159                 }
160                 if (strcmp( opStr, s ) == 0) {
161                         return (Tttk_op)op;
162                 }
163         }
164         return TTDT_OP_NONE;
165 }
166
167 const char *
168 _ttDtOp(
169         Tttk_op op
170 )
171 {
172         if ((op > TTDT_OP_NONE) && (op < TTDT_OP_LAST)) {
173                 return TtDtOps[ op ];
174         } else {
175                 return 0;
176         }
177 }
178
179 char *
180 tttk_op_string(
181         Tttk_op op
182 )
183 {
184         return _tt_strdup( _ttDtOp( op ));
185 }