]> git.ozlabs.org Git - petitboot/blobdiff - ui/ncurses/generic-main.c
discover/grub2: Allow empty statements
[petitboot] / ui / ncurses / generic-main.c
index 9a22265811bd3c87cb49e4191a817160d24d2ff0..9236a800beac18a11d1041037955687f109364c6 100644 (file)
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#if defined(HAVE_CONFIG_H)
 #include "config.h"
 #include "config.h"
-#endif
 
 #define _GNU_SOURCE
 
 #define _GNU_SOURCE
+
+#include <assert.h>
 #include <errno.h>
 #include <getopt.h>
 #include <signal.h>
 #include <errno.h>
 #include <getopt.h>
 #include <signal.h>
@@ -45,7 +45,7 @@ static void print_usage(void)
 {
        print_version();
        printf(
 {
        print_version();
        printf(
-"Usage: petitboot-nc [-d, --dry-run] [-h, --help] [-l, --log log-file]\n"
+"Usage: petitboot-nc [-h, --help] [-l, --log log-file]\n"
 "                    [-s, --start-daemon] [-V, --version]\n");
 }
 
 "                    [-s, --start-daemon] [-V, --version]\n");
 }
 
@@ -60,7 +60,6 @@ enum opt_value {opt_undef = 0, opt_yes, opt_no};
  */
 
 struct opts {
  */
 
 struct opts {
-       enum opt_value dry_run;
        enum opt_value show_help;
        const char *log_file;
        enum opt_value start_daemon;
        enum opt_value show_help;
        const char *log_file;
        enum opt_value start_daemon;
@@ -74,7 +73,6 @@ struct opts {
 static int opts_parse(struct opts *opts, int argc, char *argv[])
 {
        static const struct option long_options[] = {
 static int opts_parse(struct opts *opts, int argc, char *argv[])
 {
        static const struct option long_options[] = {
-               {"dry-run",      no_argument,       NULL, 'd'},
                {"help",         no_argument,       NULL, 'h'},
                {"log",          required_argument, NULL, 'l'},
                {"start-daemon", no_argument,       NULL, 's'},
                {"help",         no_argument,       NULL, 'h'},
                {"log",          required_argument, NULL, 'l'},
                {"start-daemon", no_argument,       NULL, 's'},
@@ -96,9 +94,6 @@ static int opts_parse(struct opts *opts, int argc, char *argv[])
                        break;
 
                switch (c) {
                        break;
 
                switch (c) {
-               case 'd':
-                       opts->dry_run = opt_yes;
-                       break;
                case 'h':
                        opts->show_help = opt_yes;
                        break;
                case 'h':
                        opts->show_help = opt_yes;
                        break;
@@ -129,34 +124,8 @@ static int opts_parse(struct opts *opts, int argc, char *argv[])
 struct pb_cui {
        struct pmenu *mm;
        struct cui *cui;
 struct pb_cui {
        struct pmenu *mm;
        struct cui *cui;
-       struct opts opts;
 };
 
 };
 
-static struct pb_cui *pb_from_cui(struct cui *cui)
-{
-       struct pb_cui *pb;
-
-       assert(cui->c_sig == pb_cui_sig);
-       pb = cui->platform_info;
-       assert(pb->cui->c_sig == pb_cui_sig);
-       return pb;
-}
-
-/**
- * pb_kexec_cb - The kexec callback.
- */
-
-static int pb_kexec_cb(struct cui *cui, struct cui_opt_data *cod)
-{
-       struct pb_cui *pb = pb_from_cui(cui);
-
-       pb_log("%s: %s\n", __func__, cod->name);
-
-       assert(pb->cui->current == &pb->cui->main->scr);
-
-       return pb_run_kexec(cod->kd, pb->opts.dry_run);
-}
-
 /**
  * pb_mm_init - Setup the main menu instance.
  */
 /**
  * pb_mm_init - Setup the main menu instance.
  */
@@ -176,7 +145,8 @@ static struct pmenu *pb_mm_init(struct pb_cui *pb_cui)
 
        m->on_open = cui_on_open;
 
 
        m->on_open = cui_on_open;
 
-       m->scr.frame.title = talloc_strdup(m, "Petitboot");
+       m->scr.frame.title = talloc_asprintf(m,
+               "Petitboot (" PACKAGE_VERSION ")");
        m->scr.frame.help = talloc_strdup(m,
                "ESC=exit, Enter=accept, e=edit, o=open");
        m->scr.frame.status = talloc_strdup(m, "Welcome to Petitboot");
        m->scr.frame.help = talloc_strdup(m,
                "ESC=exit, Enter=accept, e=edit, o=open");
        m->scr.frame.status = talloc_strdup(m, "Welcome to Petitboot");
@@ -210,10 +180,6 @@ static void sig_handler(int signum)
        DBGS("%d\n", signum);
 
        switch (signum) {
        DBGS("%d\n", signum);
 
        switch (signum) {
-       case SIGALRM:
-               if (pb.cui)
-                       ui_timer_sigalrm(&pb.cui->timer);
-               break;
        case SIGWINCH:
                if (pb.cui)
                        cui_resize(pb.cui);
        case SIGWINCH:
                if (pb.cui)
                        cui_resize(pb.cui);
@@ -239,35 +205,35 @@ int main(int argc, char *argv[])
        static struct sigaction sa;
        int result;
        int cui_result;
        static struct sigaction sa;
        int result;
        int cui_result;
+       struct opts opts;
+       FILE *log;
 
 
-       result = opts_parse(&pb.opts, argc, argv);
+       result = opts_parse(&opts, argc, argv);
 
        if (result) {
                print_usage();
                return EXIT_FAILURE;
        }
 
 
        if (result) {
                print_usage();
                return EXIT_FAILURE;
        }
 
-       if (pb.opts.show_help == opt_yes) {
+       if (opts.show_help == opt_yes) {
                print_usage();
                return EXIT_SUCCESS;
        }
 
                print_usage();
                return EXIT_SUCCESS;
        }
 
-       if (pb.opts.show_version == opt_yes) {
+       if (opts.show_version == opt_yes) {
                print_version();
                return EXIT_SUCCESS;
        }
 
                print_version();
                return EXIT_SUCCESS;
        }
 
-       if (strcmp(pb.opts.log_file, "-")) {
-               FILE *log = fopen(pb.opts.log_file, "a");
+       log = stderr;
+       if (strcmp(opts.log_file, "-")) {
+               log = fopen(opts.log_file, "a");
 
 
-               assert(log);
-               pb_log_set_stream(log);
-       } else
-               pb_log_set_stream(stderr);
+               if (!log)
+                       log = fopen("/dev/null", "a");
+       }
 
 
-#if defined(DEBUG)
-       pb_log_always_flush(1);
-#endif
+       pb_log_init(log);
 
        pb_log("--- petitboot-nc ---\n");
 
 
        pb_log("--- petitboot-nc ---\n");
 
@@ -283,13 +249,12 @@ int main(int argc, char *argv[])
                return EXIT_FAILURE;
        }
 
                return EXIT_FAILURE;
        }
 
-       pb.cui = cui_init(&pb, pb_kexec_cb, NULL, pb.opts.start_daemon);
+       pb.cui = cui_init(&pb, NULL, opts.start_daemon);
 
        if (!pb.cui)
                return EXIT_FAILURE;
 
        pb.mm = pb_mm_init(&pb);
 
        if (!pb.cui)
                return EXIT_FAILURE;
 
        pb.mm = pb_mm_init(&pb);
-       ui_timer_disable(&pb.cui->timer);
 
        cui_result = cui_run(pb.cui, pb.mm, 0);
 
 
        cui_result = cui_run(pb.cui, pb.mm, 0);