Search
lxdream.org :: lxdream/src/xlat/disasm/safe-ctype.h :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/xlat/disasm/safe-ctype.h
changeset 1265:7c6c5d26fd2e
author nkeynes
date Tue Mar 06 12:42:33 2012 +1000 (8 years ago)
permissions -rw-r--r--
last change Merge ARM disassembler from binutils 2.22
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/xlat/disasm/safe-ctype.h Tue Mar 06 12:42:33 2012 +1000
1.3 @@ -0,0 +1,150 @@
1.4 +/* <ctype.h> replacement macros.
1.5 +
1.6 + Copyright (C) 2000, 2001 Free Software Foundation, Inc.
1.7 + Contributed by Zack Weinberg <zackw@stanford.edu>.
1.8 +
1.9 +This file is part of the libiberty library.
1.10 +Libiberty is free software; you can redistribute it and/or
1.11 +modify it under the terms of the GNU Library General Public
1.12 +License as published by the Free Software Foundation; either
1.13 +version 2 of the License, or (at your option) any later version.
1.14 +
1.15 +Libiberty is distributed in the hope that it will be useful,
1.16 +but WITHOUT ANY WARRANTY; without even the implied warranty of
1.17 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.18 +Library General Public License for more details.
1.19 +
1.20 +You should have received a copy of the GNU Library General Public
1.21 +License along with libiberty; see the file COPYING.LIB. If
1.22 +not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
1.23 +Boston, MA 02110-1301, USA. */
1.24 +
1.25 +/* This is a compatible replacement of the standard C library's <ctype.h>
1.26 + with the following properties:
1.27 +
1.28 + - Implements all isxxx() macros required by C99.
1.29 + - Also implements some character classes useful when
1.30 + parsing C-like languages.
1.31 + - Does not change behavior depending on the current locale.
1.32 + - Behaves properly for all values in the range of a signed or
1.33 + unsigned char.
1.34 +
1.35 + To avoid conflicts, this header defines the isxxx functions in upper
1.36 + case, e.g. ISALPHA not isalpha. */
1.37 +
1.38 +#ifndef SAFE_CTYPE_H
1.39 +#define SAFE_CTYPE_H
1.40 +
1.41 +/* Determine host character set. */
1.42 +#define HOST_CHARSET_UNKNOWN 0
1.43 +#define HOST_CHARSET_ASCII 1
1.44 +#define HOST_CHARSET_EBCDIC 2
1.45 +
1.46 +#if '\n' == 0x0A && ' ' == 0x20 && '0' == 0x30 \
1.47 + && 'A' == 0x41 && 'a' == 0x61 && '!' == 0x21
1.48 +# define HOST_CHARSET HOST_CHARSET_ASCII
1.49 +#else
1.50 +# if '\n' == 0x15 && ' ' == 0x40 && '0' == 0xF0 \
1.51 + && 'A' == 0xC1 && 'a' == 0x81 && '!' == 0x5A
1.52 +# define HOST_CHARSET HOST_CHARSET_EBCDIC
1.53 +# else
1.54 +# define HOST_CHARSET HOST_CHARSET_UNKNOWN
1.55 +# endif
1.56 +#endif
1.57 +
1.58 +/* Categories. */
1.59 +
1.60 +enum {
1.61 + /* In C99 */
1.62 + _sch_isblank = 0x0001, /* space \t */
1.63 + _sch_iscntrl = 0x0002, /* nonprinting characters */
1.64 + _sch_isdigit = 0x0004, /* 0-9 */
1.65 + _sch_islower = 0x0008, /* a-z */
1.66 + _sch_isprint = 0x0010, /* any printing character including ' ' */
1.67 + _sch_ispunct = 0x0020, /* all punctuation */
1.68 + _sch_isspace = 0x0040, /* space \t \n \r \f \v */
1.69 + _sch_isupper = 0x0080, /* A-Z */
1.70 + _sch_isxdigit = 0x0100, /* 0-9A-Fa-f */
1.71 +
1.72 + /* Extra categories useful to cpplib. */
1.73 + _sch_isidst = 0x0200, /* A-Za-z_ */
1.74 + _sch_isvsp = 0x0400, /* \n \r */
1.75 + _sch_isnvsp = 0x0800, /* space \t \f \v \0 */
1.76 +
1.77 + /* Combinations of the above. */
1.78 + _sch_isalpha = _sch_isupper|_sch_islower, /* A-Za-z */
1.79 + _sch_isalnum = _sch_isalpha|_sch_isdigit, /* A-Za-z0-9 */
1.80 + _sch_isidnum = _sch_isidst|_sch_isdigit, /* A-Za-z0-9_ */
1.81 + _sch_isgraph = _sch_isalnum|_sch_ispunct, /* isprint and not space */
1.82 + _sch_iscppsp = _sch_isvsp|_sch_isnvsp, /* isspace + \0 */
1.83 + _sch_isbasic = _sch_isprint|_sch_iscppsp /* basic charset of ISO C
1.84 + (plus ` and @) */
1.85 +};
1.86 +
1.87 +/* Character classification. */
1.88 +extern const unsigned short _sch_istable[256];
1.89 +
1.90 +#define _sch_test(c, bit) (_sch_istable[(c) & 0xff] & (unsigned short)(bit))
1.91 +
1.92 +#define ISALPHA(c) _sch_test(c, _sch_isalpha)
1.93 +#define ISALNUM(c) _sch_test(c, _sch_isalnum)
1.94 +#define ISBLANK(c) _sch_test(c, _sch_isblank)
1.95 +#define ISCNTRL(c) _sch_test(c, _sch_iscntrl)
1.96 +#define ISDIGIT(c) _sch_test(c, _sch_isdigit)
1.97 +#define ISGRAPH(c) _sch_test(c, _sch_isgraph)
1.98 +#define ISLOWER(c) _sch_test(c, _sch_islower)
1.99 +#define ISPRINT(c) _sch_test(c, _sch_isprint)
1.100 +#define ISPUNCT(c) _sch_test(c, _sch_ispunct)
1.101 +#define ISSPACE(c) _sch_test(c, _sch_isspace)
1.102 +#define ISUPPER(c) _sch_test(c, _sch_isupper)
1.103 +#define ISXDIGIT(c) _sch_test(c, _sch_isxdigit)
1.104 +
1.105 +#define ISIDNUM(c) _sch_test(c, _sch_isidnum)
1.106 +#define ISIDST(c) _sch_test(c, _sch_isidst)
1.107 +#define IS_ISOBASIC(c) _sch_test(c, _sch_isbasic)
1.108 +#define IS_VSPACE(c) _sch_test(c, _sch_isvsp)
1.109 +#define IS_NVSPACE(c) _sch_test(c, _sch_isnvsp)
1.110 +#define IS_SPACE_OR_NUL(c) _sch_test(c, _sch_iscppsp)
1.111 +
1.112 +/* Character transformation. */
1.113 +extern const unsigned char _sch_toupper[256];
1.114 +extern const unsigned char _sch_tolower[256];
1.115 +#define TOUPPER(c) _sch_toupper[(c) & 0xff]
1.116 +#define TOLOWER(c) _sch_tolower[(c) & 0xff]
1.117 +
1.118 +/* Prevent the users of safe-ctype.h from accidently using the routines
1.119 + from ctype.h. Initially, the approach was to produce an error when
1.120 + detecting that ctype.h has been included. But this was causing
1.121 + trouble as ctype.h might get indirectly included as a result of
1.122 + including another system header (for instance gnulib's stdint.h).
1.123 + So we include ctype.h here and then immediately redefine its macros. */
1.124 +
1.125 +#include <ctype.h>
1.126 +#undef isalpha
1.127 +#define isalpha(c) do_not_use_isalpha_with_safe_ctype
1.128 +#undef isalnum
1.129 +#define isalnum(c) do_not_use_isalnum_with_safe_ctype
1.130 +#undef iscntrl
1.131 +#define iscntrl(c) do_not_use_iscntrl_with_safe_ctype
1.132 +#undef isdigit
1.133 +#define isdigit(c) do_not_use_isdigit_with_safe_ctype
1.134 +#undef isgraph
1.135 +#define isgraph(c) do_not_use_isgraph_with_safe_ctype
1.136 +#undef islower
1.137 +#define islower(c) do_not_use_islower_with_safe_ctype
1.138 +#undef isprint
1.139 +#define isprint(c) do_not_use_isprint_with_safe_ctype
1.140 +#undef ispunct
1.141 +#define ispunct(c) do_not_use_ispunct_with_safe_ctype
1.142 +#undef isspace
1.143 +#define isspace(c) do_not_use_isspace_with_safe_ctype
1.144 +#undef isupper
1.145 +#define isupper(c) do_not_use_isupper_with_safe_ctype
1.146 +#undef isxdigit
1.147 +#define isxdigit(c) do_not_use_isxdigit_with_safe_ctype
1.148 +#undef toupper
1.149 +#define toupper(c) do_not_use_toupper_with_safe_ctype
1.150 +#undef tolower
1.151 +#define tolower(c) do_not_use_tolower_with_safe_ctype
1.152 +
1.153 +#endif /* SAFE_CTYPE_H */
.