Make our 'ascii_strtod()' helper more generic

We'll want to do sane parsing of strings, but the C library makes it
hard to handle user input sanely and the Qt toDouble() function
interface was designed by a retarded chipmunk.

So just extend our existing hacky "ascii_strtod()" to allow a more
generic interface.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Linus Torvalds 2014-01-02 20:35:35 -08:00 committed by Dirk Hohndel
parent 5511a0e14e
commit cb53a78674
4 changed files with 144 additions and 96 deletions

14
dive.h
View file

@ -618,7 +618,6 @@ struct dive *find_dive_n_near(timestamp_t when, int n, timestamp_t offset);
/* Check if two dive computer entries are the exact same dive (-1=no/0=maybe/1=yes) */
extern int match_one_dc(struct divecomputer *a, struct divecomputer *b);
extern double ascii_strtod(char *, char **);
extern void parse_xml_init(void);
extern void parse_xml_buffer(const char *url, const char *buf, int size, struct dive_table *table, const char **params, char **error);
extern void parse_xml_exit(void);
@ -783,6 +782,19 @@ extern bool weightsystems_equal(weightsystem_t *ws1, weightsystem_t *ws2);
extern void remove_cylinder(struct dive *dive, int idx);
extern void remove_weightsystem(struct dive *dive, int idx);
/*
* String handling.
*/
#define STRTOD_NO_SIGN 0x01
#define STRTOD_NO_DOT 0x02
#define STRTOD_NO_COMMA 0x04
#define STRTOD_NO_EXPONENT 0x08
extern double strtod_flags(char *str, char **ptr, unsigned int flags);
#define STRTOD_ASCII (STRTOD_NO_COMMA)
#define ascii_strtod(str,ptr) strtod_flags(str,ptr,STRTOD_ASCII)
#ifdef __cplusplus
}
#endif