annotate src/audacious/tuple_formatter.c @ 4160:472aaaca02c0

Make "jump to track" feature to normalize search and match strings (Bugzilla #20)
author Jussi Judin <jjudin+audacious@iki.fi>
date Thu, 10 Jan 2008 02:25:01 -0600
parents 040243a50bd3
children ce3f2d2455cf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
1 /*
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
2 * Audacious
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
3 * Copyright (c) 2007 William Pitcock
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
4 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
7 * the Free Software Foundation; under version 3 of the License.
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
8 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
12 * GNU General Public License for more details.
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
13 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses>.
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
16 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
17 * The Audacious team does not consider modular code linking to
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
18 * Audacious or using our public API to be a derived work.
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
19 */
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
20
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
21 #include <glib.h>
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
22 #include <mowgli.h>
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
23
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
24 #include "config.h"
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
25 #include "tuple.h"
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
26 #include "tuple_formatter.h"
3872
b02853ac8466 revise tuple_formatter_make_title_string()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3870
diff changeset
27 #include "strings.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
28
3788
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
29 /*
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
30 * TUPLE_USE_COMPILER:
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
31 * Undefine this to disable usage of the Tuplez compiler implementation.
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
32 * 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
33 */
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
34 #define TUPLE_USE_COMPILER
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
35
3790
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
36 /*
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
37 * TUPLE_COMPILER_DEBUG:
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
38 * 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
39 * bytecode. This may be useful if bugs creep in.
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
40 */
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
41 #undef TUPLE_COMPILER_DEBUG
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
42
3788
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
43 #ifdef TUPLE_USE_COMPILER
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
44 # include "tuple_compiler.h"
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
45 #endif
3331
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
46
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
47 #ifdef _DEBUG
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
48 # 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
49 #else
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
50 # define _TRACE(fmt, ...)
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
51 #endif
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
52
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
53 /*
6062ef95818b Add first revision parser code. 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 * 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
55 *
6062ef95818b Add first revision parser code. 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 * 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
57 * 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
58 *
6062ef95818b Add first revision parser code. 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 * 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
60 * - 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
61 * - 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
62 *
6062ef95818b Add first revision parser code. 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 * 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
64 * - ${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
65 * - ${?field:expr}: evaluates expr if field exists
3284
70789a2a5a65 documentation fixes
William Pitcock <nenolod@atheme-project.org>
parents: 3283
diff changeset
66 * - ${=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
67 * tuple as string value of "value"
3284
70789a2a5a65 documentation fixes
William Pitcock <nenolod@atheme-project.org>
parents: 3283
diff changeset
68 * - ${=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
69 * 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
70 * - ${==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
71 * - ${!=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
72 * - ${(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
73 * - %{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
74 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
75 * everything else is treated as raw text.
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
76 * 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
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
6062ef95818b Add first revision parser code. 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 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
80 Tuple *tuple;
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
81 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
82 } 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
83
6062ef95818b Add first revision parser code. 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 /* 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
85 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
86 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
87 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
88 {
6062ef95818b Add first revision parser code. 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 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
90 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
91 gchar *out;
3314
328221f7a580 fix parser
William Pitcock <nenolod@atheme-project.org>
parents: 3313
diff changeset
92 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
93
6062ef95818b Add first revision parser code. 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(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
95 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
96
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
97 ctx = g_new0(TupleFormatterContext, 1);
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
98 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
99
3331
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
100 _TRACE("parsing <%s>", string);
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
101
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
102 /* 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
103 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
104 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
105 /* 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
106 if (*iter != '$' && *iter != '%' && *iter != '}' )
63d7947d7376 simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents: 3331
diff changeset
107 {
63d7947d7376 simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents: 3331
diff changeset
108 g_string_append_c(ctx->str, *iter);
63d7947d7376 simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents: 3331
diff changeset
109 }
63d7947d7376 simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents: 3331
diff changeset
110 else if (*iter == '}' && level > 0)
3314
328221f7a580 fix parser
William Pitcock <nenolod@atheme-project.org>
parents: 3313
diff changeset
111 {
328221f7a580 fix parser
William Pitcock <nenolod@atheme-project.org>
parents: 3313
diff changeset
112 level--;
328221f7a580 fix parser
William Pitcock <nenolod@atheme-project.org>
parents: 3313
diff changeset
113 }
3313
257c0d0c5806 use g_str_has_prefix() more.
William Pitcock <nenolod@atheme-project.org>
parents: 3292
diff changeset
114 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
115 {
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
116 GString *expression = g_string_new("");
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
117 GString *argument = g_string_new("");
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
118 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
119 gchar *result;
3335
63d7947d7376 simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents: 3331
diff changeset
120 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
121
6062ef95818b Add first revision parser code. 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 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
123 {
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
124 if (*iter == ':')
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
125 {
3316
6ce62683e8c4 test nesting
William Pitcock <nenolod@atheme-project.org>
parents: 3314
diff changeset
126 if (sel != argument)
6ce62683e8c4 test nesting
William Pitcock <nenolod@atheme-project.org>
parents: 3314
diff changeset
127 {
6ce62683e8c4 test nesting
William Pitcock <nenolod@atheme-project.org>
parents: 3314
diff changeset
128 sel = argument;
6ce62683e8c4 test nesting
William Pitcock <nenolod@atheme-project.org>
parents: 3314
diff changeset
129 continue;
6ce62683e8c4 test nesting
William Pitcock <nenolod@atheme-project.org>
parents: 3314
diff changeset
130 }
6ce62683e8c4 test nesting
William Pitcock <nenolod@atheme-project.org>
parents: 3314
diff changeset
131 else
6ce62683e8c4 test nesting
William Pitcock <nenolod@atheme-project.org>
parents: 3314
diff changeset
132 g_string_append_c(sel, *iter);
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
133 continue;
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
134 }
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
135
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
136 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
137 {
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
138 if (sel == argument)
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
139 {
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
140 g_string_append_c(sel, *iter);
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
141 level++;
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
142 }
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
143 }
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
144 else if (*iter == '}')
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
145 {
3314
328221f7a580 fix parser
William Pitcock <nenolod@atheme-project.org>
parents: 3313
diff changeset
146 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
147 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
148 {
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 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
150 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
151 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
152 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
153 }
3335
63d7947d7376 simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents: 3331
diff changeset
154 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
155 break;
3314
328221f7a580 fix parser
William Pitcock <nenolod@atheme-project.org>
parents: 3313
diff changeset
156 }
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
157 else
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
158 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
159 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
160
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
161 if (expression->len == 0)
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
162 {
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
163 g_string_free(expression, TRUE);
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
164 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
165 continue;
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
166 }
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
167
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
168 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
169 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
170 {
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
171 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
172 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
173 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
174
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
175 g_string_free(expression, TRUE);
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
176 g_string_free(argument, TRUE);
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
177
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
178 if (*iter == '\0')
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
179 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
180 }
3313
257c0d0c5806 use g_str_has_prefix() more.
William Pitcock <nenolod@atheme-project.org>
parents: 3292
diff changeset
181 else if (g_str_has_prefix(iter, "%{") == TRUE)
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
182 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
183 GString *expression = g_string_new("");
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
184 GString *argument = g_string_new("");
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
185 GString *sel = expression;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
186 gchar *result;
3335
63d7947d7376 simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents: 3331
diff changeset
187 level++;
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
188
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
189 for (iter += 2; *iter != '\0'; iter++)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
190 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
191 if (*iter == ':')
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
192 {
3322
de29bf952b77 fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents: 3316
diff changeset
193 if (sel != argument)
de29bf952b77 fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents: 3316
diff changeset
194 {
de29bf952b77 fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents: 3316
diff changeset
195 sel = argument;
de29bf952b77 fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents: 3316
diff changeset
196 continue;
de29bf952b77 fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents: 3316
diff changeset
197 }
de29bf952b77 fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents: 3316
diff changeset
198 else
de29bf952b77 fix recursion and combination of functions and expressions too
William Pitcock <nenolod@atheme-project.org>
parents: 3316
diff changeset
199 g_string_append_c(sel, *iter);
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
200 continue;
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
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
203 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
204 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
205 if (sel == argument)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
206 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
207 g_string_append_c(sel, *iter);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
208 level++;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
209 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
210 }
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
211 else if (*iter == '}')
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
212 {
3314
328221f7a580 fix parser
William Pitcock <nenolod@atheme-project.org>
parents: 3313
diff changeset
213 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
214 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
215 {
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 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
217 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
218 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
219 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
220 }
3335
63d7947d7376 simplified the tuple formatter a bit
Giacomo Lozito <james@develia.org>
parents: 3331
diff changeset
221 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
222 break;
3314
328221f7a580 fix parser
William Pitcock <nenolod@atheme-project.org>
parents: 3313
diff changeset
223 }
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
224 else
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
225 g_string_append_c(sel, *iter);
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
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
228 if (expression->len == 0)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
229 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
230 g_string_free(expression, TRUE);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
231 g_string_free(argument, TRUE);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
232 continue;
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
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
235 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
236 if (result != NULL)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
237 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
238 g_string_append(ctx->str, result);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
239 g_free(result);
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
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
242 g_string_free(expression, TRUE);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
243 g_string_free(argument, TRUE);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
244
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
245 if (*iter == '\0')
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
246 break;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
247 }
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
248 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
249
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
250 out = g_strdup(ctx->str->str);
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
251 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
252 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
253
3331
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
254 _TRACE("parsed <%s> as <%s>", string, out);
9c53688bb559 some debugging for giacomo
William Pitcock <nenolod@atheme-project.org>
parents: 3322
diff changeset
255
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
256 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
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
6062ef95818b Add first revision parser code. 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 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
260
6062ef95818b Add first revision parser code. 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 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
262 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
263 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
264 } 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
265
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
266 /* 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
267 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
268 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
269 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
270 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
271 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
272 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
273
6062ef95818b Add first revision parser code. 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(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
275 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
276
6062ef95818b Add first revision parser code. 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 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
278 {
6062ef95818b Add first revision parser code. 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 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
280
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
281 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
282 {
6062ef95818b Add first revision parser code. 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 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
284 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
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
6062ef95818b Add first revision parser code. 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 /* ${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
289 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
290 {
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
291 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
292
6062ef95818b Add first revision parser code. 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 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
294 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
295 case TUPLE_STRING:
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
296 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
297 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
298 case TUPLE_INT:
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
299 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
300 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
301 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
302 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
303 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
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 }
6062ef95818b Add first revision parser code. 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 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
307 {
6062ef95818b Add first revision parser code. 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 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
309 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
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
6062ef95818b Add first revision parser code. 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 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
313 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
314
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
315 static GList *tuple_formatter_func_list = NULL;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
316
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
317 typedef struct {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
318 const gchar *name;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
319 gchar *(*func)(Tuple *tuple, gchar **args);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
320 } TupleFormatterFunction;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
321
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
322 /* processes a function */
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
323 gchar *
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
324 tuple_formatter_process_function(Tuple *tuple, const gchar *expression,
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
325 const gchar *argument)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
326 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
327 TupleFormatterFunction *expr = NULL;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
328 GList *iter;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
329
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
330 g_return_val_if_fail(tuple != NULL, NULL);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
331 g_return_val_if_fail(expression != NULL, NULL);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
332
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
333 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
334 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
335 TupleFormatterFunction *tmp = (TupleFormatterFunction *) iter->data;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
336
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
337 if (g_str_has_prefix(expression, tmp->name) == TRUE)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
338 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
339 expr = tmp;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
340 expression += strlen(tmp->name);
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
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
344 if (expr != NULL)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
345 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
346 gchar **args;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
347 gchar *ret;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
348
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
349 if (argument)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
350 args = g_strsplit(argument, ",", 10);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
351 else
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
352 args = NULL;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
353
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
354 ret = expr->func(tuple, args);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
355
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
356 if (args)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
357 g_strfreev(args);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
358
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
359 return ret;
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
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
362 return NULL;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
363 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
364
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
365 /* 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
366 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
367 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
368 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
369 {
6062ef95818b Add first revision parser code. 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 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
371
6062ef95818b Add first revision parser code. 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(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
373 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
374
6062ef95818b Add first revision parser code. 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 = 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
376 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
377 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
378
6062ef95818b Add first revision parser code. 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 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
380 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
381
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
382 /* registers a function */
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
383 void
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
384 tuple_formatter_register_function(const gchar *keyword,
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
385 gchar *(*func)(Tuple *tuple, gchar **argument))
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
386 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
387 TupleFormatterFunction *expr;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
388
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
389 g_return_if_fail(keyword != NULL);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
390 g_return_if_fail(func != NULL);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
391
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
392 expr = g_new0(TupleFormatterFunction, 1);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
393 expr->name = keyword;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
394 expr->func = func;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
395
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
396 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
397 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
398
3339
c23513d0ee17 adjusted comments for == and != tuple operators
Giacomo Lozito <james@develia.org>
parents: 3338
diff changeset
399 /* 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
400 <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
401 static gboolean
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
402 tuple_formatter_expression_match(Tuple *tuple, const gchar *expression)
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
403 {
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
404 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
405 gchar *arg1 = NULL, *arg2 = NULL;
3286
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
406 gint ret;
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
407
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
408 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
409 {
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 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
411 {
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 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
413 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
414 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
415 }
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 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
417 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
418 }
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
419 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
420 {
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 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
422 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
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
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 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
426 {
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 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
428 {
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 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
430 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
431 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
432 }
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 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
434 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
435 }
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
436 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
437 {
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
438 g_strfreev(args);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
439 return FALSE;
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
440 }
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
441
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
442 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
443 {
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
444 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
445 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
446 else
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
447 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
448 }
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
449
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
450 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
451 {
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
452 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
453 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
454 else
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
455 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
456 }
3286
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
457
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
458 ret = g_ascii_strcasecmp(arg1, arg2);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
459 g_free(arg1);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
460 g_free(arg2);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
461 g_strfreev(args);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
462
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
463 return ret ? FALSE : TRUE;
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
464 }
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
465
3339
c23513d0ee17 adjusted comments for == and != tuple operators
Giacomo Lozito <james@develia.org>
parents: 3338
diff changeset
466 /* 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
467 <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
468 static gboolean
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
469 tuple_formatter_expression_nonmatch(Tuple *tuple, const gchar *expression)
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
470 {
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
471 return tuple_formatter_expression_match(tuple, expression) ^ 1;
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
472 }
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
473
3521
2f5ef443b231 tuple_formatter_expression_exists() now checks for empty fields, becoming
Matti Hamalainen <ccr@tnsp.org>
parents: 3519
diff changeset
474 /* 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
475 static gboolean
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
476 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
477 {
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
478 gboolean ret = TRUE;
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
479 const gchar *iter;
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
480 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
481
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
482 if (type == TUPLE_UNKNOWN)
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
483 return TRUE;
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
484
3522
23bf72b8c95c tuple_formatter_expression_empty() was fundamentally broken, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 3521
diff changeset
485 if (type == TUPLE_INT)
23bf72b8c95c tuple_formatter_expression_empty() was fundamentally broken, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 3521
diff changeset
486 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
487
3490
602ec8c40d0d Fixed to comply with the Tuple API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
488 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
489 if (!iter)
23bf72b8c95c tuple_formatter_expression_empty() was fundamentally broken, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 3521
diff changeset
490 return TRUE;
3290
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
491
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
492 while (ret && *iter != '\0')
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
493 {
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
494 if (*iter == ' ')
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
495 iter++;
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
496 else
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
497 ret = FALSE;
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
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
500 return ret;
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
501 }
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
502
3521
2f5ef443b231 tuple_formatter_expression_exists() now checks for empty fields, becoming
Matti Hamalainen <ccr@tnsp.org>
parents: 3519
diff changeset
503 /* 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
504 static gboolean
2f5ef443b231 tuple_formatter_expression_exists() now checks for empty fields, becoming
Matti Hamalainen <ccr@tnsp.org>
parents: 3519
diff changeset
505 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
506 {
2f5ef443b231 tuple_formatter_expression_exists() now checks for empty fields, becoming
Matti Hamalainen <ccr@tnsp.org>
parents: 3519
diff changeset
507 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
508 }
2f5ef443b231 tuple_formatter_expression_exists() now checks for empty fields, becoming
Matti Hamalainen <ccr@tnsp.org>
parents: 3519
diff changeset
509
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
510 /* builtin function: %{audacious-version} */
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
511 static gchar *
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
512 tuple_formatter_function_version(Tuple *tuple, gchar **args)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
513 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
514 return g_strdup(PACKAGE_NAME " " PACKAGE_VERSION);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
515 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
516
3788
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
517 /*
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
518 * Compile a tuplez string and cache the result.
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
519 * This caches the result for the last string, so that
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
520 * successive calls are sped up.
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
521 *
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
522 * 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
523 */
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
524 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
525 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
526 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
527 static gboolean initialized = FALSE;
3788
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
528 static gchar *last_string = NULL;
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
529 #ifdef TUPLE_USE_COMPILER
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
530 static TupleEvalContext *last_ctx = NULL;
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
531 static TupleEvalNode *last_ev = NULL;
3948
1382d265b71d Error reporting added.
Matti Hamalainen <ccr@tnsp.org>
parents: 3790
diff changeset
532 gchar *result = NULL;
3788
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
533 #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
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 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
536 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
537 tuple_formatter_register_expression("?", tuple_formatter_expression_exists);
3286
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
538 tuple_formatter_register_expression("==", tuple_formatter_expression_match);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
539 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
540 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
541
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
542 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
543 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
544 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
545
3788
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
546 #ifdef TUPLE_USE_COMPILER
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
547 if (last_string == NULL ||
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
548 (last_string != NULL && strcmp(last_string, 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 g_free(last_string);
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 if (last_ctx != NULL)
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
553 {
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
554 tuple_evalctx_free(last_ctx);
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
555 tuple_evalnode_free(last_ev);
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
556 }
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
557
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
558 last_ctx = tuple_evalctx_new();
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
559 last_string = g_strdup(string);
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
560 last_ev = tuple_formatter_compile(last_ctx, last_string);
3948
1382d265b71d Error reporting added.
Matti Hamalainen <ccr@tnsp.org>
parents: 3790
diff changeset
561 if (last_ctx->iserror) {
1382d265b71d Error reporting added.
Matti Hamalainen <ccr@tnsp.org>
parents: 3790
diff changeset
562 fprintf(stderr, "[TuplezCC]: %s", last_ctx->errmsg);
1382d265b71d Error reporting added.
Matti Hamalainen <ccr@tnsp.org>
parents: 3790
diff changeset
563 }
1382d265b71d Error reporting added.
Matti Hamalainen <ccr@tnsp.org>
parents: 3790
diff changeset
564 if (!last_ev) {
1382d265b71d Error reporting added.
Matti Hamalainen <ccr@tnsp.org>
parents: 3790
diff changeset
565 fprintf(stderr, "[TuplezCC]: Compilation failed!\n");
1382d265b71d Error reporting added.
Matti Hamalainen <ccr@tnsp.org>
parents: 3790
diff changeset
566 }
3788
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
567 }
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
568
3790
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
569 #ifdef TUPLE_COMPILER_DEBUG
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
570 {
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
571 gint level = 0;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
572
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
573 tuple_formatter_print(stderr, &level, last_ctx, last_ev);
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
574 }
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
575 #endif
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
576
3788
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
577 tuple_evalctx_reset(last_ctx);
3948
1382d265b71d Error reporting added.
Matti Hamalainen <ccr@tnsp.org>
parents: 3790
diff changeset
578 result = tuple_formatter_eval(last_ctx, last_ev, tuple);
1382d265b71d Error reporting added.
Matti Hamalainen <ccr@tnsp.org>
parents: 3790
diff changeset
579 if (last_ctx->iserror) {
1382d265b71d Error reporting added.
Matti Hamalainen <ccr@tnsp.org>
parents: 3790
diff changeset
580 fprintf(stderr, "[TuplezEV]: %s", last_ctx->errmsg);
1382d265b71d Error reporting added.
Matti Hamalainen <ccr@tnsp.org>
parents: 3790
diff changeset
581 }
1382d265b71d Error reporting added.
Matti Hamalainen <ccr@tnsp.org>
parents: 3790
diff changeset
582 return result;
3788
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
583 #else
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
584 return tuple_formatter_process_construct(tuple, string);
3788
a76b55624e51 hook up tuple compiler.
William Pitcock <nenolod@atheme.org>
parents: 3522
diff changeset
585 #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
586 }
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
587
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 /* 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
589 * 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
590 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
591 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
592 {
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 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
594
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
595 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
596
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
597 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
598
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
599 if(!rv || !strcmp(rv, "")) {
3870
6d0db63e05aa file name should be un-escaped when it is used as a title in the playlist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3790
diff changeset
600 const gchar *file_name = tuple_get_string(tuple, FIELD_FILE_NAME, NULL);
3872
b02853ac8466 revise tuple_formatter_make_title_string()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 3870
diff changeset
601
4070
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 4051
diff changeset
602 if(file_name) {
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 4051
diff changeset
603 gchar *realfn = g_filename_from_uri(file_name, NULL, NULL);
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 4051
diff changeset
604 g_free(rv);
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 4051
diff changeset
605 rv = str_to_utf8(realfn ? realfn : file_name);
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 4051
diff changeset
606 g_free(realfn);
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 4051
diff changeset
607 }
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 4051
diff changeset
608 else {
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 4051
diff changeset
609 g_free(rv);
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 4051
diff changeset
610 rv = g_strdup("<unknown>");
040243a50bd3 - modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 4051
diff changeset
611 }
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
612 }
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
613
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
614 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
615 }
3790
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
616
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
617 #ifdef TUPLE_COMPILER_DEBUG
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
618 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
619 {
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
620 gint i;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
621 g_return_if_fail(node != NULL);
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
622 g_return_if_fail(ctx != NULL);
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
623 g_return_if_fail(start >= 0);
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
624 g_return_if_fail(start <= end);
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
625 g_return_if_fail(end < MAX_VAR);
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
626
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
627 for (i = start; i <= end; i++) {
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
628 TupleEvalVar *v = NULL;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
629 gchar *s = NULL;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
630 gint n = node->var[i];
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 if (n >= 0) {
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
633 v = ctx->variables[n];
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
634 if (v) {
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
635 s = v->name;
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 if (v->type == VAR_CONST)
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
638 fprintf(f, "(const)");
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
639 else if (v->type == VAR_DEF)
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
640 fprintf(f, "(def)");
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 }
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
643
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
644 fprintf(f, "var[%d]=(%d),\"%s\" ", i, n, s);
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
645 }
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
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
648 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
649 {
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
650 TupleEvalNode *curr = expr;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
651
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
652 if (!expr) return -1;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
653
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
654 (*level)++;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
655
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
656 /* Evaluate tuple in given TupleEval expression in given
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
657 * context and return resulting string.
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
658 */
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
659 while (curr) {
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
660 gint i;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
661 for (i = 0; i < *level; i++)
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
662 fprintf(f, " ");
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
663
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
664 switch (curr->opcode) {
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
665 case OP_RAW:
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
666 fprintf(f, "OP_RAW text=\"%s\"\n", curr->text);
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
667 break;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
668
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
669 case OP_FIELD:
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
670 fprintf(f, "OP_FIELD ");
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
671 print_vars(f, ctx, curr, 0, 0);
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
672 fprintf(f, "\n");
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
673 break;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
674
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
675 case OP_EXISTS:
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
676 fprintf(f, "OP_EXISTS ");
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
677 print_vars(f, ctx, curr, 0, 0);
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
678 fprintf(f, "\n");
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
679 tuple_formatter_print(f, level, ctx, curr->children);
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
680 break;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
681
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
682 case OP_DEF_STRING:
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
683 fprintf(f, "OP_DEF_STRING ");
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
684 fprintf(f, "\n");
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
685 break;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
686
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
687 case OP_DEF_INT:
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
688 fprintf(f, "OP_DEF_INT ");
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
689 fprintf(f, "\n");
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
690 break;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
691
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
692 case OP_EQUALS:
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
693 fprintf(f, "OP_EQUALS ");
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
694 print_vars(f, ctx, curr, 0, 1);
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
695 fprintf(f, "\n");
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
696 tuple_formatter_print(f, level, ctx, curr->children);
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
697 break;
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 case OP_NOT_EQUALS:
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
700 fprintf(f, "OP_NOT_EQUALS ");
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
701 print_vars(f, ctx, curr, 0, 1);
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
702 fprintf(f, "\n");
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
703 tuple_formatter_print(f, level, ctx, curr->children);
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
704 break;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
705
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
706 case OP_IS_EMPTY:
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
707 fprintf(f, "OP_IS_EMPTY ");
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
708 print_vars(f, ctx, curr, 0, 0);
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
709 fprintf(f, "\n");
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
710 tuple_formatter_print(f, level, ctx, curr->children);
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
711 break;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
712
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
713 default:
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
714 fprintf(f, "Unimplemented opcode %d!\n", curr->opcode);
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
715 break;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
716 }
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
717
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
718 curr = curr->next;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
719 }
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
720
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
721 (*level)--;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
722
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
723 return 0;
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
724 }
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
725
9121baaf0190 add some debugging support code.
William Pitcock <nenolod@atheme.org>
parents: 3788
diff changeset
726 #endif