Search
lxdream.org :: lxdream/src/xlat/disasm/safe-ctype.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/xlat/disasm/safe-ctype.c
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, 2002, 2003, 2004,
nkeynes@1265
     4
   2005 Free Software Foundation, Inc.
nkeynes@1265
     5
   Contributed by Zack Weinberg <zackw@stanford.edu>.
nkeynes@1265
     6
nkeynes@1265
     7
This file is part of the libiberty library.
nkeynes@1265
     8
Libiberty is free software; you can redistribute it and/or
nkeynes@1265
     9
modify it under the terms of the GNU Library General Public
nkeynes@1265
    10
License as published by the Free Software Foundation; either
nkeynes@1265
    11
version 2 of the License, or (at your option) any later version.
nkeynes@1265
    12
nkeynes@1265
    13
Libiberty is distributed in the hope that it will be useful,
nkeynes@1265
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@1265
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
nkeynes@1265
    16
Library General Public License for more details.
nkeynes@1265
    17
nkeynes@1265
    18
You should have received a copy of the GNU Library General Public
nkeynes@1265
    19
License along with libiberty; see the file COPYING.LIB.  If
nkeynes@1265
    20
not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
nkeynes@1265
    21
Boston, MA 02110-1301, USA.  */
nkeynes@1265
    22
nkeynes@1265
    23
