tamashell: accepts script as arg, this makes shebang possible
This commit is contained in:
parent
8c3caed99f
commit
af7d04cd04
2 changed files with 48 additions and 27 deletions
|
@ -3,6 +3,7 @@
|
||||||
pn53x-tamashell \- PN53x TAMA communication demonstration shell
|
pn53x-tamashell \- PN53x TAMA communication demonstration shell
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B pn53x-tamashell
|
.B pn53x-tamashell
|
||||||
|
.IR [script]
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
.B pn53x-tamashell
|
.B pn53x-tamashell
|
||||||
is a simple interactive tool to send so called TAMA commands
|
is a simple interactive tool to send so called TAMA commands
|
||||||
|
@ -50,6 +51,10 @@ Same thing, with a script:
|
||||||
Rx: Command Not Acceptable
|
Rx: Command Not Acceptable
|
||||||
> Bye!
|
> Bye!
|
||||||
|
|
||||||
|
.SH OPTIONS
|
||||||
|
.IR script
|
||||||
|
Script file with tama commands
|
||||||
|
|
||||||
.SH BUGS
|
.SH BUGS
|
||||||
Please report any bugs on the
|
Please report any bugs on the
|
||||||
.B libnfc
|
.B libnfc
|
||||||
|
|
|
@ -36,15 +36,12 @@
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif // HAVE_CONFIG_H
|
#endif // HAVE_CONFIG_H
|
||||||
|
|
||||||
#if defined(HAVE_READLINE)
|
|
||||||
# include <stdio.h>
|
|
||||||
# include <readline/readline.h>
|
|
||||||
# include <readline/history.h>
|
|
||||||
#else
|
|
||||||
# define _GNU_SOURCE // for getline on system with glibc < 2.10
|
# define _GNU_SOURCE // for getline on system with glibc < 2.10
|
||||||
# define _POSIX_C_SOURCE 200809L // for getline on system with glibc >= 2.10
|
# define _POSIX_C_SOURCE 200809L // for getline on system with glibc >= 2.10
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
extern FILE* stdin;
|
#if defined(HAVE_READLINE)
|
||||||
|
# include <readline/readline.h>
|
||||||
|
# include <readline/history.h>
|
||||||
#endif //HAVE_READLINE
|
#endif //HAVE_READLINE
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -68,6 +65,15 @@ int main(int argc, const char* argv[])
|
||||||
byte_t abtTx[MAX_FRAME_LEN] = { 0xD4 };
|
byte_t abtTx[MAX_FRAME_LEN] = { 0xD4 };
|
||||||
size_t szRx;
|
size_t szRx;
|
||||||
size_t szTx;
|
size_t szTx;
|
||||||
|
extern FILE* stdin;
|
||||||
|
FILE* input = NULL;
|
||||||
|
|
||||||
|
if (argc >= 2) {
|
||||||
|
if((input=fopen(argv[1], "r"))==NULL) {
|
||||||
|
ERR ("%s", "Cannot open file.");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Try to open the NFC reader
|
// Try to open the NFC reader
|
||||||
pnd = nfc_connect(NULL);
|
pnd = nfc_connect(NULL);
|
||||||
|
@ -78,7 +84,6 @@ int main(int argc, const char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("Connected to NFC reader: %s\n", pnd->acName);
|
printf ("Connected to NFC reader: %s\n", pnd->acName);
|
||||||
|
|
||||||
nfc_initiator_init(pnd);
|
nfc_initiator_init(pnd);
|
||||||
|
|
||||||
char * cmd;
|
char * cmd;
|
||||||
|
@ -86,6 +91,7 @@ int main(int argc, const char* argv[])
|
||||||
while(1) {
|
while(1) {
|
||||||
int offset=0;
|
int offset=0;
|
||||||
#if defined(HAVE_READLINE)
|
#if defined(HAVE_READLINE)
|
||||||
|
if (input==NULL) { // means we use stdin
|
||||||
cmd=readline(prompt);
|
cmd=readline(prompt);
|
||||||
// NULL if ctrl-d
|
// NULL if ctrl-d
|
||||||
if (cmd==NULL) {
|
if (cmd==NULL) {
|
||||||
|
@ -93,13 +99,18 @@ int main(int argc, const char* argv[])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
add_history(cmd);
|
add_history(cmd);
|
||||||
#else
|
} else {
|
||||||
|
#endif //HAVE_READLINE
|
||||||
cmd = NULL;
|
cmd = NULL;
|
||||||
printf("%s", prompt);
|
printf("%s", prompt);
|
||||||
fflush(0);
|
fflush(0);
|
||||||
size_t n;
|
size_t n;
|
||||||
extern FILE* stdin;
|
int s;
|
||||||
int s = getline(&cmd, &n, stdin);
|
if (input != NULL) {
|
||||||
|
s = getline(&cmd, &n, input);
|
||||||
|
} else {
|
||||||
|
s = getline(&cmd, &n, stdin);
|
||||||
|
}
|
||||||
if (s <= 0) {
|
if (s <= 0) {
|
||||||
printf("Bye!\n");
|
printf("Bye!\n");
|
||||||
free(cmd);
|
free(cmd);
|
||||||
|
@ -107,6 +118,8 @@ int main(int argc, const char* argv[])
|
||||||
}
|
}
|
||||||
// FIXME print only if read from redirected stdin (i.e. script)
|
// FIXME print only if read from redirected stdin (i.e. script)
|
||||||
printf("%s", cmd);
|
printf("%s", cmd);
|
||||||
|
#if defined(HAVE_READLINE)
|
||||||
|
}
|
||||||
#endif //HAVE_READLINE
|
#endif //HAVE_READLINE
|
||||||
if (cmd[0]=='q') {
|
if (cmd[0]=='q') {
|
||||||
printf("Bye!\n");
|
printf("Bye!\n");
|
||||||
|
@ -151,6 +164,9 @@ int main(int argc, const char* argv[])
|
||||||
free(cmd);
|
free(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (input != NULL) {
|
||||||
|
fclose(input);
|
||||||
|
}
|
||||||
nfc_disconnect(pnd);
|
nfc_disconnect(pnd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue