annotate src/audacious/tuple_formatter.c @ 3292:a97fb19a0148 trunk

Add support for functions.
author William Pitcock <nenolod@atheme-project.org>
date Thu, 09 Aug 2007 10:29:45 -0500
parents 4e7cc6d9b525
children 257c0d0c5806
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
1 /*
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
2 * Audacious
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
3 * Copyright (c) 2007 William Pitcock
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
4 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
7 * the Free Software Foundation; under version 3 of the License.
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
8 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
12 * GNU General Public License for more details.
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
13 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses>.
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
16 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
17 * The Audacious team does not consider modular code linking to
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
18 * Audacious or using our public API to be a derived work.
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
19 */
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
20
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
21 #include <glib.h>
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
22 #include <mowgli.h>
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
23
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
24 #include "config.h"
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
25 #include "tuple.h"
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
26 #include "tuple_formatter.h"
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
27
6062ef95818b Add first revision parser code. 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 /*
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
29 * 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
30 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
31 * 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
32 * 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
33 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
34 * 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
35 * - 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
36 * - 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
37 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
38 * 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
39 * - ${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
40 * - ${?field:expr}: evaluates expr if field exists
3284
70789a2a5a65 documentation fixes
William Pitcock <nenolod@atheme-project.org>
parents: 3283
diff changeset
41 * - ${=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
42 * tuple as string value of "value"
3284
70789a2a5a65 documentation fixes
William Pitcock <nenolod@atheme-project.org>
parents: 3283
diff changeset
43 * - ${=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
44 * 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
45 * - ${==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
46 * - ${!=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
47 * - ${(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
48 * - %{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
49 *
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
50 * everything else is treated as raw text.
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
51 * 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
52 */
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
53
6062ef95818b Add first revision parser code. 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 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
55 Tuple *tuple;
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
56 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
57 } 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
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 /* 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
60 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
61 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
62 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
63 {
6062ef95818b Add first revision parser code. 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 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
65 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
66 gchar *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
67
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
68 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
69 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
70
6062ef95818b Add first revision parser code. 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 ctx = g_new0(TupleFormatterContext, 1);
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
72 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
73
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
74 /* 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
75 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
76 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
77 /* if it's raw text, just copy the byte */
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
78 if (*iter != '$' && *iter != '%')
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
79 g_string_append_c(ctx->str, *iter);
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
80 else if (*iter == '$' && *(iter + 1) == '{')
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
81 {
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
82 GString *expression = g_string_new("");
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
83 GString *argument = g_string_new("");
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
84 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
85 gchar *result;
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
86 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
87
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
88 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
89 {
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
90 if (*iter == ':')
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
91 {
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
92 sel = argument;
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
93 continue;
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
94 }
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
95
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
96 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
97 {
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
98 if (sel == argument)
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
99 {
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
100 g_string_append_c(sel, *iter);
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
101 level++;
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
102 }
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
103 }
3286
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
104 else if (*iter == '}' && (sel == argument && --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
105 g_string_append_c(sel, *iter);
3286
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
106 else if (*iter == '}' && ((sel != argument) || (sel == argument && level <= 0)))
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
107 {
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
108 if (sel == argument)
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
109 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
110 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
111 }
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
112 else
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
113 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
114 }
6062ef95818b Add first revision parser code. 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 if (expression->len == 0)
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
117 {
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
118 g_string_free(expression, TRUE);
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
119 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
120 continue;
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
121 }
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
122
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
123 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
124 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
125 {
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
126 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
127 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
128 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
129
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
130 g_string_free(expression, TRUE);
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
131 g_string_free(argument, TRUE);
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
132
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
133 if (*iter == '\0')
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
134 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
135 }
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
136 else if (*iter == '%' && *(iter + 1) == '{')
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
137 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
138 GString *expression = g_string_new("");
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
139 GString *argument = g_string_new("");
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
140 GString *sel = expression;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
141 gchar *result;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
142 gint level = 0;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
143
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
144 for (iter += 2; *iter != '\0'; iter++)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
145 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
146 if (*iter == ':')
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
147 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
148 sel = argument;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
149 continue;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
150 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
151
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
152 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
153 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
154 if (sel == argument)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
155 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
156 g_string_append_c(sel, *iter);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
157 level++;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
158 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
159 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
160 else if (*iter == '}' && (sel == argument && --level > 0))
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
161 g_string_append_c(sel, *iter);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
162 else if (*iter == '}' && ((sel != argument) || (sel == argument && level <= 0)))
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
163 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
164 if (sel == argument)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
165 iter++;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
166 break;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
167 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
168 else
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
169 g_string_append_c(sel, *iter);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
170 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
171
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
172 if (expression->len == 0)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
173 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
174 g_string_free(expression, TRUE);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
175 g_string_free(argument, TRUE);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
176 continue;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
177 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
178
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
179 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
180 if (result != NULL)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
181 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
182 g_string_append(ctx->str, result);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
183 g_free(result);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
184 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
185
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
186 g_string_free(expression, TRUE);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
187 g_string_free(argument, TRUE);
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 if (*iter == '\0')
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
190 break;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
191 }
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
192 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
193
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
194 out = g_strdup(ctx->str->str);
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
195 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
196 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
197
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
198 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
199 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
200
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
201 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
202
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
203 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
204 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
205 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
206 } 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
207
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
208 /* 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
209 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
210 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
211 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
212 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
213 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
214 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
215
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
216 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
217 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
218
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
219 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
220 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
221 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
222
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
223 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
224 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
225 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
226 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
227 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
228 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
229
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
230 /* ${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
231 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
232 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
233 TupleValueType type = tuple_get_value_type(tuple, 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
234
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
235 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
236 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
237 case TUPLE_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
238 return g_strdup(tuple_get_string(tuple, 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
239 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
240 case TUPLE_INT:
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
241 return g_strdup_printf("%d", tuple_get_int(tuple, 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
242 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
243 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
244 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
245 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
246 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
247 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
248 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
249 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
250 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
251 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
252 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
253
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
254 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
255 }
6062ef95818b Add first revision parser code. 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
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
257 static GList *tuple_formatter_func_list = NULL;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
258
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
259 typedef struct {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
260 const gchar *name;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
261 gchar *(*func)(Tuple *tuple, gchar **args);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
262 } TupleFormatterFunction;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
263
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
264 /* processes a function */
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
265 gchar *
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
266 tuple_formatter_process_function(Tuple *tuple, const gchar *expression,
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
267 const gchar *argument)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
268 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
269 TupleFormatterFunction *expr = NULL;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
270 GList *iter;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
271
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
272 g_return_val_if_fail(tuple != NULL, NULL);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
273 g_return_val_if_fail(expression != NULL, NULL);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
274
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
275 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
276 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
277 TupleFormatterFunction *tmp = (TupleFormatterFunction *) iter->data;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
278
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
279 if (g_str_has_prefix(expression, tmp->name) == TRUE)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
280 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
281 expr = tmp;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
282 expression += strlen(tmp->name);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
283 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
284 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
285
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
286 if (expr != NULL)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
287 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
288 gchar **args;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
289 gchar *ret;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
290
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
291 if (argument)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
292 args = g_strsplit(argument, ",", 10);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
293 else
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
294 args = NULL;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
295
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
296 ret = expr->func(tuple, args);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
297
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
298 if (args)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
299 g_strfreev(args);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
300
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
301 return ret;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
302 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
303
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
304 return NULL;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
305 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
306
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
307 /* 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
308 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
309 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
310 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
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 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
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 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
315 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
316
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
317 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
318 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
319 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
320
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
321 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
322 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
323
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
324 /* registers a function */
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
325 void
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
326 tuple_formatter_register_function(const gchar *keyword,
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
327 gchar *(*func)(Tuple *tuple, gchar **argument))
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
328 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
329 TupleFormatterFunction *expr;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
330
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
331 g_return_if_fail(keyword != NULL);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
332 g_return_if_fail(func != NULL);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
333
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
334 expr = g_new0(TupleFormatterFunction, 1);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
335 expr->name = keyword;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
336 expr->func = func;
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
337
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
338 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
339 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
340
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
341 /* builtin-keyword: ${?arg}, returns TRUE if <arg> exists. */
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
342 static gboolean
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
343 tuple_formatter_expression_exists(Tuple *tuple, const gchar *expression)
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
344 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
345 return (tuple_get_value_type(tuple, expression) != TUPLE_UNKNOWN) ? TRUE : 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
346 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
347
3286
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
348 /* builtin-keyword: ${==arg1,arg2}, returns TRUE if <arg1> and <arg2> match. */
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
349 static gboolean
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
350 tuple_formatter_expression_match(Tuple *tuple, const gchar *expression)
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
351 {
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
352 gchar **args = g_strsplit(expression, ",", 2);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
353 gchar *arg1, *arg2;
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
354 gint ret;
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
355
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
356 if (tuple_get_value_type(tuple, args[0]) == TUPLE_UNKNOWN)
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
357 {
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
358 g_strfreev(args);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
359 return FALSE;
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
360 }
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
361
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
362 if (tuple_get_value_type(tuple, args[1]) == TUPLE_UNKNOWN)
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
363 {
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
364 g_strfreev(args);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
365 return FALSE;
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
366 }
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
367
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
368 if (tuple_get_value_type(tuple, args[0]) == TUPLE_STRING)
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
369 arg1 = g_strdup(tuple_get_string(tuple, args[0]));
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
370 else
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
371 arg1 = g_strdup_printf("%d", tuple_get_int(tuple, args[0]));
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
372
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
373 if (tuple_get_value_type(tuple, args[1]) == TUPLE_STRING)
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
374 arg2 = g_strdup(tuple_get_string(tuple, args[1]));
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
375 else
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
376 arg2 = g_strdup_printf("%d", tuple_get_int(tuple, args[1]));
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
377
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
378 ret = g_ascii_strcasecmp(arg1, arg2);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
379 g_free(arg1);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
380 g_free(arg2);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
381 g_strfreev(args);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
382
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
383 return ret ? FALSE : TRUE;
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
384 }
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
385
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
386 /* builtin-keyword: ${!=arg1,arg2}. returns TRUE if <arg1> and <arg2> don't match. */
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
387 static gboolean
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
388 tuple_formatter_expression_nonmatch(Tuple *tuple, const gchar *expression)
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
389 {
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
390 return tuple_formatter_expression_match(tuple, expression) ^ 1;
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
391 }
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
392
3290
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
393 /* builtin-keyword: ${empty?}. returns TRUE if <arg> is empty. */
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
394 static gboolean
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
395 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
396 {
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
397 gboolean ret = TRUE;
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
398 const gchar *iter;
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
399 TupleValueType type = tuple_get_value_type(tuple, expression);
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
400
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
401 if (type == TUPLE_UNKNOWN)
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
402 return TRUE;
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
403
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
404 if (type == TUPLE_INT && tuple_get_int(tuple, expression) != 0)
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
405 return FALSE;
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
406
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
407 iter = tuple_get_string(tuple, expression);
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
408
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
409 while (ret && *iter != '\0')
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
410 {
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
411 if (*iter == ' ')
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
412 iter++;
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
413 else
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
414 ret = FALSE;
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
415 }
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
416
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
417 return ret;
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
418 }
4e7cc6d9b525 add (empty)? function to formatter
William Pitcock <nenolod@atheme-project.org>
parents: 3286
diff changeset
419
3292
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
420 /* builtin function: %{audacious-version} */
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
421 static gchar *
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
422 tuple_formatter_function_version(Tuple *tuple, gchar **args)
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
423 {
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
424 return g_strdup(PACKAGE_NAME " " PACKAGE_VERSION);
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
425 }
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
426
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
427 /* processes a string containing instructions. does initialization phases
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
428 if not already done */
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
429 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
430 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
431 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
432 static gboolean initialized = FALSE;
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
433
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
434 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
435 {
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
436 tuple_formatter_register_expression("?", tuple_formatter_expression_exists);
3286
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
437 tuple_formatter_register_expression("==", tuple_formatter_expression_match);
8576de468e23 Add != operator.
William Pitcock <nenolod@atheme-project.org>
parents: 3285
diff changeset
438 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
439 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
440
a97fb19a0148 Add support for functions.
William Pitcock <nenolod@atheme-project.org>
parents: 3290
diff changeset
441 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
442 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
443 }
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
444
3285
740c6f845554 revise tuple formatting engine logic
William Pitcock <nenolod@atheme-project.org>
parents: 3284
diff changeset
445 return tuple_formatter_process_construct(tuple, string);
3283
6062ef95818b Add first revision parser code. May or may not work, not hooked up, so I can't test it yet. ;)
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
446 }