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
23 /* $TOG: Parse.c /main/5 1998/01/12 16:47:01 cshi $ */
24 /*****************************************************************************
30 * Description: This file contains the parsing functions for Front Panel
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.
38 *****************************************************************************/
41 #include <Dt/DbReader.h>
42 #include <Dt/UserMsg.h>
46 #include "DataBaseLoad.h"
50 /************************************************************************
54 ************************************************************************/
57 StringToString (char * parse_source,
61 *parse_return = (void *) strdup (parse_source);
69 /************************************************************************
73 ************************************************************************/
76 StringToInt (char * parse_source,
80 char * source_ptr = parse_source;
85 while (chr = *source_ptr++)
87 if (chr >= '0' && chr <= '9')
94 _DtSimpleError (panel.app_name, DtError, NULL,
95 "Invalid Integer -- %s", parse_source);
100 *parse_return = (void *) value;
107 /************************************************************************
111 ************************************************************************/
114 StringToBoolean (char * parse_source,
115 void ** parse_return)
118 _DtWmParseToLower((unsigned char *)parse_source);
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;
126 _DtSimpleError (panel.app_name, DtError, NULL,
127 "Invalid Boolean -- %s", parse_source);
137 /************************************************************************
141 ************************************************************************/
144 StringToResolution (char * parse_source,
145 void ** parse_return)
148 _DtWmParseToLower ((unsigned char *) parse_source);
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;
160 _DtSimpleError (panel.app_name, DtError, NULL,
161 "Invalid Resolution -- %s", parse_source);
171 /************************************************************************
173 * StringToControlBehavior
175 ************************************************************************/
178 StringToControlBehavior (char * parse_source,
179 void ** parse_return)
182 _DtWmParseToLower ((unsigned char *) parse_source);
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;
190 _DtSimpleError (panel.app_name, DtError, NULL,
191 "Invalid Control Behavior -- %s", parse_source);
201 /************************************************************************
205 ************************************************************************/
208 StringToGeometry (char * parse_source,
209 void ** parse_return)
214 int x, y, width, height;
217 x = y = width = height = 0;
219 mask = XParseGeometry ((char *) parse_source, &x, &y,
220 (unsigned int *) &width, (unsigned int *) &height);
224 /* Allocate space for the geometry structure */
226 value = (GeometryData *) XtMalloc (sizeof (GeometryData));
231 value->width = width;
232 value->height = height;
234 *parse_return = (void *) value;
238 _DtSimpleError (panel.app_name, DtError, NULL,
239 "Invalid Geometry -- %s", parse_source);
249 /************************************************************************
253 ************************************************************************/
257 StringToAction (char * parse_source,
258 void ** parse_return)
262 PanelActionData * action_data;
263 unsigned char * string, * source, * head_ptr;
266 head_ptr = source = (unsigned char *) strdup (parse_source);
268 if ((string = _DtWmParseNextTokenC (&source, False)) != NULL)
270 action_data = (PanelActionData *) XtMalloc (sizeof (PanelActionData));
272 action_data->action_name = strdup ((char *) string);
273 action_data->action_label = NULL;
274 action_data->aap = NULL;
275 action_data->count = 0;
277 while ((string = _DtWmParseNextTokenC (&source, False)) != NULL)
279 action_data->count++;
281 (DtActionArg *) XtRealloc ((char *) action_data->aap,
282 (sizeof (DtActionArg) * action_data->count));
283 action_data->aap[action_data->count-1].argClass = DtACTION_FILE;
285 action_data->aap[action_data->count-1].u.file.name =
286 strdup((char *)string);
291 _DtSimpleError (panel.app_name, DtError, NULL,
292 "Invalid Action -- %s", parse_source);
296 free ((char *) head_ptr);
297 *parse_return = (void *) action_data;
304 /************************************************************************
306 * StringToControlType
308 ************************************************************************/
311 StringToControlType (char * parse_source,
312 void ** parse_return)
315 _DtWmParseToLower ((unsigned char *) parse_source);
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;
333 _DtSimpleError (panel.app_name, DtError, NULL,
334 "Invalid Control Type -- %s", parse_source);
344 /************************************************************************
346 * StringToMonitorType
348 ************************************************************************/
351 StringToMonitorType (char * parse_source,
352 void ** parse_return)
355 _DtWmParseToLower ((unsigned char *) parse_source);
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;
365 _DtSimpleError (panel.app_name, DtError, NULL,
366 "Invalid Monitor Type -- %s", parse_source);
376 /************************************************************************
378 * StringToControlContainerType
380 ************************************************************************/
383 StringToControlContainerType (char * parse_source,
384 void ** parse_return)
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;
395 _DtSimpleError (panel.app_name, DtError, NULL,
396 "Invalid Control Container Type -- %s", parse_source);
406 /************************************************************************
408 * StringToPositionHints
410 ************************************************************************/
413 StringToPositionHints (char * parse_source,
414 void ** parse_return)
419 _DtWmParseToLower ((unsigned char *) parse_source);
421 if (strcmp (parse_source, "first") == 0)
423 else if (strcmp (parse_source, "last") == 0)
424 parse_source = "100";
426 status = StringToInt (parse_source, parse_return);
428 if ((int) *parse_return < 0 || (int) *parse_return > 100)
431 _DtSimpleError (panel.app_name, DtError, NULL,
432 "Invalid Position Hints value -- %d",
433 (int) *parse_return);
441 /************************************************************************
444 * Converts net file format to a file format.
446 ************************************************************************/
449 StringToFileName (char * parse_source,
450 void ** parse_return)
453 return (StringToString(parse_source, parse_return));
459 /************************************************************************
463 ************************************************************************/
466 FreeString (void ** parse_value)
469 XtFree ((char *) *parse_value);
475 /************************************************************************
479 ************************************************************************/
482 FreeGeometry (void ** parse_value)
485 XtFree ((char *) *parse_value);
491 /************************************************************************
495 ************************************************************************/
498 FreeAction (void ** parse_value)
500 PanelActionData * actionData = (PanelActionData *) *parse_value;
503 XtFree (actionData->action_name);
505 for (i = 0; i < actionData->count; i++)
506 XtFree ((char *) actionData->aap[i].u.file.name);
508 XtFree ((char *) actionData->aap);
510 XtFree ((char *) *parse_value);