From f062634a3fcd13256cdfe19754691e8302d27646 Mon Sep 17 00:00:00 2001 From: "Thomas \"Cakeisalie5\" Touhey" Date: Tue, 17 Jan 2017 00:55:06 +0100 Subject: [PATCH] Corrected sum' stupid things man. --- src/p7os/args.c | 1 + src/p7os/main.c | 68 +++++++++++++++++++++++++++------------------- src/p7os/main.h | 8 ++---- src/p7os/prepare.c | 3 ++ 4 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/p7os/args.c b/src/p7os/args.c index 7d309b5..cc95413 100644 --- a/src/p7os/args.c +++ b/src/p7os/args.c @@ -76,6 +76,7 @@ FOOT; /* ************************************************************************** */ /* Help macro */ #define sub_init(CMD, NARGS) { \ + args->menu = mn_##CMD; \ if (help || pc != (NARGS)) { \ puts(help_##CMD); \ return (1); \ diff --git a/src/p7os/main.c b/src/p7os/main.c index 5bd4ad4..dcf9ee8 100644 --- a/src/p7os/main.c +++ b/src/p7os/main.c @@ -60,49 +60,61 @@ int main(int ac, char **av) p7_handle_t *handle; int err; if (args.com) err = p7_cominit(&handle, 1, 1, args.com); else err = p7_init(&handle, 1, 1); - if (err) { - /* displaying error */ - switch (err) { - case p7_error_nocalc: log(error_noconnexion); break; - case p7_error_noaccess: log(error_noaccess); break; - case p7_error_unsupported: log(error_unsupported); break; - default: log(error_unplanned, p7_strerror(err)); - } - - /* closing, removing if necessary */ - if (args.localpath) { - fclose(args.local); - remove(args.localpath); - } - return (1); - } + if (err) goto init_error; /* prepare */ - if (!args.noprepare && prepare_ops(handle, args.uexe)) { - if (args.local) fclose(args.local); - return (1); + if (!args.noprepare) { + /* make the preparation thing */ + if (prepare_ops(handle, args.uexe)) { + if (args.local) fclose(args.local); + return (1); + } + handle = NULL; + + /* was only about preparing? */ + if (args.menu == mn_prepare_only) + return (0); + + /* sleep a little, in case */ + sleep(1); + + /* re-open the handle */ + if (args.com) err = p7_cominit(&handle, 1, 1, args.com); + else err = p7_init(&handle, 1, 1); + if (err) goto init_error; } /* check according to menu */ switch (args.menu) { - /* prepare-only menu, skip */ - case mn_prepare_only: break; - - /* get menu */ + /* backup the thing menu */ case mn_get: /* get the os */ fprintf(stderr, "Unimplemented, yet.\n"); err = 1; fclose(args.local); /* if there was an error, delete created file */ - if (err) unlink(args.localpath); + if (err) remove(args.localpath); break; } - /* exit libp7 - * due to the nature of command 0x56, - * no need to terminate communication! */ - p7_exit(handle, 0); + /* exit libp7 */ + p7_exit(handle, 1); /* then we're good */ return (0); + +init_error: + /* displaying error */ + switch (err) { + case p7_error_nocalc: log(error_noconnexion); break; + case p7_error_noaccess: log(error_noaccess); break; + case p7_error_unsupported: log(error_unsupported); break; + default: log(error_unplanned, p7_strerror(err)); + } + + /* closing, removing if necessary */ + if (args.localpath) { + fclose(args.local); + remove(args.localpath); + } + return (1); } diff --git a/src/p7os/main.h b/src/p7os/main.h index 6e40457..da7dfb4 100644 --- a/src/p7os/main.h +++ b/src/p7os/main.h @@ -19,15 +19,13 @@ /* CLI options */ /* ************************************************************************** */ /* Menu */ -typedef enum { - mn_prepare_only, - mn_get -} menu_t; +# define mn_prepare_only 1 +# define mn_get 2 /* Arguments */ typedef struct { /* basic things */ - menu_t menu; + int menu; /* communication and tweaks */ int com, noprepare; diff --git a/src/p7os/prepare.c b/src/p7os/prepare.c index eb94637..e1f08cc 100644 --- a/src/p7os/prepare.c +++ b/src/p7os/prepare.c @@ -68,6 +68,9 @@ int prepare_ops(p7_handle_t *handle, FILE *uexe) return (1); } + /* close the handle */ + p7_exit(handle, 0); + /* no error! */ fclose(uexe); return (0);