Fix some minor issues and re-enable building of DE, ES, FR, and IT locale data (help...
[oweals/cde.git] / cde / programs / dtwm / Parse.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 /* $TOG: Parse.c /main/5 1998/01/12 16:47:01 cshi $ */
24 /*****************************************************************************
25  *
26  *   File:         Parse.c
27  *
28  *   Project:       CDE
29  *
30  *   Description:  This file contains the parsing functions for Front Panel
31  *                 file information.
32  *
33  * (c) Copyright 1993, 1994 Hewlett-Packard Company
34  * (c) Copyright 1993, 1994 International Business Machines Corp.
35  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
36  * (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of Novell, Inc.
37  *
38  *****************************************************************************/
39
40 #include <Dt/DtP.h>
41 #include <Dt/DbReader.h>
42 #include <Dt/UserMsg.h>
43
44 #include "WmGlobal.h"
45 #include "WmParse.h"
46 #include "DataBaseLoad.h"
47 #include "Parse.h"
48
49
50 /************************************************************************
51  *
52  *  StringToString
53  *
54  ************************************************************************/
55
56 Boolean
57 StringToString (char * parse_source,
58                 void ** parse_return)
59
60 {
61    *parse_return = (void *) strdup (parse_source);
62
63    return (True);
64 }
65
66
67
68
69 /************************************************************************
70  *
71  *  StrintToInt
72  *
73  ************************************************************************/
74
75 Boolean
76 StringToInt (char * parse_source,
77              void ** parse_return)
78
79 {
80    char * source_ptr = parse_source;
81    int    value = 0;
82    char   chr;
83
84
85    while (chr = *source_ptr++) 
86    {
87       if (chr >= '0' && chr <= '9') 
88       {
89          value *= 10;
90          value += chr - '0';
91       }
92       else
93       {
94          _DtSimpleError (panel.app_name, DtError, NULL, 
95                         "Invalid Integer -- %s", parse_source);
96          return (False);
97       }
98    }
99
100    *parse_return = (void *) value;
101    return (True);
102 }
103
104
105
106
107 /************************************************************************
108  *
109  *  StringToBoolean
110  *
111  ************************************************************************/
112
113 Boolean
114 StringToBoolean (char * parse_source,
115                  void ** parse_return)
116
117 {
118    _DtWmParseToLower((unsigned char *)parse_source);
119
120    if (strcmp (parse_source, "true") == 0)
121       *parse_return = (void *) True;
122    else if (strcmp (parse_source, "false") == 0)
123       *parse_return = (void *) False;
124    else
125    {
126       _DtSimpleError (panel.app_name, DtError, NULL, 
127                      "Invalid Boolean -- %s", parse_source);
128       return (False);
129    }
130
131    return (True);
132 }
133
134
135
136
137 /************************************************************************
138  *
139  *  StringToResolution
140  *
141  ************************************************************************/
142
143 Boolean
144 StringToResolution (char * parse_source,
145                     void ** parse_return)
146
147 {
148    _DtWmParseToLower ((unsigned char *) parse_source);
149    
150    if (strcmp (parse_source, resolution_types[HIGH]) == 0)
151       *parse_return = (void *) HIGH;
152    else if (strcmp (parse_source, resolution_types[MEDIUM]) == 0)
153       *parse_return = (void *) MEDIUM;
154    else if (strcmp (parse_source, resolution_types[LOW]) == 0)
155       *parse_return = (void *) LOW;
156    else if (strcmp (parse_source, resolution_types[MATCH_DISPLAY]) == 0)
157       *parse_return = (void *) MATCH_DISPLAY;
158    else
159    {
160       _DtSimpleError (panel.app_name, DtError, NULL, 
161                      "Invalid Resolution -- %s", parse_source);
162       return (False);
163    }
164
165    return (True);
166 }
167
168
169
170
171 /************************************************************************
172  *
173  *  StringToControlBehavior 
174  *
175  ************************************************************************/
176
177 Boolean
178 StringToControlBehavior (char * parse_source,
179                          void ** parse_return)
180
181 {
182    _DtWmParseToLower ((unsigned char *) parse_source);
183
184    if (strcmp (parse_source, "double_click") == 0)
185       *parse_return = (void *) DOUBLE_CLICK;
186    else if (strcmp (parse_source, "single_click") == 0)
187       *parse_return = (void *) SINGLE_CLICK;
188    else
189    {
190       _DtSimpleError (panel.app_name, DtError, NULL, 
191                      "Invalid Control Behavior -- %s", parse_source);
192       return (False);
193    }
194
195    return (True);
196 }
197
198
199
200
201 /************************************************************************
202  *
203  *  StringToGeometry
204  *
205  ************************************************************************/
206
207 Boolean
208 StringToGeometry (char * parse_source,
209                   void ** parse_return)
210
211 {
212    GeometryData *value;
213    int mask;
214    int x, y, width, height;
215
216
217    x = y = width = height = 0;
218
219    mask = XParseGeometry ((char *) parse_source, &x, &y, 
220                           (unsigned int *) &width, (unsigned int *) &height);
221
222    if (mask)
223    {
224       /* Allocate space for the geometry structure  */
225
226       value = (GeometryData *) XtMalloc (sizeof (GeometryData));
227
228       value->flags = mask;
229       value->x = x;
230       value->y = y;
231       value->width = width;
232       value->height = height;
233        
234       *parse_return = (void *) value;
235    }
236    else
237    {
238       _DtSimpleError (panel.app_name, DtError, NULL, 
239                      "Invalid Geometry -- %s", parse_source);
240       return (False);
241    }
242
243    return (True);
244 }
245
246
247
248
249 /************************************************************************
250  *
251  *  StringToAction
252  *
253  ************************************************************************/
254
255
256 Boolean
257 StringToAction (char * parse_source,
258                 void ** parse_return)
259
260
261 {
262    PanelActionData * action_data;
263    unsigned char * string, * source, * head_ptr;
264
265
266    head_ptr = source = (unsigned char *) strdup (parse_source);
267
268    if ((string = _DtWmParseNextTokenC (&source, False)) != NULL)
269    {
270       action_data = (PanelActionData *) XtMalloc (sizeof (PanelActionData));
271
272       action_data->action_name = strdup ((char *) string);
273       action_data->action_label = NULL;
274       action_data->aap = NULL;
275       action_data->count = 0;
276
277       while ((string = _DtWmParseNextTokenC (&source, False)) != NULL)
278       {
279          action_data->count++;
280          action_data->aap =
281             (DtActionArg *) XtRealloc ((char *) action_data->aap,
282                                     (sizeof (DtActionArg) * action_data->count));
283          action_data->aap[action_data->count-1].argClass = DtACTION_FILE;
284
285          action_data->aap[action_data->count-1].u.file.name =
286                                                  strdup((char *)string);
287       }
288    }
289    else
290    {
291       _DtSimpleError (panel.app_name, DtError, NULL, 
292                      "Invalid Action -- %s", parse_source);
293       return (False);
294    }
295
296    free ((char *) head_ptr);
297    *parse_return = (void *) action_data;
298    return (True);
299 }
300
301
302
303
304 /************************************************************************
305  *
306  *  StringToControlType
307  *
308  ************************************************************************/
309
310 Boolean
311 StringToControlType (char * parse_source,
312                      void ** parse_return)
313
314 {
315    _DtWmParseToLower ((unsigned char *) parse_source);
316
317    if (strcmp (parse_source, control_types[CONTROL_BLANK]) == 0)
318       *parse_return = (void *) CONTROL_BLANK;
319    else if (strcmp (parse_source, control_types[CONTROL_BUSY]) == 0)
320       *parse_return = (void *) CONTROL_BUSY;
321    else if (strcmp (parse_source, control_types[CONTROL_ICON]) == 0)
322       *parse_return = (void *) CONTROL_ICON;
323    else if (strcmp (parse_source, control_types[CONTROL_CLIENT]) == 0)
324       *parse_return = (void *) CONTROL_CLIENT;
325    else if (strcmp (parse_source, control_types[CONTROL_CLOCK]) == 0)
326       *parse_return = (void *) CONTROL_CLOCK;
327    else if (strcmp (parse_source, control_types[CONTROL_DATE]) == 0)
328       *parse_return = (void *) CONTROL_DATE;
329    else if (strcmp (parse_source, control_types[CONTROL_FILE]) == 0)
330       *parse_return = (void *) CONTROL_FILE;
331    else
332    {
333       _DtSimpleError (panel.app_name, DtError, NULL, 
334                      "Invalid Control Type -- %s", parse_source);
335       return (False);
336    }
337
338    return (True);
339 }
340
341
342
343
344 /************************************************************************
345  *
346  *  StringToMonitorType
347  *
348  ************************************************************************/
349
350 Boolean
351 StringToMonitorType (char * parse_source,
352                      void ** parse_return)
353
354 {
355    _DtWmParseToLower ((unsigned char *) parse_source);
356
357    if (strcmp (parse_source, monitor_types[MONITOR_NONE]) == 0)
358       *parse_return = (void *) MONITOR_NONE;
359    else if (strcmp (parse_source, monitor_types[MONITOR_MAIL]) == 0)
360       *parse_return = (void *) MONITOR_MAIL;
361    else if (strcmp (parse_source, monitor_types[MONITOR_FILE]) == 0)
362       *parse_return = (void *) MONITOR_FILE;
363    else
364    {
365       _DtSimpleError (panel.app_name, DtError, NULL, 
366                      "Invalid Monitor Type -- %s", parse_source);
367       return (False);
368    }
369
370    return (True);
371 }
372
373
374
375
376 /************************************************************************
377  *
378  *  StringToControlContainerType
379  *
380  ************************************************************************/
381
382 Boolean
383 StringToControlContainerType (char * parse_source,
384                               void ** parse_return)
385
386 {
387    if (strcmp (parse_source, entry_types[BOX]) == 0)
388       *parse_return = (void *) BOX;
389    else if (strcmp (parse_source, entry_types[SUBPANEL]) == 0)
390       *parse_return = (void *) SUBPANEL;
391    else if (strcmp (parse_source, entry_types[SWITCH]) == 0)
392       *parse_return = (void *) SWITCH;
393    else
394    {
395       _DtSimpleError (panel.app_name, DtError, NULL, 
396                      "Invalid Control Container Type -- %s", parse_source);
397       return (False);
398    }
399
400    return (True);
401 }
402
403
404
405
406 /************************************************************************
407  *
408  *  StringToPositionHints
409  *
410  ************************************************************************/
411
412 Boolean
413 StringToPositionHints (char * parse_source,
414                        void ** parse_return)
415
416 {
417    Boolean status;
418
419    _DtWmParseToLower ((unsigned char *) parse_source);
420
421    if (strcmp (parse_source, "first") == 0)
422       parse_source = "0";
423    else if (strcmp (parse_source, "last") == 0)
424       parse_source = "100";
425
426    status = StringToInt (parse_source, parse_return);
427
428    if ((int) *parse_return < 0 || (int) *parse_return > 100)
429    {
430       
431       _DtSimpleError (panel.app_name, DtError, NULL, 
432                      "Invalid Position Hints value -- %d",
433                      (int) *parse_return);
434       return (False);
435    }
436
437    return ( True );
438 }
439
440
441 /************************************************************************
442  *
443  *  StringToFileName
444  *     Converts net file format to a file format.
445  *
446  ************************************************************************/
447
448 Boolean
449 StringToFileName (char * parse_source,
450                   void ** parse_return)
451
452 {
453    return (StringToString(parse_source, parse_return));
454 }
455
456
457
458
459 /************************************************************************
460  *
461  *  FreeString
462  *
463  ************************************************************************/
464
465 void
466 FreeString (void ** parse_value)
467
468 {
469     XtFree ((char *) *parse_value);
470 }
471
472
473
474
475 /************************************************************************
476  *
477  *  FreeGeometry
478  *
479  ************************************************************************/
480
481 void
482 FreeGeometry (void ** parse_value)
483
484 {
485    XtFree ((char *) *parse_value);
486 }
487
488
489
490
491 /************************************************************************
492  *
493  *  FreeAction
494  *
495  ************************************************************************/
496
497 void
498 FreeAction (void ** parse_value)
499 {
500    PanelActionData * actionData = (PanelActionData *) *parse_value;
501    int i;
502
503    XtFree (actionData->action_name);
504
505    for (i = 0; i < actionData->count; i++)
506      XtFree ((char *) actionData->aap[i].u.file.name);
507
508    XtFree ((char *) actionData->aap);
509
510    XtFree ((char *) *parse_value);
511 }