forked from osmocom/wireshark
Add --help and --version long options.
Also, make the convention for long-only options be that their case-statement values start at 128, so they avoid colliding with any ASCII code points, including control characters. Make the tables of long options "static const" while we're at it, and get rid of unnecessary casts. Change-Id: I55702a85e9bc078b1cd0f2803ebb68a710405bab Reviewed-on: https://code.wireshark.org/review/2491 Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
parent
6808afd017
commit
312ed10900
|
@ -40,15 +40,30 @@
|
|||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* Attention:
|
||||
for tshark, we're using a leading - in the optstring to prevent getopt()
|
||||
from permuting the argv[] entries, in this case, unknown argv[] entries
|
||||
will be returned as parameters to a dummy-option 1
|
||||
in short: we must not use 1 here */
|
||||
|
||||
/* this does not clash with tshark's -2 option which returns '2' */
|
||||
#define LONGOPT_NUM_CAP_COMMENT 2
|
||||
/*
|
||||
* Long options.
|
||||
* We do not currently have long options corresponding to all short
|
||||
* options; we should probably pick appropriate option names for them.
|
||||
*
|
||||
* For long options with no corresponding short options, we define values
|
||||
* outside the range of ASCII graphic characters, make that the last
|
||||
* component of the entry for the long option, and have a case for that
|
||||
* option in the switch statement.
|
||||
*
|
||||
* NOTE:
|
||||
* for tshark, we're using a leading - in the optstring to prevent getopt()
|
||||
* from permuting the argv[] entries, in this case, unknown argv[] entries
|
||||
* will be returned as parameters to a dummy-option 1.
|
||||
* In short: we must not use 1 here, which is another reason to use
|
||||
* values outside the range of ASCII graphic characters.
|
||||
*/
|
||||
#define LONGOPT_NUM_CAP_COMMENT 128
|
||||
|
||||
/*
|
||||
* Non-capture long-only options should start here, to avoid collision
|
||||
* with capture options.
|
||||
*/
|
||||
#define MIN_NON_CAPTURE_LONGOPT 129
|
||||
|
||||
#ifdef HAVE_PCAP_REMOTE
|
||||
/* Type of capture source */
|
||||
|
|
|
@ -4176,8 +4176,10 @@ main(int argc, char *argv[])
|
|||
GString *comp_info_str;
|
||||
GString *runtime_info_str;
|
||||
int opt;
|
||||
struct option long_options[] = {
|
||||
static const struct option long_options[] = {
|
||||
{(char *)"capture-comment", required_argument, NULL, LONGOPT_NUM_CAP_COMMENT },
|
||||
{(char *)"help", no_argument, NULL, 'h'},
|
||||
{(char *)"version", no_argument, NULL, 'v'},
|
||||
{0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
@ -4525,8 +4527,8 @@ main(int argc, char *argv[])
|
|||
global_capture_opts.saving_to_file = TRUE;
|
||||
global_capture_opts.has_ring_num_files = TRUE;
|
||||
|
||||
/* Pass on capture_child mode for capture_opts */
|
||||
global_capture_opts.capture_child = capture_child;
|
||||
/* Pass on capture_child mode for capture_opts */
|
||||
global_capture_opts.capture_child = capture_child;
|
||||
|
||||
/* Now get our args */
|
||||
while ((opt = getopt_long(argc, argv, OPTSTRING, long_options, NULL)) != -1) {
|
||||
|
|
4
tshark.c
4
tshark.c
|
@ -922,8 +922,10 @@ main(int argc, char *argv[])
|
|||
GString *runtime_info_str;
|
||||
char *init_progfile_dir_error;
|
||||
int opt;
|
||||
struct option long_options[] = {
|
||||
static const struct option long_options[] = {
|
||||
{(char *)"capture-comment", required_argument, NULL, LONGOPT_NUM_CAP_COMMENT },
|
||||
{(char *)"help", no_argument, NULL, 'h'},
|
||||
{(char *)"version", no_argument, NULL, 'v'},
|
||||
{0, 0, 0, 0 }
|
||||
};
|
||||
gboolean arg_error = FALSE;
|
||||
|
|
|
@ -516,8 +516,10 @@ int main(int argc, char *argv[])
|
|||
#endif
|
||||
|
||||
#define OPTSTRING "a:b:" OPTSTRING_B "c:C:Df:g:Hhi:" OPTSTRING_I "jJ:kK:lLm:nN:o:P:pQr:R:Ss:t:u:vw:X:y:z:"
|
||||
struct option long_options[] = {
|
||||
{(char *)"read-file", required_argument, NULL, (int)'r' },
|
||||
static const struct option long_options[] = {
|
||||
{(char *)"help", no_argument, NULL, 'h'},
|
||||
{(char *)"read-file", required_argument, NULL, 'r' },
|
||||
{(char *)"version", no_argument, NULL, 'v'},
|
||||
{0, 0, 0, 0 }
|
||||
};
|
||||
static const char optstring[] = OPTSTRING;
|
||||
|
|
Loading…
Reference in New Issue