Changeset d5ccd83 for set.h


Ignore:
Timestamp:
2006-08-13T19:15:23Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
08cdb93
Parents:
846cec61
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • set.h

    r846cec61 rd5ccd83  
    2424*/
    2525
     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
    2636typedef struct set
    2737{
    28         void *data;
     38        void *data;     /* Here you can save a pointer to the
     39                           object this settings belongs to. */
    2940       
    3041        char *key;
    3142        char *value;
    32         char *def;      /* Default */
     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! */
    3347       
    34         int flags;
     48        int flags;      /* See account.h, for example. set.c doesn't use
     49                           this (yet?). */
    3550       
    3651        /* Eval: Returns NULL if the value is incorrect or exactly the
     
    4156} set_t;
    4257
     58/* Should be pretty clear. */
    4359set_t *set_add( set_t **head, char *key, char *def, void *eval, void *data );
     60
     61/* Returns the raw set_t. Might be useful sometimes. */
    4462set_t *set_find( set_t **head, char *key );
     63
     64/* Returns a pointer to the string value of this setting. Don't modify the
     65   returned string, and don't free() it! */
    4566G_MODULE_EXPORT char *set_getstr( set_t **head, char *key );
     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. */
    4671G_MODULE_EXPORT int set_getint( set_t **head, char *key );
    4772G_MODULE_EXPORT int set_getbool( set_t **head, char *key );
     73
     74/* set_setstr() strdup()s the given value, so after using this function
     75   you can free() it, if you want. */
    4876int set_setstr( set_t **head, char *key, char *value );
    4977int set_setint( set_t **head, char *key, int value );
    5078void set_del( set_t **head, char *key );
    5179
     80/* Two very useful generic evaluators. */
    5281char *set_eval_int( set_t *set, char *value );
    5382char *set_eval_bool( set_t *set, char *value );
    5483
     84/* Some not very generic evaluators that really shouldn't be here... */
    5585char *set_eval_to_char( set_t *set, char *value );
    5686char *set_eval_ops( set_t *set, char *value );
Note: See TracChangeset for help on using the changeset viewer.