3 Extension module for the rfxswf library.
4 Part of the swftools package.
6 Copyright (c) 2008 Matthias Kramm <kramm@quiss.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
28 dict_t*d = malloc(sizeof(dict_t));
29 memset(d, 0, sizeof(dict_t));
33 void dict_free(dict_t*dict) {
35 free(dict->d);dict->d = 0;
39 const char*dict_getstr(dict_t*dict, int nr) {
40 if(nr > dict->num || nr<0) {
41 printf("error: reference to string %d in dict\n");
44 return dict->d[nr].name;
46 char*dict_getdata(dict_t*dict, int nr) {
47 if(nr > dict->num || nr<0) {
48 printf("error: reference to string %d in dict\n");
51 return dict->d[nr].data;
53 int dict_append(dict_t*dict, const char*name, void*data) {
54 while(dict->size <= dict->num) {
57 dict->d = malloc(sizeof(dict_entry_t)*dict->size);
59 dict->d = realloc(dict->d, sizeof(dict_entry_t)*dict->size);
63 dict->d[dict->num].name = strdup(name);
65 dict->d[dict->num].name = 0;
67 dict->d[dict->num].data = data;
70 int dict_find(dict_t*dict, const char*name)
75 for(t=0;t<dict->num;t++) {
76 if(dict->d[t].name && !strcmp(dict->d[t].name,name))
81 int dict_find2(dict_t*dict, const char*name, void*data)
86 for(t=0;t<dict->num;t++) {
87 if(dict->d[t].name && !strcmp(dict->d[t].name,name) && dict->d[t].data == data)
92 int dict_update(dict_t*dict, const char*name, void*data) {
93 int pos = dict_find(dict, name);
95 dict->d[pos].data = data;
98 return dict_append(dict, name, data);
100 int dict_append_if_new(dict_t*dict, const char*name, void*data) {
101 int pos = dict_find(dict, name);
104 return dict_append(dict, name, data);
106 int dict_append_if_new2(dict_t*dict, const char*name, void*data) {
107 int pos = dict_find2(dict, name, data);
110 return dict_append(dict, name, data);
113 typedef struct _commonlist {
115 struct _commonlist*next;
116 struct _commonlist*last[0];
119 int list_length(void*_list)
121 commonlist_t*l = (commonlist_t*)_list;
129 void list_append(void*_list, void*entry)
131 commonlist_t**list = (commonlist_t**)_list;
134 n = malloc(sizeof(commonlist_t)+sizeof(commonlist_t*));
137 n = malloc(sizeof(commonlist_t));
138 (*list)->last[0]->next = n;
142 (*list)->last[0] = n;