#endif
+ /*
+ * Make locale aware float (but maybe restrict to whole numbers). */
+static int mkfloat (const char *str, float *num, int whole) {
+ char *ep;
+
+ if (whole)
+ *num = (float)strtol(str, &ep, 0);
+ else
+ *num = strtof(str, &ep);
+ if (ep != str && *ep == '\0' && *num < MAXINT)
+ return 1;
+ return 0;
+} // end: mkfloat
+
+
/*
* This routine provides the i/o in support of files whose size
* cannot be determined in advance. Given a stream pointer, he'll
if (line[0] == kbd_ESC || Frames_signal) return GET_NUM_ESC;
if (!line[0]) return GET_NUM_NOT;
// note: we're not allowing negative floats
- if (strcspn(line, "+,.0123456789")) {
+ if (!mkfloat(line, &f, 0) || f < 0) {
show_msg(N_txt(BAD_numfloat_txt));
return GET_NUM_BAD;
}
- sscanf(line, "%f", &f);
return f;
} // end: get_float
* Get an integer from the user, returning INT_MIN for error */
static int get_int (const char *prompt) {
char *line;
- int n;
+ float f;
line = ioline(prompt);
if (line[0] == kbd_ESC || Frames_signal) return GET_NUM_ESC;
if (!line[0]) return GET_NUM_NOT;
// note: we've got to allow negative ints (renice)
- if (strcspn(line, "-+0123456789")) {
+ if (!mkfloat(line, &f, 1)) {
show_msg(N_txt(BAD_integers_txt));
return GET_NUM_BAD;
}
- sscanf(line, "%d", &n);
- return n;
+ return (int)f;
} // end: get_int
} // end: hex_make
- /*
- * Make locale aware float (but maybe restrict to whole numbers). */
-static int mkfloat (const char *str, float *num, int whole) {
- char *ep;
-
- if (whole)
- *num = (float)strtol(str, &ep, 0);
- else
- *num = strtof(str, &ep);
- if (ep != str && *ep == '\0' && *num < MAXINT)
- return 1;
- return 0;
-} // end: mkfloat
-
-
/*
* This sructure is hung from a WIN_t when other filtering is active */
struct osel_s {
//atic int ioch (int ech, char *buf, unsigned cnt);
//atic int iokey (int action);
//atic char *ioline (const char *prompt);
+//atic int mkfloat (const char *str, float *num, int whole);
//atic int readfile (FILE *fp, char **baddr, size_t *bsize, size_t *bread);
/*------ Small Utility routines ----------------------------------------*/
//atic float get_float (const char *prompt);
//atic int get_int (const char *prompt);
//atic inline const char *hex_make (KLONG num, int noz);
-//atic int mkfloat (const char *str, float *num, int whole);
//atic void osel_clear (WIN_t *q);
//atic inline int osel_matched (const WIN_t *q, FLG_t enu, const char *str);
//atic const char *user_certify (WIN_t *q, const char *str, char typ);