commit 01919fd716b474dc5c5e3ced502938e97273d6e7
parent 987f736fa710cde772537b1f68d93985fad0191a
Author: Claudio Alessi <smoppy@gmail.com>
Date: Thu, 12 May 2016 23:01:47 +0200
Add startup actions.
No more setview() inside of the setup() routine. A simple startup mechanism has
been added and the new viewdblist() is called as specified into the default
config.h file.
Diffstat:
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -7,6 +7,11 @@ static const char *dbhost = "";
static const char *dbuser = "";
static const char *dbpass = "";
+/* gets executed when myadm is started */
+static Action actions[] = {
+ { viewdblist },
+};
+
#if defined CTRL && defined _AIX
#undef CTRL
#endif
diff --git a/myadm.c b/myadm.c
@@ -46,6 +46,10 @@ typedef union {
const void *v;
} Arg;
+typedef struct {
+ void (*cmd)(void);
+} Action;
+
typedef struct Item Item;
struct Item {
char **cols;
@@ -120,6 +124,7 @@ void reload(const Arg *arg);
void run(void);
void setview(const char *name, void (*func)(void));
void setup(void);
+void startup(void);
void ui_end(void);
struct stfl_form *ui_getform(wchar_t *code);
void ui_init(void);
@@ -135,6 +140,7 @@ void ui_sql_edit_exec(char *sql);
void usage(void);
void viewdb(const Arg *arg);
void viewdb_show(void);
+void viewdblist(void);
void viewdblist_show(void);
void viewprev(const Arg *arg);
void viewtable(const Arg *arg);
@@ -598,7 +604,6 @@ ui_sql_edit_exec(char *sql) {
return;
}
close(fd);
-
stat(tmpf, &sb);
while(1) {
editfile(tmpf);
@@ -700,7 +705,12 @@ setup(void) {
die("Cannot connect to the database.\n");
fldseplen = strlen(FLDSEP);
ui_init();
- setview("databases", viewdblist_show);
+}
+
+void
+startup(void) {
+ for (unsigned int i = 0; i < LENGTH(actions); i++)
+ actions[i].cmd();
}
void
@@ -830,6 +840,11 @@ viewdb_show(void) {
}
void
+viewdblist(void) {
+ setview("databases", viewdblist_show);
+}
+
+void
viewdblist_show(void) {
MYSQL_RES *res;
@@ -897,6 +912,7 @@ main(int argc, char **argv) {
} ARGEND;
setup();
+ startup();
run();
cleanup();
return 0;