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 libraries 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(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 (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 (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);
297 free ((char *) head_ptr);
298 *parse_return = (void *) action_data;
305 /************************************************************************
307 * StringToControlType
309 ************************************************************************/
312 StringToControlType (char * parse_source,
313 void ** parse_return)
316 _DtWmParseToLower (parse_source);
318 if (strcmp (parse_source, control_types[CONTROL_BLANK]) == 0)
319 *parse_return = (void *) CONTROL_BLANK;
320 else if (strcmp (parse_source, control_types[CONTROL_BUSY]) == 0)
321 *parse_return = (void *) CONTROL_BUSY;
322 else if (strcmp (parse_source, control_types[CONTROL_ICON]) == 0)
323 *parse_return = (void *) CONTROL_ICON;
324 else if (strcmp (parse_source, control_types[CONTROL_CLIENT]) == 0)
325 *parse_return = (void *) CONTROL_CLIENT;
326 else if (strcmp (parse_source, control_types[CONTROL_CLOCK]) == 0)
327 *parse_return = (void *) CONTROL_CLOCK;
328 else if (strcmp (parse_source, control_types[CONTROL_DATE]) == 0)
329 *parse_return = (void *) CONTROL_DATE;
330 else if (strcmp (parse_source, control_types[CONTROL_FILE]) == 0)
331 *parse_return = (void *) CONTROL_FILE;
334 _DtSimpleError (panel.app_name, DtError, NULL,
335 "Invalid Control Type -- %s", parse_source);
345 /************************************************************************
347 * StringToMonitorType
349 ************************************************************************/
352 StringToMonitorType (char * parse_source,
353 void ** parse_return)
356 _DtWmParseToLower (parse_source);
358 if (strcmp (parse_source, monitor_types[MONITOR_NONE]) == 0)
359 *parse_return = (void *) MONITOR_NONE;
360 else if (strcmp (parse_source, monitor_types[MONITOR_MAIL]) == 0)
361 *parse_return = (void *) MONITOR_MAIL;
362 else if (strcmp (parse_source, monitor_types[MONITOR_FILE]) == 0)
363 *parse_return = (void *) MONITOR_FILE;
366 _DtSimpleError (panel.app_name, DtError, NULL,
367 "Invalid Monitor Type -- %s", parse_source);
377 /************************************************************************
379 * StringToControlContainerType
381 ************************************************************************/
384 StringToControlContainerType (char * parse_source,
385 void ** parse_return)
388 if (strcmp (parse_source, entry_types[BOX]) == 0)
389 *parse_return = (void *) BOX;
390 else if (strcmp (parse_source, entry_types[SUBPANEL]) == 0)
391 *parse_return = (void *) SUBPANEL;
392 else if (strcmp (parse_source, entry_types[SWITCH]) == 0)
393 *parse_return = (void *) SWITCH;
396 _DtSimpleError (panel.app_name, DtError, NULL,
397 "Invalid Control Container Type -- %s", parse_source);
407 /************************************************************************
409 * StringToPositionHints
411 ************************************************************************/
414 StringToPositionHints (char * parse_source,
415 void ** parse_return)
420 _DtWmParseToLower (parse_source);
422 if (strcmp (parse_source, "first") == 0)
424 else if (strcmp (parse_source, "last") == 0)
425 parse_source = "100";
427 status = StringToInt (parse_source, parse_return);
429 if ((long) *parse_return < 0 || (long) *parse_return > 100)
432 _DtSimpleError (panel.app_name, DtError, NULL,
433 "Invalid Position Hints value -- %d",
434 (long) *parse_return);
442 /************************************************************************
445 * Converts net file format to a file format.
447 ************************************************************************/
450 StringToFileName (char * parse_source,
451 void ** parse_return)
454 return (StringToString(parse_source, parse_return));
460 /************************************************************************
464 ************************************************************************/
467 FreeString (void ** parse_value)
470 XtFree ((char *) *parse_value);
476 /************************************************************************
480 ************************************************************************/
483 FreeGeometry (void ** parse_value)
486 XtFree ((char *) *parse_value);
492 /************************************************************************
496 ************************************************************************/
499 FreeAction (void ** parse_value)
501 PanelActionData * actionData = (PanelActionData *) *parse_value;
504 XtFree (actionData->action_name);
506 for (i = 0; i < actionData->count; i++)
507 XtFree ((char *) actionData->aap[i].u.file.name);
509 XtFree ((char *) actionData->aap);
511 XtFree ((char *) *parse_value);