/*
nkeynes@1265
    24
nkeynes@1265
    25
@defvr Extension HOST_CHARSET
nkeynes@1265
    26
This macro indicates the basic character set and encoding used by the
nkeynes@1265
    27
host: more precisely, the encoding used for character constants in
nkeynes@1265
    28
preprocessor @samp{#if} statements (the C "execution character set").
nkeynes@1265
    29
It is defined by @file{safe-ctype.h}, and will be an integer constant
nkeynes@1265
    30
with one of the following values:
nkeynes@1265
    31
nkeynes@1265
    32
@ftable @code
nkeynes@1265
    33
@item HOST_CHARSET_UNKNOWN
nkeynes@1265
    34
The host character set is unknown - that is, not one of the next two
nkeynes@1265
    35
possibilities.
nkeynes@1265
    36
nkeynes@1265
    37
@item HOST_CHARSET_ASCII
nkeynes@1265
    38
The host character set is ASCII.
nkeynes@1265
    39
nkeynes@1265
    40
@item HOST_CHARSET_EBCDIC
nkeynes@1265
    41
The host character set is some variant of EBCDIC.  (Only one of the
nkeynes@1265
    42
nineteen EBCDIC varying characters is tested; exercise caution.)
nkeynes@1265
    43
@end ftable
nkeynes@1265
    44
@end defvr
nkeynes@1265
    45
nkeynes@1265
    46
@deffn  Extension ISALPHA  (@var{c})
nkeynes@1265
    47
@deffnx Extension ISALNUM  (@var{c})
nkeynes@1265
    48
@deffnx Extension ISBLANK  (@var{c})
nkeynes@1265
    49
@deffnx Extension ISCNTRL  (@var{c})
nkeynes@1265
    50
@deffnx Extension ISDIGIT  (@var{c})
nkeynes@1265
    51
@deffnx Extension ISGRAPH  (@var{c})
nkeynes@1265
    52
@deffnx Extension ISLOWER  (@var{c})
nkeynes@1265
    53
@deffnx Extension ISPRINT  (@var{c})
nkeynes@1265
    54
@deffnx Extension ISPUNCT  (@var{c})
nkeynes@1265
    55
@deffnx Extension ISSPACE  (@var{c})
nkeynes@1265
    56
@deffnx Extension ISUPPER  (@var{c})
nkeynes@1265
    57
@deffnx Extension ISXDIGIT (@var{c})
nkeynes@1265
    58
nkeynes@1265
    59
These twelve macros are defined by @file{safe-ctype.h}.  Each has the
nkeynes@1265
    60
same meaning as the corresponding macro (with name in lowercase)
nkeynes@1265
    61
defined by the standard header @file{ctype.h}.  For example,
nkeynes@1265
    62
@code{ISALPHA} returns true for alphabetic characters and false for
nkeynes@1265
    63
others.  However, there are two differences between these macros and
nkeynes@1265
    64
those provided by @file{ctype.h}:
nkeynes@1265
    65
nkeynes@1265
    66
@itemize @bullet
nkeynes@1265
    67
@item These macros are guaranteed to have well-defined behavior for all 
nkeynes@1265
    68
values representable by @code{signed char} and @code{unsigned char}, and
nkeynes@1265
    69
for @code{EOF}.
nkeynes@1265
    70
nkeynes@1265
    71
@item These macros ignore the current locale; they are true for these
nkeynes@1265
    72
fixed sets of characters:
nkeynes@1265
    73
@multitable {@code{XDIGIT}} {yada yada yada yada yada yada yada yada}
nkeynes@1265
    74
@item @code{ALPHA}  @tab @kbd{A-Za-z}
nkeynes@1265
    75
@item @code{ALNUM}  @tab @kbd{A-Za-z0-9}
nkeynes@1265
    76
@item @code{BLANK}  @tab @kbd{space tab}
nkeynes@1265
    77
@item @code{CNTRL}  @tab @code{!PRINT}
nkeynes@1265
    78
@item @code{DIGIT}  @tab @kbd{0-9}
nkeynes@1265
    79
@item @code{GRAPH}  @tab @code{ALNUM || PUNCT}
nkeynes@1265
    80
@item @code{LOWER}  @tab @kbd{a-z}
nkeynes@1265
    81
@item @code{PRINT}  @tab @code{GRAPH ||} @kbd{space}
nkeynes@1265
    82
@item @code{PUNCT}  @tab @kbd{`~!@@#$%^&*()_-=+[@{]@}\|;:'",<.>/?}
nkeynes@1265
    83
@item @code{SPACE}  @tab @kbd{space tab \n \r \f \v}
nkeynes@1265
    84
@item @code{UPPER}  @tab @kbd{A-Z}
nkeynes@1265
    85
@item @code{XDIGIT} @tab @kbd{0-9A-Fa-f}
nkeynes@1265
    86
@end multitable
nkeynes@1265
    87
nkeynes@1265
    88
Note that, if the host character set is ASCII or a superset thereof,
nkeynes@1265
    89
all these macros will return false for all values of @code{char} outside
nkeynes@1265
    90
the range of 7-bit ASCII.  In particular, both ISPRINT and ISCNTRL return
nkeynes@1265
    91
false for characters with numeric values from 128 to 255.
nkeynes@1265
    92
@end itemize
nkeynes@1265
    93
@end deffn
nkeynes@1265
    94
nkeynes@1265
    95
@deffn  Extension ISIDNUM         (@var{c})
nkeynes@1265
    96
@deffnx Extension ISIDST          (@var{c})
nkeynes@1265
    97
@deffnx Extension IS_VSPACE       (@var{c})
nkeynes@1265
    98
@deffnx Extension IS_NVSPACE      (@var{c})
nkeynes@1265
    99
@deffnx Extension IS_SPACE_OR_NUL (@var{c})
nkeynes@1265
   100
@deffnx Extension IS_ISOBASIC     (@var{c})
nkeynes@1265
   101
These six macros are defined by @file{safe-ctype.h} and provide
nkeynes@1265
   102
additional character classes which are useful when doing lexical
nkeynes@1265
   103
analysis of C or similar languages.  They are true for the following
nkeynes@1265
   104
sets of characters:
nkeynes@1265
   105
nkeynes@1265
   106
@multitable {@code{SPACE_OR_NUL}} {yada yada yada yada yada yada yada yada}
nkeynes@1265
   107
@item @code{IDNUM}        @tab @kbd{A-Za-z0-9_}
nkeynes@1265
   108
@item @code{IDST}         @tab @kbd{A-Za-z_}
nkeynes@1265
   109
@item @code{VSPACE}       @tab @kbd{\r \n}
nkeynes@1265
   110
@item @code{NVSPACE}      @tab @kbd{space tab \f \v \0}
nkeynes@1265
   111
@item @code{SPACE_OR_NUL} @tab @code{VSPACE || NVSPACE}
nkeynes@1265
   112
@item @code{ISOBASIC}     @tab @code{VSPACE || NVSPACE || PRINT}
nkeynes@1265
   113
@end multitable
nkeynes@1265
   114
@end deffn
nkeynes@1265
   115
nkeynes@1265
   116
*/
nkeynes@1265
   117
