- Timestamp:
- 2015-02-20T22:50:54Z (9 years ago)
- Branches:
- master
- Children:
- 0b9daac, 3d45471, 7733b8c
- Parents:
- af359b4
- git-author:
- Indent <please@…> (19-02-15 05:47:20)
- git-committer:
- dequis <dx@…> (20-02-15 22:50:54)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
set.h
raf359b4 r5ebff60 1 1 /********************************************************************\ 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * … … 32 32 (so it can also be used for account_t structs). It's pretty simple, but 33 33 so far pretty useful. 34 34 35 35 In short, it just keeps a linked list of settings/variables and it also 36 36 remembers a default value for every setting. And to prevent the user … … 39 39 NULL, or replace it by returning a new value. See struct set.eval. */ 40 40 41 typedef char *(*set_eval) ( struct set *set, char *value);41 typedef char *(*set_eval) (struct set *set, char *value); 42 42 43 43 extern char *SET_INVALID; 44 44 45 typedef enum 46 { 45 typedef enum { 47 46 SET_NOSAVE = 0x0001, /* Don't save this setting (i.e. stored elsewhere). */ 48 47 SET_NULL_OK = 0x0100, /* set->value == NULL is allowed. */ … … 52 51 } set_flags_t; 53 52 54 typedef struct set 55 { 53 typedef struct set { 56 54 void *data; /* Here you can save a pointer to the 57 55 object this settings belongs to. */ 58 56 59 57 char *key; 60 58 char *old_key; /* Previously known as; for smooth upgrades. */ … … 66 64 In fact, you should only read values using 67 65 set_getstr/int(). */ 68 66 69 67 set_flags_t flags; /* Mostly defined per user. */ 70 68 71 69 /* Eval: Returns SET_INVALID if the value is incorrect, exactly 72 70 the passed value variable, or a corrected value. In case of … … 77 75 } set_t; 78 76 79 #define set_value( set) ((set)->value) ? ((set)->value) : ((set)->def)77 #define set_value(set) ((set)->value) ? ((set)->value) : ((set)->def) 80 78 81 79 /* Should be pretty clear. */ 82 set_t *set_add( set_t **head, const char *key, const char *def, set_eval eval, void *data);80 set_t *set_add(set_t **head, const char *key, const char *def, set_eval eval, void *data); 83 81 84 82 /* Returns the raw set_t. Might be useful sometimes. */ 85 set_t *set_find( set_t **head, const char *key);83 set_t *set_find(set_t **head, const char *key); 86 84 87 85 /* Returns a pointer to the string value of this setting. Don't modify the 88 86 returned string, and don't free() it! */ 89 G_MODULE_EXPORT char *set_getstr( set_t **head, const char *key);87 G_MODULE_EXPORT char *set_getstr(set_t **head, const char *key); 90 88 91 89 /* Get an integer. In previous versions set_getint() was also used to read 92 90 boolean values, but this SHOULD be done with set_getbool() now! */ 93 G_MODULE_EXPORT int set_getint( set_t **head, const char *key);94 G_MODULE_EXPORT int set_getbool( set_t **head, const char *key);91 G_MODULE_EXPORT int set_getint(set_t **head, const char *key); 92 G_MODULE_EXPORT int set_getbool(set_t **head, const char *key); 95 93 96 94 /* set_setstr() strdup()s the given value, so after using this function 97 95 you can free() it, if you want. */ 98 int set_setstr( set_t **head, const char *key, char *value);99 int set_setint( set_t **head, const char *key, int value);100 void set_del( set_t **head, const char *key);101 int set_reset( set_t **head, const char *key);96 int set_setstr(set_t **head, const char *key, char *value); 97 int set_setint(set_t **head, const char *key, int value); 98 void set_del(set_t **head, const char *key); 99 int set_reset(set_t **head, const char *key); 102 100 103 101 /* returns true if a setting shall be shown to the user */ 104 int set_isvisible( set_t *set);102 int set_isvisible(set_t *set); 105 103 106 104 /* Two very useful generic evaluators. */ 107 char *set_eval_int( set_t *set, char *value);108 char *set_eval_bool( set_t *set, char *value);105 char *set_eval_int(set_t *set, char *value); 106 char *set_eval_bool(set_t *set, char *value); 109 107 110 108 /* Another more complicated one. */ 111 char *set_eval_list( set_t *set, char *value);109 char *set_eval_list(set_t *set, char *value); 112 110 113 111 /* Some not very generic evaluators that really shouldn't be here... */ 114 char *set_eval_to_char( set_t *set, char *value);115 char *set_eval_oauth( set_t *set, char *value);112 char *set_eval_to_char(set_t *set, char *value); 113 char *set_eval_oauth(set_t *set, char *value); 116 114 117 115 #endif /* __SET_H__ */
Note: See TracChangeset
for help on using the changeset viewer.