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:02 root
15
* Revision 1.2 2001/06/12 16:25:28 andre
16
* *** empty log message ***
23
#include <Xmt/Color.h>
24
#include <Xmt/ConvertersP.h>
25
#include <Xmt/Lexer.h>
26
#include <Xmt/LookupP.h>
27
#include <X11/IntrinsicP.h>
30
#if NeedFunctionPrototypes
31
Boolean XmtConvertStringToColorTable(Display *dpy,
32
XrmValue *args, Cardinal *num_args,
33
XrmValue *from, XrmValue *to,
36
Boolean XmtConvertStringToColorTable(dpy, args, num_args, from, to, data)
45
static XmtLexer l = NULL;
46
XmtColorTable parent = *((XmtColorTable *)args[0].addr);
47
Screen *screen = *((Screen **)args[1].addr);
48
String s = (String)from->addr;
54
* First, check if this is a symbolic color table name.
55
* If so, look it up, and recurse to parse its value
61
while(isspace(*s)) s++;
64
* lookup value of that symbolic name under:
65
* _Colortables_.palette.visual.depth
66
* Note that we don't have to free the return value.
68
value = _XmtLookupResource(screen, "TVDp", s);
70
/* if no value defined, warn and fail */
72
XmtWarningMsg("XmtConvertStringToColorTable", "nosymbol",
73
"No color table named '%s' defined in resource file under _ColorTables_",
75
XtDisplayStringConversionWarning(dpy, from->addr,
81
* Otherwise, recurse to convert the definition we've found
82
* The programmer must be smart enough to avoid infinite recursion
84
new_from.addr = (XPointer) value;
85
new_from.size = strlen(value) + 1;
86
return XmtConvertStringToColorTable(dpy, args, num_args,
91
table = XmtCreateColorTable(parent);
93
if (l == NULL) l = XmtLexerCreate(NULL, 0);
97
symbol = color = NULL;
98
if (XmtLexerGetToken(l) != XmtLexerIdent) goto error;
99
symbol = XmtLexerStrValue(l);
100
XmtLexerConsumeToken(l);
101
if (XmtLexerGetToken(l) != XmtLexerEqual) goto error;
102
XmtLexerConsumeToken(l);
103
token = XmtLexerGetToken(l);
104
if ((token != XmtLexerString) && (token != XmtLexerIdent)) goto error;
105
color = XmtLexerStrValue(l);
106
XmtLexerConsumeToken(l);
107
XmtRegisterColor(table, symbol, color);
110
if (XmtLexerGetToken(l) == XmtLexerComma)
111
XmtLexerConsumeToken(l);
116
if (XmtLexerGetToken(l) == XmtLexerEndOfString)
117
done(XmtColorTable, table);
120
XmtWarningMsg("XmtConvertStringToColorTable", "syntax", "syntax error");
121
XtDisplayStringConversionWarning(dpy, from->addr, XmtRXmtColorTable);
124
XmtDestroyColorTable(table);
130
#if NeedFunctionPrototypes
131
static void FreeConvertedColorTable(XtAppContext app, XrmValue *to,
133
XrmValue *args, Cardinal *num_args)
135
static void FreeConvertedColorTable(app, to, closure, args, num_args)
143
XmtDestroyColorTable(*((XmtColorTable *) to->addr));
146
static XtConvertArgRec color_table_args[] = {
147
{XtProcedureArg, (XtPointer)_XmtFetchColorTable, 0},
148
{XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.screen),
152
#if NeedFunctionPrototypes
153
void XmtRegisterColorTableConverter(void)
155
void XmtRegisterColorTableConverter()
158
static Boolean registered = False;
161
XtSetTypeConverter(XtRString, XmtRXmtColorTable,
162
XmtConvertStringToColorTable,
163
color_table_args, XtNumber(color_table_args),
164
XtCacheNone | XtCacheRefCount,
165
FreeConvertedColorTable);
166
_XmtColorTableConverter = XmtConvertStringToColorTable;