about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-10-10 18:45:03 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-10-10 18:45:03 +0000
commit7041fc86d84257995ca97af94523a6405566d868 (patch)
tree1566b6f866942046f9d7624479554763a83161ae /lib
parent0861102cd5955111404467c4fff111208bc9f06d (diff)
downloadnetpbm-mirror-7041fc86d84257995ca97af94523a6405566d868.tar.gz
netpbm-mirror-7041fc86d84257995ca97af94523a6405566d868.tar.xz
netpbm-mirror-7041fc86d84257995ca97af94523a6405566d868.zip
Add pm_parse_maxval
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4747 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib')
-rw-r--r--lib/libpm.c24
-rw-r--r--lib/pm.h3
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/libpm.c b/lib/libpm.c
index 21d869a5..d1fc6c42 100644
--- a/lib/libpm.c
+++ b/lib/libpm.c
@@ -906,3 +906,27 @@ pm_parse_height(const char * const arg) {
 
 
 
+unsigned int
+pm_parse_maxval(const char * const arg) {
+/*----------------------------------------------------------------------------
+  Same as pm_parse_width(), but for maxval.
+-----------------------------------------------------------------------------*/
+    unsigned int maxval;
+    const char * error;
+
+    pm_string_to_uint(arg, &maxval, &error);
+
+    if (error) {
+        pm_error("'%s' is invalid as a maxval.  %s", arg, error);
+        pm_strfree(error);
+    } else {
+        if (maxval > INT_MAX-1)
+            pm_error("Maxval %u is too large for computations.", maxval);
+        if (maxval == 0)
+            pm_error("Maxval argument must be a positive number.  You "
+                     "specified 0.");
+    }
+    return maxval;
+}
+
+
diff --git a/lib/pm.h b/lib/pm.h
index 2a87aca1..62ad5355 100644
--- a/lib/pm.h
+++ b/lib/pm.h
@@ -458,6 +458,9 @@ pm_parse_width(const char * const arg);
 unsigned int
 pm_parse_height(const char * const arg);
 
+unsigned int
+pm_parse_maxval(const char * const arg);
+
 #ifdef __cplusplus
 }
 #endif