~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/3rdparty/qmon/Xmt310/Xmt/ColorTblCvt.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Motif Tools Library, Version 3.1
 
3
 * $Id$
 
4
 * 
 
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.
 
10
 *
 
11
 * $Log$
 
12
 * Revision 1.1.1.1  2001/07/18 11:06:02  root
 
13
 * Initial checkin.
 
14
 *
 
15
 * Revision 1.2  2001/06/12 16:25:28  andre
 
16
 * *** empty log message ***
 
17
 *
 
18
 *
 
19
 */
 
20
 
 
21
#include <ctype.h>
 
22
#include <Xmt/Xmt.h>
 
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>
 
28
 
 
29
/* ARGSUSED */
 
30
#if NeedFunctionPrototypes
 
31
Boolean XmtConvertStringToColorTable(Display *dpy,
 
32
                                     XrmValue *args, Cardinal *num_args,
 
33
                                     XrmValue *from, XrmValue *to,
 
34
                                     XtPointer *data)
 
35
#else
 
36
Boolean XmtConvertStringToColorTable(dpy, args, num_args, from, to, data)
 
37
Display *dpy;
 
38
XrmValue *args;
 
39
Cardinal *num_args;
 
40
XrmValue *from;
 
41
XrmValue *to;
 
42
XtPointer *data;
 
43
#endif
 
44
{
 
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;
 
49
    XmtColorTable table;
 
50
    String symbol, color;
 
51
    XmtLexerToken token;
 
52
 
 
53
    /*
 
54
     * First, check if this is a symbolic color table name.
 
55
     * If so, look it up, and recurse to parse its value
 
56
     */
 
57
    if (s[0] == '$') {
 
58
        String value;
 
59
        XrmValue new_from;
 
60
        s++;
 
61
        while(isspace(*s)) s++;
 
62
 
 
63
        /*
 
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.
 
67
         */
 
68
        value = _XmtLookupResource(screen, "TVDp", s);
 
69
        
 
70
        /* if no value defined, warn and fail */
 
71
        if (!value) {
 
72
            XmtWarningMsg("XmtConvertStringToColorTable", "nosymbol",
 
73
                          "No color table named '%s' defined in resource file under _ColorTables_",
 
74
                          s);
 
75
            XtDisplayStringConversionWarning(dpy, from->addr,
 
76
                                             XmtRXmtColorTable);
 
77
            return False;
 
78
        }
 
79
 
 
80
        /*
 
81
         * Otherwise, recurse to convert the definition we've found 
 
82
         * The programmer must be smart enough to avoid infinite recursion
 
83
         */
 
84
        new_from.addr = (XPointer) value;
 
85
        new_from.size = strlen(value) + 1;
 
86
        return XmtConvertStringToColorTable(dpy, args, num_args,
 
87
                                            &new_from, to, data);
 
88
 
 
89
    }
 
90
 
 
91
    table = XmtCreateColorTable(parent);
 
92
    
 
93
    if (l == NULL) l = XmtLexerCreate(NULL, 0);
 
94
    XmtLexerInit(l, s);
 
95
 
 
96
    for(;;) {
 
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);
 
108
        XtFree(symbol);
 
109
        XtFree(color);
 
110
        if (XmtLexerGetToken(l) == XmtLexerComma)
 
111
            XmtLexerConsumeToken(l);
 
112
        else
 
113
            break;
 
114
    }
 
115
 
 
116
    if (XmtLexerGetToken(l) == XmtLexerEndOfString)
 
117
        done(XmtColorTable, table);
 
118
 
 
119
 error:
 
120
    XmtWarningMsg("XmtConvertStringToColorTable", "syntax", "syntax error");
 
121
    XtDisplayStringConversionWarning(dpy, from->addr, XmtRXmtColorTable);
 
122
    XtFree(symbol);
 
123
    XtFree(color);
 
124
    XmtDestroyColorTable(table);
 
125
    return False;
 
126
}
 
127
 
 
128
 
 
129
/* ARGSUSED */
 
130
#if NeedFunctionPrototypes
 
131
static void FreeConvertedColorTable(XtAppContext app, XrmValue *to,
 
132
                                    XtPointer closure,
 
133
                                    XrmValue *args, Cardinal *num_args)
 
134
#else
 
135
static void FreeConvertedColorTable(app, to, closure, args, num_args)
 
136
XtAppContext app;
 
137
XrmValue *to;
 
138
XtPointer closure;
 
139
XrmValue *args;
 
140
Cardinal *num_args;
 
141
#endif
 
142
{
 
143
    XmtDestroyColorTable(*((XmtColorTable *) to->addr));
 
144
}
 
145
 
 
146
static XtConvertArgRec color_table_args[] = {
 
147
    {XtProcedureArg, (XtPointer)_XmtFetchColorTable, 0},
 
148
    {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.screen),
 
149
     sizeof(Screen *)},
 
150
};
 
151
 
 
152
#if NeedFunctionPrototypes
 
153
void XmtRegisterColorTableConverter(void)
 
154
#else
 
155
void XmtRegisterColorTableConverter()
 
156
#endif
 
157
{
 
158
    static Boolean registered = False;
 
159
 
 
160
    if (!registered) {
 
161
        XtSetTypeConverter(XtRString, XmtRXmtColorTable,
 
162
                           XmtConvertStringToColorTable,
 
163
                           color_table_args, XtNumber(color_table_args),
 
164
                           XtCacheNone | XtCacheRefCount,
 
165
                           FreeConvertedColorTable);
 
166
        _XmtColorTableConverter = XmtConvertStringToColorTable;
 
167
        registered = True;
 
168
    }
 
169
}
 
170
 
 
171