diff options
author | Max Kellermann <max@duempel.org> | 2008-10-06 14:55:31 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-10-06 14:55:31 +0200 |
commit | 147e3849ba1f451d195e33f1eb35ab5a7b86f035 (patch) | |
tree | 27745b857e15b24a9278a2bcc70947227f8d2a12 /src/wreadln.c | |
parent | dc190f330bba1632e76ca6993c22865f0da88f2c (diff) | |
download | mpd-147e3849ba1f451d195e33f1eb35ab5a7b86f035.tar.gz mpd-147e3849ba1f451d195e33f1eb35ab5a7b86f035.tar.xz mpd-147e3849ba1f451d195e33f1eb35ab5a7b86f035.zip |
wreadln: moved code to insert_byte()
Remove some clutter from wreadln(), isolate some code into a function.
Diffstat (limited to '')
-rw-r--r-- | src/wreadln.c | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/src/wreadln.c b/src/wreadln.c index d68185a7e..f10b8c23f 100644 --- a/src/wreadln.c +++ b/src/wreadln.c @@ -117,6 +117,29 @@ static inline void drawline(const struct wreadln *wr) doupdate(); } +static void +wreadln_insert_byte(struct wreadln *wr, gint key) +{ + if (strlen(wr->line + wr->cursor)) { /* if the cursor is */ + /* not at the last pos */ + gchar *tmp = NULL; + gsize rest = strlen(wr->line + wr->cursor) + 1; + + tmp = g_malloc0(rest); + g_strlcpy (tmp, wr->line + wr->cursor, rest); + wr->line[wr->cursor] = key; + wr->line[wr->cursor + 1] = 0; + g_strlcat(&wr->line[wr->cursor + 1], tmp, rest); + g_free(tmp); + cursor_move_right(wr); + } else { + wr->line[wr->cursor + 1] = 0; + wr->line[wr->cursor] = key; + } + + cursor_move_right(wr); +} + /* libcurses version */ static gchar * @@ -308,25 +331,8 @@ _wreadln(WINDOW *w, /* ignore char */ break; default: - if (key >= 32) { - if (strlen(wr.line + wr.cursor)) { /* if the cursor is */ - /* not at the last pos */ - gchar *tmp = NULL; - gsize size = strlen(wr.line + wr.cursor) + 1; - - tmp = g_malloc0(size); - g_strlcpy (tmp, wr.line + wr.cursor, size); - wr.line[wr.cursor] = key; - wr.line[wr.cursor + 1] = 0; - g_strlcat(&wr.line[wr.cursor + 1], tmp, size); - g_free(tmp); - cursor_move_right(&wr); - } else { - wr.line[wr.cursor + 1] = 0; - wr.line[wr.cursor] = key; - cursor_move_right(&wr); - } - } + if (key >= 32) + wreadln_insert_byte(&wr, key); } drawline(&wr); |