Mercurial > audlegacy
annotate src/audacious/tuple_formatter.c @ 3790:9121baaf0190 audacious-1.4.0-beta2
add some debugging support code.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Fri, 19 Oct 2007 02:37:01 -0500 |
parents | a76b55624e51 |
children | df7c8b32c389 6d0db63e05aa 1382d265b71d |
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 |
3788
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
28 /* |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
29 * TUPLE_USE_COMPILER: |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
30 * Undefine this to disable usage of the Tuplez compiler implementation. |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
31 * This may be useful for prototyping new features of the language. |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
32 */ |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
33 #define TUPLE_USE_COMPILER |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
34 |
3790
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
35 /* |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
36 * TUPLE_COMPILER_DEBUG: |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
37 * Define this to debug the execution process of the Tuplez compiled |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
38 * bytecode. This may be useful if bugs creep in. |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
39 */ |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
40 #undef TUPLE_COMPILER_DEBUG |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
41 |
3788
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
42 #ifdef TUPLE_USE_COMPILER |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
43 # include "tuple_compiler.h" |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
44 #endif |
3331
9c53688bb559
some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents:
3322
diff
changeset
|
45 |
9c53688bb559
some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents:
3322
diff
changeset
|
46 #ifdef _DEBUG |
9c53688bb559
some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents:
3322
diff
changeset
|
47 # 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
|
48 #else |
9c53688bb559
some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents:
3322
diff
changeset
|
49 # define _TRACE(fmt, ...) |
9c53688bb559
some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents:
3322
diff
changeset
|
50 #endif |
9c53688bb559
some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents:
3322
diff
changeset
|
51 |
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 /* |
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 * 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
|
54 * |
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
|
55 * 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
|
56 * 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
|
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 * 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
|
59 * - 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
|
60 * - 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
|
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 * 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
|
63 * - ${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
|
64 * - ${?field:expr}: evaluates expr if field exists |
3284
70789a2a5a65
documentation fixes
William Pitcock <nenolod@atheme-project.org>
parents:
3283
diff
changeset
|
65 * - ${=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
|
66 * tuple as string value of "value" |
3284
70789a2a5a65
documentation fixes
William Pitcock <nenolod@atheme-project.org>
parents:
3283
diff
changeset
|
67 * - ${=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
|
68 * 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
|
69 * - ${==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
|
70 * - ${!=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
|
71 * - ${(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
|
72 * - %{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
|
73 * |
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 * everything else is treated as raw text. |
3292
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
75 * 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
|
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 |
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 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
|
79 Tuple *tuple; |
3285
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
80 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
|
81 } 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
|
82 |
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
|
83 /* 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
|
84 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
|
85 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
|
86 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
|
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 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
|
89 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
|
90 gchar *out; |
3314 | 91 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
|
92 |
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
|
93 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
|
94 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
|
95 |
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
|
96 ctx = g_new0(TupleFormatterContext, 1); |
3285
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
97 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
|
98 |
3331
9c53688bb559
some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents:
3322
diff
changeset
|
99 _TRACE("parsing <%s>", string); |
9c53688bb559
some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents:
3322
diff
changeset
|
100 |
3285
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
101 /* 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
|
102 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
|
103 { |
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 /* 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
|
105 if (*iter != '$' && *iter != '%' && *iter != '}' ) |
63d7947d7376
simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents:
3331
diff
changeset
|
106 { |
63d7947d7376
simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents:
3331
diff
changeset
|
107 g_string_append_c(ctx->str, *iter); |
63d7947d7376
simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents:
3331
diff
changeset
|
108 } |
63d7947d7376
simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents:
3331
diff
changeset
|
109 else if (*iter == '}' && level > 0) |
3314 | 110 { |
111 level--; | |
112 } | |
3313
257c0d0c5806
use g_str_has_prefix() more.
William Pitcock <nenolod@atheme-project.org>
parents:
3292
diff
changeset
|
113 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
|
114 { |
3285
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
115 GString *expression = g_string_new(""); |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
116 GString *argument = g_string_new(""); |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
117 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
|
118 gchar *result; |
3335
63d7947d7376
simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents:
3331
diff
changeset
|
119 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
|
120 |
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
|
121 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
|
122 { |
3285
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
123 if (*iter == ':') |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
124 { |
3316 | 125 if (sel != argument) |
126 { | |
127 sel = argument; | |
128 continue; | |
129 } | |
130 else | |
131 g_string_append_c(sel, *iter); | |
3285
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
132 continue; |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
133 } |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
134 |
3292
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
135 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
|
136 { |
3285
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
137 if (sel == argument) |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
138 { |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
139 g_string_append_c(sel, *iter); |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
140 level++; |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
141 } |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
142 } |
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
|
143 else if (*iter == '}') |
3285
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
144 { |
3314 | 145 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
|
146 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
|
147 { |
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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 } |
3335
63d7947d7376
simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents:
3331
diff
changeset
|
153 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
|
154 break; |
3314 | 155 } |
3285
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
156 else |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
157 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
|
158 } |
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
|
159 |
3285
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
160 if (expression->len == 0) |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
161 { |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
162 g_string_free(expression, TRUE); |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
163 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
|
164 continue; |
3285
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
165 } |
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
|
166 |
3285
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
167 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
|
168 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
|
169 { |
3285
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
170 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
|
171 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
|
172 } |
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
|
173 |
3285
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
174 g_string_free(expression, TRUE); |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
175 g_string_free(argument, TRUE); |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
176 |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
177 if (*iter == '\0') |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
178 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
|
179 } |
3313
257c0d0c5806
use g_str_has_prefix() more.
William Pitcock <nenolod@atheme-project.org>
parents:
3292
diff
changeset
|
180 else if (g_str_has_prefix(iter, "%{") == TRUE) |
3292
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
181 { |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
182 GString *expression = g_string_new(""); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
183 GString *argument = g_string_new(""); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
184 GString *sel = expression; |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
185 gchar *result; |
3335
63d7947d7376
simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents:
3331
diff
changeset
|
186 level++; |
3292
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 for (iter += 2; *iter != '\0'; iter++) |
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 if (*iter == ':') |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
191 { |
3322
de29bf952b77
fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents:
3316
diff
changeset
|
192 if (sel != argument) |
de29bf952b77
fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents:
3316
diff
changeset
|
193 { |
de29bf952b77
fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents:
3316
diff
changeset
|
194 sel = argument; |
de29bf952b77
fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents:
3316
diff
changeset
|
195 continue; |
de29bf952b77
fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents:
3316
diff
changeset
|
196 } |
de29bf952b77
fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents:
3316
diff
changeset
|
197 else |
de29bf952b77
fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents:
3316
diff
changeset
|
198 g_string_append_c(sel, *iter); |
3292
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
199 continue; |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
200 } |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
201 |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
202 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
|
203 { |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
204 if (sel == argument) |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
205 { |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
206 g_string_append_c(sel, *iter); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
207 level++; |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
208 } |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
209 } |
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
|
210 else if (*iter == '}') |
3292
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
211 { |
3314 | 212 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
|
213 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
|
214 { |
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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 } |
3335
63d7947d7376
simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents:
3331
diff
changeset
|
220 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
|
221 break; |
3314 | 222 } |
3292
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
223 else |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
224 g_string_append_c(sel, *iter); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
225 } |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
226 |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
227 if (expression->len == 0) |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
228 { |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
229 g_string_free(expression, TRUE); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
230 g_string_free(argument, TRUE); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
231 continue; |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
232 } |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
233 |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
234 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
|
235 if (result != NULL) |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
236 { |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
237 g_string_append(ctx->str, result); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
238 g_free(result); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
239 } |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
240 |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
241 g_string_free(expression, TRUE); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
242 g_string_free(argument, TRUE); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
243 |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
244 if (*iter == '\0') |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
245 break; |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
246 } |
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
|
247 } |
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 |
3285
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
249 out = g_strdup(ctx->str->str); |
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
250 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
|
251 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
|
252 |
3331
9c53688bb559
some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents:
3322
diff
changeset
|
253 _TRACE("parsed <%s> as <%s>", string, out); |
9c53688bb559
some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents:
3322
diff
changeset
|
254 |
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
|
255 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
|
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 |
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 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
|
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 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
|
261 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
|
262 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
|
263 } 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
|
264 |
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 /* 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
|
266 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
|
267 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
|
268 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
|
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 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
|
271 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
|
272 |
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 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
|
274 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
|
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 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
|
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 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
|
279 |
3285
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
280 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
|
281 { |
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
|
282 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
|
283 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
|
284 } |
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 } |
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 |
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 /* ${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
|
288 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
|
289 { |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
290 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
|
291 |
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 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
|
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 case TUPLE_STRING: |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
295 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
|
296 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
|
297 case TUPLE_INT: |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
298 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
|
299 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
|
300 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
|
301 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
|
302 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
|
303 } |
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
|
304 } |
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
|
305 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
|
306 { |
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
|
307 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
|
308 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
|
309 } |
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
|
310 |
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
|
311 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
|
312 } |
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
|
313 |
3292
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
314 static GList *tuple_formatter_func_list = 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 typedef struct { |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
317 const gchar *name; |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
318 gchar *(*func)(Tuple *tuple, gchar **args); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
319 } TupleFormatterFunction; |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
320 |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
321 /* processes a function */ |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
322 gchar * |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
323 tuple_formatter_process_function(Tuple *tuple, const gchar *expression, |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
324 const gchar *argument) |
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 TupleFormatterFunction *expr = NULL; |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
327 GList *iter; |
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 g_return_val_if_fail(tuple != NULL, NULL); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
330 g_return_val_if_fail(expression != NULL, NULL); |
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 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
|
333 { |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
334 TupleFormatterFunction *tmp = (TupleFormatterFunction *) iter->data; |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
335 |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
336 if (g_str_has_prefix(expression, tmp->name) == TRUE) |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
337 { |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
338 expr = tmp; |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
339 expression += strlen(tmp->name); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
340 } |
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 |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
343 if (expr != NULL) |
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 gchar **args; |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
346 gchar *ret; |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
347 |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
348 if (argument) |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
349 args = g_strsplit(argument, ",", 10); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
350 else |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
351 args = NULL; |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
352 |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
353 ret = expr->func(tuple, args); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
354 |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
355 if (args) |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
356 g_strfreev(args); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
357 |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
358 return ret; |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
359 } |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
360 |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
361 return NULL; |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
362 } |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
363 |
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
|
364 /* 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
|
365 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
|
366 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
|
367 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
|
368 { |
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
|
369 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
|
370 |
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
|
371 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
|
372 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
|
373 |
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
|
374 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
|
375 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
|
376 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
|
377 |
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
|
378 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
|
379 } |
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
|
380 |
3292
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
381 /* registers a function */ |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
382 void |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
383 tuple_formatter_register_function(const gchar *keyword, |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
384 gchar *(*func)(Tuple *tuple, gchar **argument)) |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
385 { |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
386 TupleFormatterFunction *expr; |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
387 |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
388 g_return_if_fail(keyword != NULL); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
389 g_return_if_fail(func != NULL); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
390 |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
391 expr = g_new0(TupleFormatterFunction, 1); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
392 expr->name = keyword; |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
393 expr->func = func; |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
394 |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
395 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
|
396 } |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
397 |
3339
c23513d0ee17
adjusted comments for == and != tuple operators
Giacomo Lozito <james@develia.org>
parents:
3338
diff
changeset
|
398 /* 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
|
399 <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
|
400 static gboolean |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
401 tuple_formatter_expression_match(Tuple *tuple, const gchar *expression) |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
402 { |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
403 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
|
404 gchar *arg1 = NULL, *arg2 = NULL; |
3286
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
405 gint ret; |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
406 |
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
|
407 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
|
408 { |
07ed916b7176
added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents:
3335
diff
changeset
|
409 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
|
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 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
|
412 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
|
413 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
|
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 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
|
416 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
|
417 } |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
418 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
|
419 { |
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 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
|
421 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
|
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 |
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 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
|
425 { |
07ed916b7176
added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents:
3335
diff
changeset
|
426 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
|
427 { |
07ed916b7176
added support for raw text comparisons in tuple == operator (and that means != as well)
Giacomo Lozito <james@develia.org>
parents:
3335
diff
changeset
|
428 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
|
429 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
|
430 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
|
431 } |
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 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
|
433 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
|
434 } |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
435 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
|
436 { |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
437 g_strfreev(args); |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
438 return FALSE; |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
439 } |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
440 |
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
|
441 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
|
442 { |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
443 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
|
444 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
|
445 else |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
446 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
|
447 } |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
448 |
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
|
449 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
|
450 { |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
451 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
|
452 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
|
453 else |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
454 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
|
455 } |
3286
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
456 |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
457 ret = g_ascii_strcasecmp(arg1, arg2); |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
458 g_free(arg1); |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
459 g_free(arg2); |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
460 g_strfreev(args); |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
461 |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
462 return ret ? FALSE : TRUE; |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
463 } |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
464 |
3339
c23513d0ee17
adjusted comments for == and != tuple operators
Giacomo Lozito <james@develia.org>
parents:
3338
diff
changeset
|
465 /* 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
|
466 <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
|
467 static gboolean |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
468 tuple_formatter_expression_nonmatch(Tuple *tuple, const gchar *expression) |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
469 { |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
470 return tuple_formatter_expression_match(tuple, expression) ^ 1; |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
471 } |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
472 |
3521
2f5ef443b231
tuple_formatter_expression_exists() now checks for empty fields, becoming
Matti Hamalainen <ccr@tnsp.org>
parents:
3519
diff
changeset
|
473 /* builtin-keyword: ${(empty)?}. returns TRUE if <arg> is empty. */ |
3290
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
474 static gboolean |
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
475 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
|
476 { |
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
477 gboolean ret = TRUE; |
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
478 const gchar *iter; |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
479 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
|
480 |
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
481 if (type == TUPLE_UNKNOWN) |
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
482 return TRUE; |
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
483 |
3522
23bf72b8c95c
tuple_formatter_expression_empty() was fundamentally broken, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
3521
diff
changeset
|
484 if (type == TUPLE_INT) |
23bf72b8c95c
tuple_formatter_expression_empty() was fundamentally broken, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
3521
diff
changeset
|
485 return (tuple_get_int(tuple, -1, expression) == 0); |
3290
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
486 |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
487 iter = tuple_get_string(tuple, -1, expression); |
3522
23bf72b8c95c
tuple_formatter_expression_empty() was fundamentally broken, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
3521
diff
changeset
|
488 if (!iter) |
23bf72b8c95c
tuple_formatter_expression_empty() was fundamentally broken, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
3521
diff
changeset
|
489 return TRUE; |
3290
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
490 |
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
491 while (ret && *iter != '\0') |
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
492 { |
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
493 if (*iter == ' ') |
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
494 iter++; |
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
495 else |
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
496 ret = FALSE; |
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
497 } |
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
498 |
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
499 return ret; |
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
500 } |
4e7cc6d9b525
add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents:
3286
diff
changeset
|
501 |
3521
2f5ef443b231
tuple_formatter_expression_exists() now checks for empty fields, becoming
Matti Hamalainen <ccr@tnsp.org>
parents:
3519
diff
changeset
|
502 /* builtin-keyword: ${?arg}, returns TRUE if <arg> exists. */ |
2f5ef443b231
tuple_formatter_expression_exists() now checks for empty fields, becoming
Matti Hamalainen <ccr@tnsp.org>
parents:
3519
diff
changeset
|
503 static gboolean |
2f5ef443b231
tuple_formatter_expression_exists() now checks for empty fields, becoming
Matti Hamalainen <ccr@tnsp.org>
parents:
3519
diff
changeset
|
504 tuple_formatter_expression_exists(Tuple *tuple, const gchar *expression) |
2f5ef443b231
tuple_formatter_expression_exists() now checks for empty fields, becoming
Matti Hamalainen <ccr@tnsp.org>
parents:
3519
diff
changeset
|
505 { |
2f5ef443b231
tuple_formatter_expression_exists() now checks for empty fields, becoming
Matti Hamalainen <ccr@tnsp.org>
parents:
3519
diff
changeset
|
506 return !tuple_formatter_expression_empty(tuple, expression); |
2f5ef443b231
tuple_formatter_expression_exists() now checks for empty fields, becoming
Matti Hamalainen <ccr@tnsp.org>
parents:
3519
diff
changeset
|
507 } |
2f5ef443b231
tuple_formatter_expression_exists() now checks for empty fields, becoming
Matti Hamalainen <ccr@tnsp.org>
parents:
3519
diff
changeset
|
508 |
3292
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
509 /* builtin function: %{audacious-version} */ |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
510 static gchar * |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
511 tuple_formatter_function_version(Tuple *tuple, gchar **args) |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
512 { |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
513 return g_strdup(PACKAGE_NAME " " PACKAGE_VERSION); |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
514 } |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
515 |
3788
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
516 /* |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
517 * Compile a tuplez string and cache the result. |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
518 * This caches the result for the last string, so that |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
519 * successive calls are sped up. |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
520 * |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
521 * TODO/1.5: Implement a more efficient use of the compiler. |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
522 */ |
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
|
523 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
|
524 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
|
525 { |
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
|
526 static gboolean initialized = FALSE; |
3788
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
527 static gchar *last_string = NULL; |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
528 #ifdef TUPLE_USE_COMPILER |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
529 static TupleEvalContext *last_ctx = NULL; |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
530 static TupleEvalNode *last_ev = NULL; |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
531 #endif |
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
|
532 |
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
|
533 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
|
534 { |
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
|
535 tuple_formatter_register_expression("?", tuple_formatter_expression_exists); |
3286
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
536 tuple_formatter_register_expression("==", tuple_formatter_expression_match); |
8576de468e23
Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents:
3285
diff
changeset
|
537 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
|
538 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
|
539 |
a97fb19a0148
Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents:
3290
diff
changeset
|
540 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
|
541 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
|
542 } |
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
|
543 |
3788
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
544 #ifdef TUPLE_USE_COMPILER |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
545 if (last_string == NULL || |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
546 (last_string != NULL && strcmp(last_string, string))) |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
547 { |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
548 g_free(last_string); |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
549 |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
550 if (last_ctx != NULL) |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
551 { |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
552 tuple_evalctx_free(last_ctx); |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
553 tuple_evalnode_free(last_ev); |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
554 } |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
555 |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
556 last_ctx = tuple_evalctx_new(); |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
557 last_string = g_strdup(string); |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
558 last_ev = tuple_formatter_compile(last_ctx, last_string); |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
559 } |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
560 |
3790
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
561 #ifdef TUPLE_COMPILER_DEBUG |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
562 { |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
563 gint level = 0; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
564 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
565 tuple_formatter_print(stderr, &level, last_ctx, last_ev); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
566 } |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
567 #endif |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
568 |
3788
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
569 tuple_evalctx_reset(last_ctx); |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
570 return tuple_formatter_eval(last_ctx, last_ev, tuple); |
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
571 #else |
3285
740c6f845554
revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents:
3284
diff
changeset
|
572 return tuple_formatter_process_construct(tuple, string); |
3788
a76b55624e51
hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents:
3522
diff
changeset
|
573 #endif |
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
|
574 } |
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
|
575 |
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
|
576 /* 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
|
577 * 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
|
578 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
|
579 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
|
580 { |
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
|
581 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
|
582 |
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
|
583 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
|
584 |
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
|
585 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
|
586 |
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
|
587 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
|
588 g_free(rv); |
3490
602ec8c40d0d
Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
3409
diff
changeset
|
589 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
|
590 } |
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
|
591 |
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
|
592 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
|
593 } |
3790
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
594 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
595 #ifdef TUPLE_COMPILER_DEBUG |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
596 static void print_vars(FILE *f, TupleEvalContext *ctx, TupleEvalNode *node, gint start, gint end) |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
597 { |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
598 gint i; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
599 g_return_if_fail(node != NULL); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
600 g_return_if_fail(ctx != NULL); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
601 g_return_if_fail(start >= 0); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
602 g_return_if_fail(start <= end); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
603 g_return_if_fail(end < MAX_VAR); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
604 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
605 for (i = start; i <= end; i++) { |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
606 TupleEvalVar *v = NULL; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
607 gchar *s = NULL; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
608 gint n = node->var[i]; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
609 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
610 if (n >= 0) { |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
611 v = ctx->variables[n]; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
612 if (v) { |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
613 s = v->name; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
614 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
615 if (v->type == VAR_CONST) |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
616 fprintf(f, "(const)"); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
617 else if (v->type == VAR_DEF) |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
618 fprintf(f, "(def)"); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
619 } |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
620 } |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
621 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
622 fprintf(f, "var[%d]=(%d),\"%s\" ", i, n, s); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
623 } |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
624 } |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
625 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
626 gint tuple_formatter_print(FILE *f, gint *level, TupleEvalContext *ctx, TupleEvalNode *expr) |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
627 { |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
628 TupleEvalNode *curr = expr; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
629 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
630 if (!expr) return -1; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
631 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
632 (*level)++; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
633 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
634 /* Evaluate tuple in given TupleEval expression in given |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
635 * context and return resulting string. |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
636 */ |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
637 while (curr) { |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
638 gint i; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
639 for (i = 0; i < *level; i++) |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
640 fprintf(f, " "); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
641 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
642 switch (curr->opcode) { |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
643 case OP_RAW: |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
644 fprintf(f, "OP_RAW text=\"%s\"\n", curr->text); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
645 break; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
646 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
647 case OP_FIELD: |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
648 fprintf(f, "OP_FIELD "); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
649 print_vars(f, ctx, curr, 0, 0); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
650 fprintf(f, "\n"); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
651 break; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
652 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
653 case OP_EXISTS: |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
654 fprintf(f, "OP_EXISTS "); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
655 print_vars(f, ctx, curr, 0, 0); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
656 fprintf(f, "\n"); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
657 tuple_formatter_print(f, level, ctx, curr->children); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
658 break; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
659 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
660 case OP_DEF_STRING: |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
661 fprintf(f, "OP_DEF_STRING "); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
662 fprintf(f, "\n"); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
663 break; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
664 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
665 case OP_DEF_INT: |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
666 fprintf(f, "OP_DEF_INT "); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
667 fprintf(f, "\n"); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
668 break; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
669 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
670 case OP_EQUALS: |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
671 fprintf(f, "OP_EQUALS "); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
672 print_vars(f, ctx, curr, 0, 1); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
673 fprintf(f, "\n"); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
674 tuple_formatter_print(f, level, ctx, curr->children); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
675 break; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
676 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
677 case OP_NOT_EQUALS: |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
678 fprintf(f, "OP_NOT_EQUALS "); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
679 print_vars(f, ctx, curr, 0, 1); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
680 fprintf(f, "\n"); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
681 tuple_formatter_print(f, level, ctx, curr->children); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
682 break; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
683 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
684 case OP_IS_EMPTY: |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
685 fprintf(f, "OP_IS_EMPTY "); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
686 print_vars(f, ctx, curr, 0, 0); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
687 fprintf(f, "\n"); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
688 tuple_formatter_print(f, level, ctx, curr->children); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
689 break; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
690 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
691 default: |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
692 fprintf(f, "Unimplemented opcode %d!\n", curr->opcode); |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
693 break; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
694 } |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
695 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
696 curr = curr->next; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
697 } |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
698 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
699 (*level)--; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
700 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
701 return 0; |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
702 } |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
703 |
9121baaf0190
add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents:
3788
diff
changeset
|
704 #endif |