~ubuntu-branches/ubuntu/lucid/libx11/lucid

« back to all changes in this revision

Viewing changes to src/Xrm.c

  • Committer: Bazaar Package Importer
  • Author(s): Timo Aaltonen
  • Date: 2009-01-17 16:34:54 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20090117163454-gaey3cd32xyavueo
Tags: 2:1.1.99.2-1build1
Fakesync with Debian, all previous Ubuntu changes are included
in the new upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
                        All Rights Reserved
7
7
 
8
 
Permission to use, copy, modify, and distribute this software and its 
9
 
documentation for any purpose and without fee is hereby granted, 
 
8
Permission to use, copy, modify, and distribute this software and its
 
9
documentation for any purpose and without fee is hereby granted,
10
10
provided that the above copyright notice appear in all copies and that
11
 
both that copyright notice and this permission notice appear in 
 
11
both that copyright notice and this permission notice appear in
12
12
supporting documentation, and that the name Digital not be
13
13
used in advertising or publicity pertaining to distribution of the
14
 
software without specific, written prior permission.  
 
14
software without specific, written prior permission.
15
15
 
16
16
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
17
17
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
1071
1071
 */
1072
1072
 
1073
1073
/*
1074
 
 * This function is highly optimized to inline as much as possible. 
1075
 
 * Be very careful with modifications, or simplifications, as they 
 
1074
 * This function is highly optimized to inline as much as possible.
 
1075
 * Be very careful with modifications, or simplifications, as they
1076
1076
 * may adversely affect the performance.
1077
1077
 *
1078
1078
 * Chris Peterson, MIT X Consortium             5/17/90.
1079
1079
 */
1080
1080
 
1081
 
/* 
 
1081
/*
1082
1082
 * Xlib spec says max 100 quarks in a lookup, will stop and return if
1083
1083
 * return if any single production's lhs has more than 100 components.
1084
1084
 */
1085
1085
#define QLIST_SIZE 100
1086
1086
 
1087
 
/* 
 
1087
/*
1088
1088
 * This should be big enough to handle things like the XKeysymDB or biggish
1089
1089
 * ~/.Xdefaults or app-defaults files. Anything bigger will be allocated on
1090
1090
 * the heap.
1125
1125
    if (!db)
1126
1126
        return;
1127
1127
 
1128
 
    /* 
1129
 
     * if strlen (str) < DEF_BUFF_SIZE allocate buffers on the stack for 
 
1128
    /*
 
1129
     * if strlen (str) < DEF_BUFF_SIZE allocate buffers on the stack for
1130
1130
     * speed otherwise malloc the buffer. From a buffer overflow standpoint
1131
1131
     * we can be sure that neither: a) a component on the lhs, or b) a
1132
1132
     * value on the rhs, will be longer than the overall length of str,
1133
1133
     * i.e. strlen(str).
1134
1134
     *
1135
 
     * This should give good performance when parsing "*foo: bar" type 
 
1135
     * This should give good performance when parsing "*foo: bar" type
1136
1136
     * databases as might be passed with -xrm command line options; but
1137
1137
     * with larger databases, e.g. .Xdefaults, app-defaults, or KeysymDB
1138
1138
     * files, the size of the buffers will be overly large. One way
1143
1143
 
1144
1144
    str_len = strlen (str);
1145
1145
    if (DEF_BUFF_SIZE > str_len) lhs = lhs_s;
1146
 
    else if ((lhs = (char*) Xmalloc (str_len)) == NULL) 
 
1146
    else if ((lhs = (char*) Xmalloc (str_len)) == NULL)
1147
1147
        return;
1148
1148
 
1149
1149
    alloc_chars = DEF_BUFF_SIZE < str_len ? str_len : DEF_BUFF_SIZE;
1159
1159
        dolines = doall;
1160
1160
 
1161
1161
        /*
1162
 
         * First: Remove extra whitespace. 
 
1162
         * First: Remove extra whitespace.
1163
1163
         */
1164
1164
 
