From: Andre Noll Date: Sat, 10 Nov 2007 16:33:06 +0000 (+0100) Subject: Use FOR_EACH_STATUS_ITEM everywhere. X-Git-Tag: v0.3.0~122 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=84f3cda92d0fb3d072b1a2d9bf8c2156c18d6398 Use FOR_EACH_STATUS_ITEM everywhere. --- diff --git a/audiod.c b/audiod.c index d4b728af..b8c072d5 100644 --- a/audiod.c +++ b/audiod.c @@ -951,7 +951,7 @@ static void close_stat_pipe(void) return; client_close(stat_task->pcd); stat_task->pcd = NULL; - for (i = 0; i < NUM_STAT_ITEMS; i++) { + FOR_EACH_STATUS_ITEM(i) { free(stat_task->stat_item_values[i]); stat_task->stat_item_values[i] = NULL; } diff --git a/audiod_command.c b/audiod_command.c index a225b76b..855e5cea 100644 --- a/audiod_command.c +++ b/audiod_command.c @@ -259,8 +259,7 @@ int com_stat(int fd, __a_unused int argc, __a_unused char **argv) goto out; free(df); } - - for (i = 0; i < NUM_STAT_ITEMS; i++) { + FOR_EACH_STATUS_ITEM(i) { char *tmp, *v; if (!((1 << i) & mask)) continue; @@ -529,7 +528,7 @@ void dump_empty_status(void) { int i; - FOR_EACH_STAT_ITEM(i) { + FOR_EACH_STATUS_ITEM(i) { char *tmp = make_message("%s:\n", status_item_list[i]); stat_client_write(tmp, i); free(tmp); diff --git a/gui.c b/gui.c index 40d521bc..126b40fe 100644 --- a/gui.c +++ b/gui.c @@ -664,14 +664,15 @@ static void print_all_items(void) if (!curses_active) return; - for (i = 0; i < NUM_STAT_ITEMS; i++) + FOR_EACH_STATUS_ITEM(i) print_stat_item(i); } + static void clear_all_items(void) { int i; - for (i = 0; i < NUM_STAT_ITEMS; i++) { + FOR_EACH_STATUS_ITEM(i) { free(stat_content[i]); stat_content[i] = para_strdup(""); } @@ -683,7 +684,7 @@ static void init_colors(void) if (!has_colors()) msg_n_exit(EXIT_FAILURE, "Error: No color term\n"); start_color(); - for (i = 0; i < NUM_STAT_ITEMS; i++) + FOR_EACH_STATUS_ITEM(i) if (theme.data[i].len) init_pair(i + 1, theme.data[i].fg, theme.data[i].bg); init_pair(COLOR_STATUSBAR, theme.sb_fg, theme.sb_bg); diff --git a/gui_theme.c b/gui_theme.c index 262d9d56..b0779791 100644 --- a/gui_theme.c +++ b/gui_theme.c @@ -295,8 +295,7 @@ static void init_theme_colorful_blackness(struct gui_theme *t) void init_theme(int num, struct gui_theme *t) { int i; - - for (i = 0; i < NUM_STAT_ITEMS; i++) + FOR_EACH_STATUS_ITEM(i) t->data[i].len = 0; current_theme_num = num; diff --git a/para.h b/para.h index 2c95f817..9ee318e5 100644 --- a/para.h +++ b/para.h @@ -158,15 +158,15 @@ int tv_convex_combination(const long a, const struct timeval *tv1, struct timeval *result); void ms2tv(const long unsigned n, struct timeval *tv); +/** The enum of all status items. */ enum status_items {STATUS_ITEM_ENUM NUM_STAT_ITEMS}; extern const char *status_item_list[]; - +/** Loop over each status item. */ +#define FOR_EACH_STATUS_ITEM(i) for (i = 0; i < NUM_STAT_ITEMS; i++) int stat_item_valid(const char *item); int stat_line_valid(const char *); void stat_client_write(const char *msg, int itemnum); int stat_client_add(int fd, long unsigned mask); -/** Loop over each status item. */ -#define FOR_EACH_STAT_ITEM(i) for (i = 0; i < NUM_STAT_ITEMS; i++) __printf_2_3 void para_log(int, const char*, ...); diff --git a/stat.c b/stat.c index feb669bc..59ac4235 100644 --- a/stat.c +++ b/stat.c @@ -149,7 +149,7 @@ int stat_item_valid(const char *item) PARA_ERROR_LOG("%s\n", "no item"); return -E_UNKNOWN_STAT_ITEM; } - FOR_EACH_STAT_ITEM(i) + FOR_EACH_STATUS_ITEM(i) if (!strcmp(status_item_list[i], item)) return i; PARA_ERROR_LOG("invalid stat item: %s\n", item); @@ -173,7 +173,7 @@ int stat_line_valid(const char *line) if (!line || !*line) return -E_UNKNOWN_STAT_ITEM; line_len = strlen(line); - FOR_EACH_STAT_ITEM(i) { + FOR_EACH_STATUS_ITEM(i) { const char *s = status_item_list[i]; size_t item_len = strlen(s);