nkeynes@1265
   118
#include "ansidecl.h"
nkeynes@1265
   119
#include "xlat/disasm/safe-ctype.h"
nkeynes@1265
   120
#include <stdio.h>  /* for EOF */
nkeynes@1265
   121
nkeynes@1265
   122
#if EOF != -1
nkeynes@1265
   123
 #error "<safe-ctype.h> requires EOF == -1"
nkeynes@1265
   124
#endif
nkeynes@1265
   125
nkeynes@1265
   126
/* Shorthand */
nkeynes@1265
   127
#define bl _sch_isblank
nkeynes@1265
   128
#define cn _sch_iscntrl
nkeynes@1265
   129
#define di _sch_isdigit
nkeynes@1265
   130
#define is _sch_isidst
nkeynes@1265
   131
#define lo _sch_islower
nkeynes@1265
   132
#define nv _sch_isnvsp
nkeynes@1265
   133
#define pn _sch_ispunct
nkeynes@1265
   134
#define pr _sch_isprint
nkeynes@1265
   135
#define sp _sch_isspace
nkeynes@1265
   136
#define up _sch_isupper
nkeynes@1265
   137
#define vs _sch_isvsp
nkeynes@1265
   138
#define xd _sch_isxdigit
nkeynes@1265
   139
nkeynes@1265
   140
/* Masks.  */
nkeynes@1265
   141
#define L  (const unsigned short) (lo|is   |pr)	/* lower case letter */
nkeynes@1265
   142
#define XL (const unsigned short) (lo|is|xd|pr)	/* lowercase hex digit */
nkeynes@1265
   143
#define U  (const unsigned short) (up|is   |pr)	/* upper case letter */
nkeynes@1265
   144
#define XU (const unsigned short) (up|is|xd|pr)	/* uppercase hex digit */
nkeynes@1265
   145
#define D  (const unsigned short) (di   |xd|pr)	/* decimal digit */
nkeynes@1265
   146
#define P  (const unsigned short) (pn      |pr)	/* punctuation */
nkeynes@1265
   147
#define _  (const unsigned short) (pn|is   |pr)	/* underscore */
nkeynes@1265
   148
nkeynes@1265
   149
#define C  (const unsigned short) (         cn)	/* control character */
nkeynes@1265
   150
#define Z  (const unsigned short) (nv      |cn)	/* NUL */
nkeynes@1265
   151
#define M  (const unsigned short) (nv|sp   |cn)	/* cursor movement: \f \v */
nkeynes@1265
   152
#define V  (const unsigned short) (vs|sp   |cn)	/* vertical space: \r \n */
nkeynes@1265
   153
#define T  (const unsigned short) (nv|sp|bl|cn)	/* tab */
nkeynes@1265
   154
#define S  (const unsigned short) (nv|sp|bl|pr)	/* space */
nkeynes@1265
   155
nkeynes@1265
   156
/* Are we ASCII? */
nkeynes@1265
   157
#if HOST_CHARSET == HOST_CHARSET_ASCII
nkeynes@1265
   158
nkeynes@1265
   159
