opensc-explorer: fix&clarify handling of interactive mode
* make 'interactive' a global variable * set it when opensc was called with the SCRIPT argument * document the behaviour in the manual page Make interactive a global variable and set it in main.
This commit is contained in:
parent
c5679bfe39
commit
9616ad4d94
@ -28,10 +28,18 @@
|
|||||||
<title>Description</title>
|
<title>Description</title>
|
||||||
<para>
|
<para>
|
||||||
The <command>opensc-explorer</command> utility can be
|
The <command>opensc-explorer</command> utility can be
|
||||||
used interactively to perform miscellaneous operations
|
used to perform miscellaneous operations
|
||||||
such as exploring the contents of or sending arbitrary
|
such as exploring the contents of or sending arbitrary
|
||||||
APDU commands to a smart card or similar security token.
|
APDU commands to a smart card or similar security token.
|
||||||
</para>
|
</para>
|
||||||
|
<para>
|
||||||
|
If a <replaceable class="parameter">SCRIPT</replaceable> is given,
|
||||||
|
<command>opensc-explorer</command> runs in non-interactive mode,
|
||||||
|
reading the commands from <replaceable class="parameter">SCRIPT</replaceable>,
|
||||||
|
one command per line.
|
||||||
|
If no script is given, <command>opensc-explorer</command>
|
||||||
|
runs in interactive mode, reading commands from standard input.
|
||||||
|
</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
<refsect1>
|
<refsect1>
|
||||||
|
@ -63,6 +63,7 @@ static sc_file_t *current_file = NULL;
|
|||||||
static sc_path_t current_path;
|
static sc_path_t current_path;
|
||||||
static sc_context_t *ctx = NULL;
|
static sc_context_t *ctx = NULL;
|
||||||
static sc_card_t *card = NULL;
|
static sc_card_t *card = NULL;
|
||||||
|
static int interactive = 1;
|
||||||
|
|
||||||
static const struct option options[] = {
|
static const struct option options[] = {
|
||||||
{ "reader", 1, NULL, 'r' },
|
{ "reader", 1, NULL, 'r' },
|
||||||
@ -2051,19 +2052,14 @@ static char *read_cmdline(FILE *script, char *prompt)
|
|||||||
{
|
{
|
||||||
static char buf[SC_MAX_EXT_APDU_BUFFER_SIZE];
|
static char buf[SC_MAX_EXT_APDU_BUFFER_SIZE];
|
||||||
static int initialized;
|
static int initialized;
|
||||||
static int interactive;
|
|
||||||
|
|
||||||
if (!initialized) {
|
|
||||||
initialized = 1;
|
|
||||||
interactive = isatty(fileno(script));
|
|
||||||
#ifdef ENABLE_READLINE
|
|
||||||
if (interactive)
|
|
||||||
using_history();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
if (interactive) {
|
if (interactive) {
|
||||||
#ifdef ENABLE_READLINE
|
#ifdef ENABLE_READLINE
|
||||||
|
if (!initialized) {
|
||||||
|
initialized = 1;
|
||||||
|
using_history();
|
||||||
|
}
|
||||||
|
|
||||||
char *line = readline(prompt);
|
char *line = readline(prompt);
|
||||||
|
|
||||||
/* add line to history if longer than 2 characters */
|
/* add line to history if longer than 2 characters */
|
||||||
@ -2196,9 +2192,11 @@ int main(int argc, char *argv[])
|
|||||||
util_print_usage_and_die(app_name, options, option_help, "[SCRIPT]");
|
util_print_usage_and_die(app_name, options, option_help, "[SCRIPT]");
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
|
interactive = 1;
|
||||||
script = stdin;
|
script = stdin;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
interactive = 0;
|
||||||
if (strcmp(argv[optind], "-") == 0) {
|
if (strcmp(argv[optind], "-") == 0) {
|
||||||
script = stdin;
|
script = stdin;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user