diff --git a/include/tig/string.h b/include/tig/string.h index d12e22c3b..2ac1a95e6 100644 --- a/include/tig/string.h +++ b/include/tig/string.h @@ -15,12 +15,21 @@ #define TIG_STRING_H #include "tig/tig.h" -#include "tig/string.h" /* * Strings. */ +#if defined(__APPLE__) +/* See COMPATIBILITY in isspace(3). */ +#define isalnum(c) iswalnum(btowc(c)) +#define iscntrl(c) iswcntrl(btowc(c)) +#define isdigit(c) iswdigit(btowc(c)) +#define ispunct(c) iswpunct(btowc(c)) +#define isspace(c) iswspace(btowc(c)) +#define isxdigit(c) iswxdigit(btowc(c)) +#endif + #define prefixcmp(str1, str2) \ strncmp(str1, str2, STRING_SIZE(str2)) diff --git a/include/tig/tig.h b/include/tig/tig.h index 2b0bc53d5..278726ef7 100644 --- a/include/tig/tig.h +++ b/include/tig/tig.h @@ -67,6 +67,10 @@ #include #include +#if defined(__APPLE__) +#include +#endif + #if defined HAVE_PCRE2 #include #elif defined HAVE_PCRE diff --git a/src/argv.c b/src/argv.c index 032b0705b..80f4d6f4b 100644 --- a/src/argv.c +++ b/src/argv.c @@ -129,7 +129,7 @@ parse_arg(char **cmd, bool remove_quotes) break; } - if (!quote && isspace(c)) + if (!quote && isspace((unsigned char)c)) break; *next++ = *pos; @@ -315,7 +315,7 @@ format_expand_arg(struct format_context *format, const char *name, const char *e if (end && msglen > 0 && string_format(msgbuf, "%.*s", msglen, msgstart)) { const char *msg = msgbuf; - while (isspace(*msg)) + while (isspace((unsigned char)*msg)) msg++; if (*msg) prompt = msg; diff --git a/src/main.c b/src/main.c index d9b5f61d7..3ac88c6fc 100644 --- a/src/main.c +++ b/src/main.c @@ -444,7 +444,7 @@ main_read(struct view *view, struct buffer *buf, bool force_stop) state->in_header = true; line += STRING_SIZE("commit "); is_boundary = *line == '-'; - while (*line && !isalnum(*line)) + while (*line && !isalnum((unsigned char)*line)) line++; main_flush_commit(view, commit); @@ -524,7 +524,7 @@ main_read(struct view *view, struct buffer *buf, bool force_stop) line += 4; /* Well, if the title starts with a whitespace character, * try to be forgiving. Otherwise we end up with no title. */ - while (isspace(*line)) + while (isspace((unsigned char)*line)) line++; if (*line == '\0') break; diff --git a/src/options.c b/src/options.c index 4e0d26f49..56cbe5025 100644 --- a/src/options.c +++ b/src/options.c @@ -319,7 +319,7 @@ parse_step(double *opt, const char *arg) { int value = atoi(arg); - if (!value && !isdigit(*arg)) + if (!value && !isdigit((unsigned char)*arg)) return error("Invalid double or percentage"); *opt = value; diff --git a/src/pager.c b/src/pager.c index 0f81e110d..e15530f7c 100644 --- a/src/pager.c +++ b/src/pager.c @@ -126,7 +126,7 @@ pager_common_read(struct view *view, const char *data, enum line_type type, stru if (line->type == LINE_COMMIT && view_has_flags(view, VIEW_ADD_PAGER_REFS)) { data += STRING_SIZE("commit "); - while (*data && !isalnum(*data)) + while (*data && !isalnum((unsigned char)*data)) data++; add_pager_refs(view, data); } diff --git a/src/parse.c b/src/parse.c index 1d91cda0d..983afdb82 100644 --- a/src/parse.c +++ b/src/parse.c @@ -23,7 +23,7 @@ parse_size(const char *text) while (*text == ' ') text++; - while (isdigit(*text)) + while (isdigit((unsigned char)*text)) size = (size * 10) + (*text++ - '0'); return size; @@ -98,7 +98,7 @@ parse_number(const char **posref, size_t *number) *posref = NULL; pos = strchr(pos + 1, ' '); - if (!pos || !isdigit(pos[1])) + if (!pos || !isdigit((unsigned char)pos[1])) return false; *number = atoi(pos + 1); @@ -197,7 +197,7 @@ parse_ulong(const char **pos_ptr, unsigned long *value, char skip, bool optional if (end == start) return false; - while (isspace(*end)) + while (isspace((unsigned char)*end)) end++; *pos_ptr = end; return true; diff --git a/src/string.c b/src/string.c index 6146d8aee..a90fc1bb0 100644 --- a/src/string.c +++ b/src/string.c @@ -25,7 +25,7 @@ string_isnumber(const char *str) int pos; for (pos = 0; str[pos]; pos++) { - if (!isdigit(str[pos])) + if (!isdigit((unsigned char)str[pos])) return false; } @@ -38,7 +38,7 @@ iscommit(const char *str) int pos; for (pos = 0; str[pos]; pos++) { - if (!isxdigit(str[pos])) + if (!isxdigit((unsigned char)str[pos])) return false; } @@ -73,7 +73,7 @@ string_copy_rev(char *dst, const char *src) return; for (srclen = 0; srclen < SIZEOF_REV; srclen++) - if (!src[srclen] || isspace(src[srclen])) + if (!src[srclen] || isspace((unsigned char)src[srclen])) break; string_ncopy_do(dst, SIZEOF_REV, src, srclen); @@ -83,7 +83,7 @@ void string_copy_rev_from_commit_line(char *dst, const char *src) { src += STRING_SIZE("commit "); - while (*src && !isalnum(*src)) + while (*src && !isalnum((unsigned char)*src)) src++; string_copy_rev(dst, src); } @@ -103,7 +103,7 @@ string_expand(char *dst, size_t dstlen, const char *src, int srclen, int tabsize expanded = dstlen - size - 1; memcpy(dst + size, " ", expanded); size += expanded; - } else if (isspace(c) || iscntrl(c)) { + } else if (isspace((unsigned char)c) || iscntrl((unsigned char)c)) { dst[size++] = ' '; } else { dst[size++] = src[pos]; @@ -119,7 +119,7 @@ string_trim_end(char *name) { int namelen = strlen(name) - 1; - while (namelen > 0 && isspace(name[namelen])) + while (namelen > 0 && isspace((unsigned char)name[namelen])) name[namelen--] = 0; return name; @@ -128,7 +128,7 @@ string_trim_end(char *name) char * string_trim(char *name) { - while (isspace(*name)) + while (isspace((unsigned char)*name)) name++; return string_trim_end(name); @@ -166,7 +166,7 @@ strcmp_numeric(const char *s1, const char *s2) for (; *s1 && *s2 && *s1 == *s2; s1++, s2++) { int c = *s1; - if (isdigit(c)) { + if (isdigit((unsigned char)c)) { number = 10 * number + (c - '0'); } else { number = 0;