aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--uxd.110
-rw-r--r--uxd.c79
-rw-r--r--uxd.rst10
3 files changed, 82 insertions, 17 deletions
diff --git a/uxd.1 b/uxd.1
index ee2e88e..4d102b5 100644
--- a/uxd.1
+++ b/uxd.1
@@ -55,6 +55,10 @@ to a pager, try \fBless \-R\fP\&.
These options can be used on the command line, and/or in the
\fBUXD_OPTS\fP environment variable. The command line takes precedence
over the environment.
+.sp
+Options can be bundled: \fB\-ubc1234\fP is the same as \fB\-u\fP \fB\-n\fP \fB\-c
+1234\fP\&. The one exception is the \fB\-n\fP option, which should appear
+by itself.
.INDENT 0.0
.TP
.B \-b
@@ -84,6 +88,10 @@ Use this if you have trouble distinguishing the colors, or if they
look too much like angry fruit salad.
NOT IMPLEMENTED YET.
.TP
+.B \-n
+Ignore \fBUXD_OPTS\fP environment variable. This option should not be
+bundled with other options (e.g. use \fB\-n \-u\fP, not \fB\-nu\fP).
+.TP
.BI \-o \ offset
Add this amount to the hex offsets (left column). May be negative,
if you can think of a reason to want it to be. Can be given in
@@ -252,13 +260,11 @@ any files other than standard output. There\(aqs no config file.
.B \fBUXD_OPTS\fP
If this is set, its value is treated as a set of options, which
get applied before any command\-line options.
-NOT IMPLEMENTED YET.
.TP
.B \fBNO_COLOR\fP
If this is set (to any value), \fBuxd\fP runs in monochrome mode, just
as though the \fB\-m\fP option were given. This variable is also
respected by \fBxxd\fP\&.
-NOT IMPLEMENTED YET.
.UNINDENT
.sp
It\(aqs \fInot\fP necessary to have a UTF\-8 locale set in e.g. \fBLANG\fP or
diff --git a/uxd.c b/uxd.c
index de6501a..3fc0bbb 100644
--- a/uxd.c
+++ b/uxd.c
@@ -46,6 +46,10 @@ extern int optind;
#define BUFSIZ 4096
#endif
+#define NO_COLOR "NO_COLOR"
+#define ENV_OPTS "UXD_OPTS"
+#define MAX_ARGS 64
+
/* ANSI colors */
#define BLACK 0 /* don't use (could be the background color) */
#define RED 1
@@ -76,6 +80,18 @@ char right_buf[4096];
int dump_column = 0;
int filepos = 0;
+/* Unicode control character printable equivalents. For 0, use
+ the "empty set" symbol. It's a lot more readable than the "nul"
+ symbol, ␀. Escape, tab, newline, space are what urxvt uses in
+ its "keycap picture" mode. The rest of there are hard to read at
+ normal font sizes, but it's still better than using a dot for
+ everything like xxd does. */
+char * const special_symbols[] = {
+ "∅", "␁", "␂", "␃", "␄", "␅", "␆", "␇", "␈", "⇥", "↵", "␋", "␌", "␍", "␎", "␏",
+ "␐", "␑", "␒", "␓", "␔", "␕", "␖", "␗", "␘", "␙", "␚", "⎋", "␜", "␝", "␞", "␟",
+ "␣",
+};
+
/* options */
int bold = 0; /* -b */
int hilite_multi = 0; /* -r */
@@ -116,7 +132,7 @@ long parse_number(const char *s) {
return strtol(s, NULL, 0); /* TODO: error checking */
}
-void parse_options(int argc, char **argv) {
+void parse_args(int argc, char **argv) {
int opt;
if(argc > 1) {
@@ -126,8 +142,10 @@ void parse_options(int argc, char **argv) {
version();
}
- while((opt = my_getopt(argc, argv, "bl:rmo:S:s:uhv")) != -1) {
+ while((opt = my_getopt(argc, argv, "nbl:rmo:S:s:uhv")) != -1) {
switch(opt) {
+ case 'n':
+ break;
case 'b':
bold = 1; break;
case 'l':
@@ -162,17 +180,52 @@ void parse_options(int argc, char **argv) {
open_input(argv[optind]);
}
-/* Unicode control character printable equivalents. For 0, use
- the "empty set" symbol. It's a lot more readable than the "nul"
- symbol, ␀. Escape, tab, newline, space are what urxvt uses in
- its "keycap picture" mode. The rest of there are hard to read at
- normal font sizes, but it's still better than using a dot for
- everything like xxd does. */
-char * const special_symbols[] = {
- "∅", "␁", "␂", "␃", "␄", "␅", "␆", "␇", "␈", "⇥", "↵", "␋", "␌", "␍", "␎", "␏",
- "␐", "␑", "␒", "␓", "␔", "␕", "␖", "␗", "␘", "␙", "␚", "⎋", "␜", "␝", "␞", "␟",
- "␣",
-};
+/* read options from the environment and the command line, create a
+ new argv/argc that has all the options from both, with the
+ environment ones first. */
+void parse_options(int argc, char **argv) {
+ int nargc;
+ char **real_argv = argv;
+ char *nargv[MAX_ARGS + 1];
+ char *env, *p;
+
+ if(getenv(NO_COLOR))
+ mono = 1;
+
+ env = getenv(ENV_OPTS);
+ if(!env) {
+ /* nothing in the env, use regular args as-is */
+ parse_args(argc, argv);
+ return;
+ }
+
+ nargv[0] = (char *)self;
+ nargv[1] = env;
+ nargc = 2;
+
+ for(p = env; *p; p++) {
+ if(*p == ' ' || *p == '\t') {
+ *p = '\0';
+ if(nargc == MAX_ARGS) break;
+ nargv[nargc++] = p + 1;
+ }
+ }
+
+ argv++; /* skip exe name */
+ while(*argv) {
+ /* have to check for the -n option here */
+ if(argv[0][0] == '-' && argv[0][1] == 'n') {
+ parse_args(argc, real_argv);
+ return;
+ }
+ if(nargc == MAX_ARGS) break;
+ nargv[nargc++] = *argv;
+ argv++;
+ }
+
+ nargv[nargc] = NULL;
+ parse_args(nargc, nargv);
+}
char *get_special(unsigned char c) {
if(c == 0x7f) return "⌦"; /* tab */
diff --git a/uxd.rst b/uxd.rst
index 8a06eab..db230ab 100644
--- a/uxd.rst
+++ b/uxd.rst
@@ -46,6 +46,10 @@ These options can be used on the command line, and/or in the
**UXD_OPTS** environment variable. The command line takes precedence
over the environment.
+Options can be bundled: **-ubc1234** is the same as **-u** **-n** **-c
+1234**. The one exception is the **-n** option, which should appear
+by itself.
+
-b
Bold output. This may be more or less readable, depending on your
terminal and its color settings. Ignored if **-m** given.
@@ -73,6 +77,10 @@ over the environment.
look too much like angry fruit salad.
NOT IMPLEMENTED YET.
+-n
+ Ignore **UXD_OPTS** environment variable. This option should not be
+ bundled with other options (e.g. use **-n -u**, not **-nu**).
+
-o offset
Add this amount to the hex offsets (left column). May be negative,
if you can think of a reason to want it to be. Can be given in
@@ -237,13 +245,11 @@ ENVIRONMENT
**UXD_OPTS**
If this is set, its value is treated as a set of options, which
get applied before any command-line options.
- NOT IMPLEMENTED YET.
**NO_COLOR**
If this is set (to any value), **uxd** runs in monochrome mode, just
as though the **-m** option were given. This variable is also
respected by **xxd**.
- NOT IMPLEMENTED YET.
It's *not* necessary to have a UTF-8 locale set in e.g. **LANG** or
**LC_ALL**. Also, the **TERM** variable is not used.