- Timestamp:
- 2006-08-13T19:15:23Z (18 years ago)
- Branches:
- master
- Children:
- 08cdb93
- Parents:
- 846cec61
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
set.h
r846cec61 rd5ccd83 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 26 36 typedef struct set 27 37 { 28 void *data; 38 void *data; /* Here you can save a pointer to the 39 object this settings belongs to. */ 29 40 30 41 char *key; 31 42 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! */ 33 47 34 int flags; 48 int flags; /* See account.h, for example. set.c doesn't use 49 this (yet?). */ 35 50 36 51 /* Eval: Returns NULL if the value is incorrect or exactly the … … 41 56 } set_t; 42 57 58 /* Should be pretty clear. */ 43 59 set_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. */ 44 62 set_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! */ 45 66 G_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. */ 46 71 G_MODULE_EXPORT int set_getint( set_t **head, char *key ); 47 72 G_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. */ 48 76 int set_setstr( set_t **head, char *key, char *value ); 49 77 int set_setint( set_t **head, char *key, int value ); 50 78 void set_del( set_t **head, char *key ); 51 79 80 /* Two very useful generic evaluators. */ 52 81 char *set_eval_int( set_t *set, char *value ); 53 82 char *set_eval_bool( set_t *set, char *value ); 54 83 84 /* Some not very generic evaluators that really shouldn't be here... */ 55 85 char *set_eval_to_char( set_t *set, char *value ); 56 86 char *set_eval_ops( set_t *set, char *value );
Note: See TracChangeset
for help on using the changeset viewer.