Changeset 69cb623 for set.h


Ignore:
Timestamp:
2006-10-15T09:41:12Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
2529faf
Parents:
695e392 (diff), e97827b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merging with storage-xml. It seems to be working pretty well, so maybe
this way more people will test it. :-)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • set.h

    r695e392 r69cb623  
    22  * BitlBee -- An IRC to other IM-networks gateway                     *
    33  *                                                                    *
    4   * Copyright 2002-2004 Wilmer van der Gaast and others                *
     4  * Copyright 2002-2006 Wilmer van der Gaast and others                *
    55  \********************************************************************/
    66
     
    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
     36typedef char *(*set_eval) ( struct set *set, char *value );
     37
    2638typedef struct set
    2739{
     40        void *data;     /* Here you can save a pointer to the
     41                           object this settings belongs to. */
     42       
    2843        char *key;
    2944        char *value;
    30         char *def;      /* Default */
     45        char *def;      /* Default value. If the set_setstr() function
     46                           notices a new value is exactly the same as
     47                           the default, value gets set to NULL. So when
     48                           you read a setting, don't forget about this! */
    3149       
    32         /* Eval: Returns NULL if the value is incorrect. Can return a
    33            corrected value. set_setstr() should be able to free() the
    34            returned string! */
    35         char *(*eval) ( irc_t *irc, struct set *set, char *value );
     50        int flags;      /* See account.h, for example. set.c doesn't use
     51                           this (yet?). */
     52       
     53        /* Eval: Returns NULL if the value is incorrect or exactly the
     54           passed value variable. When returning a corrected value,
     55           set_setstr() should be able to free() the returned string! */
     56        set_eval eval;
    3657        struct set *next;
    3758} set_t;
    3859
    39 set_t *set_add( irc_t *irc, char *key, char *def, void *eval );
    40 G_MODULE_EXPORT set_t *set_find( irc_t *irc, char *key );
    41 G_MODULE_EXPORT char *set_getstr( irc_t *irc, char *key );
    42 G_MODULE_EXPORT int set_getint( irc_t *irc, char *key );
    43 int set_setstr( irc_t *irc, char *key, char *value );
    44 int set_setint( irc_t *irc, char *key, int value );
    45 void set_del( irc_t *irc, char *key );
     60/* Should be pretty clear. */
     61set_t *set_add( set_t **head, char *key, char *def, set_eval eval, void *data );
    4662
    47 char *set_eval_int( irc_t *irc, set_t *set, char *value );
    48 char *set_eval_bool( irc_t *irc, set_t *set, char *value );
    49 char *set_eval_to_char( irc_t *irc, set_t *set, char *value );
    50 char *set_eval_ops( irc_t *irc, set_t *set, char *value );
     63/* Returns the raw set_t. Might be useful sometimes. */
     64set_t *set_find( set_t **head, char *key );
    5165
     66/* Returns a pointer to the string value of this setting. Don't modify the
     67   returned string, and don't free() it! */
     68G_MODULE_EXPORT char *set_getstr( set_t **head, char *key );
    5269
     70/* Get an integer. Right now this also converts true/false/on/off/etc to
     71   numbers, but this is for historical reasons, please use set_getbool()
     72   for booleans instead. */
     73G_MODULE_EXPORT int set_getint( set_t **head, char *key );
     74G_MODULE_EXPORT int set_getbool( set_t **head, char *key );
     75
     76/* set_setstr() strdup()s the given value, so after using this function
     77   you can free() it, if you want. */
     78int set_setstr( set_t **head, char *key, char *value );
     79int set_setint( set_t **head, char *key, int value );
     80void set_del( set_t **head, char *key );
     81
     82/* Two very useful generic evaluators. */
     83char *set_eval_int( set_t *set, char *value );
     84char *set_eval_bool( set_t *set, char *value );
     85
     86/* Some not very generic evaluators that really shouldn't be here... */
     87char *set_eval_to_char( set_t *set, char *value );
     88char *set_eval_ops( set_t *set, char *value );
     89char *set_eval_charset( set_t *set, char *value );
Note: See TracChangeset for help on using the changeset viewer.