summaryrefslogtreecommitdiff
path: root/generators-replace-table.c
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2009-02-26 22:50:39 +0100
committerTomas Bzatek <tbzatek@users.sourceforge.net>2009-02-26 22:50:39 +0100
commit89c58dc04c264c5778ae34d1428e12483f3ac5ac (patch)
treed5aef506841b3b0e2e91016d0c0bbb608535873c /generators-replace-table.c
parent10a77c7a1c4648693ded958d6ac8641afcdf1d34 (diff)
downloadcataract-89c58dc04c264c5778ae34d1428e12483f3ac5ac.tar.xz
Autotoolize
Diffstat (limited to 'generators-replace-table.c')
-rw-r--r--generators-replace-table.c174
1 files changed, 0 insertions, 174 deletions
diff --git a/generators-replace-table.c b/generators-replace-table.c
deleted file mode 100644
index 23771fc..0000000
--- a/generators-replace-table.c
+++ /dev/null
@@ -1,174 +0,0 @@
-/* Cataract - Static web photo gallery generator
- * Copyright (C) 2009 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 <glib/gprintf.h>
-
-#include "generators-replace-table.h"
-#include "gallery-utils.h"
-
-
-
-
-#if 0
-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);
-}
-#endif
-
-ReplaceTable *
-replace_table_new ()
-{
- return (ReplaceTable *) g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
-}
-
-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));
-}
-
-void
-replace_table_add_key_printf (ReplaceTable *table, const gchar *tag, const gchar *format, ...)
-{
- va_list args;
- gchar *s = NULL;
-
- g_return_if_fail (table != NULL);
-
- if (tag != NULL && format != NULL) {
- va_start (args, format);
- g_vasprintf (&s, format, args);
- g_hash_table_replace (table, g_strdup (tag), s);
- va_end (args);
- }
-}
-
-
-
-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);
-
- /* replace <!-- $(xxx) --> tags */
- tag = g_strdup_printf ("<!-- $(%s) -->", (gchar *) key);
- tag_value = g_strdup ((gchar *) value);
- adjust_tags_normal (&tag_value);
- while (strstr (*buffer, tag)) {
- str_replace (buffer, tag, tag_value);
- }
- g_free (tag_value);
- g_free (tag);
-
- /* replace $(xxx) tags */
- tag = g_strdup_printf ("$(%s)", (gchar *) key);
- tag_value = g_strdup ((gchar *) value);
- adjust_tags_parameter (&tag_value);
- while (strstr (*buffer, tag)) {
- str_replace (buffer, tag, tag_value);
- }
- 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);
-*/
-}
-
-
-/*
- * adjust_tags_normal: adjust string for normal HTML use
- * adjust_tags_parameter: adjust string for use as tag parameter value
- * - both funtions return newly allocated string
- */
-void
-adjust_tags_normal (char **str)
-{
- fix_entities (str);
-}
-
-void
-adjust_tags_parameter (char **str)
-{
- /* TODO: replace line endings with single space? */
- remove_tags (str, "<!--", "-->"); /* comments */
- remove_tags (str, "<", ">"); /* tags */
- fix_entities (str); /* entities */
- str_replace (str, "\"", "&quot;"); /* " */
- str_replace (str, "'", "&apos;"); /* ' */
-}