1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
/* Cataract - Static web photo gallery generator
* Copyright (C) 2008 Tomas Bzatek <tbzatek@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include <unistd.h>
#include <glib.h>
#include "generators-replace-table.h"
#include "gallery-utils.h"
static void
replace_table_destroy_notify (gpointer data)
{
g_print ("replace_table_destroy_notify: %s\n", (gchar *) data);
if ((gchar *) data)
g_free ((gchar *) data);
}
ReplaceTable *
replace_table_new ()
{
return (ReplaceTable *) g_hash_table_new_full (g_str_hash, g_str_equal, replace_table_destroy_notify, replace_table_destroy_notify);
}
void
replace_table_free (ReplaceTable *table)
{
g_return_if_fail (table != NULL);
g_hash_table_destroy (table);
}
/*
* replace_table_add_key: add tag/value pair to replace
*
* tag, value will be referenced inside
*
*/
void
replace_table_add_key (ReplaceTable *table, const gchar *tag, const gchar *value)
{
g_return_if_fail (table != NULL);
if (tag != NULL && value != NULL)
g_hash_table_replace (table, g_strdup (tag), g_strdup (value));
}
void
replace_table_add_key_int (ReplaceTable *table, const gchar *tag, gint value)
{
g_return_if_fail (table != NULL);
if (tag != NULL)
g_hash_table_replace (table, g_strdup (tag), g_strdup_printf ("%d", value));
}
static void
replace_table_process_value (gpointer key, gpointer value, gpointer user_data)
{
gchar **buffer = user_data;
gchar *tag;
gchar *tag_value;
g_return_if_fail (key != NULL);
g_return_if_fail (value != NULL);
g_return_if_fail (user_data != NULL);
// g_print ("replace_table_print: key = '%s', value = '%s'\n", (gchar *) key, (gchar *) value);
/* replace <!-- $(xxx) --> tags */
tag = g_strdup_printf ("<!-- $(%s) -->", (gchar *) key);
tag_value = g_strdup ((gchar *) value);
/* TODO: do something with tag_value? */
/* fix_entities (&s1); */
/* s1 = g_markup_escape_text (s4, -1); */
while (strstr (*buffer, tag)) {
str_replace (buffer, tag, tag_value, NULL);
}
g_free (tag_value);
g_free (tag);
/* replace $(xxx) tags */
tag = g_strdup_printf ("$(%s)", (gchar *) key);
tag_value = g_strdup ((gchar *) value);
/* TODO: do something with tag_value? */
/* fix_entities (&s1); */
/* s1 = g_markup_escape_text (s4, -1); */
/* remove all tags as we're tag value */
while (strstr (*buffer, tag)) {
str_replace (buffer, tag, tag_value, NULL);
}
g_free (tag_value);
g_free (tag);
}
/*
* replace_table_process: process buffer and replace all tags filled in the replace table
*
* - reallocates source buffer
*
*/
void
replace_table_process (gchar **buffer, ReplaceTable *table)
{
g_return_if_fail (table != NULL);
g_hash_table_foreach (table, replace_table_process_value, buffer);
/*
gchar *val = g_hash_table_lookup (table, "TAG");
g_print ("replace_table_process: val = '%s'\n", val);
*/
}
|