FreeBSD 10 clang port
[oweals/cde.git] / cde / lib / DtTerm / TermPrim / TermPrimRepType.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 #ifndef lint
24 #ifdef  VERBOSE_REV_INFO
25 static char rcs_id[] = "$XConsortium: TermPrimRepType.c /main/1 1996/04/21 19:19:11 drk $";
26 #endif  /* VERBOSE_REV_INFO */
27 #endif  /* lint */
28
29 /*                                                                      *
30  * (c) Copyright 1993, 1994, 1996 Hewlett-Packard Company               *
31  * (c) Copyright 1993, 1994, 1996 International Business Machines Corp. *
32  * (c) Copyright 1993, 1994, 1996 Sun Microsystems, Inc.                *
33  * (c) Copyright 1993, 1994, 1996 Novell, Inc.                          *
34  * (c) Copyright 1996 Digital Equipment Corporation.                    *
35  * (c) Copyright 1996 FUJITSU LIMITED.                                  *
36  * (c) Copyright 1996 Hitachi.                                          *
37  */
38
39 #include "TermHeader.h"
40
41 #include <Xm/RepType.h>
42
43 #include "TermPrimP.h"
44 #include "TermPrimRepType.h"
45
46 static void CvtStringToTerminalSizeDestroy
47 (
48         XtAppContext app,
49         XrmValue *to,
50         XtPointer converter_data,
51         XrmValue *args,
52         Cardinal *num_args
53 );
54
55 static void CvtStringToTerminalSizeListDestroy
56 (
57         XtAppContext app,
58         XrmValue *to,
59         XtPointer converter_data,
60         XrmValue *args,
61         Cardinal *num_args
62 );
63
64 static Boolean CvtStringToTerminalSize
65 (
66         Display *display,
67         XrmValue *args,
68         Cardinal *num_args,
69         XrmValue *from,
70         XrmValue *to,
71         XtPointer *converter_data
72 );
73
74 static Boolean CvtStringToTerminalSizeList
75 (
76         Display *display,
77         XrmValue *args,
78         Cardinal *num_args,
79         XrmValue *from,
80         XrmValue *to,
81         XtPointer *converter_data
82 );
83
84
85
86 static String TermEmulationModeStrings[] = {
87     "termemulation_hp",
88     "termemulation_ansi",
89 };
90
91 static String CharCursorStyleStrings[] = {
92     "char_cursor_box",
93     "char_cursor_bar",
94 };
95
96 XmRepTypeId _DtTermPrimEmulationMode;
97 XmRepTypeId _DtTermPrimCharCursorStyle;
98
99 void _DtTermPrimInitRepTypes(void)
100 {
101     static Boolean first = True;
102
103     _DtTermProcessLock();
104     if (first) {
105         /* register our resource converters... */
106 #ifdef NotDefined
107         (void) XtSetTypeConverter(XmRString, DtRDtTermTerminalSize,
108                 CvtStringToTerminalSize, NULL, 0, XtCacheNone,
109                 CvtStringToTerminalSizeDestroy);
110 #endif /* NotDefined */
111         (void) XtSetTypeConverter(XmRString, DtRDtTermTerminalSizeList,
112                 CvtStringToTerminalSizeList, NULL, 0, XtCacheNone,
113                 CvtStringToTerminalSizeListDestroy);
114         (void) XmRepTypeRegister(DtRDtTermEmulationMode,
115                 TermEmulationModeStrings,
116                 NULL, (unsigned char ) XtNumber(TermEmulationModeStrings));
117         (void) XmRepTypeRegister(DtRDtTermCharCursorStyle,
118                 CharCursorStyleStrings,
119                 NULL, (unsigned char ) XtNumber(CharCursorStyleStrings));
120
121         _DtTermPrimEmulationMode = XmRepTypeGetId(DtRDtTermEmulationMode);
122         _DtTermPrimCharCursorStyle = XmRepTypeGetId(DtRDtTermCharCursorStyle);
123
124         first = False;
125     }
126     _DtTermProcessUnlock();
127
128     return;
129 }
130
131 #ifdef NotDefined
132 static void
133 CvtStringToTerminalSizeDestroy
134 (
135     XtAppContext app,
136     XrmValue *to,
137     XtPointer converter_data,
138     XrmValue *args,
139     Cardinal *num_args
140 )
141 {
142     (void) XtFree(*((char **) to->addr));
143 }
144
145
146 static Boolean
147 CvtStringToTerminalSize
148 (
149     Display *display,
150     XrmValue *args,
151     Cardinal *num_args,
152     XrmValue *from,
153     XrmValue *to,
154     XtPointer *converter_data
155 )
156 {
157     char *str;
158     static DtTermTerminalSize _size;
159     DtTermTerminalSize *size = &_size;
160     char *c1;
161
162     str = (char *) from->addr;
163
164     if (to->addr) {
165         if (to->size < sizeof(*size)) {
166             to->size = sizeof(*size);
167             return(False);
168         }
169         size = (DtTermTerminalSize *)(to->addr);
170     } else {
171         to->addr = (XtPointer) size;
172         to->size = sizeof(DtTermTerminalSize);
173     }
174
175     /* find the separating 'x'... */
176     c1 = strchr(str, 'x');
177
178     /* set default values for rows and columns... */
179     size->rows = -1;
180     size->columns = -1;
181
182     /* we now have one of 3 possible valid expressions:
183      *          <columns>x<rows>        use <columns> and <rows>
184      *          <columns>[x]            use <columns> and current rows
185      *          x<rows>                 use <rows> and current columns
186      */
187     if (c1 && (c1 == str)) {
188         /* "x<rows>", no columns supplied... */
189         size->rows = atoi(++c1);
190     } else {
191         /* we have a column value before the 'x'... */
192         size->columns = atoi(str);
193         if (c1 && *++c1) {
194             /* we have a an 'x' and a row value after the 'x'... */
195             size->rows = atoi(c1);
196         }
197     }
198
199     return(True);
200 }
201 #endif /* NotDefined */
202
203 static void
204 CvtStringToTerminalSizeListDestroy
205 (
206     XtAppContext app,
207     XrmValue *to,
208     XtPointer converter_data,
209     XrmValue *args,
210     Cardinal *num_args
211 )
212 {
213     DtTermTerminalSizeList *sizeList;
214
215     sizeList = (DtTermTerminalSizeList *) (to->addr);
216     if (sizeList->sizes) {
217         (void) XtFree((char *) sizeList->sizes);
218     }
219     (void) XtFree((char *) sizeList);
220 }
221
222 static Boolean
223 CvtStringToTerminalSizeList
224 (
225     Display *display,
226     XrmValue *args,
227     Cardinal *num_args,
228     XrmValue *from,
229     XrmValue *to,
230     XtPointer *converter_data
231 )
232 {
233     char *str;
234     static DtTermTerminalSizeList _sizeList;
235     DtTermTerminalSizeList *sizeList = &_sizeList;
236     char *c1;
237     char *c2;
238     char *tmpStr;
239     int numSizes = 0;
240     int sizesSize = 0;
241     DtTermTerminalSize *sizes = (DtTermTerminalSize *) 0;
242
243     str = (char *) from->addr;
244
245     if (to->addr) {
246         if (to->size < sizeof(*sizeList)) {
247             to->size = sizeof(*sizeList);
248             return(False);
249         }
250         sizeList = (DtTermTerminalSizeList *)(to->addr);
251     } else {
252         to->addr = (XtPointer) sizeList;
253         to->size = sizeof(DtTermTerminalSizeList);
254     }
255
256     sizesSize += 10;
257     sizes = (DtTermTerminalSize *) XtRealloc((char *) sizes,
258                           sizesSize * sizeof(DtTermTerminalSize));
259
260     for (numSizes = 0, c1 = str; c1 && *c1; numSizes++) {
261         if (numSizes + 1 > sizesSize) {
262             sizesSize += 10;
263             sizes = (DtTermTerminalSize *) XtRealloc((char *) sizes,
264                     sizesSize * sizeof(DtTermTerminalSize));
265         }
266         sizes[numSizes].rows = 0;
267         sizes[numSizes].columns = 0;
268         if (*c1 != 'x') {
269             /* parse off columns... */
270             if ((*c1 >= '0') && (*c1 <= '9')) {
271                 sizes[numSizes].columns = (short) strtol(c1, &c1, 10);
272             } else {
273                 /* skip over all garbage up to possible 'x' */
274                 while (c1 && *c1 && *c1 != 'x' && !isspace(*c1)) {
275                     c1++;
276                 }
277             }
278         }
279
280         if (*c1 == 'x') {
281             /* parse off rows... */
282             (void) c1++;
283             if ((*c1 >= '0') && (*c1 <= '9')) {
284                 sizes[numSizes].rows = (short) strtol(c1, &c1, 10);
285             }
286         }
287
288         /* skip over all garbage up to whitespace... */
289         while (c1 && *c1 && !isspace(*c1)) {
290             c1++;
291         }
292
293         /* skip over whitespace... */
294         while (c1 && *c1 && isspace(*c1)) {
295             c1++;
296         }
297
298         /* check to see if we actually found any numbers */
299         if ( sizes[numSizes].rows ==0 && sizes[numSizes].columns == 0)
300            numSizes--;
301     }
302
303     /* we can now allocate our returned size array... */
304     if ( numSizes <= 0 ) {
305        numSizes =1;
306        sizes[0].rows = 24;
307        sizes[0].columns = 80;
308      }
309     sizeList->numSizes = numSizes;
310     sizeList->sizes = (DtTermTerminalSize *)
311             XtMalloc(numSizes * sizeof(DtTermTerminalSize));
312     (void) memcpy(sizeList->sizes, sizes, numSizes *
313             sizeof(DtTermTerminalSize));
314     (void) XtFree((char *) sizes);
315
316     return(True);
317 }