1165
1165
        do {
1231
1231
         * Third: loop through the LHS of the resource specification
1232
1232
         * storing characters and converting this to a Quark.
1233
1233
         */
1234
 
        
 
1234
 
1235
1235
        num_quarks = 0;
1236
1236
        t_bindings = bindings;
1237
1237
 
1238
1238
        sig = 0;
1239
1239
        ptr = lhs;
1240
 
        *t_bindings = XrmBindTightly;   
 
1240
        *t_bindings = XrmBindTightly;
1241
1241
        for(;;) {
1242
1242
            if (!is_binding(bits)) {
1243
1243
                while (!is_EOQ(bits)) {
1246
1246
                    bits = next_char(c, str);
1247
1247
                }
1248
1248
 
1249
 
                quarks[num_quarks++] = 
 
1249
                quarks[num_quarks++] =
1250
1250
                        _XrmInternalStringToQuark(lhs, ptr - lhs, sig, False);
1251
1251
 
1252
1252
                if (num_quarks > QLIST_SIZE) {
1266
1266
                        sig = (sig << 1) + c; /* Compute the signature. */
1267
1267
                    } while (is_space(bits = next_char(c, str)));
1268
1268
 
1269
 
                    /* 
 
1269
                    /*
1270
1270
                     * The spec doesn't permit it, but support spaces
1271
 
                     * internal to resource name/class 
 
1271
                     * internal to resource name/class
1272
1272
                     */
1273
1273
 
1274
1274
                    if (is_separator(bits))
1292
1292
                 * If two separators appear with no Text between them then
1293
1293
                 * ignore them.
1294
1294
                 *
1295
 
                 * If anyone of those separators is a '*' then the binding 
 
1295
                 * If anyone of those separators is a '*' then the binding
1296
1296
                 * will be loose, otherwise it will be tight.
1297
1297
                 */
1298
1298
 
1337
1337
         * the right hand side.
1338
1338
         */
1339
1339
 
1340
 
        /* 
 
1340
        /*
1341
1341
         * Fourth: Remove more whitespace
1342
1342
         */
1343
1343
 
1355
1355
            break;
1356
1356
        }
1357
1357
 
1358
 
        /* 
 
1358
        /*
1359
1359
         * Fifth: Process the right hand side.
1360
1360
         */
1361
1361
 
1456
1456
                    else {
1457
1457
                        int tcount;
1458
1458
 
1459
 
                        /* 
1460
 
                         * Otherwise just insert those characters into the 
 
1459
                        /*
 
1460
                         * Otherwise just insert those characters into the
1461
1461
                         * string, since no special processing is needed on
1462
1462
                         * numerics we can skip the special processing.
1463
1463
                         */
1480
1480
                }
1481
1481
            }
1482
1482
 
1483
 
            /* 
 
1483
            /*
1484
1484
             * It is important to make sure that there is room for at least
1485
1485
             * four more characters in the buffer, since I can add that
1486
1486
             * many characters into the buffer after a backslash has occured.
1489
1489
            if (ptr + len > ptr_max) {
1490
1490
                char * temp_str;
1491
1491
 
1492
 
                alloc_chars += BUFSIZ/10;               
 
1492
                alloc_chars += BUFSIZ/10;
1493
1493
                temp_str = Xrealloc(rhs, sizeof(char) * alloc_chars);
1494
1494
 
1495
1495
                if (!temp_str) {
1506
1506
        }
1507
1507
 
1508
1508
        /*
1509
 
         * Lastly: Terminate the value string, and store this entry 
 
1509
         * Lastly: Terminate the value string, and store this entry
1510
1510
         *         into the database.
1511
1511
         */
1512
1512
 
1515
1515
        /* Store it in database */
1516
1516
        value.size = ptr - rhs;
1517
1517
        value.addr = (XPointer) rhs;
1518
 
        
 
1518
 
1519
1519
        PutEntry(db, bindings, quarks, XrmQString, &value);
1520
1520
    }
1521
1521
 
2280
2280
        } else {
2281
2281
            if (table && !table->leaf)
2282
2282
                table = table->next;
2283
 
            if (table && 
 
2283
            if (table &&
2284
2284
                AppendLEntry((LTable)table, names, classes, &closure)) {
2285
2285
                _XUnlockMutex(&db->linfo);
2286
2286
                return False;