Google
 

Trailing-Edge - PDP-10 Archives - scratch - 10,7/unscsp/strlib/strcnv.mac
There are 5 other files named strcnv.mac in the archive. Click here to see a list.
	TITLE	CNVSTR
	SEARCH	STRDCL
	IFE HIGH,<
	TWOSEG
	RELOC	400000>



;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED
;  OR COPIED IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE.
;
;COPYRIGHT (C) 1974,1979 BY DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
; USAGE -- CNVSTR(ARG1, ARG2, BASE, MODE)
; MODE = (TO-ASC,FROM-ASC)*(ZERO-PAD,BL-PAD)*(NOFILL)

	ENTRY CNVSTR,CNVST.

CNVSTR:
CNVST.:

	C2=T1
	BASE=CNT
	SOURCE=BP2
	DEST=BP2
	REM=SOURCE+1
	SAVALL

	MOVE	MODE,@3(AP)
	MOVE	BASE,@2(AP)

	TRNN	MODE,TO.ASCII	;SKIP SAYS TO
	JRST	ST.NUM

; ***************

NUM.ST:
	STRARG	0,AP,BP1,LEN1
	HRRZ	R2,R1		;GET R1 ALONE WILL NEED LATER
	MOVM	SOURCE,@1(AP)	;GET NUM TO CNV.
NS1:
	IFE CHECK,<
	SOJL	LEN1,[ERROR	LEM$##,CNV.FA
]>
	IFN CHECK,<
	SOJL	LEN1,CNV.FA>
	IDIV	SOURCE,BASE	;REM=SOURCE+1
	ADDI	REM,60		;CNV. RESIDUE TO BASE OF ASCII-NUMERIC(60-71)
	PUSH	P,REM
	JUMPN	SOURCE,NS1	;KEEP GOING TIL SOURCE EXHAUSTED BY REP. DIV.


	SUB	R2,LEN1		;R2 NOW CONTAINS NO. OF CHAR PUSHED
NS2:	SKIPGE	@1(AP)	;NEED MINUS SIGN--NO SKIP SAYS YES
	JRST	[MOVEI	REM,"-"

		 IFE CHECK,<
		 SOJL	LEN1,[ERROR	LEM$##,CNV.FA
]>
		 IFN CHECK,<
		 SOJL	LEN1,CNV.FA>

		 TRNN	MODE,NOFILL	;IF NOFILL THE (-) WILL ALWAYS BE
					;IMMED. LEFT OF HIGH ORD. DIGIT (I.E. SAME AS BLANK PAD)
		 TRNN	MODE,Z.PAD	; SKIP SAYS ZERO PAD WHICH MEANS
					;MINUS SIGN THEN 0'S AS
					;OPPOSED TO BLKS AND THEN -.
		 JRST	[PUSH	P,REM	;MAKE IT SEEM AS IF (-) PUT OUT BY NS1 LP.
			 AOJA	R2,NS3]
		 IDPB	REM,BP1
		 JRST	NS3]

NS3:	TRNE	MODE,NOFILL	;NO SKIP SAYS NO ZEROS OR BL.
	JRST	[FUNCT	SETST.##,<$1,0(AP),R2,$2,[-1]>
		 JRST	STK.STR]

	JUMPE	LEN1,STK.STR	;NO ROOM LEFT...EVERYONE'S NOFILL

	MOVEI	REM,40
	TRNE	MODE,Z.PAD	;NO SKIP SETS UP ZERO CHAR
	MOVEI	REM,60
NUM.FL:			;DO FILLING
	IDPB	REM,BP1
	SOJG	LEN1,NUM.FL

STK.STR:				;GET OFF STK
	POP	P,REM
	IDPB	REM,BP1
	SOJG	R2,STK.STR

	JRST	CNV.SU

; ************

ST.NUM:
	STRARG	1,AP,BP1,LEN1
	SETZ	DEST,
	SETZ	T0,		;FOR MINUS SIGN CHK
	SETO	R0,		;PRESET SUCCESS
	JUMPLE	LEN1,ST.N2	;CAN'T STRIP LEAD CHAR IF SOURCE-STR EXHAUSTED
ST.N0:
	ILDB	C1,BP1
	CAIN	C1,40		;SKIP FOR BLANK
	SOJG	LEN1,ST.N0
	CAIN	C1,11		;SKIP FOR TAB
	SOJG	LEN1,ST.N0
	CAIE	C1,"-"	;(-) OR DIGIT TERMS STRIPPING LOOP
	JRST	ST.N1A		;DON'T  ILDB OVER THE DIGIT YOU'RE LOOKIN AT

	SETO	T0,		;TELLS TEST BEFORE ST.N2 TO NEGATE RESULT
	SOJLE	LEN1,ST.N2	;GET INDEX PAST THE (-).
ST.N1:
	IMUL	DEST,BASE	;CREATE NUM AS I*BASE**N+J*BASE**N-1 ETC.
	ILDB	C1,BP1	;GET NEW-LOW ORDER DIGIT
ST.N1A:
	CAIL	C1,60		;IS CHAR LESS THAN ASCII 0?
	CAIG	BASE,-60(C1)	;GTR THAN "10-1" SO TO SPEAK?
	SETZ	R0,		;SET FAILURE

	ADDI	DEST,-60(C1)	;CNV. TO NUM AND ADD TO SUM
	SOJG	LEN1,ST.N1

	SKIPGE	T0
	MOVNS	DEST
ST.N2:
	SKIPL	R0			;SUCCESS-ALWAYS RET VAL
	TRNE	MODE,ALWAYS		;SET USER VAR EVEN IF FAIL?
	MOVEM	DEST,@0(AP)		;RET VAL TO USR
	RETURN

CNV.FA:	SETZ	R0,
	JRST	CNVEND
