Revise --binary functionality
This commit is contained in:
parent
0e1183a62c
commit
e586f29e6d
@ -2,7 +2,7 @@
|
|||||||
#define ARG_H
|
#define ARG_H
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define LAT_VERSION "0.9.2"
|
#define LAT_VERSION "0.9.3"
|
||||||
|
|
||||||
struct config {
|
struct config {
|
||||||
bool stdin;
|
bool stdin;
|
||||||
@ -10,7 +10,7 @@ struct config {
|
|||||||
bool color;
|
bool color;
|
||||||
bool lines;
|
bool lines;
|
||||||
bool headers;
|
bool headers;
|
||||||
bool force_binary;
|
int force_binary;
|
||||||
bool has_read_stdin;
|
bool has_read_stdin;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,19 +17,26 @@ void help(void) {
|
|||||||
"\t-n, --lines\t toggle whether to print line numbers or not\n"
|
"\t-n, --lines\t toggle whether to print line numbers or not\n"
|
||||||
"\t-t, --headers\t toggle whether to print file headers or not\n"
|
"\t-t, --headers\t toggle whether to print file headers or not\n"
|
||||||
"\t-b, --binary\t toggle whether to force the data to be treated as "
|
"\t-b, --binary\t toggle whether to force the data to be treated as "
|
||||||
"binary or not\n"
|
"binary or not. see examples\n"
|
||||||
"\t-V, --version\t show program version\n"
|
"\t-V, --version\t show program version\n"
|
||||||
"\t-h, --help\t display this help text\n\n");
|
"\t-h, --help\t display this help text\n\n");
|
||||||
printf("environment:\n"
|
printf("environment:\n"
|
||||||
"\tNO_COLOR, see https://no-color.org/\n\n");
|
"\tNO_COLOR, see https://no-color.org/\n\n");
|
||||||
printf("examples:\n"
|
printf(
|
||||||
"\tlat file1\n\t\t print the content of file1 witht default formatting\n"
|
"examples:\n"
|
||||||
"\tlat - file1\n\t\t read from stdin (the '-' character reads from stdin) "
|
"\tlat file1\n\t\t print the content of file1 witht default formatting\n"
|
||||||
"and then print the contents of stdin and file1\n"
|
"\tlat - file1\n\t\t read from stdin (the '-' character reads from "
|
||||||
"\tlat -nc file1 file2\n\t\t print the contents of file1 and file2 "
|
"stdin) "
|
||||||
"without printing line numbers or colors\n"
|
"and then print the contents of stdin and file1\n"
|
||||||
"\tcurl example.com | lat\n\t\t pipe the results of 'curl example.com' "
|
"\tlat --lines --color file1 file2\n\t\t print the contents of file1 and "
|
||||||
"into lat\n");
|
"file2 "
|
||||||
|
"without printing line numbers or colors\n"
|
||||||
|
"\tlat --binary file.txt\n\t\t force file.txt to be treated as a binary "
|
||||||
|
"file\n"
|
||||||
|
"\tlat -bb file.txt\n\t\t force file.txt to NOT be treated as a binary "
|
||||||
|
"file\n"
|
||||||
|
"\tcurl example.com | lat\n\t\t pipe the results of 'curl example.com' "
|
||||||
|
"into lat\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void version(void) {
|
void version(void) {
|
||||||
@ -62,7 +69,10 @@ void parselongarg(char *arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(arg, "--binary") == 0) {
|
if (strcmp(arg, "--binary") == 0) {
|
||||||
conf.force_binary = !conf.force_binary;
|
if (conf.force_binary < 0)
|
||||||
|
conf.force_binary = 1;
|
||||||
|
else
|
||||||
|
conf.force_binary = !conf.force_binary;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +106,10 @@ void parseshortarg(char *arg) {
|
|||||||
conf.headers = !conf.headers;
|
conf.headers = !conf.headers;
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
conf.force_binary = !conf.force_binary;
|
if (conf.force_binary < 0)
|
||||||
|
conf.force_binary = 1;
|
||||||
|
else
|
||||||
|
conf.force_binary = !conf.force_binary;
|
||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
version();
|
version();
|
||||||
|
@ -23,8 +23,10 @@ void run(FILE *fp, char *filename, bool tty) {
|
|||||||
struct filedata f;
|
struct filedata f;
|
||||||
f = readfile(fp, conf.stdin);
|
f = readfile(fp, conf.stdin);
|
||||||
|
|
||||||
if (conf.force_binary) {
|
if (conf.force_binary > 0) {
|
||||||
f.binary = !f.binary;
|
f.binary = true;
|
||||||
|
} else if (conf.force_binary == 0) {
|
||||||
|
f.binary = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
conf.headers = conf.headers && tty; // tty still overrides user
|
conf.headers = conf.headers && tty; // tty still overrides user
|
||||||
@ -72,7 +74,7 @@ void run(FILE *fp, char *filename, bool tty) {
|
|||||||
|
|
||||||
void initconf(void) {
|
void initconf(void) {
|
||||||
conf.stdin = false;
|
conf.stdin = false;
|
||||||
conf.force_binary = false;
|
conf.force_binary = -1;
|
||||||
conf.has_read_stdin = false;
|
conf.has_read_stdin = false;
|
||||||
conf.process = true;
|
conf.process = true;
|
||||||
conf.headers = true;
|
conf.headers = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user