diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2023-10-10 18:45:31 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2023-10-10 18:45:31 +0000 |
commit | 48efce7e5dd088bc355c113f56986f60932b3ab9 (patch) | |
tree | e324c9062d71c8b2cf465b991c1dd9c151cd6636 /generator | |
parent | 7041fc86d84257995ca97af94523a6405566d868 (diff) | |
download | netpbm-mirror-48efce7e5dd088bc355c113f56986f60932b3ab9.tar.gz netpbm-mirror-48efce7e5dd088bc355c113f56986f60932b3ab9.tar.xz netpbm-mirror-48efce7e5dd088bc355c113f56986f60932b3ab9.zip |
Replace atoi
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4748 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'generator')
-rw-r--r-- | generator/pamgauss.c | 7 | ||||
-rw-r--r-- | generator/pamgradient.c | 11 | ||||
-rw-r--r-- | generator/pamseq.c | 29 | ||||
-rw-r--r-- | generator/pgmkernel.c | 29 | ||||
-rw-r--r-- | generator/ppmpat.c | 8 |
5 files changed, 56 insertions, 28 deletions
diff --git a/generator/pamgauss.c b/generator/pamgauss.c index 3697fdc7..5553e757 100644 --- a/generator/pamgauss.c +++ b/generator/pamgauss.c @@ -106,8 +106,8 @@ parseCommandLine(int argc, const char ** argv, pm_error("Only two arguments allowed: width and height. " "You specified %d", argc-1); else { - cmdlineP->width = atoi(argv[1]); - cmdlineP->height = atoi(argv[2]); + cmdlineP->width = pm_parse_width(argv[1]); + cmdlineP->height = pm_parse_height(argv[2]); if (cmdlineP->width <= 0) pm_error("width argument must be a positive number. You " "specified '%s'", argv[1]); @@ -347,3 +347,6 @@ main(int argc, const char **argv) { return 0; } + + + diff --git a/generator/pamgradient.c b/generator/pamgradient.c index 526efdae..bbbaad30 100644 --- a/generator/pamgradient.c +++ b/generator/pamgradient.c @@ -53,8 +53,8 @@ parseCommandLine(int argc, const char **argv, else { if (cmdlineP->maxval > PAM_OVERALL_MAXVAL) pm_error("The value you specified for -maxval (%u) is too big. " - "Max allowed is %u", cmdlineP->maxval, - PAM_OVERALL_MAXVAL); + "Max allowed is %lu", cmdlineP->maxval, + (unsigned long int) PAM_OVERALL_MAXVAL); if (cmdlineP->maxval < 1) pm_error("You cannot specify 0 for -maxval"); @@ -68,8 +68,8 @@ parseCommandLine(int argc, const char **argv, cmdlineP->colorTopRight = pnm_parsecolor(argv[2], cmdlineP->maxval); cmdlineP->colorBottomLeft = pnm_parsecolor(argv[3], cmdlineP->maxval); cmdlineP->colorBottomRight = pnm_parsecolor(argv[4], cmdlineP->maxval); - cmdlineP->cols = atoi(argv[5]); - cmdlineP->rows = atoi(argv[6]); + cmdlineP->cols = pm_parse_width(argv[5]); + cmdlineP->rows = pm_parse_height(argv[6]); if (cmdlineP->cols <= 0) pm_error("width argument must be a positive number. You " "specified '%s'", argv[5]); @@ -211,3 +211,6 @@ main(int argc, const char *argv[]) { return 0; } + + + diff --git a/generator/pamseq.c b/generator/pamseq.c index 4c00e2a5..998b7ea5 100644 --- a/generator/pamseq.c +++ b/generator/pamseq.c @@ -192,18 +192,29 @@ parseCommandLine(int argc, const char ** argv, pm_error("Only two argumeents allowed: depth and maxval. " "You specified %d", argc-1); else { - cmdlineP->depth = atoi(argv[1]); - cmdlineP->maxval = atoi(argv[2]); - if (cmdlineP->depth <= 0) + const char * error; + unsigned int depth, maxval; + + pm_string_to_uint(argv[1], &depth, &error); + if (error) { + pm_error("'%s' is invalid as an image depth. %s", argv[1], error); + pm_strfree(error); + } + else if (depth <= 0) pm_error("depth argument must be a positive number. You " "specified '%s'", argv[1]); - if (cmdlineP->maxval <= 0) - pm_error("maxval argument must be a positive number. You " - "specified '%s'", argv[2]); - if (cmdlineP->maxval > PNM_OVERALLMAXVAL) + else + cmdlineP->depth = depth; + + maxval = pm_parse_maxval(argv[2]); + + if (maxval > PAM_OVERALL_MAXVAL) pm_error("The maxval you specified (%u) is too big. " - "Maximum is %u", (unsigned int) cmdlineP->maxval, - PNM_OVERALLMAXVAL); + "Maximum is %lu", maxval, PAM_OVERALL_MAXVAL); + else + cmdlineP->maxval = maxval; + + if (pm_maxvaltobits(cmdlineP->maxval) + pm_maxvaltobits(cmdlineP->depth-1) > sizeof(unsigned int)*8) pm_error("The maxval (%u) and depth (%u) you specified result " diff --git a/generator/pgmkernel.c b/generator/pgmkernel.c index cbae0882..8d99a76d 100644 --- a/generator/pgmkernel.c +++ b/generator/pgmkernel.c @@ -20,7 +20,7 @@ #include "shhopt.h" #include "mallocvar.h" #include "pgm.h" - +#include "nstring.h" struct CmdlineInfo { @@ -89,20 +89,30 @@ parseCommandLine(int argc, const char ** argv, if (argc-1 < 1) pm_error("Need at least one argument: size of (square) kernel"); else if (argc-1 == 1) { - if (atoi(argv[1]) <= 0) + unsigned int dimension; + const char * error; + + pm_string_to_uint(argv[1], &dimension, &error); + if (error) { + pm_error("'%s' is invalid as an image width/height. %s", argv[1], error); + pm_strfree(error); + } + if (dimension <= 0) pm_error("Dimension must be a positive number. " "You specified '%s'", argv[1]); - cmdlineP->cols = atoi(argv[1]); - cmdlineP->rows = atoi(argv[1]); + cmdlineP->cols = cmdlineP->rows = dimension; + } else if (argc-1 == 2) { - if (atoi(argv[1]) <= 0) + unsigned int const width = pm_parse_width(argv[1]); + unsigned int const height = pm_parse_height(argv[2]); + if (width <= 0) pm_error("Width must be a positive number. " "You specified '%s'", argv[1]); - if (atoi(argv[2]) <= 0) + if (height <= 0) pm_error("Height must be a positive number. " "You specified '%s'", argv[2]); - cmdlineP->cols = atoi(argv[1]); - cmdlineP->rows = atoi(argv[2]); + cmdlineP->cols = width; + cmdlineP->rows = height; } else pm_error("At most two arguments allowed. " "You specified %u", argc-1); @@ -243,3 +253,6 @@ main(int argc, const char * argv[]) { return 0; } + + + diff --git a/generator/ppmpat.c b/generator/ppmpat.c index 170bfc58..2f71914e 100644 --- a/generator/ppmpat.c +++ b/generator/ppmpat.c @@ -344,8 +344,8 @@ parseCommandLine(int argc, const char ** argv, pm_error("You must specify 2 non-option arguments: width and height " "in pixels. You specified %u", argc-1); else { - cmdlineP->width = atoi(argv[1]); - cmdlineP->height = atoi(argv[2]); + cmdlineP->width = pm_parse_width(argv[1]); + cmdlineP->height = pm_parse_height(argv[2]); if (cmdlineP->width < 1) pm_error("Width must be at least 1 pixel"); @@ -438,9 +438,6 @@ randomDarkColor(struct pm_randSt * const randStP, - - - static void nextColor(ColorTable * const colorTableP) { /*---------------------------------------------------------------------------- @@ -1654,3 +1651,4 @@ main(int argc, const char ** argv) { } + |