2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
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 */
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. *
39 #include "TermHeader.h"
41 #include <Xm/RepType.h>
43 #include "TermPrimP.h"
44 #include "TermPrimRepType.h"
46 static void CvtStringToTerminalSizeDestroy
50 XtPointer converter_data,
55 static void CvtStringToTerminalSizeListDestroy
59 XtPointer converter_data,
64 static Boolean CvtStringToTerminalSize
71 XtPointer *converter_data
74 static Boolean CvtStringToTerminalSizeList
81 XtPointer *converter_data
86 static String TermEmulationModeStrings[] = {
91 static String CharCursorStyleStrings[] = {
96 XmRepTypeId _DtTermPrimEmulationMode;
97 XmRepTypeId _DtTermPrimCharCursorStyle;
99 void _DtTermPrimInitRepTypes(void)
101 static Boolean first = True;
103 _DtTermProcessLock();
105 /* register our resource converters... */
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));
121 _DtTermPrimEmulationMode = XmRepTypeGetId(DtRDtTermEmulationMode);
122 _DtTermPrimCharCursorStyle = XmRepTypeGetId(DtRDtTermCharCursorStyle);
126 _DtTermProcessUnlock();
133 CvtStringToTerminalSizeDestroy
137 XtPointer converter_data,
142 (void) XtFree(*((char **) to->addr));
147 CvtStringToTerminalSize
154 XtPointer *converter_data
158 static DtTermTerminalSize _size;
159 DtTermTerminalSize *size = &_size;
162 str = (char *) from->addr;
165 if (to->size < sizeof(*size)) {
166 to->size = sizeof(*size);
169 size = (DtTermTerminalSize *)(to->addr);
171 to->addr = (XtPointer) size;
172 to->size = sizeof(DtTermTerminalSize);
175 /* find the separating 'x'... */
176 c1 = strchr(str, 'x');
178 /* set default values for rows and columns... */
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
187 if (c1 && (c1 == str)) {
188 /* "x<rows>", no columns supplied... */
189 size->rows = atoi(++c1);
191 /* we have a column value before the 'x'... */
192 size->columns = atoi(str);
194 /* we have a an 'x' and a row value after the 'x'... */
195 size->rows = atoi(c1);
201 #endif /* NotDefined */
204 CvtStringToTerminalSizeListDestroy
208 XtPointer converter_data,
213 DtTermTerminalSizeList *sizeList;
215 sizeList = (DtTermTerminalSizeList *) (to->addr);
216 if (sizeList->sizes) {
217 (void) XtFree((char *) sizeList->sizes);
219 (void) XtFree((char *) sizeList);
223 CvtStringToTerminalSizeList
230 XtPointer *converter_data
234 static DtTermTerminalSizeList _sizeList;
235 DtTermTerminalSizeList *sizeList = &_sizeList;
241 DtTermTerminalSize *sizes = (DtTermTerminalSize *) 0;
243 str = (char *) from->addr;
246 if (to->size < sizeof(*sizeList)) {
247 to->size = sizeof(*sizeList);
250 sizeList = (DtTermTerminalSizeList *)(to->addr);
252 to->addr = (XtPointer) sizeList;
253 to->size = sizeof(DtTermTerminalSizeList);
257 sizes = (DtTermTerminalSize *) XtRealloc((char *) sizes,
258 sizesSize * sizeof(DtTermTerminalSize));
260 for (numSizes = 0, c1 = str; c1 && *c1; numSizes++) {
261 if (numSizes + 1 > sizesSize) {
263 sizes = (DtTermTerminalSize *) XtRealloc((char *) sizes,
264 sizesSize * sizeof(DtTermTerminalSize));
266 sizes[numSizes].rows = 0;
267 sizes[numSizes].columns = 0;
269 /* parse off columns... */
270 if ((*c1 >= '0') && (*c1 <= '9')) {
271 sizes[numSizes].columns = (short) strtol(c1, &c1, 10);
273 /* skip over all garbage up to possible 'x' */
274 while (c1 && *c1 && *c1 != 'x' && !isspace(*c1)) {
281 /* parse off rows... */
283 if ((*c1 >= '0') && (*c1 <= '9')) {
284 sizes[numSizes].rows = (short) strtol(c1, &c1, 10);
288 /* skip over all garbage up to whitespace... */
289 while (c1 && *c1 && !isspace(*c1)) {
293 /* skip over whitespace... */
294 while (c1 && *c1 && isspace(*c1)) {
298 /* check to see if we actually found any numbers */
299 if ( sizes[numSizes].rows ==0 && sizes[numSizes].columns == 0)
303 /* we can now allocate our returned size array... */
304 if ( numSizes <= 0 ) {
307 sizes[0].columns = 80;
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);