Skip to content

Commit

Permalink
Unlocalized isspace and friends
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Oct 15, 2005
1 parent d402d55 commit 4546738
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ LIB_OBJS = \
object.o pack-check.o patch-delta.o path.o pkt-line.o \
quote.o read-cache.o refs.o run-command.o \
server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
tag.o tree.o usage.o config.o environment.o $(DIFF_OBJS)
tag.o tree.o usage.o config.o environment.o ctype.o \
$(DIFF_OBJS)

LIBS = $(LIB_FILE)
LIBS += -lz
Expand Down
1 change: 0 additions & 1 deletion apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* This applies patches on top of some (arbitrary) version of the SCM.
*
*/
#include <ctype.h>
#include <fnmatch.h>
#include "cache.h"

Expand Down
26 changes: 26 additions & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,30 @@ extern int git_config_bool(const char *, const char *);
extern char git_default_email[MAX_GITNAME];
extern char git_default_name[MAX_GITNAME];

/* Sane ctype - no locale, and works with signed chars */
#undef isspace
#undef isdigit
#undef isalpha
#undef isalnum
#undef tolower
#undef toupper
extern unsigned char sane_ctype[256];
#define GIT_SPACE 0x01
#define GIT_DIGIT 0x02
#define GIT_ALPHA 0x04
#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
#define isspace(x) sane_istest(x,GIT_SPACE)
#define isdigit(x) sane_istest(x,GIT_DIGIT)
#define isalpha(x) sane_istest(x,GIT_ALPHA)
#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
#define tolower(x) sane_case((unsigned char)(x), 0x20)
#define toupper(x) sane_case((unsigned char)(x), 0)

static inline int sane_case(int x, int high)
{
if (sane_istest(x, GIT_ALPHA))
x = (x & ~0x20) | high;
return x;
}

#endif /* CACHE_H */
1 change: 0 additions & 1 deletion commit-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <pwd.h>
#include <time.h>
#include <ctype.h>

#define BLOCKING (1ul << 14)

Expand Down
1 change: 0 additions & 1 deletion commit.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <ctype.h>
#include "tag.h"
#include "commit.h"
#include "cache.h"
Expand Down
1 change: 0 additions & 1 deletion config.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <ctype.h>

#include "cache.h"

Expand Down
1 change: 0 additions & 1 deletion convert-objects.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#define _XOPEN_SOURCE /* glibc2 needs this */
#include <time.h>
#include <ctype.h>
#include "cache.h"

struct entry {
Expand Down
23 changes: 23 additions & 0 deletions ctype.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Sane locale-independent, ASCII ctype.
*
* No surprises, and works with signed and unsigned chars.
*/
#include "cache.h"

#define SS GIT_SPACE
#define AA GIT_ALPHA
#define DD GIT_DIGIT

unsigned char sane_ctype[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, SS, SS, 0, 0, SS, 0, 0, /* 0-15 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 16-15 */
SS, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 32-15 */
DD, DD, DD, DD, DD, DD, DD, DD, DD, DD, 0, 0, 0, 0, 0, 0, /* 48-15 */
0, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, /* 64-15 */
AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, 0, 0, 0, 0, 0, /* 80-15 */
0, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, /* 96-15 */
AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, AA, 0, 0, 0, 0, 0, /* 112-15 */
/* Nothing in the 128.. range */
};

1 change: 0 additions & 1 deletion date.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Copyright (C) Linus Torvalds, 2005
*/

#include <ctype.h>
#include <time.h>

#include "cache.h"
Expand Down
1 change: 0 additions & 1 deletion diff-tree.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <ctype.h>
#include "cache.h"
#include "diff.h"
#include "commit.h"
Expand Down
1 change: 0 additions & 1 deletion ident.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <pwd.h>
#include <time.h>
#include <ctype.h>

static char git_default_date[50];

Expand Down
1 change: 0 additions & 1 deletion mailsplit.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <assert.h>
#include "cache.h"

Expand Down
1 change: 0 additions & 1 deletion pack-objects.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <ctype.h>
#include "cache.h"
#include "object.h"
#include "delta.h"
Expand Down
1 change: 0 additions & 1 deletion patch-id.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <ctype.h>
#include "cache.h"

static void flush_current_id(int patchlen, unsigned char *id, SHA_CTX *c)
Expand Down
1 change: 0 additions & 1 deletion refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "cache.h"

#include <errno.h>
#include <ctype.h>

/* We allow "recursive" symbolic refs. Only within reason, though */
#define MAXDEPTH 5
Expand Down
1 change: 0 additions & 1 deletion update-ref.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "cache.h"
#include "refs.h"
#include <ctype.h>

static const char git_update_ref_usage[] = "git-update-ref <refname> <value> [<oldval>]";

Expand Down

0 comments on commit 4546738

Please sign in to comment.