/*		Q/C V3.2 Utility Library		*/
/*     Copyright (c) 1984 Quality Computer Systems	*/
/*			11/25/84			*/

#include "stdio.h"

/* convert a lower case letter to upper case */
chupper(c)
register c;
	{
	return ((c>='a' && c<='z') ? c - ('a' - 'A') : c);
	}
/* convert an upper case letter to lower case */
chlower(c)
register c;
	{
	return ((c>='A' && c<='Z') ? c - ('A' - 'a') : c);
	}
/* Is c a punctation character? */
ispunct(c)
	{
	return (isprint(c) && !isalnum(c) && c != ' ');
	}

#ifdef PORTABLE
/* Is c an ASCII control character? */
iscntrl(c)
	{
	return (isascii(c) && !isprint(c));
	}
/* Is c a letter or a number */
isalnum(c)
	{
	return (isalpha(c) || isdigit(c));
	}
/* Is c a letter */
isalpha(c)
	{
	return (isupper(c) || islower(c));
	}
/* Is c an upper case letter */
isupper(c)
	{
	return (c >= 'A' && c <= 'Z');
	}
/* Is c a lower case letter */
islower(c)
	{
	return (c >= 'a' && c <= 'z');
	}
/* Is c a decimal digit */
isdigit(c)
	{
	return (c >= '0' && c <= '9');
	}
/* Is c white space */
isspace(c)
register c;
	{
	return (c == ' ' || c == '\t' || c == '\n'
		|| c == '\r' || c == '\f');
	}
/* Is c an ASCII character? */
isascii(c)
	{
	return (c >= '\0' && c <= '\177');
	}
/* Is c a printable character? */
isprint(c)
	{
	return (c >= ' ' && c <= '~');
	}
#else
iscntrl() {
#	asm 8080
	LXI	H,2
	DAD	SP
	MOV	A,M
	CPI	32
	RC
	CPI	127
	JNZ	?ISCN1
	ORA	H
	RET
?ISCN1: XRA	A
	MOV	H,A
	MOV	L,A
#	endasm
	}
isalnum() {
#asm 8080
	LXI	H,2
	DAD	SP
	MOV	A,M
	CPI	48
	JC	?ISAN1
	CPI	58
	RC
	CPI	65
	JC	?ISAN1
	CPI	91
	RC
	CPI	97
	JC	?ISAN1
	CPI	123
	RC
?ISAN1: XRA	A
	MOV	H,A
	MOV	L,A
#endasm
	}
isalpha() {
#asm 8080
	LXI	H,2
	DAD	SP
	MOV	A,M
	CPI	65
	JC	?ISAL1
	CPI	91
	RC
	CPI	97
	JC	?ISAL1
	CPI	123
	RC
?ISAL1: XRA	A
	MOV	H,A
	MOV	L,A
#endasm
	}
isupper() {
#asm 8080
	LXI	H,2
	DAD	SP
	MOV	A,M
	CPI	65
	JC	?ISUP1
	CPI	91
	RC
?ISUP1: XRA	A
	MOV	H,A
	MOV	L,A
#endasm
	}
islower() {
#asm 8080
	LXI	H,2
	DAD	SP
	MOV	A,M
	CPI	97
	JC	?ISLO1
	CPI	123
	RC
?ISLO1: XRA	A
	MOV	H,A
	MOV	L,A
#endasm
	}
isdigit() {
#asm 8080
	LXI	H,2
	DAD	SP
	MOV	A,M
	CPI	48
	JC	?ISDG1
	CPI	58
	RC
?ISDG1: XRA	A
	MOV	H,A
	MOV	L,A
#endasm
	}
isspace() {
#	asm 8080
	LXI	H,2
	DAD	SP
	MOV	A,M
	CPI	9
	JZ	?ISSP1
	CPI	10
	JZ	?ISSP1
	CPI	32
	JZ	?ISSP1
	CPI	12
	JZ	?ISSP1
	CPI	13
	JZ	?ISSP1
	XRA	A
	MOV	H,A
	MOV	L,A
	RET
?ISSP1: ORA	H
#	endasm
	}
isascii() {
#asm 8080
	LXI	H,3
	DAD	SP
	MOV	A,M
	ORA	A
	JNZ	?ISAS1
	DCX	H
	MOV	A,M
	CPI	128
	RC
?ISAS1: XRA	A
	MOV	H,A
	MOV	L,A
#endasm
	}
isprint() {
#asm 8080
	LXI	H,2
	DAD	SP
	MOV	A,M
	CPI	32
	JC	?ISPR1
	CPI	127
	RC
?ISPR1: XRA	A
	MOV	H,A
	MOV	L,A
#endasm
	}
#endif
/* do upper case translation even if c is not a letter */
toupper(c)
	{
	return (c - ('a' - 'A'));
	}
/* do lower case translation even if c is not a letter */
tolower(c)
	{
	return (c - ('A' - 'a'));
	}
