diff options
Diffstat (limited to 'main/glib/inrange.c')
-rw-r--r-- | main/glib/inrange.c | 101 |
1 files changed, 54 insertions, 47 deletions
diff --git a/main/glib/inrange.c b/main/glib/inrange.c index d687a8e..bb26169 100644 --- a/main/glib/inrange.c +++ b/main/glib/inrange.c @@ -8,7 +8,7 @@ * If the value is within the range of the string specified, then * return 1; else return 0. * The incoming string can be a mix of ranges and values with each - * range and/or value separated by a comma and a range is specified + * range and/or value separated by a comma and a range is specified * by 2 numbers separated by a dash. * Also, incoming ranges of "all" or "any" immediately return true * and an incoming range of "none" or a null or empty pointer will @@ -17,55 +17,62 @@ int inRange(char *range, int value) { - int lo, hi; - char rcopy[32], *rsp, *comma, *dash; + int lo, hi; + char rcopy[32], *rsp, *comma, *dash; - /* If incoming range is NULL, return zero. - */ - if ((range == 0) || (*range == 0) || (strcmp(range,"none") == 0)) - return(0); + /* If incoming range is NULL, return zero. + */ + if((range == 0) || (*range == 0) || (strcmp(range,"none") == 0)) { + return(0); + } - /* If the range string is "all" or "any", then immediately return true... - */ - if ((strcmp(range,"all") == 0) || (strcmp(range,"any") == 0)) - return(1); + /* If the range string is "all" or "any", then immediately return true... + */ + if((strcmp(range,"all") == 0) || (strcmp(range,"any") == 0)) { + return(1); + } - /* Scan the range string for valid characters: - */ - rsp = range; - while(*rsp) { - if ((*rsp == ',') || (*rsp == '-') || - (*rsp == 'x') || isxdigit(*rsp)) - rsp++; - else - break; - } - if (*rsp) - return(0); + /* Scan the range string for valid characters: + */ + rsp = range; + while(*rsp) { + if((*rsp == ',') || (*rsp == '-') || + (*rsp == 'x') || isxdigit(*rsp)) { + rsp++; + } else { + break; + } + } + if(*rsp) { + return(0); + } - /* If incoming range string exceeds size of copy buffer, return 0. - */ - if (strlen(range) > sizeof(rcopy)-1) - return(0); + /* If incoming range string exceeds size of copy buffer, return 0. + */ + if(strlen(range) > sizeof(rcopy)-1) { + return(0); + } - strcpy(rcopy,range); - rsp = rcopy; - do { - comma = strchr(rsp,','); - if (comma) - *comma = 0; - dash = strchr(rsp,'-'); - if (dash) { - lo = strtol(rsp,0,0); - hi = strtol(dash+1,0,0); - if ((value >= lo) && (value <= hi)) - return(1); - } - else { - if (value == strtol(rsp,0,0)) - return(1); - } - rsp = comma+1; - } while (comma); - return(0); + strcpy(rcopy,range); + rsp = rcopy; + do { + comma = strchr(rsp,','); + if(comma) { + *comma = 0; + } + dash = strchr(rsp,'-'); + if(dash) { + lo = strtol(rsp,0,0); + hi = strtol(dash+1,0,0); + if((value >= lo) && (value <= hi)) { + return(1); + } + } else { + if(value == strtol(rsp,0,0)) { + return(1); + } + } + rsp = comma+1; + } while(comma); + return(0); } |