Search
lxdream.org :: lxdream/src/xlat/disasm/safe-ctype.h
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
nkeynes@1265
     1
/* <ctype.h> replacement macros.
nkeynes@1265
     2
nkeynes@1265
     3
   Copyright (C) 2000, 2001 Free Software Foundation, Inc.
nkeynes@1265
     4
   Contributed by Zack Weinberg <zackw@stanford.edu>.
nkeynes@1265
     5
nkeynes@1265
     6
This file is part of the libiberty library.
nkeynes@1265
     7
Libiberty is free software; you can redistribute it and/or
nkeynes@1265
     8
modify it under the terms of the GNU Library General Public
nkeynes@1265
     9
License as published by the Free Software Foundation; either
nkeynes@1265
    10
version 2 of the License, or (at your option) any later version.
nkeynes@1265
    11
nkeynes@1265
    12
Libiberty is distributed in the hope that it will be useful,
nkeynes@1265
    13
but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@1265
    14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
nkeynes@1265
    15
Library General Public License for more details.
nkeynes@1265
    16
nkeynes@1265
    17
You should have received a copy of the GNU Library General Public
nkeynes@1265
    18
License along with libiberty; see the file COPYING.LIB.  If
nkeynes@1265
    19
not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
nkeynes@1265
    20
Boston, MA 02110-1301, USA.  */
nkeynes@1265
    21
nkeynes@1265
    22
/* This is a compatible replacement of the standard C library's <ctype.h>
nkeynes@1265
    23
   with the following properties:
nkeynes@1265
    24
nkeynes@1265
    25
   - Implements all isxxx() macros required by C99.
nkeynes@1265
    26
   - Also implements some character classes useful when
nkeynes@1265
    27
     parsing C-like languages.
nkeynes@1265
    28
   - Does not change behavior depending on the current locale.
nkeynes@1265
    29
   - Behaves properly for all values in the range of a signed or
nkeynes@1265
    30
     unsigned char.
nkeynes@1265
    31
nkeynes@1265
    32
   To avoid conflicts, this header defines the isxxx functions in upper
nkeynes@1265
    33
   case, e.g. ISALPHA not isalpha.  */
nkeynes@1265
    34
nkeynes@1265
    35
#ifndef SAFE_CTYPE_H
nkeynes@1265
    36
#define SAFE_CTYPE_H
nkeynes@1265
    37
nkeynes@1265
    38
/* Determine host character set.  */
nkeynes@1265
    39
#define HOST_CHARSET_UNKNOWN 0
nkeynes@1265
    40
#define HOST_CHARSET_ASCII   1
nkeynes@1265
    41
#define HOST_CHARSET_EBCDIC  2
nkeynes@1265
    42
nkeynes@1265
    43
#if  '\n' == 0x0A && ' ' == 0x20 && '0' == 0x30 \
nkeynes@1265
    44
   && 'A' == 0x41 && 'a' == 0x61 && '!' == 0x21
nkeynes@1265
    45
#  define HOST_CHARSET HOST_CHARSET_ASCII
nkeynes@1265
    46
#else
nkeynes@1265
    47
# if '\n' == 0x15 && ' ' == 0x40 && '0' == 0xF0 \
nkeynes@1265
    48
   && 'A' == 0xC1 && 'a' == 0x81 && '!' == 0x5A
nkeynes@1265
    49
#  define HOST_CHARSET HOST_CHARSET_EBCDIC
nkeynes@1265
    50
# else
nkeynes@1265
    51
#  define HOST_CHARSET HOST_CHARSET_UNKNOWN
nkeynes@1265
    52
# endif
nkeynes@1265
    53
#endif
nkeynes@1265
    54
nkeynes@1265
    55
/* Categories.  */
nkeynes@1265
    56
nkeynes@1265
    57
