ref: 1260c5c1735d5cf5a60890df7471bcd808b6231d
parent: 28539de81a1a7beb10e8281a9825b9c39e8482cf
author: sirjofri <sirjofri@sirjofri.de>
date: Tue Jul 16 09:34:21 EDT 2024
makes program work without file argument, opening an empty file
--- a/README.md
+++ b/README.md
@@ -38,7 +38,7 @@
# Usage
- spread [-di] file
+ spread [-di] [file]
- `file` will be loaded as a spreadsheet
- `-d` enables extra debug output
--- a/cells.c
+++ b/cells.c
@@ -52,9 +52,12 @@
free(c->value);
if (c->procvalue && c->procvalue != c->value)
free(c->procvalue);
+ if (c->buffered)
+ free(c->buffered);
c->value = strdup(value);
c->type = type;
c->align = align;
+ c->buffered = nil;
preprocess(c);
addempty(c->procvalue);
return;
@@ -71,6 +74,12 @@
c->value = strdup(value);
c->type = type;
c->align = align;
+ c->buffered = nil;
+ c->procvalue = nil;
+ c->points = nil;
+ c->size = 0;
+ c->num = 0;
+ c->indeg = 0;
preprocess(c);
addempty(c->procvalue);
}
--- a/spread.c
+++ b/spread.c
@@ -9,7 +9,7 @@
void
usage(void)
{
- fprint(2, "usage: %s [-di] file\n", argv0);
+ fprint(2, "usage: %s [-di] [file]\n", argv0);
exits("usage");
}
@@ -131,8 +131,11 @@
Point p;
int w;
- f = strrchr(file, '/');
- f = f ? f+1 : file;
+ f = nil;
+ if (file) {
+ f = strrchr(file, '/');
+ f = f ? f+1 : file;
+ }
snprint(filebuf, sizeof(filebuf), "%s%s", f, dirty ? "*" : "");
p = addpt(screen->r.min, Pt(4, 4));
@@ -438,16 +441,20 @@
if (n == 1) {
writefile(file);
dirty = 0;
- break;
+ goto Savequit;
}
if (n == 2) {
file = strdup(args[1]);
writefile(file);
dirty = 0;
- break;
+ goto Savequit;
}
error = Ebadcmd;
break;
+Savequit:
+ if (*(args[0]+1) == 'q')
+ exits(nil);
+ break;
case 'm': /* toggle math mode */
dstate.mathmode = !dstate.mathmode;
break;
@@ -568,16 +575,14 @@
break;
}ARGEND;
- if (argc != 1)
- usage();
+ file = (argc == 1) ? *argv : nil;
- file = *argv;
-
if (!inithoc())
sysfatal("%r");
- if (!loadfile(file))
- sysfatal("%r");
+ if (file)
+ if (!loadfile(file))
+ sysfatal("%r");
if (interactive) {
interactivehoc();