;<MFEXEC>LOWER.MAC;1    16-JUL-79 23:15:46    EDIT BY WEISSMAN
	TITLE LOWER
	SEARCH XSTG
;
;	CONVERT THE STRING GIVEN IN T1 (AC1) TO LOWER CASE WITH
;	PROPER CAPITALIZATION. (RIPPED OFF FROM GRPSTS)
;
T1==1
T2==2
T3==3
P1==4
LOWER::	SETZM LOWFLG		;CAPITALIZE SMALL NAMES
	MOVEM T1,SCANPT
	MOVEM T1,BEGWRD
	PUSHJ P,FINWRD		; FINISH THIS WORD
LOWER2:	ILDB T1,SCANPT		; GET A CHAR
	JUMPE T1,LWDONE		; IF END
	CAIG T1,"z"
	CAIGE T1,"a"
	SKIPA
	SUBI T1,40		; COVNVERT TO UPPER CASE
	CAIG T1,"Z"
	CAIGE T1,"A"
	JRST [	PUSH P,T1	;SAVE SEPR
		CALL FINWRD	;REVERT TO UPPER CASE
		POP P,T1	;GET SEPR BACK
		CAIN T1," "	;WAS IT A SPACE?
		SETCMM LOWFLG	;YES, COMPL. FLAG SO "at" IS UPPER CASE
		JRST LOWER2]
	PUSH P,T1
	SKIPE CASE		; SECOND CHARA?
	JRST LOWER7		; NO, 
	CAIN T1,"C"
	CAIE T2,"M"		; CHECK FOR Mc...
	SKIPA
	JRST [	TRO T1,40
		SETOM CASE	;BACK TO UPPER CASE
		DPB T1,SCANPT
		POP P,T1
		JRST LOWER2]
	MOVSI P1,(1B0)		;CONVERT LAST 2 CHARS TO SINGLE BITS
	MOVNI T1,-"A"(T1)
	ROT P1,(T1)
	MOVNI T1,-"A"(T2)
	MOVSI T2,(1B0)
	ROT T2,(T1)
	MOVSI T1,-NOKCC
LOWER9:	HLRZ T3,OKCC(T1)	;NOW CHECK IF THEY ARE ALLOWED
	TDNN T2,0(T3)
	JRST LOWER8
	HRRZ T3,OKCC(T1)
	TDNE P1,0(T3)
	JRST LOWER7		;ALLOWED, LOWER CASE THE CHAR
LOWER8:	AOBJN T1,LOWER9
	SETOM CASE		; NOT ALLOWED, BACK TO UPPER CASE
LOWER7:	POP P,T1
	AOSLE CASE
	TRO T1,40
	MOVE T2,T1
	DPB T1,SCANPT
	JRST LOWER2

LWDONE:	PUSHJ P,FINWRD
	POPJ P,

; FINISH OFF A WORD

FINWRD:	MOVE T1,SCANPT
	EXCH T1,BEGWRD
	SETO T2,
	EXCH T2,CASE
	CAIL T2,2		;WAS LAST SEQUENCE LESS THAN 3 CHARS?
	POPJ P,
LOWER4:	CAMN T1,SCANPT		;YES
CRET:	POPJ P,
	ILDB T2,T1
	JUMPE T2,CRET
	SKIPE	LOWFLG		;LOWER SMALL STRING?
	JRST UPIT		;NO, CAPITALIZE THEM
	CAIG T2,"z"
	CAIGE T2,"a"
	 JRST LOWER4
	TRZ T2,40
LOWER1:	DPB T2,T1
	JRST LOWER4
UPIT:	CAIG T2,"Z"
	CAIGE T2,"A"
	JRST LOWER4
	TRO T2,40
	JRST LOWER1

; CHARACTER CLASSES

DEFINE	CHC(NAM,CH)<
NAM=0
IRPC CH,<NAM=NAM!1B<"CH"-65>
>
>

	CHC(VOWEL,AEIOU)
	CHC(QQQ,Q)
	CHC(HJL, HJLMNRVXYZ)
	CHC(BFG,BFGK)
	CHC(LR,LR)
	CHC(CP,CP)
	CHC(DDD,D)
	CHC(TTT,T)
	CHC(SSS,S)
	CHC(LRH,LRH)
	CHC(UUU,U)
	CHC(RRR,R)
	CHC(HRW,HRW)
	CHC(CHK,CHKLMNPQTW)
	CHC(YYY,Y)
	CHC(WWW,W)
	CHC(HR,HR)

; PERMISSIBLE INITIAL PAIRS

OKCC:	[VOWEL],,[-1]
	[YYY],,[VOWEL]
	[HJL],,[VOWEL!YYY]
	[BFG],,[VOWEL!YYY!LR]
	[CP],,[VOWEL!YYY!LRH]
	[QQQ],,[UUU]
	[DDD],,[VOWEL!YYY!RRR]
	[TTT],,[VOWEL!YYY!HRW]
	[SSS],,[VOWEL!YYY!CHK]
	[WWW],,[VOWEL!YYY!HR]
NOKCC==.-OKCC


	END
