commit 0b446856afceea539b848fd18d84a37b101cd785
parent 3361dbe483971b71157f1b70c51637a1d0c3d254
Author: rpa <rpa@laika>
Date: Sun, 18 Dec 2022 20:42:13 +0000
tabul: small fixes
Diffstat:
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/src/tabul/tabul.c b/src/tabul/tabul.c
@@ -15,6 +15,8 @@
#include <keyboard.h>
#include <mouse.h>
+#define CellWidth 8 /* in characters */
+
typedef struct Array Array;
struct Array {
long n;
@@ -37,7 +39,7 @@ char * tfetch(Array *, Point);
void tstore(Array *, Point, char *);
void cleartable(Array *, Rectangle);
Array * duptable(Array *, Rectangle);
-void pastetable(Array *, Array *, Point);
+Rectangle pastetable(Array *, Array *, Point);
Image *bord, *text, *bg, *curbg;
Rectangle cell, blank;
@@ -124,7 +126,9 @@ pastesel(void)
return;
}
Array *t = readtable(fd);
- pastetable(view, t, cells.cur);
+ cells.sel = pastetable(view, t, cells.cur);
+ cells.cur = cells.sel.min;
+
close(fd);
}
@@ -392,7 +396,7 @@ init(void)
colors();
mctl = initmouse(nil, screen);
kctl = initkeyboard(nil);
- cell = Rect(0, 0, stringwidth(font, "0") * 16 + 4, font->height + 4);
+ cell = Rect(0, 0, stringwidth(font, "0") * CellWidth + 4, font->height + 4);
edit.str = s_new();
cells.cur = ZP;
cells.scroll = ZP;
@@ -409,6 +413,7 @@ threadmain(int argc, char **argv)
ARGBEGIN {
default: usage();
} ARGEND;
+ file[0] = '\0';
if (argc == 1) {
loadfile(argv[0]);
strncat(file, argv[0], 256);
@@ -489,7 +494,7 @@ cleartable(Array *t, Rectangle r)
}
}
-void
+Rectangle
pastetable(Array *to, Array *fr, Point sp)
{
assert(to != nil);
@@ -511,6 +516,7 @@ pastetable(Array *to, Array *fr, Point sp)
char *s = tfetch(fr, subpt(Pt(x, y), r.min));
tstore(to, Pt(x, y), s);
}
+ return r;
}
char *
@@ -577,8 +583,7 @@ writetable(Array *t, int fd)
for (y = 0; y < t->n; y++) {
Array *row = afetch(t, y);
- if (row == nil) continue;
- for (x = 0; x < row->n; x++) {
+ if (row != nil) for (x = 0; x < row->n; x++) {
char *s = afetch(row, x);
if (x != 0) Bprint(b, "\t");
if (s != nil) Bprint(b, "%s", s);