#ifndef __ctype_h
#define __ctype_h
#pragma once

/*
 * Libraries and headers for PDC release 3.3 (C) 1989 Lionel Hummel.
 * PDC Software Distribution (C) 1989 Lionel Hummel and Paul Petersen.
 * PDC I/O Library (C) 1987 by J.A. Lydiatt.
 *
 * This code is freely redistributable upon the conditions that this
 * notice remains intact and that modified versions of this file not
 * be included as part of the PDC Software Distribution without the
 * express consent of the copyright holders.  No warrantee of any
 * kind is provided with this code.  For further information, contact:
 *
 *  PDC Software Distribution    Internet:                     BIX:
 *  P.O. Box 4006             or hummel@cs.uiuc.edu            lhummel
 *  Urbana, IL  61801-8801       petersen@uicsrd.csrd.uiuc.edu
 */

/* ctype.h - very efficient macros for classifying characters */

/* Changed isascii() to evaluate its argument once.
   Changed isgraph() to evaluate its argument once.
   Changed toupper() and tolower() to test the case before conversion. -ryb */

extern char __ctype[256];

#define _UPPER       (1)
#define _LOWER       (1 << 1)
#define _HEXIT       (1 << 2)
#define _DIGIT       (1 << 3)
#define _SPACE       (1 << 4)
#define _CNTRL       (1 << 5)
#define _PUNCT       (1 << 6)
#define _OCTIT       (1 << 7)

int isalnum(int);
int isalpha(int);
int iscntrl(int);
int isdigit(int);
int isgraph(int);
int islower(int);
int isprint(int);
int ispunct(int);
int isspace(int);
int isupper(int);
int isxdigit(int);

int tolower(int);
int toupper(int);

#define isalnum(x)	(__ctype[(x)&0xff] & (_UPPER | _LOWER | _DIGIT))
#define isalpha(x)	(__ctype[(x)&0xff] & (_UPPER | _LOWER))
#define iscntrl(x)	(__ctype[(x)&0xff] & _CNTRL)
#define isdigit(x)	(__ctype[(x)&0xff] & _DIGIT)
#define isgraph(x)	((!(__ctype[(x)&0xff] & (_CNTRL | _SPACE))))
#define islower(x)	(__ctype[(x)&0xff] & _LOWER)
#define isprint(x)	(!(__ctype[(x)&0xff] & _CNTRL))
#define ispunct(x)	(__ctype[(x)&0xff] & _PUNCT)
#define isspace(x)	(__ctype[(x)&0xff] & _SPACE)
#define isupper(x)	(__ctype[(x)&0xff] & _UPPER)
#define isxdigit(x)	(__ctype[(x)&0xff] & _HEXIT)

#ifdef __GNUC__
#define tolower(x)	({int _x = (x); isupper (_x) ? _x |  32 : _x; })
#define toupper(x)	({int _x = (x); islower (_x) ? _x & ~32 : _x; })
#endif

#ifndef __STRICT_ANSI__

#define iswhite(x)	(__ctype[(x)&0xff] & _SPACE)
#define isodigit(x)	(__ctype[(x)&0xff] & _OCTIT)
#define isascii(x)	(((x) & ~0x7f) == 0)
#define iscsym(x)	((__ctype[(x)&0xff] & (_UPPER | _LOWER | _DIGIT))\
			 || ((x) == '_') || ((x) == '$'))

#define tocntrl(x)	(((((x)+1)&~96)-1)&127)
#define toascii(x)	((x) & 127)
#define toint(x)	((int)((__ctype[(x)&0xff]&_DIGIT)?\
			       ((x)-'0'):(((x)|32)-'a'+10)))

#endif /* __STRICT_ANSI__ */

#endif /* __ctype_h */
