source: set.h @ d5ccd83

Last change on this file since d5ccd83 was d5ccd83, checked in by Wilmer van der Gaast <wilmer@…>, at 2006-08-13T19:15:23Z

Extra comments in set.h and now properly using set_getbool() instead of
set_getint().

  • Property mode set to 100644
File size: 3.8 KB
RevLine 
[b7d3cc34]1  /********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
[5c9512f]4  * Copyright 2002-2006 Wilmer van der Gaast and others                *
[b7d3cc34]5  \********************************************************************/
6
7/* Some stuff to register, handle and save user preferences             */
8
9/*
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License with
21  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
22  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23  Suite 330, Boston, MA  02111-1307  USA
24*/
25
[d5ccd83]26/* This used to be specific to irc_t structures, but it's more generic now
27   (so it can also be used for account_t structs). It's pretty simple, but
28   so far pretty useful.
29   
30   In short, it just keeps a linked list of settings/variables and it also
31   remembers a default value for every setting. And to prevent the user
32   from setting invalid values, you can write an evaluator function for
33   every setting, which can check a new value and block it by returning
34   NULL, or replace it by returning a new value. See struct set.eval. */
35
[b7d3cc34]36typedef struct set
37{
[d5ccd83]38        void *data;     /* Here you can save a pointer to the
39                           object this settings belongs to. */
[5c9512f]40       
[b7d3cc34]41        char *key;
42        char *value;
[d5ccd83]43        char *def;      /* Default value. If the set_setstr() function
44                           notices a new value is exactly the same as
45                           the default, value gets set to NULL. So when
46                           you read a setting, don't forget about this! */
[b7d3cc34]47       
[d5ccd83]48        int flags;      /* See account.h, for example. set.c doesn't use
49                           this (yet?). */
[5100caa]50       
[5c9512f]51        /* Eval: Returns NULL if the value is incorrect or exactly the
52           passed value variable. When returning a corrected value,
53           set_setstr() should be able to free() the returned string! */
54        char *(*eval) ( struct set *set, char *value );
[b7d3cc34]55        struct set *next;
56} set_t;
57
[d5ccd83]58/* Should be pretty clear. */
[5c9512f]59set_t *set_add( set_t **head, char *key, char *def, void *eval, void *data );
[d5ccd83]60
61/* Returns the raw set_t. Might be useful sometimes. */
[5100caa]62set_t *set_find( set_t **head, char *key );
[d5ccd83]63
64/* Returns a pointer to the string value of this setting. Don't modify the
65   returned string, and don't free() it! */
[5c9512f]66G_MODULE_EXPORT char *set_getstr( set_t **head, char *key );
[d5ccd83]67
68/* Get an integer. Right now this also converts true/false/on/off/etc to
69   numbers, but this is for historical reasons, please use set_getbool()
70   for booleans instead. */
[5c9512f]71G_MODULE_EXPORT int set_getint( set_t **head, char *key );
[fef6116]72G_MODULE_EXPORT int set_getbool( set_t **head, char *key );
[d5ccd83]73
74/* set_setstr() strdup()s the given value, so after using this function
75   you can free() it, if you want. */
[5c9512f]76int set_setstr( set_t **head, char *key, char *value );
77int set_setint( set_t **head, char *key, int value );
78void set_del( set_t **head, char *key );
[b7d3cc34]79
[d5ccd83]80/* Two very useful generic evaluators. */
[5c9512f]81char *set_eval_int( set_t *set, char *value );
82char *set_eval_bool( set_t *set, char *value );
[1719464]83
[d5ccd83]84/* Some not very generic evaluators that really shouldn't be here... */
[5c9512f]85char *set_eval_to_char( set_t *set, char *value );
86char *set_eval_ops( set_t *set, char *value );
87char *set_eval_charset( set_t *set, char *value );
Note: See TracBrowser for help on using the repository browser.