~ubuntu-branches/ubuntu/wily/xmms2/wily

« back to all changes in this revision

Viewing changes to src/clients/lib/xmmsclient/collparser.c

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2008-07-04 16:23:34 UTC
  • mfrom: (1.1.5 upstream) (6.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080704162334-b3esbkcapt8wbrk4
Tags: 0.5DrLecter-2ubuntu1
* Merge from debian unstable (LP: #241098), remaining changes:
  + debian/control:
    + Update Maintainer field
    + add lpia to xmms2-plugin-alsa supported architectures
    + Added liba52-0.7.4-dev to build depends
  + debian/rules: Added patch, patch-stamp and unpatch
  + changed 01_gcc4.3.patch:
    + src/include/xmmsclient/xmmsclient++/helpers.h: Added #include <climits>
* New upstream relase fixes LP: #212566, #222341

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*  XMMS2 - X Music Multiplexer System
2
 
 *  Copyright (C) 2003-2007 XMMS2 Team
 
2
 *  Copyright (C) 2003-2008 XMMS2 Team
3
3
 *
4
4
 *  PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!!
5
5
 *
26
26
 
27
27
#define XMMS_COLLECTION_PARSER_DEFAULT_NAMESPACE "Collections"
28
28
 
29
 
/* Properties to match by default. */
30
 
char *coll_autofilter[] = { "artist", "album", "title", NULL };
31
 
 
32
29
typedef struct {
33
 
        char  shortstr;
34
 
        char *longstr;
 
30
        char shortstr;
 
31
 
 
32
        /* this has to be large enough to hold all of the longstr's
 
33
         * below.
 
34
         */
 
35
        char longstr[8];
35
36
} xmmsc_coll_prop_t;
36
37
 
37
 
xmmsc_coll_prop_t
 
38
static const xmmsc_coll_prop_t
38
39
xmmsc_coll_prop_short[] = { { 'a', "artist" },
39
40
                            { 'l', "album" },
40
41
                            { 't', "title" },
41
42
                            { 'n', "tracknr" },
42
43
                            { 'y', "year" },
43
44
                            { 'g', "genre" },
44
 
                            { 'u', "url" },
45
 
                            { '\0', NULL } };
 
45
                            { 'u', "url" } };
46
46
 
47
47
 
48
48
#define TOKEN_MATCH_CHAR(symbol, type) if (*tmp == (symbol)) { *newpos = tmp + 1; return coll_token_new (type, NULL); }
175
175
                k = parse_f (pattern, &next);
176
176
                if (k == NULL || k->type == XMMS_COLLECTION_TOKEN_INVALID) {
177
177
                        /* FIXME: Check for invalid token */
 
178
                        break;
178
179
                }
179
180
 
180
181
                if (!last)
221
222
        char quote;
222
223
 
223
224
        while (*str == ' ') str++;
 
225
        if (*str == '\0') {
 
226
                return NULL;
 
227
        }
224
228
        tmp = str;
225
229
 
226
230
        TOKEN_MATCH_CHAR ('(', XMMS_COLLECTION_TOKEN_GROUP_OPEN);
258
262
                                } else if ((*tmp == '*') || (*tmp == '?')) {
259
263
                                        type = XMMS_COLLECTION_TOKEN_PATTERN;
260
264
                                }
261
 
 
262
 
                                /* FIXME: Kinda dirty, and we should escape % and _ then ! */
263
 
                                switch (*tmp) {
264
 
                                case '*':  strval[i++] = '%';  break;
265
 
                                case '?':  strval[i++] = '_';  break;
266
 
                                default:   strval[i++] = *tmp; break;
267
 
                                }
 
265
                                strval[i++] = *tmp;
268
266
                        }
269
267
 
270
268
                        tmp++;
337
335
                        escape = 0;
338
336
                }
339
337
 