CNV.SU:	SETO	R0,

CNVEND:	RETURN
	PRGEND

	TITLE	MAPSTR
	SEARCH	STRDCL
	IFE HIGH,<
	TWOSEG
	RELOC	400000>

; USAGE = MAPSTR(STR1,STR2,TRANSLATE,MODE, [LOWER.UPPER])
; MODE = (CNV67/CNV76)*(TRANSLATE)*(CONDIT. TRANSLATE-(YES.IN/NO))

	ENTRY MAPSTR,MAPST.

MAPSTR:
MAPST.:
	C2=R2
	TRNVAL=CNT
	LOWBND=T1
	UPBND=T0

	SAVALL

	STRARG	1,AP,BP2,LEN2

	STRARG	0,AP,BP1,LEN1,ML1

	MOVE	MODE,@3(AP)
	MOVE	TRNVAL,@2(AP)	;IF TRANSLATE SET

	MOVEI	C2,40		;THE DEFAULT PAD CHAR

	TRNE	MODE,TLATE	
	JRST	MAP.TRN
	TLZ	BP1,7700	;ZERO BOTH SIZES
	TLZ	BP2,7700

	TRNE	MODE,TO.ASCII
	JRST	[MOVEI	TRNVAL,40
		 TLO	BP1,700	;SET DEST SIZE TO 7
		 TLO	BP2,600	;SOURCE SIZE TO 6
		 JRST	.+2]
	JRST	[MOVNI	TRNVAL,40
		 TLO	BP1,600
		 TLO	BP2,700
		 SETZ	C2,		;THE PAD CHAR IF NECESS.
		 JRST	.+1]

; ********* BODY OF MAPSTR

MAP.TRN:
	IFE BND.CH,<
	CAMGE	ML1,LEN2
	  IFN CHECK, <JRST	MAP.FA>
	  IFE CHECK, <ERROR	LEM$##,MAP.FA>
>

	MOVE	R2,LEN2	;DON'T DESTROY LEN2
	TRNE	MODE,LB.UB
	JRST	MAP.CND
MAP.NOCND:
	ILDB	C1,BP2
	ADD	C1,TRNVAL		;TRANSLATE
	IDPB	C1,BP1
	SOJG	R2,MAP.NOCND
	JRST	MAP.IFPAD
MAP.CND:
	SETZ	R0,
	TRNN	MODE,YES.IN
	SETO	R0,

	HRRZ	UPBND,@4(AP)
	HLRZ	LOWBND,@4(AP)
MAP.C1:	 ILDB	C1,BP2

	; NEXT 5 INST. DETER. IF C1 BETWEEN LOWBND AND UPBND INCLUSIVE

	SETZ	R1,
	CAMGE	C1,LOWBND
	SETO	R1,
	CAMLE	C1,UPBND
	SETO	R1,	;HITTING EITHER SETO SAYS CHAR NOT BETWEEN LOW/UP

	CAMN	R1,R0	;WILL DO ADD FOR R0 = YES.IN = -1 AND R1 = IN = -1
	;AND FOR R0 = 0 AND R1 = 0 

	ADD	C1,TRNVAL
	IDPB	C1,BP1
			 SOJG	R2,MAP.C1
MAP.IFPAD:
	SUB	LEN1,LEN2	;IS PADDING NECES?
	JUMPG	LEN1,MAP.PAD
	JUMPE	LEN1,MAP.SU

	; WHEN NO PADDING, IT IS ASSUMED THAT PASSED LENGTH OF STRING1 IS NOT MEANINGFUL

	FUNCT	SETST.##,<$1,0(AP),LEN2,$2,[-1]>
	JRST	MAP.SU
MAP.PAD:
	IDPB	C2,BP1
	SOJG	LEN1,MAP.PAD

	JRST	MAP.SU

MAP.FA:
	SETZ	R0,
	JRST MAPEND
MAP.SU:
	SETO	R0,
MAPEND:
	RETURN
	PRGEND
	TITLE	REVSTR
	SEARCH	STRDCL
	IFE HIGH,<
	TWOSEG
	RELOC	400000>

; USAGE -- REVSTR(STRING1,STRING2 OR 0)

	ENTRY REVSTR,REVST.

REVSTR:
REVST.:
	C2=T1
	SAVALL

; THE STRARG & LOCSUB SET UP 2 STR PTRS -- ONE AT
; THE BEGINNING OF THE STRING AND ONE AT THE END

	STRARG	0,AP,BP1,LEN1,ML1

	SKIPE	@1(AP)	;NO SKIP SAYS 2 STRING ARGS
	JRST	REV2S

; **************

	LOCSUB	REL$L##,<[BP1],LEN1>
	MOVE	BP2,R0		;PRESERVE R0 & R1 FOR RET VAL
	HRRZ	LEN2,R1

	LSH	LEN2,-1	;DIVIDE BY TWO AND TRUNCATE

REV1:	LDB	C1,BP2	;AT BEGINNING
	LDB	C2,BP1	;AT END
	IDPB	C2,BP2	;THE INVERSION
	DECR	DPB,C1,BP1
	SOJG	LEN2,REV1

REVEND:
	POPALL
	POPJ	P,

; ******************

REV2S:
	STRARG	1,AP,BP2,LEN2
	MOVE	R0,BP1		;SETUP RETURN BP
	LOCSUB	REL$L##,<[BP1],LEN2>

	IFE BND.CH,<
	IFE CHECK,<
	CAMGE	ML1,LEN2
	ERROR	LEM$##,REV.FA>>

REV2:	ILDB	C1,BP2
	DECR	DPB,C1,BP1
	SOJG	LEN2,REV2
	JRST	REVEND
REV.FA:
	SETZ	R0,
	SETZ	R1,
	JRST	REVEND

	END