OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [tags/] [start/] [insight/] [libiberty/] [safe-ctype.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/* <ctype.h> replacement macros.
2
 
3
   Copyright (C) 2000 Free Software Foundation, Inc.
4
   Contributed by Zack Weinberg <zackw@stanford.edu>.
5
 
6
This file is part of the libiberty library.
7
Libiberty is free software; you can redistribute it and/or
8
modify it under the terms of the GNU Library General Public
9
License as published by the Free Software Foundation; either
10
version 2 of the License, or (at your option) any later version.
11
 
12
Libiberty is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
Library General Public License for more details.
16
 
17
You should have received a copy of the GNU Library General Public
18
License along with libiberty; see the file COPYING.LIB.  If
19
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
Boston, MA 02111-1307, USA.  */
21
 
22
/* This is a compatible replacement of the standard C library's <ctype.h>
23
   with the following properties:
24
 
25
   - Implements all isxxx() macros required by C99.
26
   - Also implements some character classes useful when
27
     parsing C-like languages.
28
   - Does not change behavior depending on the current locale.
29
   - Behaves properly for all values in the range of a signed or
30
     unsigned char.  */
31
 
32
#include "ansidecl.h"
33
#include <safe-ctype.h>
34
#include <stdio.h>  /* for EOF */
35
 
36
/* Shorthand */
37
#define bl _sch_isblank
38
#define cn _sch_iscntrl
39
#define di _sch_isdigit
40
#define is _sch_isidst
41
#define lo _sch_islower
42
#define nv _sch_isnvsp
43
#define pn _sch_ispunct
44
#define pr _sch_isprint
45
#define sp _sch_isspace
46
#define up _sch_isupper
47
#define vs _sch_isvsp
48
#define xd _sch_isxdigit
49
 
50
/* Masks.  */
51
#define L  lo|is   |pr  /* lower case letter */
52
#define XL lo|is|xd|pr  /* lowercase hex digit */
53
#define U  up|is   |pr  /* upper case letter */
54
#define XU up|is|xd|pr  /* uppercase hex digit */
55
#define D  di   |xd|pr  /* decimal digit */
56
#define P  pn      |pr  /* punctuation */
57
#define _  pn|is   |pr  /* underscore */
58
 
59
#define C           cn  /* control character */
60
#define Z  nv      |cn  /* NUL */
61
#define M  nv|sp   |cn  /* cursor movement: \f \v */
62
#define V  vs|sp   |cn  /* vertical space: \r \n */
63
#define T  nv|sp|bl|cn  /* tab */
64
#define S  nv|sp|bl|pr  /* space */
65
 
66
/* Are we ASCII? */
67
#if '\n' == 0x0A && ' ' == 0x20 && '0' == 0x30 \
68
  && 'A' == 0x41 && 'a' == 0x61 && '!' == 0x21 \
69
  && EOF == -1
70
 
71
const unsigned short _sch_istable[256] =
72
{
73
  Z,  C,  C,  C,   C,  C,  C,  C,   /* NUL SOH STX ETX  EOT ENQ ACK BEL */
74
  C,  T,  V,  M,   M,  V,  C,  C,   /* BS  HT  LF  VT   FF  CR  SO  SI  */
75
  C,  C,  C,  C,   C,  C,  C,  C,   /* DLE DC1 DC2 DC3  DC4 NAK SYN ETB */
76
  C,  C,  C,  C,   C,  C,  C,  C,   /* CAN EM  SUB ESC  FS  GS  RS  US  */
77
  S,  P,  P,  P,   P,  P,  P,  P,   /* SP  !   "   #    $   %   &   '   */
78
  P,  P,  P,  P,   P,  P,  P,  P,   /* (   )   *   +    ,   -   .   /   */
79
  D,  D,  D,  D,   D,  D,  D,  D,   /* 0   1   2   3    4   5   6   7   */
80
  D,  D,  P,  P,   P,  P,  P,  P,   /* 8   9   :   ;    <   =   >   ?   */
81
  P, XU, XU, XU,  XU, XU, XU,  U,   /* @   A   B   C    D   E   F   G   */
82
  U,  U,  U,  U,   U,  U,  U,  U,   /* H   I   J   K    L   M   N   O   */
83
  U,  U,  U,  U,   U,  U,  U,  U,   /* P   Q   R   S    T   U   V   W   */
84
  U,  U,  U,  P,   P,  P,  P,  _,   /* X   Y   Z   [    \   ]   ^   _   */
85
  P, XL, XL, XL,  XL, XL, XL,  L,   /* `   a   b   c    d   e   f   g   */
86
  L,  L,  L,  L,   L,  L,  L,  L,   /* h   i   j   k    l   m   n   o   */
87
  L,  L,  L,  L,   L,  L,  L,  L,   /* p   q   r   s    t   u   v   w   */
88
  L,  L,  L,  P,   P,  P,  P,  C,   /* x   y   z   {    |   }   ~   DEL */
89
 
90
  /* high half of unsigned char is locale-specific, so all tests are
91
     false in "C" locale */
92
  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
93
  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
94
  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
95
  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
96
 
97
  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
98
  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
99
  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
100
  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
101
};
102
 
103
const unsigned char _sch_tolower[256] =
104
{
105
   0,  1,  2,  3,   4,  5,  6,  7,   8,  9, 10, 11,  12, 13, 14, 15,
106
  16, 17, 18, 19,  20, 21, 22, 23,  24, 25, 26, 27,  28, 29, 30, 31,
107
  32, 33, 34, 35,  36, 37, 38, 39,  40, 41, 42, 43,  44, 45, 46, 47,
108
  48, 49, 50, 51,  52, 53, 54, 55,  56, 57, 58, 59,  60, 61, 62, 63,
109
  64,
110
 
111
  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
112
  'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
113
 
114
  91, 92, 93, 94, 95, 96,
115
 
116
  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
117
  'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
118
 
119
 123,124,125,126,127,
120
 
121
 128,129,130,131, 132,133,134,135, 136,137,138,139, 140,141,142,143,
122
 144,145,146,147, 148,149,150,151, 152,153,154,155, 156,157,158,159,
123
 160,161,162,163, 164,165,166,167, 168,169,170,171, 172,173,174,175,
124
 176,177,178,179, 180,181,182,183, 184,185,186,187, 188,189,190,191,
125
 
126
 192,193,194,195, 196,197,198,199, 200,201,202,203, 204,205,206,207,
127
 208,209,210,211, 212,213,214,215, 216,217,218,219, 220,221,222,223,
128
 224,225,226,227, 228,229,230,231, 232,233,234,235, 236,237,238,239,
129
 240,241,242,243, 244,245,246,247, 248,249,250,251, 252,253,254,255,
130
};
131
 
132
const unsigned char _sch_toupper[256] =
133
{
134
   0,  1,  2,  3,   4,  5,  6,  7,   8,  9, 10, 11,  12, 13, 14, 15,
135
  16, 17, 18, 19,  20, 21, 22, 23,  24, 25, 26, 27,  28, 29, 30, 31,
136
  32, 33, 34, 35,  36, 37, 38, 39,  40, 41, 42, 43,  44, 45, 46, 47,
137
  48, 49, 50, 51,  52, 53, 54, 55,  56, 57, 58, 59,  60, 61, 62, 63,
138
  64,
139
 
140
  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
141
  'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
142
 
143
  91, 92, 93, 94, 95, 96,
144
 
145
  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
146
  'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
147
 
148
 123,124,125,126,127,
149
 
150
 128,129,130,131, 132,133,134,135, 136,137,138,139, 140,141,142,143,
151
 144,145,146,147, 148,149,150,151, 152,153,154,155, 156,157,158,159,
152
 160,161,162,163, 164,165,166,167, 168,169,170,171, 172,173,174,175,
153
 176,177,178,179, 180,181,182,183, 184,185,186,187, 188,189,190,191,
154
 
155
 192,193,194,195, 196,197,198,199, 200,201,202,203, 204,205,206,207,
156
 208,209,210,211, 212,213,214,215, 216,217,218,219, 220,221,222,223,
157
 224,225,226,227, 228,229,230,231, 232,233,234,235, 236,237,238,239,
158
 240,241,242,243, 244,245,246,247, 248,249,250,251, 252,253,254,255,
159
};
160
 
161
#else
162
 #error "Unsupported host character set"
163
#endif /* not ASCII */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.