2002-03-20 23:21:22 +00:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002
|
|
|
|
* Antti Tapaninen <aet@cc.hut.fi>
|
|
|
|
*
|
|
|
|
* Originally based on source by Timo Sirainen <tss@iki.fi>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SC_CONF_H
|
|
|
|
#define _SC_CONF_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct _scconf_block scconf_block;
|
|
|
|
|
|
|
|
typedef struct _scconf_list {
|
|
|
|
struct _scconf_list *next;
|
|
|
|
char *data;
|
|
|
|
} scconf_list;
|
|
|
|
|
|
|
|
#define SCCONF_ITEM_TYPE_COMMENT 0 /* key = NULL, data = char *comment */
|
|
|
|
#define SCCONF_ITEM_TYPE_BLOCK 1 /* key = class, data = scconf_block */
|
|
|
|
#define SCCONF_ITEM_TYPE_VALUE 2 /* key = key, value = scconf_list */
|
|
|
|
|
|
|
|
typedef struct _scconf_item {
|
|
|
|
struct _scconf_item *next;
|
|
|
|
int type;
|
|
|
|
char *key;
|
|
|
|
union {
|
|
|
|
char *comment;
|
|
|
|
scconf_block *block;
|
|
|
|
scconf_list *list;
|
|
|
|
} value;
|
|
|
|
} scconf_item;
|
|
|
|
|
|
|
|
struct _scconf_block {
|
|
|
|
scconf_block *parent;
|
|
|
|
scconf_list *name;
|
|
|
|
scconf_item *items;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char *filename;
|
|
|
|
scconf_block *root;
|
|
|
|
} scconf_context;
|
|
|
|
|
2002-03-25 20:10:44 +00:00
|
|
|
/* Init configuration
|
|
|
|
* The filename can be NULL
|
|
|
|
*/
|
2002-03-20 23:21:22 +00:00
|
|
|
extern scconf_context *scconf_init(const char *filename);
|
2002-03-25 20:10:44 +00:00
|
|
|
|
|
|
|
/* Free configuration
|
|
|
|
*/
|
2002-03-20 23:21:22 +00:00
|
|
|
extern void scconf_deinit(scconf_context * config);
|
|
|
|
|
2002-03-25 20:10:44 +00:00
|
|
|
/* Parse configuration
|
|
|
|
* Returns 1 = ok, 0 = error, -1 = error opening config file
|
|
|
|
*/
|
2002-03-20 23:21:22 +00:00
|
|
|
extern int scconf_parse(scconf_context * config);
|
|
|
|
|
2002-03-25 20:10:44 +00:00
|
|
|
/* Write config to a file
|
|
|
|
* If the filename is NULL, use the config->filename
|
2002-03-20 23:21:22 +00:00
|
|
|
* Returns 0 = ok, else = errno
|
|
|
|
*/
|
|
|
|
extern int scconf_write(scconf_context * config, const char *filename);
|
|
|
|
|
2002-03-25 20:10:44 +00:00
|
|
|
/* Find a config by the item_name
|
|
|
|
* If the block is NULL, the root block is used
|
|
|
|
*/
|
|
|
|
extern const scconf_block *scconf_find_block(scconf_context * config, const scconf_block * block, const char *item_name);
|
|
|
|
|
|
|
|
/* Find a config by the item_name
|
|
|
|
* If the block is NULL, the root block is used
|
|
|
|
* The key can be used to specify what the blocks first name should be.
|
|
|
|
*/
|
|
|
|
extern scconf_block **scconf_find_blocks(scconf_context * config, const scconf_block * block, const char *item_name, const char *key);
|
|
|
|
|
|
|
|
/* Get a list of values for option
|
|
|
|
*/
|
|
|
|
extern const scconf_list *scconf_find_value(const scconf_block * block, const char *option);
|
2002-03-20 23:21:22 +00:00
|
|
|
|
2002-03-25 20:10:44 +00:00
|
|
|
/* Return the first value of the option
|
|
|
|
*/
|
|
|
|
extern const char *scconf_find_value_first(const scconf_block * block, const char *option);
|
2002-03-20 23:21:22 +00:00
|
|
|
|
2002-03-25 20:10:44 +00:00
|
|
|
/* Free list structure
|
|
|
|
*/
|
2002-03-20 23:21:22 +00:00
|
|
|
extern void scconf_list_destroy(scconf_list * list);
|
2002-03-25 20:10:44 +00:00
|
|
|
|
|
|
|
/* Free block structure
|
|
|
|
*/
|
2002-03-20 23:21:22 +00:00
|
|
|
extern void scconf_block_destroy(scconf_block * block);
|
|
|
|
|
2002-03-25 20:10:44 +00:00
|
|
|
/* Return the length of an list array
|
|
|
|
*/
|
|
|
|
extern int scconf_list_array_length(const scconf_list * list);
|
2002-03-20 23:21:22 +00:00
|
|
|
|
2002-03-25 20:10:44 +00:00
|
|
|
/* Return the combined length of the strings on all arrays
|
|
|
|
*/
|
|
|
|
extern int scconf_list_strings_length(const scconf_list * list);
|
2002-03-20 23:21:22 +00:00
|
|
|
|
2002-03-25 20:10:44 +00:00
|
|
|
/* Return an allocated string that contains all
|
|
|
|
* the strings in a list separated by the filler
|
|
|
|
*/
|
|
|
|
extern char *scconf_list_strdup(const scconf_list * list, const char *filler);
|
2002-03-20 23:21:22 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|