commit 40116c8499e5d11864520a068b13a71cc4b7d9a7
parent 2965e38ef6be8f6177fc7f506be7a32d55b24fe5
Author: Claudio Alessi <smoppy@gmail.com>
Date: Thu, 14 Apr 2016 22:51:54 +0200
Add setview() which makes code a bit more compact.
The viewdblist() function has been removed since it only was doing a single
call to setview().
Diffstat:
M | myadm.c | | | 22 | ++++++++++------------ |
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/myadm.c b/myadm.c
@@ -102,6 +102,7 @@ View *newaview(const char *name, void (*func)(void));
void quit(const Arg *arg);
void reload(const Arg *arg);
void run(void);
+void setview(const char *name, void (*func)(void));
void setup(void);
void sigint_handler(int unused);
int stripesc(char *src, char *dst, int len);
@@ -118,7 +119,6 @@ void ui_showitems(Item *items, int *lens);
void usage(void);
void viewdb(const Arg *arg);
void viewdb_show(void);
-void viewdblist(const Arg *arg);
void viewdblist_show(void);
void viewprev(const Arg *arg);
void viewtable(const Arg *arg);
@@ -521,6 +521,12 @@ run(void) {
}
void
+setview(const char *name, void (*func)(void)) {
+ selview = newaview(name, func);
+ func();
+}
+
+void
setup(void) {
struct sigaction sa;
@@ -534,7 +540,7 @@ setup(void) {
sa.sa_handler = sigint_handler;
sigaction(SIGINT, &sa, NULL);
ui_init();
- viewdblist(NULL);
+ setview("databases", viewdblist_show);
}
void
@@ -658,8 +664,7 @@ viewdb(const Arg *arg) {
return;
}
mysql_select_db(mysql, choice->cols[0]);
- selview = newaview("tables", viewdb_show);
- viewdb_show();
+ setview("tables", viewdb_show);
}
void
@@ -676,12 +681,6 @@ viewdb_show(void) {
}
void
-viewdblist(const Arg *arg) {
- selview = newaview("databases", viewdblist_show);
- viewdblist_show();
-}
-
-void
viewdblist_show(void) {
MYSQL_RES *res;
@@ -711,8 +710,7 @@ viewtable(const Arg *arg) {
ui_set("status", "No table selected.");
return;
}
- selview = newaview("records", viewtable_show);
- viewtable_show();
+ setview("records", viewtable_show);
}
void