commit 978bd51f2027bff5fb3d242fed25b156512a9e93
parent 7cd41b83fd66c66f1b943f9fb79bd9077e76cca7
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Thu, 1 Oct 2020 14:36:04 +0000
cleanup
Diffstat:
M | cells.c | | | 59 | +---------------------------------------------------------- |
M | cells.h | | | 13 | +++---------- |
M | sss.c | | | 20 | +++++++++----------- |
M | stack.c | | | 14 | +++++++++----- |
M | stack.h | | | 4 | ++-- |
5 files changed, 24 insertions(+), 86 deletions(-)
diff --git a/cells.c b/cells.c
@@ -58,63 +58,6 @@ free_table(Stack *T)
}
Stack*
-empty_table(void)
-{
- Stack *T;
- T = malloc(sizeof(Stack));
- T->data = nil;
- T->size = 0;
- return T;
-}
-
-Stack*
-copy_table(Stack *T)
-{
- Stack *N;
- Value *nv, *v;
- long i;
- N = empty_table();
- for (i = 0; i < T->size; i++) {
- v = T->data[i];
- nv = malloc(sizeof(Value));
- nv->addr = v->addr;
- nv->data = strdup(v->data);
- push(N, nv);
- }
- return N;
-}
-
-Stack*
-table_put(Stack *T, Value v)
-{
- Stack *N;
- Value *nv;
- N = copy_table(T);
- nv = malloc(sizeof(Value));
- nv->addr = v.addr;
- nv->data = strdup(v.data);
- push(N, nv);
- return N;
-}
-
-Value
-table_get(Stack *T, Addr addr)
-{
- Value *v, r;
- long i;
- r.addr = addr;
- r.data = strdup("");
- for (i = 0; i < T->size; i++) {
- v = T->data[i];
- if (addrcmp(v->addr, addr) == 0) {
- free(r.data);
- r.data = strdup(v->data);
- }
- }
- return r;
-}
-
-Stack*
table_read(char *path)
{
Stack *T;
@@ -122,7 +65,7 @@ table_read(char *path)
char b, *buf;
long bufsize, x, y;
int fd;
- T = empty_table();
+ T = newstack();
buf = mallocz(1, 1);
bufsize = 0;
x = 0;
diff --git a/cells.h b/cells.h
@@ -23,16 +23,10 @@ void free_value(Value);
/*** TABLE ***/
-void free_table(Stack*);
-Stack* empty_table(void);
-Stack* copy_table(Stack*);
-Stack* table_put(Stack*, Value);
-Value table_get(Stack*, Addr);
Stack* table_read(char*);
-
void print_table(Stack*);
// TODO:
-Stack* eval_table(Stack*);
-Stack* table_join(Stack*, Stack*);
-Stack* table_transform(Stack*, void (*func)(void**), void**);
-\ No newline at end of file
+//Stack* eval_table(Stack*);
+//Stack* table_join(Stack*, Stack*);
+//Stack* table_transform(Stack*, void (*func)(void**), void**);
diff --git a/sss.c b/sss.c
@@ -9,12 +9,11 @@
#include "stack.h"
#include "cells.h"
-Stack hp, hr;
+Stack *hp, *hr;
Stack *T;
int defcwidth, defcheight;
-
Image *Iborder, *Ibg, *Ifg, *Ibg2;
Point view;
@@ -68,10 +67,9 @@ threadmain(int argc, char **argv)
defcwidth = stringwidth(font, "01234567") + 4;
if (argc == 1) T = table_read(argv[0]);
- else T = empty_table();
- hp.size = 0;
- hp.data = nil;
- push(&hp, T);
+ else T = newstack();
+ hp = newstack();
+ push(hp, T);
clear();
draw_cells();
draw_columns();
@@ -235,7 +233,7 @@ draw_cells(void)
while (pt.y < screen->r.max.y) {
if ((pt.x >= screen->r.min.x) && (pt.y >= screen->r.min.y)) {
r = rectaddpt(Rect(0,0,defcwidth, defcheight), pt);
- v = hist_get_value(&hp, xy2addr(x, y));
+ v = hist_get_value(hp, xy2addr(x, y));
if (v == nil) text = "";
else text = v->data;
draw_cell(screen, r, Ibg, Iborder, Ifg, text, -1);
@@ -266,19 +264,18 @@ edit_cell(Addr addr, Mousectl *mc, Keyboardctl *kc)
{
Value *v;
Stack *N;
- N = empty_table();
+ N = newstack();
char prompt[256], buf[1024];
snprint(prompt, 256, "%ld,%ld:", addr.x, addr.y);
- v = hist_get_value(&hp, addr);
+ v = hist_get_value(hp, addr);
*buf = 0;
if ((v != nil)&&(v->data != nil)) strncat(buf, v->data, 1024);
if (enter(prompt, buf, 1024, mc, kc, 0) < 0) return;
- //if (strcmp(v->data, buf) == 0) return;
v = malloc(sizeof(Value));
v->addr = addr;
v->data = strdup(buf);
push(N, v);
- push(&hp, N);
+ push(hp, N);
T = N;
}
@@ -297,3 +294,4 @@ hist_get_value(Stack *H, Addr addr)
}
return nil;
}
+
diff --git a/stack.c b/stack.c
@@ -21,8 +21,12 @@ pop(Stack *S)
return v;
}
-//void
-//purge(Stack *s)
-//{
-// for(;S->size > 0; S->size--)
-//}
+Stack*
+newstack(void)
+{
+ Stack *R;
+ R = malloc(sizeof(Stack));
+ R->size = 0;
+ R->data = nil;
+ return R;
+}
diff --git a/stack.h b/stack.h
@@ -6,5 +6,4 @@ struct Stack {
int push(Stack*, void*);
void* pop(Stack*);
-
-// void purge(Stack*);
+Stack* newstack(void);
+\ No newline at end of file