aboutsummaryrefslogtreecommitdiff
path: root/toys/pending
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-12-23 18:16:23 -0600
committerRob Landley <rob@landley.net>2015-12-23 18:16:23 -0600
commite32e802240c5b3803b9769948dc7a18b3fc1630c (patch)
tree737f86c1d3b634f7293b54efdc4a2c3198e78f71 /toys/pending
parent432d2f1faf23f5ac5fba10facc06f86b55344b1f (diff)
downloadtoybox-e32e802240c5b3803b9769948dc7a18b3fc1630c.tar.gz
Factor out draw_str() and friends.
Diffstat (limited to 'toys/pending')
-rw-r--r--toys/pending/vi.c83
1 files changed, 7 insertions, 76 deletions
diff --git a/toys/pending/vi.c b/toys/pending/vi.c
index 20d765cf..bf8db841 100644
--- a/toys/pending/vi.c
+++ b/toys/pending/vi.c
@@ -24,85 +24,16 @@ GLOBALS(
char *statline;
)
-struct linestack {
- long len, max;
- struct ptr_len idx[];
+struct linestack_show {
+ struct linestack_show *next;
+ long top, left;
+ int x, width, y, height;
};
-// Insert one stack into another before position in old stack.
-// (Does not copy contents of strings, just shuffles index array contents.)
-void linestack_addstack(struct linestack **lls, struct linestack *throw,
- long pos)
+// linestack, what to show, where to show it
+void linestack_show(struct linestack *ls, struct linestack_show *lss)
{
- struct linestack *catch = *lls;
-
- if (CFG_TOYBOX_DEBUG)
- if (pos > catch->len) error_exit("linestack_addstack past end.");
-
- // Make a hole, allocating more space if necessary.
- if (catch->len+throw->len >= catch->max) {
- // New size rounded up to next multiple of 64, allocate and copy start.
- catch->max = ((catch->len+throw->len)|63)+1;
- *lls = xmalloc(sizeof(struct linestack)+catch->max*sizeof(struct ptr_len));
- memcpy(*lls, catch, sizeof(struct linestack)+pos*sizeof(struct ptr_len));
- }
-
- // Copy end (into new allocation if necessary)
- if (pos != catch->len)
- memmove((*lls)->idx+pos+throw->len, catch->idx+pos,
- (catch->len-pos)*sizeof(struct ptr_len));
-
- // Cleanup if we had to realloc.
- if (catch != *lls) {
- free(catch);
- catch = *lls;
- }
-
- memcpy(catch->idx+pos, throw->idx, throw->len*sizeof(struct ptr_len));
- catch->len += throw->len;
-}
-
-void linestack_insert(struct linestack **lls, long pos, char *line, long len)
-{
- // alloca() was in 32V and Turbo C for DOS, but isn't in posix or c99.
- // I'm not thrashing the heap for this, but this should work even if
- // a broken compiler adds gratuitous padding.
- struct {
- struct linestack ls;
- struct ptr_len pl;
- } ls;
-
- ls.ls.len = ls.ls.max = 1;
- ls.ls.idx[0].ptr = line;
- ls.ls.idx[0].len = len;
- linestack_addstack(lls, &ls.ls, pos);
-}
-
-void linestack_append(struct linestack **lls, char *line)
-{
- linestack_insert(lls, (*lls)->len, line, strlen(line));
-}
-
-struct linestack *linestack_load(char *name)
-{
- FILE *fp = fopen(name, "r");
- struct linestack *ls;
-
- if (!fp) return 0;
-
- ls = xzalloc(sizeof(struct linestack));
-
- for (;;) {
- char *line = 0;
- ssize_t len;
-
- if ((len = getline(&line, (void *)&len, fp))<1) break;
- if (line[len-1]=='\n') len--;
- linestack_insert(&ls, ls->len, line, len);
- }
- fclose(fp);
-
- return ls;
+ return;
}
void vi_main(void)