2
* Motif Tools Library, Version 3.1
5
* Written by David Flanagan.
6
* Copyright (c) 1992-2001 by David Flanagan.
7
* All Rights Reserved. See the file COPYRIGHT for details.
8
* This is open source software. See the file LICENSE for details.
9
* There is no warranty for this software. See NO_WARRANTY for details.
12
* Revision 1.1.1.1 2001/07/18 11:06:03 root
15
* Revision 1.2 2001/06/12 16:25:28 andre
16
* *** empty log message ***
23
#include <Xmt/ConvertersP.h>
25
#define skipblanks(s) while (isspace(*s)) s++
28
* Convert a string to a NULL-terminated array of strings.
29
* Individual strings must be surrounded by double quotes, and
30
* may be optionally comma-separated. Newlines and whitespace
31
* outside of double quotes are ignored.
34
#if NeedFunctionPrototypes
35
Boolean XmtConvertStringToStringList(Display *dpy,
36
XrmValue *args, Cardinal *num_args,
37
XrmValue *from, XrmValue *to,
38
XtPointer *converter_data)
40
Boolean XmtConvertStringToStringList(dpy, args, num_args,
41
from, to, converter_data)
47
XtPointer *converter_data;
50
char *s = (char *)from->addr;
54
String *items = (String *) XtMalloc(max_items * sizeof(String));
58
if (*s == '\0') break;
61
XtDisplayStringConversionWarning(dpy, (char *)from->addr,
63
XmtWarningMsg("XmtConvertStringToStringList", "expected",
64
"open quote expected.");
65
XtFree((char *)items);
70
while (*s && *s != '"') s++;
73
XtDisplayStringConversionWarning(dpy, (char *)from->addr,
75
XmtWarningMsg("XmtConvertStringToStringList", "expected",
76
"close quote expected.");
77
XtFree((char *)items);
81
if (num_items == max_items) {
83
items = (String *) XtRealloc((char *)items,
84
max_items * sizeof(String));
87
items[num_items] = (String) XtMalloc((s - mark) + 1);
88
strncpy(items[num_items], mark, (s-mark));
89
items[num_items][s-mark] = '\0';
100
/* NULL-terminate the array */
101
items = (String *) XtRealloc((char *)items, (num_items+1)*sizeof(String));
102
items[num_items] = NULL;
104
/* do the right thing: see ConvertersP.h */
105
done(String *, items);
109
#if NeedFunctionPrototypes
110
static void XmtDestroyStringList(XtAppContext app, XrmValue *to,
111
XtPointer converter_data,
112
XrmValue *args, Cardinal *num_args)
114
static void XmtDestroyStringList(app, to, converter_data, args, num_args)
117
XtPointer converter_data;
122
String *items = *(String **) to->addr;
125
for(i=0; items[i] != NULL; i++)
127
XtFree((char *)items);
130
#if NeedFunctionPrototypes
131
void XmtRegisterStringListConverter(void)
133
void XmtRegisterStringListConverter()
136
static Boolean registered = False;
140
XtSetTypeConverter(XtRString, XmtRStringList,
141
XmtConvertStringToStringList, NULL, 0,
142
XtCacheAll | XtCacheRefCount,
143
XmtDestroyStringList);