forked from osmocom/wireshark
Move "get_natural_int()" and "get_positive_int()" from "capture_opts.c"
to "clopts_common.c", make them not static, and use them in "gtk/main.c". svn path=/trunk/; revision=13541
This commit is contained in:
parent
36833b76d8
commit
343810d95a
|
@ -43,7 +43,7 @@
|
|||
|
||||
#include "capture.h"
|
||||
#include "ringbuffer.h"
|
||||
|
||||
#include "clopts_common.h"
|
||||
|
||||
void
|
||||
capture_opts_init(capture_options *capture_opts, void *cfile)
|
||||
|
@ -85,49 +85,6 @@ capture_opts_init(capture_options *capture_opts, void *cfile)
|
|||
capture_opts->fork_child = -1; /* invalid process handle */
|
||||
}
|
||||
|
||||
static int
|
||||
get_natural_int(const char *appname, const char *string, const char *name)
|
||||
{
|
||||
long number;
|
||||
char *p;
|
||||
|
||||
number = strtol(string, &p, 10);
|
||||
if (p == string || *p != '\0') {
|
||||
fprintf(stderr, "%s: The specified %s \"%s\" isn't a decimal number\n",
|
||||
appname, name, string);
|
||||
exit(1);
|
||||
}
|
||||
if (number < 0) {
|
||||
fprintf(stderr, "%s: The specified %s \"%s\" is a negative number\n",
|
||||
appname, name, string);
|
||||
exit(1);
|
||||
}
|
||||
if (number > INT_MAX) {
|
||||
fprintf(stderr, "%s: The specified %s \"%s\" is too large (greater than %d)\n",
|
||||
appname, name, string, INT_MAX);
|
||||
exit(1);
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
get_positive_int(const char *appname, const char *string, const char *name)
|
||||
{
|
||||
long number;
|
||||
|
||||
number = get_natural_int(appname, string, name);
|
||||
|
||||
if (number == 0) {
|
||||
fprintf(stderr, "%s: The specified %s is zero\n",
|
||||
appname, name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Given a string of the form "<autostop criterion>:<value>", as might appear
|
||||
* as an argument to a "-a" option, parse it and set the criterion in
|
||||
|
|
|
@ -61,3 +61,45 @@ handle_dashG_option(int argc, char **argv, char *progname)
|
|||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
get_natural_int(const char *appname, const char *string, const char *name)
|
||||
{
|
||||
long number;
|
||||
char *p;
|
||||
|
||||
number = strtol(string, &p, 10);
|
||||
if (p == string || *p != '\0') {
|
||||
fprintf(stderr, "%s: The specified %s \"%s\" isn't a decimal number\n",
|
||||
appname, name, string);
|
||||
exit(1);
|
||||
}
|
||||
if (number < 0) {
|
||||
fprintf(stderr, "%s: The specified %s \"%s\" is a negative number\n",
|
||||
appname, name, string);
|
||||
exit(1);
|
||||
}
|
||||
if (number > INT_MAX) {
|
||||
fprintf(stderr, "%s: The specified %s \"%s\" is too large (greater than %d)\n",
|
||||
appname, name, string, INT_MAX);
|
||||
exit(1);
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
get_positive_int(const char *appname, const char *string, const char *name)
|
||||
{
|
||||
long number;
|
||||
|
||||
number = get_natural_int(appname, string, name);
|
||||
|
||||
if (number == 0) {
|
||||
fprintf(stderr, "%s: The specified %s is zero\n",
|
||||
appname, name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return number;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,10 @@ extern "C" {
|
|||
*/
|
||||
void handle_dashG_option(int argc, char **argv, char *progname);
|
||||
|
||||
int get_natural_int(const char *appname, const char *string, const char *name);
|
||||
|
||||
int get_positive_int(const char *appname, const char *string, const char *name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
|
47
gtk/main.c
47
gtk/main.c
|
@ -1116,47 +1116,6 @@ show_version(void)
|
|||
comp_info_str->str, runtime_info_str->str);
|
||||
}
|
||||
|
||||
static int
|
||||
get_natural_int(const char *string, const char *name)
|
||||
{
|
||||
long number;
|
||||
char *p;
|
||||
|
||||
number = strtol(string, &p, 10);
|
||||
if (p == string || *p != '\0') {
|
||||
fprintf(stderr, "ethereal: The specified %s \"%s\" isn't a decimal number\n",
|
||||
name, string);
|
||||
exit(1);
|
||||
}
|
||||
if (number < 0) {
|
||||
fprintf(stderr, "ethereal: The specified %s \"%s\" is a negative number\n",
|
||||
name, string);
|
||||
exit(1);
|
||||
}
|
||||
if (number > INT_MAX) {
|
||||
fprintf(stderr, "ethereal: The specified %s \"%s\" is too large (greater than %d)\n",
|
||||
name, string, INT_MAX);
|
||||
exit(1);
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
static int
|
||||
get_positive_int(const char *string, const char *name)
|
||||
{
|
||||
long number;
|
||||
|
||||
number = get_natural_int(string, name);
|
||||
|
||||
if (number == 0) {
|
||||
fprintf(stderr, "ethereal: The specified %s is zero\n",
|
||||
name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
#if defined(_WIN32) || GTK_MAJOR_VERSION < 2 || ! defined USE_THREADS
|
||||
/*
|
||||
Once every 3 seconds we get a callback here which we use to update
|
||||
|
@ -1899,7 +1858,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/*** all non capture option specific ***/
|
||||
case 'B': /* Byte view pane height */
|
||||
bv_size = get_positive_int(optarg, "byte view pane height");
|
||||
bv_size = get_positive_int("ethereal", optarg, "byte view pane height");
|
||||
break;
|
||||
case 'h': /* Print help and exit */
|
||||
print_usage(TRUE);
|
||||
|
@ -1956,7 +1915,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
break;
|
||||
case 'P': /* Packet list pane height */
|
||||
pl_size = get_positive_int(optarg, "packet list pane height");
|
||||
pl_size = get_positive_int("ethereal", optarg, "packet list pane height");
|
||||
break;
|
||||
case 'r': /* Read capture file xxx */
|
||||
/* We may set "last_open_dir" to "cf_name", and if we change
|
||||
|
@ -1985,7 +1944,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
break;
|
||||
case 'T': /* Tree view pane height */
|
||||
tv_size = get_positive_int(optarg, "tree view pane height");
|
||||
tv_size = get_positive_int("ethereal", optarg, "tree view pane height");
|
||||
break;
|
||||
case 'v': /* Show version and exit */
|
||||
show_version();
|
||||
|
|
Loading…
Reference in New Issue