const unsigned short _sch_istable[256] =
nkeynes@1265
   160
{
nkeynes@1265
   161
  Z,  C,  C,  C,   C,  C,  C,  C,   /* NUL SOH STX ETX  EOT ENQ ACK BEL */
nkeynes@1265
   162
  C,  T,  V,  M,   M,  V,  C,  C,   /* BS  HT  LF  VT   FF  CR  SO  SI  */
nkeynes@1265
   163
  C,  C,  C,  C,   C,  C,  C,  C,   /* DLE DC1 DC2 DC3  DC4 NAK SYN ETB */
nkeynes@1265
   164
  C,  C,  C,  C,   C,  C,  C,  C,   /* CAN EM  SUB ESC  FS  GS  RS  US  */
nkeynes@1265
   165
  S,  P,  P,  P,   P,  P,  P,  P,   /* SP  !   "   #    $   %   &   '   */
nkeynes@1265
   166
  P,  P,  P,  P,   P,  P,  P,  P,   /* (   )   *   +    ,   -   .   /   */
nkeynes@1265
   167
  D,  D,  D,  D,   D,  D,  D,  D,   /* 0   1   2   3    4   5   6   7   */
nkeynes@1265
   168
  D,  D,  P,  P,   P,  P,  P,  P,   /* 8   9   :   ;    <   =   >   ?   */
nkeynes@1265
   169
  P, XU, XU, XU,  XU, XU, XU,  U,   /* @   A   B   C    D   E   F   G   */
nkeynes@1265
   170
  U,  U,  U,  U,   U,  U,  U,  U,   /* H   I   J   K    L   M   N   O   */
nkeynes@1265
   171
  U,  U,  U,  U,   U,  U,  U,  U,   /* P   Q   R   S    T   U   V   W   */
nkeynes@1265
   172
  U,  U,  U,  P,   P,  P,  P,  _,   /* X   Y   Z   [    \   ]   ^   _   */
nkeynes@1265
   173
  P, XL, XL, XL,  XL, XL, XL,  L,   /* `   a   b   c    d   e   f   g   */
nkeynes@1265
   174
  L,  L,  L,  L,   L,  L,  L,  L,   /* h   i   j   k    l   m   n   o   */
nkeynes@1265
   175
  L,  L,  L,  L,   L,  L,  L,  L,   /* p   q   r   s    t   u   v   w   */
nkeynes@1265
   176
  L,  L,  L,  P,   P,  P,  P,  C,   /* x   y   z   {    |   }   ~   DEL */
nkeynes@1265
   177
nkeynes@1265
   178
  /* high half of unsigned char is locale-specific, so all tests are
nkeynes@1265
   179
     false in "C" locale */
nkeynes@1265
   180
  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
nkeynes@1265
   181
  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
nkeynes@1265
   182
  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
nkeynes@1265
   183
  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
nkeynes@1265
   184
nkeynes@1265
   185
  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
nkeynes@1265
   186
  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
nkeynes@1265
   187
  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
nkeynes@1265
   188
  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
nkeynes@1265
   189
};
nkeynes@1265
   190
nkeynes@1265
   191