enum {
nkeynes@1265
    58
  /* In C99 */
nkeynes@1265
    59
  _sch_isblank  = 0x0001,	/* space \t */
nkeynes@1265
    60
  _sch_iscntrl  = 0x0002,	/* nonprinting characters */
nkeynes@1265
    61
  _sch_isdigit  = 0x0004,	/* 0-9 */
nkeynes@1265
    62
  _sch_islower  = 0x0008,	/* a-z */
nkeynes@1265
    63
  _sch_isprint  = 0x0010,	/* any printing character including ' ' */
nkeynes@1265
    64
  _sch_ispunct  = 0x0020,	/* all punctuation */
nkeynes@1265
    65
  _sch_isspace  = 0x0040,	/* space \t \n \r \f \v */
nkeynes@1265
    66
  _sch_isupper  = 0x0080,	/* A-Z */
nkeynes@1265
    67
  _sch_isxdigit = 0x0100,	/* 0-9A-Fa-f */
nkeynes@1265
    68
nkeynes@1265
    69
  /* Extra categories useful to cpplib.  */
nkeynes@1265
    70
  _sch_isidst	= 0x0200,	/* A-Za-z_ */
nkeynes@1265
    71
  _sch_isvsp    = 0x0400,	/* \n \r */
nkeynes@1265
    72
  _sch_isnvsp   = 0x0800,	/* space \t \f \v \0 */
nkeynes@1265
    73
nkeynes@1265
    74
  /* Combinations of the above.  */
nkeynes@1265
    75
  _sch_isalpha  = _sch_isupper|_sch_islower,	/* A-Za-z */
nkeynes@1265
    76
  _sch_isalnum  = _sch_isalpha|_sch_isdigit,	/* A-Za-z0-9 */
nkeynes@1265
    77
  _sch_isidnum  = _sch_isidst|_sch_isdigit,	/* A-Za-z0-9_ */
nkeynes@1265
    78
  _sch_isgraph  = _sch_isalnum|_sch_ispunct,	/* isprint and not space */
nkeynes@1265
    79
  _sch_iscppsp  = _sch_isvsp|_sch_isnvsp,	/* isspace + \0 */
nkeynes@1265
    80
  _sch_isbasic  = _sch_isprint|_sch_iscppsp     /* basic charset of ISO C
nkeynes@1265
    81
						   (plus ` and @)  */
nkeynes@1265
    82
};
nkeynes@1265
    83
nkeynes@1265
    84
/* Character classification.  */
nkeynes@1265
    85
extern const unsigned short _sch_istable[256];
nkeynes@1265
    86
nkeynes@1265
    87
#define _sch_test(c, bit) (_sch_istable[(c) & 0xff] & (unsigned short)(bit))
nkeynes@1265
    88
nkeynes@1265
    89
#define ISALPHA(c)  _sch_test(c, _sch_isalpha)
nkeynes@1265
    90
#define ISALNUM(c)  _sch_test(c, _sch_isalnum)
nkeynes@1265
    91
#define ISBLANK(c)  _sch_test(c, _sch_isblank)
nkeynes@1265
    92
#define ISCNTRL(c)  _sch_test(c, _sch_iscntrl)
nkeynes@1265
    93
#define ISDIGIT(c)  _sch_test(c, _sch_isdigit)
nkeynes@1265
    94
#define ISGRAPH(c)  _sch_test(c, _sch_isgraph)
nkeynes@1265
    95
#define ISLOWER(c)  _sch_test(c, _sch_islower)
nkeynes@1265
    96
#define ISPRINT(c)  _sch_test(c, _sch_isprint)
nkeynes@1265
    97
#define ISPUNCT(c)  _sch_test(c, _sch_ispunct)
nkeynes@1265
    98
#define ISSPACE(c)  _sch_test(c, _sch_isspace)
nkeynes@1265
    99
#define ISUPPER(c)  _sch_test(c, _sch_isupper)
nkeynes@1265
   100
#define ISXDIGIT(c) _sch_test(c, _sch_isxdigit)
nkeynes@1265
   101
