123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511 |
- /*
- * CDE - Common Desktop Environment
- *
- * Copyright (c) 1993-2012, The Open Group. All rights reserved.
- *
- * These libraries and programs are free software; you can
- * redistribute them and/or modify them under the terms of the GNU
- * Lesser General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * These libraries and programs are distributed in the hope that
- * they will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with these libraries and programs; if not, write
- * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110-1301 USA
- */
- /*****************************************************************************
- *
- * File: Parse.c
- *
- * Project: CDE
- *
- * Description: This file contains the parsing functions for Front Panel
- * file information.
- *
- * (c) Copyright 1993, 1994 Hewlett-Packard Company
- * (c) Copyright 1993, 1994 International Business Machines Corp.
- * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
- * (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of Novell, Inc.
- *
- *****************************************************************************/
- #include <Dt/DtP.h>
- #include <Dt/DbReader.h>
- #include <Dt/UserMsg.h>
- #include "WmGlobal.h"
- #include "WmParse.h"
- #include "DataBaseLoad.h"
- #include "Parse.h"
- /************************************************************************
- *
- * StringToString
- *
- ************************************************************************/
- Boolean
- StringToString (char * parse_source,
- void ** parse_return)
- {
- *parse_return = (void *) strdup (parse_source);
- return (True);
- }
- /************************************************************************
- *
- * StrintToInt
- *
- ************************************************************************/
- Boolean
- StringToInt (char * parse_source,
- void ** parse_return)
- {
- char * source_ptr = parse_source;
- long value = 0;
- char chr;
- while (chr = *source_ptr++)
- {
- if (chr >= '0' && chr <= '9')
- {
- value *= 10;
- value += chr - '0';
- }
- else
- {
- _DtSimpleError (panel.app_name, DtError, NULL,
- "Invalid Integer -- %s", parse_source);
- return (False);
- }
- }
- *parse_return = (void *) value;
- return (True);
- }
- /************************************************************************
- *
- * StringToBoolean
- *
- ************************************************************************/
- Boolean
- StringToBoolean (char * parse_source,
- void ** parse_return)
- {
- _DtWmParseToLower(parse_source);
- if (strcmp (parse_source, "true") == 0)
- *parse_return = (void *) True;
- else if (strcmp (parse_source, "false") == 0)
- *parse_return = (void *) False;
- else
- {
- _DtSimpleError (panel.app_name, DtError, NULL,
- "Invalid Boolean -- %s", parse_source);
- return (False);
- }
- return (True);
- }
- /************************************************************************
- *
- * StringToResolution
- *
- ************************************************************************/
- Boolean
- StringToResolution (char * parse_source,
- void ** parse_return)
- {
- _DtWmParseToLower (parse_source);
-
- if (strcmp (parse_source, resolution_types[HIGH]) == 0)
- *parse_return = (void *) HIGH;
- else if (strcmp (parse_source, resolution_types[MEDIUM]) == 0)
- *parse_return = (void *) MEDIUM;
- else if (strcmp (parse_source, resolution_types[LOW]) == 0)
- *parse_return = (void *) LOW;
- else if (strcmp (parse_source, resolution_types[MATCH_DISPLAY]) == 0)
- *parse_return = (void *) MATCH_DISPLAY;
- else
- {
- _DtSimpleError (panel.app_name, DtError, NULL,
- "Invalid Resolution -- %s", parse_source);
- return (False);
- }
- return (True);
- }
- /************************************************************************
- *
- * StringToControlBehavior
- *
- ************************************************************************/
- Boolean
- StringToControlBehavior (char * parse_source,
- void ** parse_return)
- {
- _DtWmParseToLower (parse_source);
- if (strcmp (parse_source, "double_click") == 0)
- *parse_return = (void *) DOUBLE_CLICK;
- else if (strcmp (parse_source, "single_click") == 0)
- *parse_return = (void *) SINGLE_CLICK;
- else
- {
- _DtSimpleError (panel.app_name, DtError, NULL,
- "Invalid Control Behavior -- %s", parse_source);
- return (False);
- }
- return (True);
- }
- /************************************************************************
- *
- * StringToGeometry
- *
- ************************************************************************/
- Boolean
- StringToGeometry (char * parse_source,
- void ** parse_return)
- {
- GeometryData *value;
- int mask;
- int x, y, width, height;
- x = y = width = height = 0;
- mask = XParseGeometry ((char *) parse_source, &x, &y,
- (unsigned int *) &width, (unsigned int *) &height);
- if (mask)
- {
- /* Allocate space for the geometry structure */
- value = (GeometryData *) XtMalloc (sizeof (GeometryData));
- value->flags = mask;
- value->x = x;
- value->y = y;
- value->width = width;
- value->height = height;
-
- *parse_return = (void *) value;
- }
- else
- {
- _DtSimpleError (panel.app_name, DtError, NULL,
- "Invalid Geometry -- %s", parse_source);
- return (False);
- }
- return (True);
- }
- /************************************************************************
- *
- * StringToAction
- *
- ************************************************************************/
- Boolean
- StringToAction (char * parse_source,
- void ** parse_return)
- {
- PanelActionData * action_data;
- unsigned char * string, * source, * head_ptr;
- head_ptr = source = (unsigned char *) strdup (parse_source);
- if ((string = _DtWmParseNextTokenC (&source, False)) != NULL)
- {
- action_data = (PanelActionData *) XtMalloc (sizeof (PanelActionData));
- action_data->action_name = strdup ((char *) string);
- action_data->action_label = NULL;
- action_data->aap = NULL;
- action_data->count = 0;
- while ((string = _DtWmParseNextTokenC (&source, False)) != NULL)
- {
- action_data->count++;
- action_data->aap =
- (DtActionArg *) XtRealloc ((char *) action_data->aap,
- (sizeof (DtActionArg) * action_data->count));
- action_data->aap[action_data->count-1].argClass = DtACTION_FILE;
- action_data->aap[action_data->count-1].u.file.name =
- strdup((char *)string);
- }
- }
- else
- {
- _DtSimpleError (panel.app_name, DtError, NULL,
- "Invalid Action -- %s", parse_source);
- free (head_ptr);
- return (False);
- }
- free ((char *) head_ptr);
- *parse_return = (void *) action_data;
- return (True);
- }
- /************************************************************************
- *
- * StringToControlType
- *
- ************************************************************************/
- Boolean
- StringToControlType (char * parse_source,
- void ** parse_return)
- {
- _DtWmParseToLower (parse_source);
- if (strcmp (parse_source, control_types[CONTROL_BLANK]) == 0)
- *parse_return = (void *) CONTROL_BLANK;
- else if (strcmp (parse_source, control_types[CONTROL_BUSY]) == 0)
- *parse_return = (void *) CONTROL_BUSY;
- else if (strcmp (parse_source, control_types[CONTROL_ICON]) == 0)
- *parse_return = (void *) CONTROL_ICON;
- else if (strcmp (parse_source, control_types[CONTROL_CLIENT]) == 0)
- *parse_return = (void *) CONTROL_CLIENT;
- else if (strcmp (parse_source, control_types[CONTROL_CLOCK]) == 0)
- *parse_return = (void *) CONTROL_CLOCK;
- else if (strcmp (parse_source, control_types[CONTROL_DATE]) == 0)
- *parse_return = (void *) CONTROL_DATE;
- else if (strcmp (parse_source, control_types[CONTROL_FILE]) == 0)
- *parse_return = (void *) CONTROL_FILE;
- else
- {
- _DtSimpleError (panel.app_name, DtError, NULL,
- "Invalid Control Type -- %s", parse_source);
- return (False);
- }
- return (True);
- }
- /************************************************************************
- *
- * StringToMonitorType
- *
- ************************************************************************/
- Boolean
- StringToMonitorType (char * parse_source,
- void ** parse_return)
- {
- _DtWmParseToLower (parse_source);
- if (strcmp (parse_source, monitor_types[MONITOR_NONE]) == 0)
- *parse_return = (void *) MONITOR_NONE;
- else if (strcmp (parse_source, monitor_types[MONITOR_MAIL]) == 0)
- *parse_return = (void *) MONITOR_MAIL;
- else if (strcmp (parse_source, monitor_types[MONITOR_FILE]) == 0)
- *parse_return = (void *) MONITOR_FILE;
- else
- {
- _DtSimpleError (panel.app_name, DtError, NULL,
- "Invalid Monitor Type -- %s", parse_source);
- return (False);
- }
- return (True);
- }
- /************************************************************************
- *
- * StringToControlContainerType
- *
- ************************************************************************/
- Boolean
- StringToControlContainerType (char * parse_source,
- void ** parse_return)
- {
- if (strcmp (parse_source, entry_types[BOX]) == 0)
- *parse_return = (void *) BOX;
- else if (strcmp (parse_source, entry_types[SUBPANEL]) == 0)
- *parse_return = (void *) SUBPANEL;
- else if (strcmp (parse_source, entry_types[SWITCH]) == 0)
- *parse_return = (void *) SWITCH;
- else
- {
- _DtSimpleError (panel.app_name, DtError, NULL,
- "Invalid Control Container Type -- %s", parse_source);
- return (False);
- }
- return (True);
- }
- /************************************************************************
- *
- * StringToPositionHints
- *
- ************************************************************************/
- Boolean
- StringToPositionHints (char * parse_source,
- void ** parse_return)
- {
- Boolean status;
- _DtWmParseToLower (parse_source);
- if (strcmp (parse_source, "first") == 0)
- parse_source = "0";
- else if (strcmp (parse_source, "last") == 0)
- parse_source = "100";
- status = StringToInt (parse_source, parse_return);
- if ((long) *parse_return < 0 || (long) *parse_return > 100)
- {
-
- _DtSimpleError (panel.app_name, DtError, NULL,
- "Invalid Position Hints value -- %d",
- (long) *parse_return);
- return (False);
- }
- return ( True );
- }
- /************************************************************************
- *
- * StringToFileName
- * Converts net file format to a file format.
- *
- ************************************************************************/
- Boolean
- StringToFileName (char * parse_source,
- void ** parse_return)
- {
- return (StringToString(parse_source, parse_return));
- }
- /************************************************************************
- *
- * FreeString
- *
- ************************************************************************/
- void
- FreeString (void ** parse_value)
- {
- XtFree ((char *) *parse_value);
- }
- /************************************************************************
- *
- * FreeGeometry
- *
- ************************************************************************/
- void
- FreeGeometry (void ** parse_value)
- {
- XtFree ((char *) *parse_value);
- }
- /************************************************************************
- *
- * FreeAction
- *
- ************************************************************************/
- void
- FreeAction (void ** parse_value)
- {
- PanelActionData * actionData = (PanelActionData *) *parse_value;
- int i;
- XtFree (actionData->action_name);
- for (i = 0; i < actionData->count; i++)
- XtFree ((char *) actionData->aap[i].u.file.name);
- XtFree ((char *) actionData->aap);
- XtFree ((char *) *parse_value);
- }
|