const unsigned char _sch_tolower[256] =
nkeynes@1265
   192
{
nkeynes@1265
   193
   0,  1,  2,  3,   4,  5,  6,  7,   8,  9, 10, 11,  12, 13, 14, 15,
nkeynes@1265
   194
  16, 17, 18, 19,  20, 21, 22, 23,  24, 25, 26, 27,  28, 29, 30, 31,
nkeynes@1265
   195
  32, 33, 34, 35,  36, 37, 38, 39,  40, 41, 42, 43,  44, 45, 46, 47,
nkeynes@1265
   196
  48, 49, 50, 51,  52, 53, 54, 55,  56, 57, 58, 59,  60, 61, 62, 63,
nkeynes@1265
   197
  64,
nkeynes@1265
   198
nkeynes@1265
   199
  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
nkeynes@1265
   200
  'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
nkeynes@1265
   201
nkeynes@1265
   202
  91, 92, 93, 94, 95, 96,
nkeynes@1265
   203
nkeynes@1265
   204
  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
nkeynes@1265
   205
  'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
nkeynes@1265
   206
nkeynes@1265
   207
 123,124,125,126,127,
nkeynes@1265
   208
nkeynes@1265
   209
 128,129,130,131, 132,133,134,135, 136,137,138,139, 140,141,142,143,
nkeynes@1265
   210
 144,145,146,147, 148,149,150,151, 152,153,154,155, 156,157,158,159,
nkeynes@1265
   211
 160,161,162,163, 164,165,166,167, 168,169,170,171, 172,173,174,175,
nkeynes@1265
   212
 176,177,178,179, 180,181,182,183, 184,185,186,187, 188,189,190,191,
nkeynes@1265
   213
nkeynes@1265
   214
 192,193,194,195, 196,197,198,199, 200,201,202,203, 204,205,206,207,
nkeynes@1265
   215
 208,209,210,211, 212,213,214,215, 216,217,218,219, 220,221,222,223,
nkeynes@1265
   216
 224,225,226,227, 228,229,230,231, 232,233,234,235, 236,237,238,239,
nkeynes@1265
   217
 240,241,242,243, 244,245,246,247, 248,249,250,251, 252,253,254,255,
nkeynes@1265
   218
};
nkeynes@1265
   219
nkeynes@1265
   220
const unsigned char _sch_toupper[256] =
nkeynes@1265
   221
{
nkeynes@1265
   222
   0,  1,  2,  3,   4,  5,  6,  7,   8,  9, 10, 11,  12, 13, 14, 15,
nkeynes@1265
   223
  16, 17, 18, 19,  20, 21, 22, 23,  24, 25, 26, 27,  28, 29, 30, 31,
nkeynes@1265
   224
  32, 33, 34, 35,  36, 37, 38, 39,  40, 41, 42, 43,  44, 45, 46, 47,
nkeynes@1265
   225
  48, 49, 50, 51,  52, 53, 54, 55,  56, 57, 58, 59,  60, 61, 62, 63,
nkeynes@1265
   226
  64,
nkeynes@1265
   227
nkeynes@1265
   228
  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
nkeynes@1265
   229
  'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
nkeynes@1265
   230
nkeynes@1265
   231
  91, 92, 93, 94, 95, 96,
nkeynes@1265
   232
nkeynes@1265
   233
  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
nkeynes@1265
   234
  'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
nkeynes@1265
   235
nkeynes@1265
   236
 123,124,125,126,127,
nkeynes@1265
   237
nkeynes@1265
   238
 128,129,130,131, 132,133,134,135, 136,137,138,139, 140,141,142,143,
nkeynes@1265
   239
 144,145,146,147, 148,149,150,151, 152,153,154,155, 156,157,158,159,
nkeynes@1265
   240
 160,161,162,163, 164,165,166,167, 168,169,170,171, 172,173,174,175,
nkeynes@1265
   241
 176,177,178,179, 180,181,182,183, 184,185,186,187, 188,189,190,191,
nkeynes@1265
   242
nkeynes@1265
   243
 192,193,194,195, 196,197,198,199, 200,201,202,203, 204,205,206,207,
nkeynes@1265
   244
 208,209,210,211, 212,213,214,215, 216,217,218,219, 220,221,222,223,
nkeynes@1265
   245
 224,225,226,227, 228,229,230,231, 232,233,234,235, 236,237,238,239,
nkeynes@1265
   246
 240,241,242,243, 244,245,246,247, 248,249,250,251, 252,253,254,255,
nkeynes@1265
   247
};
nkeynes@1265
   248
nkeynes@1265
   249
#else
nkeynes@1265
   250
# if HOST_CHARSET == HOST_CHARSET_EBCDIC
nkeynes@1265
   251
  #error "FIXME: write tables for EBCDIC"
nkeynes@1265
   252
# else
nkeynes@1265
   253
  #error "Unrecognized host character set"
nkeynes@1265
   254
# endif
nkeynes@1265
   255
#endif
.