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 /*****************************************************************************
29 * Description: This file contains the parsing functions for Front Panel
32 * (c) Copyright 1993, 1994 Hewlett-Packard Company
33 * (c) Copyright 1993, 1994 International Business Machines Corp.
34 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
35 * (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of Novell, Inc.
37 *****************************************************************************/
40 #include <Dt/DbReader.h>
41 #include <Dt/UserMsg.h>
45 #include "DataBaseLoad.h"
49 /************************************************************************
53 ************************************************************************/
56 StringToString (char * parse_source,
60 *parse_return = (void *) strdup (parse_source);
68 /************************************************************************
72 ************************************************************************/
75 StringToInt (char * parse_source,
79 char * source_ptr = parse_source;
84 while (chr = *source_ptr++)
86 if (chr >= '0' && chr <= '9')
93 _DtSimpleError (panel.app_name, DtError, NULL,
94 "Invalid Integer -- %s", parse_source);
99 *parse_return = (void *) value;
106 /************************************************************************
110 ************************************************************************/
113 StringToBoolean (char * parse_source,
114 void ** parse_return)
117 _DtWmParseToLower(parse_source);
119 if (strcmp (parse_source, "true") == 0)
120 *parse_return = (void *) True;
121 else if (strcmp (parse_source, "false") == 0)
122 *parse_return = (void *) False;
125 _DtSimpleError (panel.app_name, DtError, NULL,
126 "Invalid Boolean -- %s", parse_source);
136 /************************************************************************
140 ************************************************************************/
143 StringToResolution (char * parse_source,
144 void ** parse_return)
147 _DtWmParseToLower (parse_source);
149 if (strcmp (parse_source, resolution_types[HIGH]) == 0)
150 *parse_return = (void *) HIGH;
151 else if (strcmp (parse_source, resolution_types[MEDIUM]) == 0)
152 *parse_return = (void *) MEDIUM;
153 else if (strcmp (parse_source, resolution_types[LOW]) == 0)
154 *parse_return = (void *) LOW;
155 else if (strcmp (parse_source, resolution_types[MATCH_DISPLAY]) == 0)
156 *parse_return = (void *) MATCH_DISPLAY;
159 _DtSimpleError (panel.app_name, DtError, NULL,
160 "Invalid Resolution -- %s", parse_source);
170 /************************************************************************
172 * StringToControlBehavior
174 ************************************************************************/
177 StringToControlBehavior (char * parse_source,
178 void ** parse_return)
181 _DtWmParseToLower (parse_source);
183 if (strcmp (parse_source, "double_click") == 0)
184 *parse_return = (void *) DOUBLE_CLICK;
185 else if (strcmp (parse_source, "single_click") == 0)
186 *parse_return = (void *) SINGLE_CLICK;
189 _DtSimpleError (panel.app_name, DtError, NULL,
190 "Invalid Control Behavior -- %s", parse_source);
200 /************************************************************************
204 ************************************************************************/
207 StringToGeometry (char * parse_source,
208 void ** parse_return)
213 int x, y, width, height;
216 x = y = width = height = 0;
218 mask = XParseGeometry ((char *) parse_source, &x, &y,
219 (unsigned int *) &width, (unsigned int *) &height);
223 /* Allocate space for the geometry structure */
225 value = (GeometryData *) XtMalloc (sizeof (GeometryData));
230 value->width = width;
231 value->height = height;
233 *parse_return = (void *) value;
237 _DtSimpleError (panel.app_name, DtError, NULL,
238 "Invalid Geometry -- %s", parse_source);
248 /************************************************************************
252 ************************************************************************/
256 StringToAction (char * parse_source,
257 void ** parse_return)
261 PanelActionData * action_data;
262 unsigned char * string, * source, * head_ptr;
265 head_ptr = source = (unsigned char *) strdup (parse_source);
267 if ((string = _DtWmParseNextTokenC (&source, False)) != NULL)
269 action_data = (PanelActionData *) XtMalloc (sizeof (PanelActionData));
271 action_data->action_name = strdup ((char *) string);
272 action_data->action_label = NULL;
273 action_data->aap = NULL;
274 action_data->count = 0;
276 while ((string = _DtWmParseNextTokenC (&source, False)) != NULL)
278 action_data->count++;
280 (DtActionArg *) XtRealloc ((char *) action_data->aap,
281 (sizeof (DtActionArg) * action_data->count));
282 action_data->aap[action_data->count-1].argClass = DtACTION_FILE;
284 action_data->aap[action_data->count-1].u.file.name =
285 strdup((char *)string);
290 _DtSimpleError (panel.app_name, DtError, NULL,
291 "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 (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 (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 (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 ((long) *parse_return < 0 || (long) *parse_return > 100)
431 _DtSimpleError (panel.app_name, DtError, NULL,
432 "Invalid Position Hints value -- %d",
433 (long) *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);