- Timestamp:
- 2006-10-15T09:41:12Z (18 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
set.h
r695e392 r69cb623 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * 4 * Copyright 2002-200 4Wilmer van der Gaast and others *4 * Copyright 2002-2006 Wilmer van der Gaast and others * 5 5 \********************************************************************/ 6 6 … … 24 24 */ 25 25 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 36 typedef char *(*set_eval) ( struct set *set, char *value ); 37 26 38 typedef struct set 27 39 { 40 void *data; /* Here you can save a pointer to the 41 object this settings belongs to. */ 42 28 43 char *key; 29 44 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! */ 31 49 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; 36 57 struct set *next; 37 58 } set_t; 38 59 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. */ 61 set_t *set_add( set_t **head, char *key, char *def, set_eval eval, void *data ); 46 62 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. */ 64 set_t *set_find( set_t **head, char *key ); 51 65 66 /* Returns a pointer to the string value of this setting. Don't modify the 67 returned string, and don't free() it! */ 68 G_MODULE_EXPORT char *set_getstr( set_t **head, char *key ); 52 69 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. */ 73 G_MODULE_EXPORT int set_getint( set_t **head, char *key ); 74 G_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. */ 78 int set_setstr( set_t **head, char *key, char *value ); 79 int set_setint( set_t **head, char *key, int value ); 80 void set_del( set_t **head, char *key ); 81 82 /* Two very useful generic evaluators. */ 83 char *set_eval_int( set_t *set, char *value ); 84 char *set_eval_bool( set_t *set, char *value ); 85 86 /* Some not very generic evaluators that really shouldn't be here... */ 87 char *set_eval_to_char( set_t *set, char *value ); 88 char *set_eval_ops( set_t *set, char *value ); 89 char *set_eval_charset( set_t *set, char *value );
Note: See TracChangeset
for help on using the changeset viewer.