summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: dc190f3)
raw | patch | inline | side by side (parent: dc190f3)
author | Max Kellermann <max@duempel.org> | |
Mon, 6 Oct 2008 12:55:31 +0000 (14:55 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Mon, 6 Oct 2008 12:55:31 +0000 (14:55 +0200) |
Remove some clutter from wreadln(), isolate some code into a function.
src/wreadln.c | patch | blob | history |
diff --git a/src/wreadln.c b/src/wreadln.c
index d68185a7e42ffabae1702dc74d1a8edbe465e768..f10b8c23f96c125f890b7ddc187ae4415c869ac2 100644 (file)
--- a/src/wreadln.c
+++ b/src/wreadln.c
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 *
/* 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);