X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=ui%2Fncurses%2Fgeneric-main.c;h=f253469f18832da67ff44102c6d3f5fbfa2616aa;hp=2cfb9c319f634d2570662b350d3ef598e8a9056c;hb=4e30f260106ac5f7007e213db1d1e54298393290;hpb=bebb24a9f49cb4eb81df2aa3dd9de94db965536d diff --git a/ui/ncurses/generic-main.c b/ui/ncurses/generic-main.c index 2cfb9c3..f253469 100644 --- a/ui/ncurses/generic-main.c +++ b/ui/ncurses/generic-main.c @@ -28,15 +28,19 @@ #include #include #include +#include #include +#include +#include #include "log/log.h" #include "talloc/talloc.h" #include "waiter/waiter.h" +#include "i18n/i18n.h" #include "ui/common/discover-client.h" #include "nc-cui.h" -extern const char *main_menu_help_text; +extern const struct help_text main_menu_help_text; static void print_version(void) { @@ -47,8 +51,9 @@ static void print_usage(void) { print_version(); printf( -"Usage: petitboot-nc [-h, --help] [-l, --log log-file]\n" -" [-s, --start-daemon] [-V, --version]\n"); +"%s: petitboot-nc [-h, --help] [-l, --log log-file]\n" +" [-s, --start-daemon] [-v, --verbose] [-V, --version]\n", + _("Usage")); } /** @@ -65,6 +70,7 @@ struct opts { enum opt_value show_help; const char *log_file; enum opt_value start_daemon; + enum opt_value verbose; enum opt_value show_version; }; @@ -78,13 +84,12 @@ static int opts_parse(struct opts *opts, int argc, char *argv[]) {"help", no_argument, NULL, 'h'}, {"log", required_argument, NULL, 'l'}, {"start-daemon", no_argument, NULL, 's'}, + {"verbose", no_argument, NULL, 'v'}, {"version", no_argument, NULL, 'V'}, { NULL, 0, NULL, 0}, }; - static const char short_options[] = "dhl:sV"; - static const struct opts default_values = { - .log_file = "/var/log/petitboot/petitboot-nc.log", - }; + static const char short_options[] = "dhl:svV"; + static const struct opts default_values = { 0 }; *opts = default_values; @@ -105,6 +110,9 @@ static int opts_parse(struct opts *opts, int argc, char *argv[]) case 's': opts->start_daemon = opt_yes; break; + case 'v': + opts->verbose = opt_yes; + break; case 'V': opts->show_version = opt_yes; break; @@ -117,6 +125,31 @@ static int opts_parse(struct opts *opts, int argc, char *argv[]) return 0; } +static char *default_log_filename(void) +{ + const char *base = "/var/log/petitboot/petitboot-nc"; + static char name[PATH_MAX]; + char *tty; + int i; + + tty = ttyname(STDIN_FILENO); + + /* strip /dev/ */ + if (tty && !strncmp(tty, "/dev/", 5)) + tty += 5; + + /* change slashes to hyphens */ + for (i = 0; tty && tty[i]; i++) + if (tty[i] == '/') + tty[i] = '-'; + + if (!tty || !*tty) + tty = "unknown"; + + snprintf(name, sizeof(name), "%s.%s.log", base, tty); + + return name; +} /** * struct pb_cui - Main cui program instance. * @mm: Main menu. @@ -169,19 +202,28 @@ static struct pmenu *pb_mm_init(struct pb_cui *pb_cui) "Petitboot (" PACKAGE_VERSION ")"); m->scr.frame.rtitle = NULL; m->scr.frame.help = talloc_strdup(m, - "Enter=accept, e=edit, n=new, x=exit, h=help"); - m->scr.frame.status = talloc_strdup(m, "Welcome to Petitboot"); + _("Enter=accept, e=edit, n=new, x=exit, h=help")); + m->scr.frame.status = talloc_strdup(m, _("Welcome to Petitboot")); - i = pmenu_item_init(m, 0, " "); + i = pmenu_item_create(m, " "); item_opts_off(i->nci, O_SELECTABLE); - i = pmenu_item_init(m, 1, "System information"); + pmenu_item_insert(m, i, 0); + + i = pmenu_item_create(m, _("System information")); i->on_execute = pmenu_sysinfo; - i = pmenu_item_init(m, 2, "System configuration"); + pmenu_item_insert(m, i, 1); + + i = pmenu_item_create(m, _("System configuration")); i->on_execute = pmenu_config; - i = pmenu_item_init(m, 3, "Rescan devices"); + pmenu_item_insert(m, i, 2); + + i = pmenu_item_create(m, _("Rescan devices")); i->on_execute = pmenu_reinit; - i = pmenu_item_init(m, 4, "Exit to shell"); + pmenu_item_insert(m, i, 3); + + i = pmenu_item_create(m, _("Exit to shell")); i->on_execute = pmenu_exit_cb; + pmenu_item_insert(m, i, 4); result = pmenu_setup(m); @@ -191,8 +233,8 @@ static struct pmenu *pb_mm_init(struct pb_cui *pb_cui) goto fail_setup; } - m->help_title = "main menu"; - m->help_text = main_menu_help_text; + m->help_title = _("main menu"); + m->help_text = &main_menu_help_text; menu_opts_off(m->ncm, O_SHOWDESC); set_menu_mark(m->ncm, " *"); @@ -235,6 +277,7 @@ static void sig_handler(int signum) int main(int argc, char *argv[]) { static struct sigaction sa; + const char *log_filename; int result; int cui_result; struct opts opts; @@ -242,6 +285,10 @@ int main(int argc, char *argv[]) result = opts_parse(&opts, argc, argv); + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + if (result) { print_usage(); return EXIT_FAILURE; @@ -257,9 +304,14 @@ int main(int argc, char *argv[]) return EXIT_SUCCESS; } + if (opts.log_file) + log_filename = opts.log_file; + else + log_filename = default_log_filename(); + log = stderr; - if (strcmp(opts.log_file, "-")) { - log = fopen(opts.log_file, "a"); + if (strcmp(log_filename, "-")) { + log = fopen(log_filename, "a"); if (!log) log = fopen("/dev/null", "a"); @@ -267,6 +319,9 @@ int main(int argc, char *argv[]) pb_log_init(log); + if (opts.verbose == opt_yes) + pb_log_set_debug(true); + pb_log("--- petitboot-nc ---\n"); sa.sa_handler = sig_handler;