annotate src/audacious/tuple_formatter.c @ 3519:ae0b80004a41 trunk

Backed out changeset fd4fce547558 This has negative side effects. *hmm*.
author William Pitcock <nenolod@atheme.org>
date Wed, 12 Sep 2007 03:37:47 -0500
parents 3a2ee00bc962
children 2f5ef443b231
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
1 /*
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
2 * Audacious
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
3 * Copyright (c) 2007 William Pitcock
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
4 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
7 * the Free Software Foundation; under version 3 of the License.
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
8 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
12 * GNU General Public License for more details.
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
13 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses>.
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
16 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
17 * The Audacious team does not consider modular code linking to
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
18 * Audacious or using our public API to be a derived work.
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
19 */
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
20
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
21 #include <glib.h>
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
22 #include <mowgli.h>
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
23
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
24 #include "config.h"
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
25 #include "tuple.h"
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
26 #include "tuple_formatter.h"
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
27
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents: 3361
diff changeset
28 //#define _DEBUG
3331
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
29
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
30 #ifdef _DEBUG
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
31 # define _TRACE(fmt, ...) g_print("[tuple-fmt] %s(%d) " fmt "\n", __FILE__, __LINE__, __VA_ARGS__);
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
32 #else
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
33 # define _TRACE(fmt, ...)
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
34 #endif
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
35
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
36 /*
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
37 * the tuple formatter:
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
38 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
39 * this is a data-driven meta-language which eventually hopes to be
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
40 * turing complete.
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
41 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
42 * language constructs follow the following basic rules:
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
43 * - begin with ${
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
44 * - end with }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
45 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
46 * language constructs:
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
47 * - ${field}: prints a field
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
48 * - ${?field:expr}: evaluates expr if field exists
3284
70789a2a5a65 documentation fixes
William Pitcock <nenolod@atheme-project.org>
parents: 3283
diff changeset
49 * - ${=field,"value"}: defines field in the currently iterated
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
50 * tuple as string value of "value"
3284
70789a2a5a65 documentation fixes
William Pitcock <nenolod@atheme-project.org>
parents: 3283
diff changeset
51 * - ${=field,value}: defines field in the currently iterated
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
52 * tuple as integer value of "value"
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
53 * - ${==field,field:expr}: evaluates expr if both fields are the same
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
54 * - ${!=field,field:expr}: evaluates expr if both fields are not the same
3290
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
55 * - ${(empty)?field:expr}: evaluates expr if field is empty or does not exist
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
56 * - %{function:args,arg2,...}: runs function and inserts the result.
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
57 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
58 * everything else is treated as raw text.
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
59 * additionally, plugins can add additional instructions and functions!
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
60 */
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
61
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
62 typedef struct {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
63 Tuple *tuple;
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
64 GString *str;
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
65 } TupleFormatterContext;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
66
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
67 /* processes a construct, e.g. "${?artist:artist is defined}" would
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
68 return "artist is defined" if artist is defined. */
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
69 gchar *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
70 tuple_formatter_process_construct(Tuple *tuple, const gchar *string)
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
71 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
72 TupleFormatterContext *ctx;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
73 const gchar *iter;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
74 gchar *out;
3314
328221f7a580 fix parser
William Pitcock <nenolod@atheme-project.org>
parents: 3313
diff changeset
75 gint level = 0;
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
76
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
77 g_return_val_if_fail(tuple != NULL, NULL);
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
78 g_return_val_if_fail(string != NULL, NULL);
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
79
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
80 ctx = g_new0(TupleFormatterContext, 1);
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
81 ctx->str = g_string_new("");
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
82
3331
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
83 _TRACE("parsing <%s>", string);
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
84
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
85 /* parsers are ugly */
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
86 for (iter = string; *iter != '\0'; iter++)
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
87 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
88 /* if it's raw text, just copy the byte */
3335
63d7947d7376 simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents: 3331
diff changeset
89 if (*iter != '$' && *iter != '%' && *iter != '}' )
63d7947d7376 simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents: 3331
diff changeset
90 {
63d7947d7376 simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents: 3331
diff changeset
91 g_string_append_c(ctx->str, *iter);
63d7947d7376 simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents: 3331
diff changeset
92 }
63d7947d7376 simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents: 3331
diff changeset
93 else if (*iter == '}' && level > 0)
3314
328221f7a580 fix parser
William Pitcock <nenolod@atheme-project.org>
parents: 3313
diff changeset
94 {
328221f7a580 fix parser
William Pitcock <nenolod@atheme-project.org>
parents: 3313
diff changeset
95 level--;
328221f7a580 fix parser
William Pitcock <nenolod@atheme-project.org>
parents: 3313
diff changeset
96 }
3313
257c0d0c5806 use g_str_has_prefix() more.
William Pitcock <nenolod@atheme-project.org>
parents: 3292
diff changeset
97 else if (g_str_has_prefix(iter, "${") == TRUE)
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
98 {
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
99 GString *expression = g_string_new("");
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
100 GString *argument = g_string_new("");
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
101 GString *sel = expression;
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
102 gchar *result;
3335
63d7947d7376 simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents: 3331
diff changeset
103 level++;
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
104
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
105 for (iter += 2; *iter != '\0'; iter++)
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
106 {
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
107 if (*iter == ':')
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
108 {
3316
6ce62683e8c4 test nesting
William Pitcock <nenolod@atheme-project.org>
parents: 3314
diff changeset
109 if (sel != argument)
6ce62683e8c4 test nesting
William Pitcock <nenolod@atheme-project.org>
parents: 3314
diff changeset
110 {
6ce62683e8c4 test nesting
William Pitcock <nenolod@atheme-project.org>
parents: 3314
diff changeset
111 sel = argument;
6ce62683e8c4 test nesting
William Pitcock <nenolod@atheme-project.org>
parents: 3314
diff changeset
112 continue;
6ce62683e8c4 test nesting
William Pitcock <nenolod@atheme-project.org>
parents: 3314
diff changeset
113 }
6ce62683e8c4 test nesting
William Pitcock <nenolod@atheme-project.org>
parents: 3314
diff changeset
114 else
6ce62683e8c4 test nesting
William Pitcock <nenolod@atheme-project.org>
parents: 3314
diff changeset
115 g_string_append_c(sel, *iter);
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
116 continue;
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
117 }
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
118
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
119 if (g_str_has_prefix(iter, "${") == TRUE || g_str_has_prefix(iter, "%{") == TRUE)
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
120 {
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
121 if (sel == argument)
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
122 {
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
123 g_string_append_c(sel, *iter);
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
124 level++;
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
125 }
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
126 }
3361
e7d8727fb901 fixed a tuple parser bug, expression depth level wasn't correctly updated in certain nested situations
Giacomo Lozito <james@develia.org>
parents: 3359
diff changeset
127 else if (*iter == '}')
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
128 {
3314
328221f7a580 fix parser
William Pitcock <nenolod@atheme-project.org>
parents: 3313
diff changeset
129 level--;
3361
e7d8727fb901 fixed a tuple parser bug, expression depth level wasn't correctly updated in certain nested situations
Giacomo Lozito <james@develia.org>
parents: 3359
diff changeset
130 if (sel == argument)
e7d8727fb901 fixed a tuple parser bug, expression depth level wasn't correctly updated in certain nested situations
Giacomo Lozito <james@develia.org>
parents: 3359
diff changeset
131 {
e7d8727fb901 fixed a tuple parser bug, expression depth level wasn't correctly updated in certain nested situations
Giacomo Lozito <james@develia.org>
parents: 3359
diff changeset
132 if (level == 0)
e7d8727fb901 fixed a tuple parser bug, expression depth level wasn't correctly updated in certain nested situations
Giacomo Lozito <james@develia.org>
parents: 3359
diff changeset
133 break;
e7d8727fb901 fixed a tuple parser bug, expression depth level wasn't correctly updated in certain nested situations
Giacomo Lozito <james@develia.org>
parents: 3359
diff changeset
134 else
e7d8727fb901 fixed a tuple parser bug, expression depth level wasn't correctly updated in certain nested situations
Giacomo Lozito <james@develia.org>
parents: 3359
diff changeset
135 g_string_append_c(sel, *iter);
e7d8727fb901 fixed a tuple parser bug, expression depth level wasn't correctly updated in certain nested situations
Giacomo Lozito <james@develia.org>
parents: 3359
diff changeset
136 }
3335
63d7947d7376 simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents: 3331
diff changeset
137 else
3361
e7d8727fb901 fixed a tuple parser bug, expression depth level wasn't correctly updated in certain nested situations
Giacomo Lozito <james@develia.org>
parents: 3359
diff changeset
138 break;
3314
328221f7a580 fix parser
William Pitcock <nenolod@atheme-project.org>
parents: 3313
diff changeset
139 }
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
140 else
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
141 g_string_append_c(sel, *iter);
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
142 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
143
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
144 if (expression->len == 0)
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
145 {
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
146 g_string_free(expression, TRUE);
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
147 g_string_free(argument, TRUE);
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
148 continue;
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
149 }
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
150
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
151 result = tuple_formatter_process_expr(tuple, expression->str, argument->len ? argument->str : NULL);
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
152 if (result != NULL)
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
153 {
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
154 g_string_append(ctx->str, result);
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
155 g_free(result);
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
156 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
157
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
158 g_string_free(expression, TRUE);
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
159 g_string_free(argument, TRUE);
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
160
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
161 if (*iter == '\0')
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
162 break;
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
163 }
3313
257c0d0c5806 use g_str_has_prefix() more.
William Pitcock <nenolod@atheme-project.org>
parents: 3292
diff changeset
164 else if (g_str_has_prefix(iter, "%{") == TRUE)
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
165 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
166 GString *expression = g_string_new("");
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
167 GString *argument = g_string_new("");
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
168 GString *sel = expression;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
169 gchar *result;
3335
63d7947d7376 simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents: 3331
diff changeset
170 level++;
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
171
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
172 for (iter += 2; *iter != '\0'; iter++)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
173 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
174 if (*iter == ':')
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
175 {
3322
de29bf952b77 fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents: 3316
diff changeset
176 if (sel != argument)
de29bf952b77 fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents: 3316
diff changeset
177 {
de29bf952b77 fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents: 3316
diff changeset
178 sel = argument;
de29bf952b77 fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents: 3316
diff changeset
179 continue;
de29bf952b77 fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents: 3316
diff changeset
180 }
de29bf952b77 fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents: 3316
diff changeset
181 else
de29bf952b77 fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents: 3316
diff changeset
182 g_string_append_c(sel, *iter);
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
183 continue;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
184 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
185
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
186 if (g_str_has_prefix(iter, "${") == TRUE || g_str_has_prefix(iter, "%{") == TRUE)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
187 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
188 if (sel == argument)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
189 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
190 g_string_append_c(sel, *iter);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
191 level++;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
192 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
193 }
3361
e7d8727fb901 fixed a tuple parser bug, expression depth level wasn't correctly updated in certain nested situations
Giacomo Lozito <james@develia.org>
parents: 3359
diff changeset
194 else if (*iter == '}')
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
195 {
3314
328221f7a580 fix parser
William Pitcock <nenolod@atheme-project.org>
parents: 3313
diff changeset
196 level--;
3361
e7d8727fb901 fixed a tuple parser bug, expression depth level wasn't correctly updated in certain nested situations
Giacomo Lozito <james@develia.org>
parents: 3359
diff changeset
197 if (sel == argument)
e7d8727fb901 fixed a tuple parser bug, expression depth level wasn't correctly updated in certain nested situations
Giacomo Lozito <james@develia.org>
parents: 3359
diff changeset
198 {
e7d8727fb901 fixed a tuple parser bug, expression depth level wasn't correctly updated in certain nested situations
Giacomo Lozito <james@develia.org>
parents: 3359
diff changeset
199 if (level == 0)
e7d8727fb901 fixed a tuple parser bug, expression depth level wasn't correctly updated in certain nested situations
Giacomo Lozito <james@develia.org>
parents: 3359
diff changeset
200 break;
e7d8727fb901 fixed a tuple parser bug, expression depth level wasn't correctly updated in certain nested situations
Giacomo Lozito <james@develia.org>
parents: 3359
diff changeset
201 else
e7d8727fb901 fixed a tuple parser bug, expression depth level wasn't correctly updated in certain nested situations
Giacomo Lozito <james@develia.org>
parents: 3359
diff changeset
202 g_string_append_c(sel, *iter);
e7d8727fb901 fixed a tuple parser bug, expression depth level wasn't correctly updated in certain nested situations
Giacomo Lozito <james@develia.org>
parents: 3359
diff changeset
203 }
3335
63d7947d7376 simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents: 3331
diff changeset
204 else
3361
e7d8727fb901 fixed a tuple parser bug, expression depth level wasn't correctly updated in certain nested situations
Giacomo Lozito <james@develia.org>
parents: 3359
diff changeset
205 break;
3314
328221f7a580 fix parser
William Pitcock <nenolod@atheme-project.org>
parents: 3313
diff changeset
206 }
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
207 else
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
208 g_string_append_c(sel, *iter);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
209 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
210
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
211 if (expression->len == 0)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
212 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
213 g_string_free(expression, TRUE);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
214 g_string_free(argument, TRUE);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
215 continue;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
216 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
217
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
218 result = tuple_formatter_process_function(tuple, expression->str, argument->len ? argument->str : NULL);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
219 if (result != NULL)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
220 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
221 g_string_append(ctx->str, result);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
222 g_free(result);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
223 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
224
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
225 g_string_free(expression, TRUE);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
226 g_string_free(argument, TRUE);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
227
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
228 if (*iter == '\0')
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
229 break;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
230 }
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
231 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
232
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
233 out = g_strdup(ctx->str->str);
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
234 g_string_free(ctx->str, TRUE);
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
235 g_free(ctx);
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
236
3331
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
237 _TRACE("parsed <%s> as <%s>", string, out);
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
238
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
239 return out;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
240 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
241
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
242 static GList *tuple_formatter_expr_list = NULL;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
243
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
244 typedef struct {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
245 const gchar *name;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
246 gboolean (*func)(Tuple *tuple, const gchar *expression);
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
247 } TupleFormatterExpression;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
248
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
249 /* processes an expression and optional argument pair. */
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
250 gchar *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
251 tuple_formatter_process_expr(Tuple *tuple, const gchar *expression,
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
252 const gchar *argument)
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
253 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
254 TupleFormatterExpression *expr = NULL;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
255 GList *iter;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
256
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
257 g_return_val_if_fail(tuple != NULL, NULL);
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
258 g_return_val_if_fail(expression != NULL, NULL);
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
259
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
260 for (iter = tuple_formatter_expr_list; iter != NULL; iter = iter->next)
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
261 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
262 TupleFormatterExpression *tmp = (TupleFormatterExpression *) iter->data;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
263
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
264 if (g_str_has_prefix(expression, tmp->name) == TRUE)
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
265 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
266 expr = tmp;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
267 expression += strlen(tmp->name);
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
268 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
269 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
270
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
271 /* ${artist} */
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
272 if (expr == NULL && argument == NULL)
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
273 {
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
274 TupleValueType type = tuple_get_value_type(tuple, -1, expression);
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
275
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
276 switch(type)
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
277 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
278 case TUPLE_STRING:
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
279 return g_strdup(tuple_get_string(tuple, -1, expression));
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
280 break;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
281 case TUPLE_INT:
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
282 return g_strdup_printf("%d", tuple_get_int(tuple, -1, expression));
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
283 break;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
284 case TUPLE_UNKNOWN:
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
285 default:
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
286 return NULL;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
287 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
288 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
289 else if (expr != NULL)
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
290 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
291 if (expr->func(tuple, expression) == TRUE && argument != NULL)
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
292 return tuple_formatter_process_construct(tuple, argument);
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
293 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
294
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
295 return NULL;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
296 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
297
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
298 static GList *tuple_formatter_func_list = NULL;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
299
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
300 typedef struct {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
301 const gchar *name;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
302 gchar *(*func)(Tuple *tuple, gchar **args);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
303 } TupleFormatterFunction;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
304
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
305 /* processes a function */
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
306 gchar *
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
307 tuple_formatter_process_function(Tuple *tuple, const gchar *expression,
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
308 const gchar *argument)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
309 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
310 TupleFormatterFunction *expr = NULL;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
311 GList *iter;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
312
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
313 g_return_val_if_fail(tuple != NULL, NULL);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
314 g_return_val_if_fail(expression != NULL, NULL);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
315
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
316 for (iter = tuple_formatter_func_list; iter != NULL; iter = iter->next)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
317 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
318 TupleFormatterFunction *tmp = (TupleFormatterFunction *) iter->data;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
319
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
320 if (g_str_has_prefix(expression, tmp->name) == TRUE)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
321 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
322 expr = tmp;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
323 expression += strlen(tmp->name);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
324 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
325 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
326
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
327 if (expr != NULL)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
328 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
329 gchar **args;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
330 gchar *ret;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
331
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
332 if (argument)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
333 args = g_strsplit(argument, ",", 10);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
334 else
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
335 args = NULL;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
336
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
337 ret = expr->func(tuple, args);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
338
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
339 if (args)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
340 g_strfreev(args);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
341
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
342 return ret;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
343 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
344
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
345 return NULL;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
346 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
347
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
348 /* registers a formatter */
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
349 void
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
350 tuple_formatter_register_expression(const gchar *keyword,
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
351 gboolean (*func)(Tuple *tuple, const gchar *argument))
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
352 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
353 TupleFormatterExpression *expr;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
354
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
355 g_return_if_fail(keyword != NULL);
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
356 g_return_if_fail(func != NULL);
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
357
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
358 expr = g_new0(TupleFormatterExpression, 1);
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
359 expr->name = keyword;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
360 expr->func = func;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
361
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
362 tuple_formatter_expr_list = g_list_append(tuple_formatter_expr_list, expr);
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
363 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
364
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
365 /* registers a function */
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
366 void
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
367 tuple_formatter_register_function(const gchar *keyword,
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
368 gchar *(*func)(Tuple *tuple, gchar **argument))
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
369 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
370 TupleFormatterFunction *expr;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
371
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
372 g_return_if_fail(keyword != NULL);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
373 g_return_if_fail(func != NULL);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
374
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
375 expr = g_new0(TupleFormatterFunction, 1);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
376 expr->name = keyword;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
377 expr->func = func;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
378
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
379 tuple_formatter_func_list = g_list_append(tuple_formatter_func_list, expr);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
380 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
381
3519
ae0b80004a41 Backed out changeset fd4fce547558
William Pitcock <nenolod@atheme.org>
parents: 3518
diff changeset
382 /* builtin-keyword: ${?arg}, returns TRUE if <arg> exists. */
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
383 static gboolean
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
384 tuple_formatter_expression_exists(Tuple *tuple, const gchar *expression)
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
385 {
3519
ae0b80004a41 Backed out changeset fd4fce547558
William Pitcock <nenolod@atheme.org>
parents: 3518
diff changeset
386 return (tuple_get_value_type(tuple, -1, expression) != TUPLE_UNKNOWN) ? TRUE : FALSE;
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
387 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
388
3339
c23513d0ee17 adjusted comments for == and != tuple operators
Giacomo Lozito <james@develia.org>
parents: 3338
diff changeset
389 /* builtin-keyword: ${==arg1,arg2}, returns TRUE if <arg1> and <arg2> match.
c23513d0ee17 adjusted comments for == and != tuple operators
Giacomo Lozito <james@develia.org>
parents: 3338
diff changeset
390 <arg1> and <arg2> can also be raw text, which should be enclosed in "double quotes". */
3286
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
391 static gboolean
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
392 tuple_formatter_expression_match(Tuple *tuple, const gchar *expression)
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
393 {
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
394 gchar **args = g_strsplit(expression, ",", 2);
3338
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
395 gchar *arg1 = NULL, *arg2 = NULL;
3286
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
396 gint ret;
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
397
3338
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
398 if (args[0][0] == '\"') /* check if arg1 is "raw text" */
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
399 {
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
400 if ( strlen(args[0]) > 1 )
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
401 {
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
402 args[0][strlen(args[0]) - 1] = '\0';
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
403 arg1 = g_strdup(&(args[0][1]));
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
404 args[0][strlen(args[0]) - 1] = '\"';
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
405 }
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
406 else /* bad formatted arg */
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
407 return FALSE;
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
408 }
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
409 else if (tuple_get_value_type(tuple, -1, args[0]) == TUPLE_UNKNOWN)
3338
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
410 {
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
411 g_strfreev(args);
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
412 return FALSE;
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
413 }
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
414
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
415 if (args[1][0] == '\"') /* check if arg2 is "raw text" */
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
416 {
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
417 if ( strlen(args[1]) > 1 )
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
418 {
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
419 args[1][strlen(args[1]) - 1] = '\0';
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
420 arg2 = g_strdup(&(args[1][1]));
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
421 args[1][strlen(args[1]) - 1] = '\"';
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
422 }
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
423 else /* bad formatted arg */
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
424 return FALSE;
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
425 }
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
426 else if (tuple_get_value_type(tuple, -1, args[1]) == TUPLE_UNKNOWN)
3286
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
427 {
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
428 g_strfreev(args);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
429 return FALSE;
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
430 }
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
431
3338
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
432 if (!arg1) /* if arg1 is not "raw text", get the tuple value */
3286
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
433 {
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
434 if (tuple_get_value_type(tuple, -1, args[0]) == TUPLE_STRING)
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
435 arg1 = g_strdup(tuple_get_string(tuple, -1, args[0]));
3338
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
436 else
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
437 arg1 = g_strdup_printf("%d", tuple_get_int(tuple, -1, args[0]));
3286
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
438 }
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
439
3338
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
440 if (!arg2) /* if arg2 is not "raw text", get the tuple value */
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
441 {
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
442 if (tuple_get_value_type(tuple, -1, args[1]) == TUPLE_STRING)
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
443 arg2 = g_strdup(tuple_get_string(tuple, -1, args[1]));
3338
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
444 else
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
445 arg2 = g_strdup_printf("%d", tuple_get_int(tuple, -1, args[1]));
3338
07ed916b7176 added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents: 3335
diff changeset
446 }
3286
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
447
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
448 ret = g_ascii_strcasecmp(arg1, arg2);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
449 g_free(arg1);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
450 g_free(arg2);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
451 g_strfreev(args);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
452
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
453 return ret ? FALSE : TRUE;
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
454 }
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
455
3339
c23513d0ee17 adjusted comments for == and != tuple operators
Giacomo Lozito <james@develia.org>
parents: 3338
diff changeset
456 /* builtin-keyword: ${!=arg1,arg2}. returns TRUE if <arg1> and <arg2> don't match.
c23513d0ee17 adjusted comments for == and != tuple operators
Giacomo Lozito <james@develia.org>
parents: 3338
diff changeset
457 <arg1> and <arg2> can also be raw text, which should be enclosed in "double quotes". */
3286
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
458 static gboolean
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
459 tuple_formatter_expression_nonmatch(Tuple *tuple, const gchar *expression)
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
460 {
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
461 return tuple_formatter_expression_match(tuple, expression) ^ 1;
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
462 }
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
463
3290
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
464 /* builtin-keyword: ${empty?}. returns TRUE if <arg> is empty. */
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
465 static gboolean
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
466 tuple_formatter_expression_empty(Tuple *tuple, const gchar *expression)
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
467 {
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
468 gboolean ret = TRUE;
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
469 const gchar *iter;
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
470 TupleValueType type = tuple_get_value_type(tuple, -1, expression);
3290
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
471
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
472 if (type == TUPLE_UNKNOWN)
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
473 return TRUE;
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
474
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
475 if (type == TUPLE_INT && tuple_get_int(tuple, -1, expression) != 0)
3290
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
476 return FALSE;
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
477
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
478 iter = tuple_get_string(tuple, -1, expression);
3290
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
479
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
480 while (ret && *iter != '\0')
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
481 {
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
482 if (*iter == ' ')
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
483 iter++;
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
484 else
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
485 ret = FALSE;
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
486 }
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
487
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
488 return ret;
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
489 }
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
490
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
491 /* builtin function: %{audacious-version} */
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
492 static gchar *
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
493 tuple_formatter_function_version(Tuple *tuple, gchar **args)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
494 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
495 return g_strdup(PACKAGE_NAME " " PACKAGE_VERSION);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
496 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
497
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
498 /* processes a string containing instructions. does initialization phases
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
499 if not already done */
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
500 gchar *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
501 tuple_formatter_process_string(Tuple *tuple, const gchar *string)
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
502 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
503 static gboolean initialized = FALSE;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
504
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
505 if (initialized == FALSE)
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
506 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
507 tuple_formatter_register_expression("?", tuple_formatter_expression_exists);
3286
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
508 tuple_formatter_register_expression("==", tuple_formatter_expression_match);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
509 tuple_formatter_register_expression("!=", tuple_formatter_expression_nonmatch);
3290
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
510 tuple_formatter_register_expression("(empty)?", tuple_formatter_expression_empty);
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
511
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
512 tuple_formatter_register_function("audacious-version", tuple_formatter_function_version);
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
513 initialized = TRUE;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
514 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
515
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
516 return tuple_formatter_process_construct(tuple, string);
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
517 }
3349
01a241d35146 add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3339
diff changeset
518
01a241d35146 add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3339
diff changeset
519 /* wrapper function for making title string. it falls back to filename
01a241d35146 add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3339
diff changeset
520 * if process_string returns NULL or a blank string. */
01a241d35146 add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3339
diff changeset
521 gchar *
01a241d35146 add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3339
diff changeset
522 tuple_formatter_make_title_string(Tuple *tuple, const gchar *string)
01a241d35146 add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3339
diff changeset
523 {
01a241d35146 add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3339
diff changeset
524 gchar *rv;
01a241d35146 add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3339
diff changeset
525
01a241d35146 add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3339
diff changeset
526 g_return_val_if_fail(tuple != NULL, NULL);
01a241d35146 add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3339
diff changeset
527
3359
678ea77b6b1f oops. tuple_formatter_make_title_string() should call tuple_formatter_process_string().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3349
diff changeset
528 rv = tuple_formatter_process_string(tuple, string);
3349
01a241d35146 add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3339
diff changeset
529
01a241d35146 add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3339
diff changeset
530 if(!rv || !strcmp(rv, "")) {
01a241d35146 add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3339
diff changeset
531 g_free(rv);
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
532 rv = g_strdup(tuple_get_string(tuple, FIELD_FILE_NAME, NULL));
3349
01a241d35146 add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3339
diff changeset
533 }
01a241d35146 add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3339
diff changeset
534
01a241d35146 add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3339
diff changeset
535 return rv;
01a241d35146 add tuple_formatter_make_title_string(). it is a wrapper function to tuple_formatter_process_construct() to make title string. it falls back to the file name if the formatted string is blank or unavailable.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3339
diff changeset
536 }