--loop option to read input file again and again.

This commit is contained in:
antirez 2020-02-03 16:15:05 +01:00
parent 07d194bbd5
commit db9f5f34a3

View File

@ -155,6 +155,7 @@ struct {
/* Configuration */
char *filename; /* Input form file, --ifile option. */
int loop; /* Read input file again and again. */
int fix_errors; /* Single bit error correction if true. */
int check_crc; /* Only display messages with good CRC. */
int raw; /* Raw output format. */
@ -274,6 +275,7 @@ void modesInitConfig(void) {
Modes.interactive_ttl = MODES_INTERACTIVE_TTL;
Modes.aggressive = 0;
Modes.interactive_rows = getTermRows();
Modes.loop = 0;
}
void modesInit(void) {
@ -434,10 +436,11 @@ void readDataFromFile(void) {
while(toread) {
nread = read(Modes.fd, p, toread);
/* In --file mode, seek the file again from the start
* and re-play it. */
* and re-play it if --loop was given. */
if (nread == 0 &&
Modes.filename != NULL &&
Modes.fd != STDIN_FILENO)
Modes.fd != STDIN_FILENO &&
Modes.loop)
{
if (lseek(Modes.fd,0,SEEK_SET) != -1) continue;
}
@ -2440,6 +2443,7 @@ void showHelp(void) {
"--enable-agc Enable the Automatic Gain Control (default: off).\n"
"--freq <hz> Set frequency (default: 1090 Mhz).\n"
"--ifile <filename> Read data from file (use '-' for stdin).\n"
"--loop With --ifile, read the same file in a loop.\n"
"--interactive Interactive mode refreshing data on screen.\n"
"--interactive-rows <num> Max number of rows in interactive mode (default: 15).\n"
"--interactive-ttl <sec> Remove from list if idle for <sec> (default: 60).\n"
@ -2511,6 +2515,8 @@ int main(int argc, char **argv) {
Modes.freq = strtoll(argv[++j],NULL,10);
} else if (!strcmp(argv[j],"--ifile") && more) {
Modes.filename = strdup(argv[++j]);
} else if (!strcmp(argv[j],"--loop")) {
Modes.loop = 1;
} else if (!strcmp(argv[j],"--no-fix")) {
Modes.fix_errors = 0;
} else if (!strcmp(argv[j],"--no-crc-check")) {