summaryrefslogtreecommitdiff
path: root/src/lib-config/iconfig.h
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2000-04-14 11:27:14 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2000-04-14 11:27:14 +0000
commit53b248f6deafb553aae133792659a8412bc00925 (patch)
tree0c7287dfd3921308073463f4feca46a2c8e1acf6 /src/lib-config/iconfig.h
parent5fb98c2210033df3b6bdb4cdd6af77e7c32f6714 (diff)
downloadirssi-53b248f6deafb553aae133792659a8412bc00925.zip
Sorry for a big update - I still don't have internet connection at home
and this is what I've been doing a few weeks now.. :) You really shouldn't upgrade to this version without keeping a backup of the working one, since this will break everything and at least notify list is broken - probably something else too. * On the way to 0.8.0 .. Major rewriting/rearranging code. There's some changes in behaviour because I'm trying to make Irssi a bit more compatible with EPIC. * libPropList isn't needed anymore - I'm using my own configuration library. This is mostly because different proplists worked a bit differently everywhere and several people had problems with it. It's also yet another extra library that you needed to compile Irssi. New configuration library has several advantages: You can add comments to configuration file and they also stay there when it's saved. It's not nearly as vulnerable as proplist. If some error occurs, instead of just not reading anything it will try to continue if possible. Also the error messages are written to irssi's text window instead of stdout. It can be managed more easily than proplist - setting/getting the configuration is a lot more easier. * Coding style changes - I'm not using gint, gchar etc. anymore, they're just extra pain when moving code to non-glib projects and syntax hilighting doesn't work by default with most editors ;) Indentation style was also changed to K&R because of some political reasons ;) And I'm already starting to like it.. :) It forces me to split code to different functions more often and the result is that the code gets more readable. And finally I'm also using nst' all over the place. + /EVAL <commands> - Expand all the special variables from string and run it. Commands can be split with ; character. See docs/SPECIAL_VARS for more info. + Aliases are parsed just like /EVAL - arguments are in $0..$9. + Text formats are also parsed like /EVAL, arguments used to be in $1..$9, now they're in $0..$8 so it messes up existing themes.. + /SET [key [value]] - no more the '=' character. Boolean values also need to be changed with ON/OFF/TOGGLE values (not yes/no). Settings aren't saved to disk until you use /SAVE. + /TOGGLE <key> [ON/OFF] - same as /SET <key> TOGGLE git-svn-id: http://svn.irssi.org/repos/irssi/trunk@163 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/lib-config/iconfig.h')
-rw-r--r--src/lib-config/iconfig.h136
1 files changed, 136 insertions, 0 deletions
diff --git a/src/lib-config/iconfig.h b/src/lib-config/iconfig.h
new file mode 100644
index 00000000..bbee0f6e
--- /dev/null
+++ b/src/lib-config/iconfig.h
@@ -0,0 +1,136 @@
+#ifndef __ICONFIG_H
+#define __ICONFIG_H
+
+enum {
+ NODE_TYPE_KEY,
+ NODE_TYPE_VALUE,
+ NODE_TYPE_BLOCK,
+ NODE_TYPE_LIST,
+ NODE_TYPE_COMMENT,
+};
+
+#define has_node_value(a) \
+ ((a)->type == NODE_TYPE_KEY || (a)->type == NODE_TYPE_VALUE)
+#define is_node_list(a) \
+ ((a)->type == NODE_TYPE_BLOCK || (a)->type == NODE_TYPE_LIST)
+
+typedef struct {
+ int type;
+ char *key;
+ void *value;
+} CONFIG_NODE;
+
+/* a = { x=y; y=z; }
+
+ node1: type = NODE_TYPE_BLOCK, key = "a", value = (GSList *) nodes
+ nodes: (node2, node3)
+ node2: type = NODE_TYPE_KEY, key = "x", value = (char *) "y"
+ node3: type = NODE_TYPE_KEY, key = "y", value = (char *) "z"
+
+ b = ( a, { b=c; d=e; } )
+
+ node1: type = NODE_TYPE_LIST, key = "b", value = (GSList *) nodes
+ nodes: (node2, node3)
+ node2: type = NODE_TYPE_VALUE, key = NULL, value = (char *) "a"
+ node4: type = NODE_TYPE_BLOCK, key = NULL, value = (GSList *) nodes2
+ nodes2: (node4, node5)
+ node4: type = NODE_TYPE_KEY, key = "b", value = (char *) "c"
+ node5: type = NODE_TYPE_KEY, key = "d", value = (char *) "e"
+
+ Comments node has key=NULL and value is the comment line. Empty lines are
+ also in comments so they won't be forgotten when the config file is
+ written.
+
+*/
+
+struct _config_rec {
+ char *fname;
+ int handle;
+ int create_mode;
+
+ char *last_error;
+ CONFIG_NODE *mainnode;
+ GHashTable *cache;
+
+ GScanner *scanner;
+
+ /* while writing to configuration file.. */
+ int tmp_indent_level; /* indentation position */
+ int tmp_last_lf; /* last character was a line feed */
+};
+
+typedef struct _config_rec CONFIG_REC;
+
+/* Open configuration. The file is created if it doesn't exist, unless
+ `create_mode' is -1. `fname' can be NULL if you just want to use
+ config_parse_data() */
+CONFIG_REC *config_open(const char *fname, int create_mode);
+/* Release all memory used by configuration */
+void config_close(CONFIG_REC *rec);
+/* Change file name of config file */
+void config_change_file_name(CONFIG_REC *rec, const char *fname, int create_mode);
+
+/* Parse configuration file */
+int config_parse(CONFIG_REC *rec);
+/* Parse configuration found from `data'. `input_name' is specifies the
+ "configuration name" which is displayed in error messages. */
+int config_parse_data(CONFIG_REC *rec, const char *data, const char *input_name);
+
+/* Write configuration file. Write to `fname' if it's not NULL.
+ If `create_mode' is -1, use the one that was given to config_open(). */
+int config_write(CONFIG_REC *rec, const char *fname, int create_mode);
+
+#define config_last_error(rec) \
+ (rec)->last_error
+
+/* Getting values
+
+ `section' is something like "maingroup/key/subkey", or with lists
+ "maingroup/(list/subkey"
+
+ `def' is returned if the value is not found. */
+char *config_get_str(CONFIG_REC *rec, const char *section, const char *key, const char *def);
+int config_get_int(CONFIG_REC *rec, const char *section, const char *key, int def);
+int config_get_bool(CONFIG_REC *rec, const char *section, const char *key, int def);
+
+/* Return value of key `value_key' from list item where `key' is `value' */
+const char *config_list_find(CONFIG_REC *rec, const char *section, const char *key, const char *value, const char *value_key);
+/* Like config_list_find(), but return node instead of it's value */
+CONFIG_NODE *config_list_find_node(CONFIG_REC *rec, const char *section, const char *key, const char *value, const char *value_key);
+
+/* Setting values */
+int config_set_str(CONFIG_REC *rec, const char *section, const char *key, const char *value);
+int config_set_int(CONFIG_REC *rec, const char *section, const char *key, int value);
+int config_set_bool(CONFIG_REC *rec, const char *section, const char *key, int value);
+
+/* Handling the configuration directly with nodes -
+ useful when you need to read all values in a block/list. */
+CONFIG_NODE *config_node_find(CONFIG_NODE *node, const char *key);
+/* Find the section from node - if not found create it unless new_type is -1.
+ You can also specify in new_type if it's NODE_TYPE_LIST or NODE_TYPE_BLOCK */
+CONFIG_NODE *config_node_section(CONFIG_REC *rec, CONFIG_NODE *parent, const char *key, int new_type);
+/* Find the section with the whole path.
+ Create the path if necessary `create' is TRUE. */
+CONFIG_NODE *config_node_traverse(CONFIG_REC *rec, const char *section, int create);
+/* Get the value of keys `key' and `key_value' and put them to
+ `ret_key' and `ret_value'. Returns -1 if not found. */
+int config_node_get_keyvalue(CONFIG_NODE *node, const char *key, const char *value_key, char **ret_key, char **ret_value);
+
+char *config_node_get_str(CONFIG_NODE *parent, const char *key, const char *def);
+int config_node_get_int(CONFIG_NODE *parent, const char *key, int def);
+int config_node_get_bool(CONFIG_NODE *parent, const char *key, int def);
+
+void config_node_set_str(CONFIG_NODE *parent, const char *key, const char *value);
+void config_node_set_int(CONFIG_NODE *parent, const char *key, int value);
+void config_node_set_bool(CONFIG_NODE *parent, const char *key, int value);
+
+/* add/change the value of the `key' */
+void config_node_set_str(CONFIG_NODE *parent, const char *key, const char *value);
+/* remove one node from block/list.
+ ..set_str() with value = NULL does the same. */
+void config_node_remove(CONFIG_NODE *parent, CONFIG_NODE *node);
+
+/* clear the entire configuration */
+void config_nodes_remove_all(CONFIG_REC *rec);
+
+#endif