bug-datamash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

"CHAR_MIN - X" in help/version flags


From: Tim Rice
Subject: "CHAR_MIN - X" in help/version flags
Date: Fri, 5 Aug 2022 22:24:49 +0000

Hey all,

I was thinking GNU Datamash should accept -h and -V for printing help and 
version respectively. It turns out the relevant code is in system.h, where we 
can see:

```
/* These enum values cannot possibly conflict with the option values
   ordinarily used by commands, including CHAR_MAX + 1, etc.  Avoid
   CHAR_MIN - 1, as it may equal -1, the getopt end-of-options value.  */
enum
{
  GETOPT_HELP_CHAR = (CHAR_MIN - 2),
  GETOPT_VERSION_CHAR = (CHAR_MIN - 3)
};

#define GETOPT_HELP_OPTION_DECL \
  "help", no_argument, NULL, GETOPT_HELP_CHAR
#define GETOPT_VERSION_OPTION_DECL \
  "version", no_argument, NULL, GETOPT_VERSION_CHAR
```

When I do a printf on those GETOPT_(HELP|VERSION)_CHAR, I get '~' and '}'.

Yet, when I attempt to do something like `datamash -~` or `datamash -}`, it 
returns an invalid option error. I got the same response with various 
combinations of quotes and backslash-escapes around those characters.

It seems like similar code is in other GNU software like coreutils, sed and 
tar, which makes me wonder if there is some good reason why GNU has adopted the 
convention. On the other hand, I notice GNU Awk simply allows 'h' and 'V'. The 
relevant code is around line 200 of main.c in the gawk sources.

This provokes some questions:

* Is there an additional way of escaping our current options which will make 
them work correctly?

* What might be the reason for using these unconventional symbols?

* Does anyone see a problem with changing it to be like GNU Awk?

Searching the web has not provided any useful information.

Kind regards,

Tim



reply via email to

[Prev in Thread] Current Thread [Next in Thread]