summaryrefslogtreecommitdiffstats
path: root/plug-ins/imagemap/imap_taglist.c
blob: 9b03c9d094950c6c2939964f6b01098cfde86b39 (plain)
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
/*
 * This is a plug-in for GIMP.
 *
 * Generates clickable image maps.
 *
 * Copyright (C) 1998-1999 Maurits Rijk  lpeek.mrijk@consunet.nl
 *
 * 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 3 of the License, or
 * (at your option) 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, see <https://www.gnu.org/licenses/>.
 *
 */

#include "config.h"

#include <stdio.h>

#include <glib.h>

#include "imap_string.h"
#include "imap_taglist.h"

static Tag_t*
tag_create(const gchar *name, const gchar *value)
{
   Tag_t *tag = g_new(Tag_t, 1);
   tag->name = g_strdup(name);
   tag->value = g_strdup(value);
   return tag;
}

static Tag_t*
tag_clone(Tag_t *src)
{
   return tag_create(src->name, src->value);
}

static void
tag_destruct(Tag_t *tag)
{
   g_free(tag->name);
   g_free(tag->value);
   g_free(tag);
}

static void
tag_write(Tag_t *tag)
{
   printf("\"%s\"=\"%s\"\n", tag->name, tag->value);
}

TagList_t*
taglist_create(void)
{
   TagList_t *tlist = g_new(TagList_t, 1);
   tlist->list = NULL;
   return tlist;
}

TagList_t*
taglist_clone(TagList_t *src)
{
   return taglist_copy(src, taglist_create());
}

static void
taglist_remove_all(TagList_t *tlist)
{
   GList *p;
   for (p = tlist->list; p; p = p->next)
      tag_destruct((Tag_t*) p->data);
   g_list_free(tlist->list);
   tlist->list = NULL;
}

TagList_t*
taglist_copy(TagList_t *src, TagList_t *des)
{
   GList *p;

   taglist_remove_all(des);
   for (p = src->list; p; p = p->next)
      des->list = g_list_append(des->list, tag_clone((Tag_t*) p->data));
   return des;
}

void
taglist_destruct(TagList_t *tlist)
{
   taglist_remove_all(tlist);
   g_free(tlist);
}

void
taglist_set(TagList_t *tlist, const gchar *name, const gchar *value)
{
   GList *p;
   Tag_t *tag;

   for (p = tlist->list; p; p = p->next) {
      tag = (Tag_t*) p->data;
      if (!g_ascii_strcasecmp(tag->name, name)) {
         g_strreplace(&tag->value, value);
         return;
      }
   }
   /* Tag not found, add a new tag */
   tlist->list = g_list_append(tlist->list, tag_create(name, value));
}

void
taglist_write(TagList_t *tlist)
{
   GList *p;
   for (p = tlist->list; p; p = p->next)
      tag_write((Tag_t*) p->data);
}