More getopt_long, to add --help and --version support.

Change-Id: I946067b972a70154f02ab561bc0fd029a7a5abc4
Reviewed-on: https://code.wireshark.org/review/2791
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2014-07-02 21:50:54 -07:00
parent a4304de1cc
commit 8afe331369
5 changed files with 50 additions and 5 deletions

View File

@ -67,6 +67,10 @@
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
@ -1111,6 +1115,11 @@ main(int argc, char *argv[])
gchar *err_info;
int opt;
int overall_error_status;
static const struct option long_options[] = {
{(char *)"help", no_argument, NULL, 'h'},
{(char *)"version", no_argument, NULL, 'v'},
{0, 0, 0, 0 }
};
int status = 0;
#ifdef HAVE_PLUGINS
@ -1211,7 +1220,7 @@ main(int argc, char *argv[])
g_option_context_free(ctx);
#endif /* USE_GOPTION */
while ((opt = getopt(argc, argv, "tEcs" FILE_HASH_OPT "dluaeyizvhxokCALTMRrSNqQBmb")) !=-1) {
while ((opt = getopt_long(argc, argv, "tEcs" FILE_HASH_OPT "dluaeyizvhxokCALTMRrSNqQBmb", long_options, NULL)) !=-1) {
switch (opt) {

View File

@ -50,6 +50,10 @@
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
@ -842,6 +846,11 @@ main(int argc, char *argv[])
int i, j, err;
gchar *err_info;
int opt;
static const struct option long_options[] = {
{(char *)"help", no_argument, NULL, 'h'},
{(char *)"version", no_argument, NULL, 'V'},
{0, 0, 0, 0 }
};
char *p;
guint32 snaplen = 0; /* No limit */
@ -905,7 +914,7 @@ main(int argc, char *argv[])
#endif
/* Process the options */
while ((opt = getopt(argc, argv, "A:B:c:C:dD:E:F:hi:Lrs:S:t:T:vVw:")) != -1) {
while ((opt = getopt_long(argc, argv, "A:B:c:C:dD:E:F:hi:Lrs:S:t:T:vVw:", long_options, NULL)) != -1) {
switch (opt) {
case 'A':
{

View File

@ -34,6 +34,10 @@
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
@ -217,6 +221,11 @@ int
main(int argc, char *argv[])
{
int opt;
static const struct option long_options[] = {
{(char *)"help", no_argument, NULL, 'h'},
{(char *)"version", no_argument, NULL, 'V'},
{0, 0, 0, 0 }
};
gboolean do_append = FALSE;
gboolean verbose = FALSE;
int in_file_count = 0;
@ -245,7 +254,7 @@ main(int argc, char *argv[])
#endif /* _WIN32 */
/* Process the options first */
while ((opt = getopt(argc, argv, "aF:hs:T:vVw:")) != -1) {
while ((opt = getopt_long(argc, argv, "aF:hs:T:vVw:", long_options, NULL)) != -1) {
switch (opt) {
case 'a':

View File

@ -32,6 +32,10 @@
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include "wtap.h"
#ifndef HAVE_GETOPT
@ -184,12 +188,17 @@ main(int argc, char *argv[])
FrameRecord_t *prevFrame = NULL;
int opt;
static const struct option long_options[] = {
{(char *)"help", no_argument, NULL, 'h'},
{(char *)"version", no_argument, NULL, 'v'},
{0, 0, 0, 0 }
};
int file_count;
char *infile;
char *outfile;
/* Process the options first */
while ((opt = getopt(argc, argv, "hnv")) != -1) {
while ((opt = getopt_long(argc, argv, "hnv", long_options, NULL)) != -1) {
switch (opt) {
case 'n':
write_output_regardless = FALSE;

View File

@ -120,6 +120,10 @@
# include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <errno.h>
#include <assert.h>
@ -1539,6 +1543,11 @@ parse_options (int argc, char *argv[])
{
int c;
char *p;
static const struct option long_options[] = {
{(char *)"help", no_argument, NULL, 'h'},
{(char *)"version", no_argument, NULL, 'v'},
{0, 0, 0, 0 }
};
#ifdef _WIN32
arg_list_utf_16to8(argc, argv);
@ -1546,7 +1555,7 @@ parse_options (int argc, char *argv[])
#endif /* _WIN32 */
/* Scan CLI parameters */
while ((c = getopt(argc, argv, "aDdhqe:i:l:m:no:u:s:S:t:T:v4:6:")) != -1) {
while ((c = getopt_long(argc, argv, "aDdhqe:i:l:m:no:u:s:S:t:T:v4:6:", long_options, NULL)) != -1) {
switch (c) {
case '?': usage(TRUE); break;
case 'h': usage(FALSE); break;