util.h
76 lines
| 2.3 KiB
| text/x-c
|
CLexer
/ mercurial / util.h
Renato Cunha
|
r11358 | /* | ||
util.h - utility functions for interfacing with the various python APIs. | ||||
This software may be used and distributed according to the terms of | ||||
the GNU General Public License, incorporated herein by reference. | ||||
*/ | ||||
#ifndef _HG_UTIL_H_ | ||||
#define _HG_UTIL_H_ | ||||
Maciej Fijalkowski
|
r29444 | #include "compat.h" | ||
Renato Cunha
|
r11358 | #if PY_MAJOR_VERSION >= 3 | ||
#define IS_PY3K | ||||
Gregory Szorc
|
r30112 | #endif | ||
Renato Cunha
|
r11358 | |||
Siddharth Agarwal
|
r21809 | typedef struct { | ||
PyObject_HEAD | ||||
char state; | ||||
int mode; | ||||
int size; | ||||
int mtime; | ||||
} dirstateTupleObject; | ||||
André Sintzoff
|
r21838 | extern PyTypeObject dirstateTupleType; | ||
Siddharth Agarwal
|
r21809 | #define dirstate_tuple_check(op) (Py_TYPE(op) == &dirstateTupleType) | ||
Siddharth Agarwal
|
r24608 | /* This should be kept in sync with normcasespecs in encoding.py. */ | ||
enum normcase_spec { | ||||
NORMCASE_LOWER = -1, | ||||
NORMCASE_UPPER = 1, | ||||
NORMCASE_OTHER = 0 | ||||
}; | ||||
Laurent Charignon
|
r24443 | #define MIN(a, b) (((a)<(b))?(a):(b)) | ||
Matt Mackall
|
r24442 | /* VC9 doesn't include bool and lacks stdbool.h based on my searching */ | ||
Kevin Bullock
|
r24829 | #if defined(_MSC_VER) || __STDC_VERSION__ < 199901L | ||
Matt Mackall
|
r24442 | #define true 1 | ||
#define false 0 | ||||
typedef unsigned char bool; | ||||
#else | ||||
#include <stdbool.h> | ||||
#endif | ||||
Gregory Szorc
|
r32378 | static int8_t hextable[256] = { | ||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 0-9 */ | ||||
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* A-F */ | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* a-f */ | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | ||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 | ||||
}; | ||||
static inline int hexdigit(const char *p, Py_ssize_t off) | ||||
{ | ||||
int8_t val = hextable[(unsigned char)p[off]]; | ||||
if (val >= 0) { | ||||
return val; | ||||
} | ||||
PyErr_SetString(PyExc_ValueError, "input contains non-hex character"); | ||||
return 0; | ||||
} | ||||
Renato Cunha
|
r11358 | #endif /* _HG_UTIL_H_ */ | ||