cake
/
p7utils
Archived
1
0
Fork 0

Corrected sum' stupid things man.

This commit is contained in:
Thomas Touhey 2017-01-17 00:55:06 +01:00
parent eca43beea1
commit f062634a3f
4 changed files with 47 additions and 33 deletions

View File

@ -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); \

View File

@ -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);
}

View File

@ -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;

View File

@ -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);