@matheusbsbs / matheus-bagliano / commits / 4546738b58
Fork 0

Unlocalized isspace and friends

Do our own ctype.h, just to get the sane semantics: we want locale-independence, _and_ we want the right signed behaviour. Plus we only use a very small subset of ctype.h anyway (isspace, isalpha, isdigit and isalnum). Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Oct 13, 2005 at 11:03 UTC 4546738b58a0134eef154231b07d60fc174d56e3
16 files changed +51 -14
Makefile
+2 -1
@@ -159,7 +159,8 @@ LIB_OBJS = \
159 object.o pack-check.o patch-delta.o path.o pkt-line.o \
160 quote.o read-cache.o refs.o run-command.o \
161 server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
162 - tag.o tree.o usage.o config.o environment.o $(DIFF_OBJS)
162 + tag.o tree.o usage.o config.o environment.o ctype.o \
163 + $(DIFF_OBJS)
164
165 LIBS = $(LIB_FILE)
166 LIBS += -lz
apply.c
-1
@@ -6,7 +6,6 @@
6 * This applies patches on top of some (arbitrary) version of the SCM.
7 *
8 */
9 -#include <ctype.h>
9 #include <fnmatch.h>
10 #include "cache.h"
11
cache.h
+26
@@ -387,4 +387,30 @@ extern int git_config_bool(const char *, const char *);
387 extern char git_default_email[MAX_GITNAME];
388 extern char git_default_name[MAX_GITNAME];
389
390 +/* Sane ctype - no locale, and works with signed chars */
391 +#undef isspace
392 +#undef isdigit
393 +#undef isalpha
394 +#undef isalnum
395 +#undef tolower
396 +#undef toupper
397 +extern unsigned char sane_ctype[256];
398 +#define GIT_SPACE 0x01
399 +#define GIT_DIGIT 0x02
400 +#define GIT_ALPHA 0x04
401 +#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
402 +#define isspace(x) sane_istest(x,GIT_SPACE)
403 +#define isdigit(x) sane_istest(x,GIT_DIGIT)
404 +#define isalpha(x) sane_istest(x,GIT_ALPHA)
405 +#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
406 +#define tolower(x) sane_case((unsigned char)(x), 0x20)
407 +#define toupper(x) sane_case((unsigned char)(x), 0)
408 +
409 +static inline int sane_case(int x, int high)
410 +{
411 + if (sane_istest(x, GIT_ALPHA))
412 + x = (x & ~0x20) | high;
413 + return x;
414 +}
415 +
416 #endif /* CACHE_H */
commit-tree.c
-1
@@ -7,7 +7,6 @@
7
8 #include <pwd.h>
9 #include <time.h>
10 -#include <ctype.h>
10
11 #define BLOCKING (1ul << 14)
12
commit.c
-1
@@ -1,4 +1,3 @@
1 -#include <ctype.h>
1 #include "tag.h"
2 #include "commit.h"
3 #include "cache.h"
config.c
-1
@@ -1,4 +1,3 @@
1 -#include <ctype.h>
1
2 #include "cache.h"
3
convert-objects.c
-1
@@ -1,6 +1,5 @@
1 #define _XOPEN_SOURCE /* glibc2 needs this */
2 #include <time.h>
3 -#include <ctype.h>
3 #include "cache.h"
4
5 struct entry {
ctype.c new
+23
@@ -0,0 +1,23 @@
1 +/*
2 + * Sane locale-independent, ASCII ctype.
3 + *
4 + * No surprises, and works with signed and unsigned chars.
5 + */
6 +#include "cache.h"
7 +
8 +#define SS GIT_SPACE
9 +#define AA GIT_ALPHA
10 +#define DD GIT_DIGIT
11 +
12 +unsigned char sane_ctype[256] = {
13 + 0, 0, 0, 0, 0, 0, 0, 0, 0, SS, SS, 0, 0, SS, 0, 0, /* 0-15 */
14 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 16-15 */
15 + SS, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 32-15 */
16 + DD, DD, DD, DD, DD, DD, DD, DD, DD, DD, 0, 0, 0, 0, 0, 0, /* 48-15 */
17 + 0, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, /* 64-15 */
18 + AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, 0, 0, 0, 0, 0, /* 80-15 */
19 + 0, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, /* 96-15 */
20 + AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, 0, 0, 0, 0, 0, /* 112-15 */
21 + /* Nothing in the 128.. range */
22 +};
23 +
date.c
-1
@@ -4,7 +4,6 @@
4 * Copyright (C) Linus Torvalds, 2005
5 */
6
7 -#include <ctype.h>
7 #include <time.h>
8
9 #include "cache.h"
diff-tree.c
-1
@@ -1,4 +1,3 @@
1 -#include <ctype.h>
1 #include "cache.h"
2 #include "diff.h"
3 #include "commit.h"
ident.c
-1
@@ -9,7 +9,6 @@
9
10 #include <pwd.h>
11 #include <time.h>
12 -#include <ctype.h>
12
13 static char git_default_date[50];
14
mailsplit.c
-1
@@ -11,7 +11,6 @@
11 #include <sys/stat.h>
12 #include <string.h>
13 #include <stdio.h>
14 -#include <ctype.h>
14 #include <assert.h>
15 #include "cache.h"
16
pack-objects.c
-1
@@ -1,4 +1,3 @@
1 -#include <ctype.h>
1 #include "cache.h"
2 #include "object.h"
3 #include "delta.h"
patch-id.c
-1
@@ -1,4 +1,3 @@
1 -#include <ctype.h>
1 #include "cache.h"
2
3 static void flush_current_id(int patchlen, unsigned char *id, SHA_CTX *c)
refs.c
-1
@@ -2,7 +2,6 @@
2 #include "cache.h"
3
4 #include <errno.h>
5 -#include <ctype.h>
5
6 /* We allow "recursive" symbolic refs. Only within reason, though */
7 #define MAXDEPTH 5
update-ref.c
-1
@@ -1,6 +1,5 @@
1 #include "cache.h"
2 #include "refs.h"
3 -#include <ctype.h>
3
4 static const char git_update_ref_usage[] = "git-update-ref <refname> <value> [<oldval>]";
5