root/libswish3/trunk/src/libswish3/property.c

Revision 2110, 1.9 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_Property *
25 swish_init_property(
26     xmlChar *name
27 )
28 {
29     swish_Property *p;
30     p = swish_xmalloc(sizeof(swish_Property));
31     p->ref_cnt = 0;
32     p->id = -1;
33     p->name = name;
34     p->ignore_case = 1;
35     p->type = SWISH_PROP_STRING;
36     p->verbatim = 0;
37     p->alias_for = NULL;
38     p->max = 0;
39     p->sort = 0;
40     return p;
41 }
42
43 void
44 swish_debug_property(
45     swish_Property *p
46 )
47 {
48     SWISH_DEBUG_MSG("\n\
49     p->ref_cnt       = %d\n\
50     p->id            = %d\n\
51     p->name          = %s\n\
52     p->ignore_case   = %d\n\
53     p->type          = %d\n\
54     p->verbatim      = %d\n\
55     p->alias_for     = %s\n\
56     p->max           = %d\n\
57     p->sort          = %d\n\
58     ", p->ref_cnt, p->id, p->name, p->ignore_case, p->type, p->verbatim, p->alias_for, p->max, p->sort);
59 }
60
61 void
62 swish_free_property(
63     swish_Property *p
64 )
65 {
66     if (p->ref_cnt != 0) {
67         SWISH_WARN("Property ref_cnt != 0: %d", p->ref_cnt);
68     }
69
70     if (p->name != NULL) {
71         swish_xfree(p->name);
72     }
73     if (p->alias_for != NULL) {
74         swish_xfree(p->alias_for);
75     }
76
77     swish_xfree(p);
78 }
Note: See TracBrowser for help on using the browser.