--------------------------------------------------------------------------- | Facility : libnform | Function : static bool Check_Numeric_Field(FIELD * field, | const void * argp) | | Description : Validate buffer content to be a valid numeric value | | Return Values : TRUE - field is valid | FALSE -
| 99 | | FALSE - field is invalid |
| 100 | +--------------------------------------------------------------------------*/ |
| 101 | static bool Check_Numeric_Field(FIELD * field, const void * argp) |
| 102 | { |
| 103 | const numericARG *argn = (const numericARG *)argp; |
| 104 | double low = argn->low; |
| 105 | double high = argn->high; |
| 106 | int prec = argn->precision; |
| 107 | unsigned char *bp = (unsigned char *)field_buffer(field,0); |
| 108 | char *s = (char *)bp; |
| 109 | double val = 0.0; |
| 110 | char buf[64]; |
| 111 | |
| 112 | while(*bp && *bp==' ') bp++; |
| 113 | if (*bp) |
| 114 | { |
| 115 | if (*bp=='-' || *bp=='+') |
| 116 | bp++; |
| 117 | while(*bp) |
| 118 | { |
| 119 | if (!isdigit(*bp)) break; |
| 120 | bp++; |
| 121 | } |
| 122 | if (*bp==( |
| 123 | #if HAVE_LOCALE_H |
| 124 | (L && L->decimal_point) ? *(L->decimal_point) : |
| 125 | #endif |
| 126 | '.')) |
| 127 | { |
| 128 | bp++; |
| 129 | while(*bp) |
| 130 | { |
| 131 | if (!isdigit(*bp)) break; |
| 132 | bp++; |
| 133 | } |
| 134 | } |
| 135 | while(*bp && *bp==' ') bp++; |
| 136 | if (*bp=='\0') |
| 137 | { |
| 138 | val = atof(s); |
| 139 | if (low<high) |
| 140 | { |
| 141 | if (val<low || val>high) return FALSE; |
| 142 | } |
| 143 | snprintf(buf,sizeof(buf),"%.*f",(prec>0?prec:0),val); |
| 144 | set_field_buffer(field,0,buf); |
| 145 | return TRUE; |
| 146 | } |
| 147 | } |
| 148 | return FALSE; |
| 149 | } |
| 150 | |
| 151 | /*--------------------------------------------------------------------------- |
| 152 | | Facility : libnform |
nothing calls this directly
no test coverage detected
searching dependent graphs…