diff options
author | Carlos Martín Nieto <cmn@elego.de> | 2011-04-06 18:27:31 +0200 |
---|---|---|
committer | Carlos Martín Nieto <cmn@elego.de> | 2011-04-07 17:15:30 +0200 |
commit | 6b45cb8a89cd3b133183a093719a144a402450e9 (patch) | |
tree | c8278dc6580b1905e14cf9df23f88174f405e072 /src/config.h | |
parent | 0d280ea457c8ee8809062266fa365c440d35ee6b (diff) | |
download | libgit2-6b45cb8a89cd3b133183a093719a144a402450e9.tar.gz |
config: use and implement list macros
Use list macros instead of manually changing the head and/or tail of
the variable list.
Diffstat (limited to 'src/config.h')
-rw-r--r-- | src/config.h | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/src/config.h b/src/config.h index 1e954ff81..e54933d5f 100644 --- a/src/config.h +++ b/src/config.h @@ -3,9 +3,13 @@ #include "git2/config.h" +typedef struct { + git_cvar *head; + git_cvar *tail; +} git_cvar_list; + struct git_config { - git_cvar *vars; - git_cvar *vars_tail; + git_cvar_list var_list; struct { gitfo_buf buffer; @@ -23,12 +27,44 @@ struct git_cvar { char *value; }; +#define CVAR_LIST_HEAD(list) ((list)->head) + +#define CVAR_LIST_TAIL(list) ((list)->tail) + +#define CVAR_LIST_NEXT(var) ((var)->next) + +#define CVAR_LIST_EMPTY(list) ((list)->head == NULL) + +#define CVAR_LIST_APPEND(list, var) do {\ + if (CVAR_LIST_EMPTY(list)) {\ + CVAR_LIST_HEAD(list) = CVAR_LIST_TAIL(list) = var;\ + } else {\ + CVAR_LIST_NEXT(CVAR_LIST_TAIL(list)) = var;\ + CVAR_LIST_TAIL(list) = var;\ + }\ +} while(0) + +#define CVAR_LIST_REMOVE_HEAD(list) do {\ + CVAR_LIST_HEAD(list) = CVAR_LIST_NEXT(CVAR_LIST_HEAD(list));\ +} while(0) + +#define CVAR_LIST_REMOVE_AFTER(var) do {\ + CVAR_LIST_NEXT(var) = CVAR_LIST_NEXT(CVAR_LIST_NEXT(var));\ +} while(0) + +#define CVAR_LIST_FOREACH(list, iter)\ + for ((iter) = CVAR_LIST_HEAD(list);\ + (iter) != NULL;\ + (iter) = CVAR_LIST_NEXT(iter)) + /* - * If you're going to delete something inside this loop, it's such a - * hassle that you should use the for-loop directly. + * Inspired by the FreeBSD functions */ -#define CVAR_LIST_FOREACH(start, iter) \ - for ((iter) = (start); (iter) != NULL; (iter) = (iter)->next) +#define CVAR_LIST_FOREACH_SAFE(start, iter, tmp)\ + for ((iter) = CVAR_LIST_HEAD(vars);\ + (iter) && (((tmp) = CVAR_LIST_NEXT(iter) || 1));\ + (iter) = (tmp)) + void git__strtolower(char *str); void git__strntolower(char *str, int len); |