commit 01e24f0999841a8cdfa99027e2be90963742cef0
parent 5f2e561edb8bf36c8a19ec32e0a83abde936be34
Author: Quentin Rameau <quinq@fifth.space>
Date: Fri, 30 Jun 2017 17:15:27 +0200
Add setup() and cleanup(), and ui-specific equivalent
Diffstat:
3 files changed, 30 insertions(+), 9 deletions(-)
diff --git a/common.h b/common.h
@@ -22,3 +22,5 @@ void die(const char *fmt, ...);
void display(Item *item);
Item *selectitem(Item *entry);
const char *typedisplay(char t);
+void uicleanup(void);
+void uisetup(void);
diff --git a/sacc.c b/sacc.c
@@ -12,6 +12,9 @@
#include "common.h"
+static char *mainurl;
+static Item *mainentry;
+
void
die(const char *fmt, ...)
{
@@ -409,22 +412,33 @@ moldentry(char *url)
return entry;
}
+static void
+cleanup(void)
+{
+ free(mainentry); /* TODO free all tree recursively */
+ free(mainurl);
+ uicleanup();
+}
+
+static void
+setup(void)
+{
+ atexit(cleanup);
+ uisetup();
+}
+
int
main(int argc, char *argv[])
{
- Item *entry;
- char *url;
-
if (argc != 2)
usage();
- url = xstrdup(argv[1]);
+ setup();
- entry = moldentry(url);
- delve(entry);
+ mainurl = xstrdup(argv[1]);
- free(entry); /* TODO free all tree recursively */
- free(url);
+ mainentry = moldentry(mainurl);
+ delve(mainentry);
- return 0;
+ exit(0);
}
diff --git a/ui_txt.c b/ui_txt.c
@@ -8,6 +8,11 @@
#include "common.h"
void
+uisetup(void) { return; }
+void
+uicleanup(void) { return; }
+
+void
help(void)
{
puts("Commands:\n"