annotate libaudacious/formatter.c @ 2162:48c8ecbfb282 trunk

[svn] - remove deprecated symbol warnings for gdk_draw_pixmap
author nenolod
date Mon, 18 Dec 2006 09:43:42 -0800
parents f18a5b617c34
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2045
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
1 /* Audacious
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
2 * Copyright (C) 2005-2007 Audacious team
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
3 *
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
4 * XMMS - Cross-platform multimedia player
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
5 * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas,
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
6 * Thomas Nilsson and 4Front Technologies
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
7 * Copyright (C) 1999-2003 Haavard Kvaalen
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
8 *
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
9 * This program is free software; you can redistribute it and/or modify
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
10 * it under the terms of the GNU General Public License as published by
2105
f18a5b617c34 [svn] - move to GPLv2-only. Based on my interpretation of the license, we are
nenolod
parents: 2060
diff changeset
11 * the Free Software Foundation; under version 2 of the License.
2045
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
12 *
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
13 * This program is distributed in the hope that it will be useful,
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
16 * GNU General Public License for more details.
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
17 *
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
18 * You should have received a copy of the GNU General Public License
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
19 * along with this program; if not, write to the Free Software
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
21 */
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
22
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 # include "config.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27 #include <glib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 #include "formatter.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30
2045
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
31 /**
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
32 * xmms_formatter_new:
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
33 *
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
34 * Factory for #Formatter objects.
2060
53a3d5db6b58 [svn] - finish documenting the libaudacious API
nenolod
parents: 2045
diff changeset
35 *
53a3d5db6b58 [svn] - finish documenting the libaudacious API
nenolod
parents: 2045
diff changeset
36 * Return value: A #Formatter object.
2045
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
37 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 Formatter *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 xmms_formatter_new(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 Formatter *formatter = g_new0(Formatter, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 xmms_formatter_associate(formatter, '%', "%");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 return formatter;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46
2045
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
47 /**
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
48 * xmms_formatter_destroy:
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
49 * @formatter: A #Formatter object to destroy.
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
50 *
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
51 * Destroys #Formatter objects.
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
52 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 xmms_formatter_destroy(Formatter * formatter)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 int i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 for (i = 0; i < 256; i++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 if (formatter->values[i])
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 g_free(formatter->values[i]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 g_free(formatter);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63
2045
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
64 /**
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
65 * xmms_formatter_associate:
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
66 * @formatter: A #Formatter object to use.
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
67 * @id: The character to use for replacement.
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
68 * @value: The value to replace with.
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
69 *
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
70 * Adds a id->replacement set to the formatter's stack.
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
71 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 xmms_formatter_associate(Formatter * formatter, guchar id, char *value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 xmms_formatter_dissociate(formatter, id);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 formatter->values[id] = g_strdup(value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78
2045
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
79 /**
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
80 * xmms_formatter_dissociate:
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
81 * @formatter: A #Formatter object to use.
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
82 * @id: The id to remove the id->replacement mapping for.
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
83 *
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
84 * Removes an id->replacement mapping from the formatter's stack.
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
85 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 xmms_formatter_dissociate(Formatter * formatter, guchar id)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 if (formatter->values[id])
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 g_free(formatter->values[id]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 formatter->values[id] = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93
2045
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
94 /**
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
95 * xmms_formatter_format:
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
96 * @formatter: A #Formatter object to use.
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
97 * @format: A string to format.
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
98 *
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
99 * Performs id->replacement substitution on a string.
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
100 *
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
101 * Returns: The formatted string.
04961c9a5242 [svn] - document the formatter class
nenolod
parents: 0
diff changeset
102 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 xmms_formatter_format(Formatter * formatter, char *format)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 char *p, *q, *buffer;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 int len;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 for (p = format, len = 0; *p; p++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 if (*p == '%') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 if (formatter->values[(int) *++p])
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 len += strlen(formatter->values[(int) *p]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 else if (!*p) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 len += 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 p--;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 len += 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 len++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 buffer = g_malloc(len + 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 for (p = format, q = buffer; *p; p++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 if (*p == '%') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 if (formatter->values[(int) *++p]) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 strcpy(q, formatter->values[(int) *p]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 q += strlen(q);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 *q++ = '%';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 if (*p != '\0')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 *q++ = *p;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 p--;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 *q++ = *p;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 *q = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 return buffer;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 }