nkeynes@1265
   102
#define ISIDNUM(c)	_sch_test(c, _sch_isidnum)
nkeynes@1265
   103
#define ISIDST(c)	_sch_test(c, _sch_isidst)
nkeynes@1265
   104
#define IS_ISOBASIC(c)	_sch_test(c, _sch_isbasic)
nkeynes@1265
   105
#define IS_VSPACE(c)	_sch_test(c, _sch_isvsp)
nkeynes@1265
   106
#define IS_NVSPACE(c)	_sch_test(c, _sch_isnvsp)
nkeynes@1265
   107
#define IS_SPACE_OR_NUL(c)	_sch_test(c, _sch_iscppsp)
nkeynes@1265
   108
nkeynes@1265
   109
/* Character transformation.  */
nkeynes@1265
   110
extern const unsigned char  _sch_toupper[256];
nkeynes@1265
   111
extern const unsigned char  _sch_tolower[256];
nkeynes@1265
   112
#define TOUPPER(c) _sch_toupper[(c) & 0xff]
nkeynes@1265
   113
#define TOLOWER(c) _sch_tolower[(c) & 0xff]
nkeynes@1265
   114
nkeynes@1265
   115
/* Prevent the users of safe-ctype.h from accidently using the routines
nkeynes@1265
   116
   from ctype.h.  Initially, the approach was to produce an error when
nkeynes@1265
   117
   detecting that ctype.h has been included.  But this was causing
nkeynes@1265
   118
   trouble as ctype.h might get indirectly included as a result of
nkeynes@1265
   119
   including another system header (for instance gnulib's stdint.h).
nkeynes@1265
   120
   So we include ctype.h here and then immediately redefine its macros.  */
nkeynes@1265
   121
nkeynes@1265
   122
#include <ctype.h>
nkeynes@1265
   123
#undef isalpha
nkeynes@1265
   124
#define isalpha(c) do_not_use_isalpha_with_safe_ctype
nkeynes@1265
   125
#undef isalnum
nkeynes@1265
   126
#define isalnum(c) do_not_use_isalnum_with_safe_ctype
nkeynes@1265
   127
#undef iscntrl
nkeynes@1265
   128
#define iscntrl(c) do_not_use_iscntrl_with_safe_ctype
nkeynes@1265
   129
#undef isdigit
nkeynes@1265
   130
#define isdigit(c) do_not_use_isdigit_with_safe_ctype
nkeynes@1265
   131
#undef isgraph
nkeynes@1265
   132
#define isgraph(c) do_not_use_isgraph_with_safe_ctype
nkeynes@1265
   133
#undef islower
nkeynes@1265
   134
#define islower(c) do_not_use_islower_with_safe_ctype
nkeynes@1265
   135
#undef isprint
nkeynes@1265
   136
#define isprint(c) do_not_use_isprint_with_safe_ctype
nkeynes@1265
   137
#undef ispunct
nkeynes@1265
   138
#define ispunct(c) do_not_use_ispunct_with_safe_ctype
nkeynes@1265
   139
#undef isspace
nkeynes@1265
   140
#define isspace(c) do_not_use_isspace_with_safe_ctype
nkeynes@1265
   141
#undef isupper
nkeynes@1265
   142
#define isupper(c) do_not_use_isupper_with_safe_ctype
nkeynes@1265
   143
#undef isxdigit
nkeynes@1265
   144
#define isxdigit(c) do_not_use_isxdigit_with_safe_ctype
nkeynes@1265
   145
#undef toupper
nkeynes@1265
   146
#define toupper(c) do_not_use_toupper_with_safe_ctype
nkeynes@1265
   147
#undef tolower
nkeynes@1265
   148
#define tolower(c) do_not_use_tolower_with_safe_ctype
nkeynes@1265
   149
nkeynes@1265
   150
#endif /* SAFE_CTYPE_H */
.