Mercurial > projects > pwm
diff pwm.c @ 22:ec01c579024a
Add fully interactive mode
author | Guido Berhoerster <guido+pwm@berhoerster.name> |
---|---|
date | Thu, 07 Sep 2017 12:40:50 +0200 |
parents | ee4d36c85287 |
children | 1b89066d992c |
line wrap: on
line diff
--- a/pwm.c Wed Sep 06 16:41:58 2017 +0200 +++ b/pwm.c Thu Sep 07 12:40:50 2017 +0200 @@ -101,7 +101,7 @@ } static int -run_input_loop(struct pwm_ctx *ctx, int is_interactive) +run_input_loop(struct pwm_ctx *ctx) { int retval = -1; char prompt[8 + 2 + 1]; @@ -141,7 +141,7 @@ fprintf(stderr, "line too long\n"); goto out; case IO_EOF: - if (is_interactive) { + if (ctx->is_interactive) { /* treat as "q" command */ strcpy(buf, "q\n"); io_retval = IO_OK; @@ -164,13 +164,13 @@ err(1, "tok_tokenize"); case TOK_ERR_UNTERMINATED_QUOTE: fprintf(stderr, "unterminated quote\n"); - if (!is_interactive) { + if (!ctx->is_interactive) { goto out; } goto next; case TOK_ERR_TRAILING_BACKSLASH: fprintf(stderr, "trailing backslash\n"); - if (!is_interactive) { + if (!ctx->is_interactive) { goto out; } goto next; @@ -185,7 +185,7 @@ cmd = cmd_match(argv[0]); if (cmd == NULL) { pwm_err(ctx, "unknown command: %s", argv[0]); - if (is_interactive) { + if (ctx->is_interactive) { goto next; } else { goto out; @@ -198,7 +198,7 @@ case CMD_USAGE: fprintf(stderr, "usage: %s\n", cmd->usage); case CMD_ERR: /* FALLTHROUGH */ - if (!is_interactive) { + if (!ctx->is_interactive) { goto out; } break; @@ -310,7 +310,6 @@ { int status = EXIT_FAILURE; char *locale; - int is_interactive; int errflag = 0; int c; const char *master_password_filename = NULL; @@ -343,7 +342,7 @@ goto out; } - is_interactive = isatty(STDIN_FILENO); + ctx.is_interactive = isatty(STDIN_FILENO); while (!errflag && (c = getopt(argc, argv, "P:h")) != -1) { switch (c) { @@ -386,7 +385,7 @@ goto out; } - if (is_interactive) { + if (ctx.is_interactive) { printf("pwm version %s\n", VERSION); } else if (master_password_filename == NULL) { fprintf(stderr, "master password file must be specified when " @@ -419,7 +418,7 @@ } /* run main input loop */ - status = (run_input_loop(&ctx, is_interactive) != 0); + status = (run_input_loop(&ctx) != 0); out: pwfile_destroy(&ctx);