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

« back to all changes in this revision

Viewing changes to source/3rdparty/qmon/Xmt310/Xmt/StringLstCvt.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:03  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/ConvertersP.h>
 
24
 
 
25
#define skipblanks(s) while (isspace(*s)) s++
 
26
 
 
27
/*
 
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.
 
32
 */
 
33
/* ARGSUSED */
 
34
#if NeedFunctionPrototypes
 
35
Boolean XmtConvertStringToStringList(Display *dpy,
 
36
                                     XrmValue *args, Cardinal *num_args,
 
37
                                     XrmValue *from, XrmValue *to,
 
38
                                     XtPointer *converter_data)
 
39
#else
 
40
Boolean XmtConvertStringToStringList(dpy, args, num_args,
 
41
                                     from, to, converter_data)
 
42
Display *dpy;
 
43
XrmValue *args;
 
44
Cardinal *num_args;
 
45
XrmValue *from;
 
46
XrmValue *to;
 
47
XtPointer *converter_data;
 
48
#endif
 
49
{
 
50
    char *s = (char *)from->addr;
 
51
    char *mark;
 
52
    int num_items = 0;
 
53
    int max_items = 6;
 
54
    String *items = (String *) XtMalloc(max_items * sizeof(String));
 
55
 
 
56
    skipblanks(s);
 
57
    for(;;) {
 
58
        if (*s == '\0') break;
 
59
        
 
60
        if (*s != '"') {
 
61
            XtDisplayStringConversionWarning(dpy, (char *)from->addr,
 
62
                                             XmtRStringList);
 
63
            XmtWarningMsg("XmtConvertStringToStringList", "expected",
 
64
                          "open quote expected.");
 
65
            XtFree((char *)items);
 
66
            return False;
 
67
        }
 
68
        
 
69
        mark = ++s;
 
70
        while (*s && *s != '"') s++;
 
71
        
 
72
        if (*s == '\0') {
 
73
            XtDisplayStringConversionWarning(dpy, (char *)from->addr,
 
74
                                             XmtRStringList);
 
75
            XmtWarningMsg("XmtConvertStringToStringList", "expected",
 
76
                          "close quote expected.");
 
77
            XtFree((char *)items);
 
78
            return False;
 
79
        }
 
80
 
 
81
        if (num_items == max_items) {
 
82
            max_items *= 2;
 
83
            items = (String *) XtRealloc((char *)items,
 
84
                                         max_items * sizeof(String));
 
85
        }
 
86
 
 
87
        items[num_items] = (String) XtMalloc((s - mark) + 1);
 
88
        strncpy(items[num_items], mark, (s-mark));
 
89
        items[num_items][s-mark] = '\0';
 
90
        num_items++;
 
91
 
 
92
        s++;
 
93
        skipblanks(s);
 
94
        if (*s == ',') {
 
95
            s++;
 
96
            skipblanks(s);
 
97
        }
 
98
    }
 
99
 
 
100
    /* NULL-terminate the array */
 
101
    items = (String *) XtRealloc((char *)items, (num_items+1)*sizeof(String));
 
102
    items[num_items] = NULL;
 
103
 
 
104
    /* do the right thing: see ConvertersP.h */
 
105
    done(String *, items);
 
106
}
 
107
 
 
108
/* ARGSUSED */
 
109
#if NeedFunctionPrototypes
 
110
static void XmtDestroyStringList(XtAppContext app, XrmValue *to,
 
111
                                 XtPointer converter_data,
 
112
                                 XrmValue *args, Cardinal *num_args)
 
113
#else
 
114
static void XmtDestroyStringList(app, to, converter_data, args, num_args)
 
115
XtAppContext app;
 
116
XrmValue *to;
 
117
XtPointer converter_data;
 
118
XrmValue *args;
 
119
Cardinal *num_args;
 
120
#endif
 
121
{
 
122
    String *items = *(String **) to->addr;
 
123
    int i;
 
124
 
 
125
    for(i=0; items[i] != NULL; i++)
 
126
        XtFree(items[i]);
 
127
    XtFree((char *)items);
 
128
}
 
129
 
 
130
#if NeedFunctionPrototypes
 
131
void XmtRegisterStringListConverter(void)
 
132
#else
 
133
void XmtRegisterStringListConverter()
 
134
#endif
 
135
{
 
136
    static Boolean registered = False;
 
137
 
 
138
    if (!registered) {
 
139
        registered = True;
 
140
        XtSetTypeConverter(XtRString, XmtRStringList,
 
141
                           XmtConvertStringToStringList, NULL, 0,
 
142
                           XtCacheAll | XtCacheRefCount,
 
143
                           XmtDestroyStringList);
 
144
    }
 
145
}