diff --git a/src/include/ngspice/cm.h b/src/include/ngspice/cm.h index f1bd493c2..25db045ee 100644 --- a/src/include/ngspice/cm.h +++ b/src/include/ngspice/cm.h @@ -57,4 +57,27 @@ NON-STANDARD FEATURES #endif +/* + * type safe variants of the functions for char arguments + */ + +#if !defined(isalpha_c) + +inline static int char_to_int(char c) { return (unsigned char) c; } + +#define isalpha_c(x) isalpha(char_to_int(x)) +#define islower_c(x) islower(char_to_int(x)) +#define isdigit_c(x) isdigit(char_to_int(x)) +#define isalnum_c(x) isalnum(char_to_int(x)) +#define isprint_c(x) isprint(char_to_int(x)) +#define isblank_c(x) isblank(char_to_int(x)) +#define isspace_c(x) isspace(char_to_int(x)) +#define isupper_c(x) isupper(char_to_int(x)) + +#define tolower_c(x) ((char) tolower(char_to_int(x))) +#define toupper_c(x) ((char) toupper(char_to_int(x))) + +#endif + + #endif diff --git a/src/include/ngspice/ngspice.h b/src/include/ngspice/ngspice.h index 3e9465614..5c3a90fae 100644 --- a/src/include/ngspice/ngspice.h +++ b/src/include/ngspice/ngspice.h @@ -334,4 +334,27 @@ ATTRIBUTE_NORETURN void controlled_exit(int status); #endif +/* + * type safe variants of the functions for char arguments + */ + +#if !defined(isalpha_c) + +inline static int char_to_int(char c) { return (unsigned char) c; } + +#define isalpha_c(x) isalpha(char_to_int(x)) +#define islower_c(x) islower(char_to_int(x)) +#define isdigit_c(x) isdigit(char_to_int(x)) +#define isalnum_c(x) isalnum(char_to_int(x)) +#define isprint_c(x) isprint(char_to_int(x)) +#define isblank_c(x) isblank(char_to_int(x)) +#define isspace_c(x) isspace(char_to_int(x)) +#define isupper_c(x) isupper(char_to_int(x)) + +#define tolower_c(x) ((char) tolower(char_to_int(x))) +#define toupper_c(x) ((char) toupper(char_to_int(x))) + +#endif + + #endif diff --git a/src/xspice/cmpp/cmpp.h b/src/xspice/cmpp/cmpp.h index cf8f1bda5..00bbaa207 100644 --- a/src/xspice/cmpp/cmpp.h +++ b/src/xspice/cmpp/cmpp.h @@ -300,3 +300,26 @@ Status_t write_ifs_c_file(const char *filename, Ifs_Table_t *ifs_table); FILE *fopen_cmpp(const char **path_p, const char *mode); + + +/* + * type safe variants of the functions for char arguments + */ + +#if !defined(isalpha_c) + +inline static int char_to_int(char c) { return (unsigned char) c; } + +#define isalpha_c(x) isalpha(char_to_int(x)) +#define islower_c(x) islower(char_to_int(x)) +#define isdigit_c(x) isdigit(char_to_int(x)) +#define isalnum_c(x) isalnum(char_to_int(x)) +#define isprint_c(x) isprint(char_to_int(x)) +#define isblank_c(x) isblank(char_to_int(x)) +#define isspace_c(x) isspace(char_to_int(x)) +#define isupper_c(x) isupper(char_to_int(x)) + +#define tolower_c(x) ((char) tolower(char_to_int(x))) +#define toupper_c(x) ((char) toupper(char_to_int(x))) + +#endif