aboutsummaryrefslogtreecommitdiffstats
path: root/clopts_common.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2005-02-27 21:15:30 +0000
committerGuy Harris <guy@alum.mit.edu>2005-02-27 21:15:30 +0000
commit343810d95a1343a7d3f996827c938fb3109053bc (patch)
tree53cbefe97f297642f74521fd0ed7ffc4a01b91ac /clopts_common.c
parent36833b76d8b62c3eac22ef0943b9e553e3518bb9 (diff)
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
Diffstat (limited to 'clopts_common.c')
-rw-r--r--clopts_common.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/clopts_common.c b/clopts_common.c
index 487dbd5bf3..12227c4485 100644
--- a/clopts_common.c
+++ b/clopts_common.c
@@ -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;
+}