root/libswish3/trunk/src/libswish3/metaname.c

Revision 2110, 1.6 kB (checked in by karpet, 8 months ago)

Refactor duplicate id checks to use hash instead of array. Fixes bug with merging configs. Default ->id is now -1 (invalid value)

Line 
1 /*
2  * This file is part of libswish3
3  * Copyright (C) 2008 Peter Karman
4  *
5  *  libswish3 is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  libswish3 is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with libswish3; if not, write to the Free Software
17  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20 #include "libswish3.h"
21
22 extern int SWISH_DEBUG;
23
24 swish_MetaName *
25 swish_init_metaname(
26     xmlChar *name
27 )
28 {
29     swish_MetaName *m;
30     m = swish_xmalloc(sizeof(swish_MetaName));
31     m->ref_cnt = 0;
32     m->id = -1;
33     m->name = name;
34     m->bias = 0;
35     m->alias_for = NULL;
36     return m;
37 }
38
39 void
40 swish_debug_metaname(
41     swish_MetaName *m
42 )
43 {
44     SWISH_DEBUG_MSG("\n\
45     m->ref_cnt      = %d\n\
46     m->id           = %d\n\
47     m->name         = %s\n\
48     m->bias         = %d\n\
49     m->alias_for    = %s\n\
50     ", m->ref_cnt, m->id, m->name, m->bias, m->alias_for);
51 }
52
53 void
54 swish_free_metaname(
55     swish_MetaName *m
56 )
57 {
58     if (m->ref_cnt != 0) {
59         SWISH_WARN("MetaName ref_cnt != 0: %d", m->ref_cnt);
60     }
61
62     if (m->name != NULL) {
63         swish_xfree(m->name);
64     }
65     if (m->alias_for != NULL) {
66         swish_xfree(m->alias_for);
67     }
68
69     swish_xfree(m);
70 }
Note: See TracBrowser for help on using the browser.