340
 
                switch (*tmp) {
341
 
                case '*':  strval[i++] = '%';  break;
342
 
                case '?':  strval[i++] = '_';  break;
343
 
                default:   strval[i++] = *tmp; break;
344
 
                }
345
 
 
 
338
                strval[i++] = *tmp;
346
339
                tmp++;
347
340
        }
348
341
 
428
421
                                curr->type = XMMS_COLLECTION_TOKEN_STRING;
429
422
                        }
430
423
 
431
 
                        /* Fuzzy match the operand to MATCH, i.e. surround with '%' */
 
424
                        /* Fuzzy match the operand to MATCH, i.e. surround with '*' */
432
425
                        if (curr->type == XMMS_COLLECTION_TOKEN_STRING ||
433
426
                            curr->type == XMMS_COLLECTION_TOKEN_PATTERN) {
434
427
                                int i, o;
436
429
                                i = 0;
437
430
                                o = 0;
438
431
 
439
 
                                if (curr->string[i] != '%') {
440
 
                                        newstr[o++] = '%';
 
432
                                if (curr->string[i] != '*') {
 
433
                                        newstr[o++] = '*';
441
434
                                }
442
435
                                while (curr->string[i] != '\0') {
443
436
                                        newstr[o++] = curr->string[i++];
444
437
                                }
445
 
                                if (i > 0 && curr->string[i - 1] != '%') {
446
 
                                        newstr[o++] = '%';
 
438
                                if (i > 0 && curr->string[i - 1] != '*') {
 
439
                                        newstr[o++] = '*';
447
440
                                }
448
441
                                newstr[o] = '\0';
449
442
 
743
736
                        *ret = first;
744
737
                }
745
738
                else {
 
739
                        xmmsc_coll_unref (first);
746
740
                        *ret = operator;
747
741
                }
748
742
        }
749
743
        else {
750
744
                xmmsc_coll_add_operand (operator, first);
 
745
                xmmsc_coll_unref (first);
 
746
 
751
747
                tk = coll_parse_andop_append (tk, operator, &tmp);
752
748
                *ret = operator;
753
749
        }
777
773
 
778
774
        if (operator) {
779
775
                xmmsc_coll_add_operand (operator, first);
 
776
                xmmsc_coll_unref (first);
780
777
 
781
778
                if (tk && tk->type == XMMS_COLLECTION_TOKEN_OPSET_UNION) {
782
779
                        tk = coll_parse_orop_append (coll_next_token (tk), operator, ret);
946
943
        xmmsc_coll_type_t colltype;
947
944
        xmmsc_coll_t *coll, *operand;
948
945
        int i;
 
946
        /* Properties to match by default. */
 
947
        const char *coll_autofilter[] = { "artist", "album", "title", NULL };
949
948
 
950
949
        if (token->type == XMMS_COLLECTION_TOKEN_OPFIL_EQUALS) {
951
950
                colltype = XMMS_COLLECTION_TYPE_EQUALS;
1031
1030
        }
1032
1031
 
1033
1032
        switch (token->type) {
1034
 
        case XMMS_COLLECTION_TOKEN_PROP_LONG:
1035
 
                return strdup (token->string);
1036
 
 
1037
1033
        case XMMS_COLLECTION_TOKEN_PROP_SHORT:
1038
 
                for (i = 0; xmmsc_coll_prop_short[i].longstr; i++) {
 
1034
                /* try to find short prop, else fallback to long prop */
 
1035
                for (i = 0; i < X_N_ELEMENTS (xmmsc_coll_prop_short); i++) {
1039
1036
                        if (*token->string == xmmsc_coll_prop_short[i].shortstr) {
1040
1037
                                return strdup (xmmsc_coll_prop_short[i].longstr);
1041
1038
                        }
1042
1039
                }
1043
 
                break;
 
1040
 
 
1041
        case XMMS_COLLECTION_TOKEN_PROP_LONG:
 
1042
                return strdup (token->string);
1044
1043
 
1045
1044
        default:
1046
1045
                break;