]>
jfr.im git - irc/evilnet/x3.git/blob - src/recdb.h
1 /* recdb.h - recursive/record database implementation
2 * Copyright 2000-2004 srvx Development Team
4 * This file is part of x3.
6 * x3 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with srvx; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
39 struct string_list
*slist
;
44 #define SET_RECORD_QSTRING(rec, qs) do { const char *s = (qs); (rec)->type = RECDB_QSTRING; (rec)->d.qstring = (s) ? strdup(s) : NULL; } while (0)
45 #define GET_RECORD_QSTRING(rec) (((rec)->type == RECDB_QSTRING) ? (rec)->d.qstring : 0)
46 #define SET_RECORD_OBJECT(rec, obj) do { (rec)->type = RECDB_OBJECT; (rec)->d.object = (obj); } while (0)
47 #define GET_RECORD_OBJECT(rec) (((rec)->type == RECDB_OBJECT) ? (rec)->d.object : 0)
48 #define SET_RECORD_STRING_LIST(rec, sl) do { (rec)->type = RECDB_STRING_LIST; (rec)->d.slist = (sl); } while (0)
49 #define GET_RECORD_STRING_LIST(rec) (((rec)->type == RECDB_STRING_LIST) ? (rec)->d.slist : 0)
52 unsigned int used
, size
;
55 void string_list_append(struct string_list
*slist
, char *string
);
56 struct string_list
*string_list_copy(struct string_list
*orig
);
57 void string_list_sort(struct string_list
*slist
);
58 #define string_list_delete(slist, n) (free((slist)->list[n]), (slist)->list[n] = (slist)->list[--(slist)->used])
60 /* allocation functions */
61 struct string_list
*alloc_string_list(int size
);
62 struct record_data
*alloc_record_data_qstring(const char *string
);
63 struct record_data
*alloc_record_data_object(dict_t obj
);
64 struct record_data
*alloc_record_data_string_list(struct string_list
*slist
);
65 dict_t
alloc_database(void);
66 #define alloc_object() alloc_database()
69 /* note: once you give a string list a string, it frees it automatically */
70 struct record_data
*database_get_path(dict_t db
, const char *path
);
71 void *database_get_data(dict_t db
, const char *path
, enum recdb_type type
);
74 void free_string_list(struct string_list
*slist
);
75 void free_record_data(void *rdata
);
76 #define free_object(obj) dict_delete(obj)
77 #define free_database(db) dict_delete(db)
79 /* parsing stuff from disk */
80 const char *parse_record(const char *text
, char **pname
, struct record_data
**prd
);
81 dict_t
parse_database(const char *filename
);