From e5b52fcd76c94f6349cddb0e1872ff8b2109acea Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Fri, 17 Apr 2015 20:45:54 +0200 Subject: degesch: factor out buffer_get_index() --- degesch.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/degesch.c b/degesch.c index 64280c8..b15b464 100644 --- a/degesch.c +++ b/degesch.c @@ -952,6 +952,19 @@ buffer_goto (struct app_context *ctx, int n) return false; } +static int +buffer_get_index (struct app_context *ctx, struct buffer *buffer) +{ + int index = 1; + LIST_FOR_EACH (struct buffer, iter, ctx->buffers) + { + if (iter == buffer) + return index; + index++; + } + return -1; +} + static void init_buffers (struct app_context *ctx) { @@ -1291,12 +1304,8 @@ refresh_prompt (struct app_context *ctx) str_append_printf (&prompt, "(%s) ", unseen_prefix); free (unseen_prefix); - int buffer_index = 1; - for (struct buffer *iter = ctx->buffers; - iter && iter != buffer; iter = iter->next) - buffer_index++; - - str_append_printf (&prompt, "%d:%s", buffer_index, buffer->name); + str_append_printf (&prompt, "%d:%s", + buffer_get_index (ctx, buffer), buffer->name); if (buffer->type == BUFFER_CHANNEL && *buffer->mode) str_append_printf (&prompt, "(%s)", buffer->mode); -- cgit v1.2.3-70-g09d2