ctype.h

Go to the documentation of this file.
00001 /* The <ctype.h> header file defines some macros used to identify characters.
00002  * It works by using a table stored in chartab.c. When a character is presented
00003  * to one of these macros, the character is used as an index into the table
00004  * (__ctype) to retrieve a byte.  The relevant bit is then extracted.
00005  */
00006 
00007 #ifndef _CTYPE_H
00008 #define _CTYPE_H
00009 
00010 #ifndef _ANSI_H
00011 #include <ansi.h>
00012 #endif
00013 
00014 extern char     __ctype[];      /* property array defined in chartab.c */
00015 
00016 #define _U              0x01    /* this bit is for upper-case letters [A-Z] */
00017 #define _L              0x02    /* this bit is for lower-case letters [a-z] */
00018 #define _N              0x04    /* this bit is for numbers [0-9] */
00019 #define _S              0x08    /* this bit is for white space \t \n \f etc */
00020 #define _P              0x10    /* this bit is for punctuation characters */
00021 #define _C              0x20    /* this bit is for control characters */
00022 #define _X              0x40    /* this bit is for hex digits [a-f] and [A-F]*/
00023 
00024 /* Function Prototypes (have to go before the macros). */
00025 _PROTOTYPE( int isalnum, (int  _c)  );  /* alphanumeric [a-z], [A-Z], [0-9] */
00026 _PROTOTYPE( int isalpha, (int  _c)  );  /* alphabetic */
00027 _PROTOTYPE( int iscntrl, (int  _c)  );  /* control characters */
00028 _PROTOTYPE( int isdigit, (int  _c)  );  /* digit [0-9] */
00029 _PROTOTYPE( int isgraph, (int  _c)  );  /* graphic character */
00030 _PROTOTYPE( int islower, (int  _c)  );  /* lower-case letter [a-z] */
00031 _PROTOTYPE( int isprint, (int  _c)  );  /* printable character */
00032 _PROTOTYPE( int ispunct, (int  _c)  );  /* punctuation mark */
00033 _PROTOTYPE( int isspace, (int  _c)  );  /* white space sp, \f, \n, \r, \t, \v*/
00034 _PROTOTYPE( int isupper, (int  _c)  );  /* upper-case letter [A-Z] */
00035 _PROTOTYPE( int isxdigit,(int  _c)  );  /* hex digit [0-9], [a-f], [A-F] */
00036 _PROTOTYPE( int tolower, (int  _c)  );  /* convert to lower-case */
00037 _PROTOTYPE( int toupper, (int  _c)  );  /* convert to upper-case */
00038 _PROTOTYPE( int toascii, (int  _c)  );  /* convert to 7-bit ASCII */
00039 
00040 /* Macros for identifying character classes. */
00041 #define isalnum(c)      ((__ctype+1)[c]&(_U|_L|_N))
00042 #define isalpha(c)      ((__ctype+1)[c]&(_U|_L))
00043 #define iscntrl(c)      ((__ctype+1)[c]&_C)
00044 #define isgraph(c)      ((__ctype+1)[c]&(_P|_U|_L|_N))
00045 #define ispunct(c)      ((__ctype+1)[c]&_P)
00046 #define isspace(c)      ((__ctype+1)[c]&_S)
00047 #define isxdigit(c)     ((__ctype+1)[c]&(_N|_X))
00048 
00049 #define isdigit(c)      ((unsigned) ((c)-'0') < 10)
00050 #define islower(c)      ((unsigned) ((c)-'a') < 26)
00051 #define isupper(c)      ((unsigned) ((c)-'A') < 26)
00052 #define isprint(c)      ((unsigned) ((c)-' ') < 95)
00053 #define isascii(c)      ((unsigned) (c) < 128)
00054 
00055 #define toascii(c)      ((c) & 0x7f)
00056 
00057 #endif /* _CTYPE_H */

Generated on Fri Apr 14 22:56:52 2006 for minix by  doxygen 1.4.6