.NLIST TOC,SYM .TITLE CVT$$ .SBTTL ULBLIB 034 - String Conversion Routine .PSECT .LIBC. .IDENT \V01.02\ .ENABL LC,GBL ; Copyright (c) 1998 by Mentec, Inc., Nashua, NH. ; All rights reserved ; ; This software is furnished under a license for use only on a ; single computer system and may be copied only with the ; inclusion of the above copyright notice. This software, or ; any other copies thereof, may not be provided or otherwise ; made available to any other person except for use on such ; system and to one who agrees to these license terms. Title ; to and ownership of the software shall at all times remain ; in Mentec, Inc. ; ; The information in this document is subject to change without ; notice and should not be construed as a commitment by Digital ; Equipment Corporation, or Mentec, Inc. ; ; Digital and Mentec assume no responsibility for the use or ; reliability of its software on equipment which is not supplied ; by Digital or Mentec, and listed in the Software Product ; Description. ;+ ; CVT$$ ; This routine does string translation of various forms. ; ; R0 -> input string ; R1 -> output string ; R2 = flag bits ; = 1 => strip parity ; = 2 => remove all 's and 's ; = 4 => remove all , , , , , and ; = 10 => remove all leading 's and 's ; = 20 => replace all multiple 's and with ; = 40 => convert lower case to upper case ; = 100 => remove all trailing 's and 's ; ; CALL CVT$$ ; ; R0 - R2 = random ;- TAB = 11 LF = 12 VT = 13 FF = 14 CR = 15 ESC = 33 SPACE = 40 RUB = 177 .PSECT .LIBC. .SBTTL Pointers to action routines .WORD 0 ;End of table .WORD RMVTSP ;Remove trailing , .WORD CVTUC ;Convert lower case to upper space .WORD REPMSP ;Replace multiple , with .WORD RMVLSP ;Remove all leading and .WORD RMVOTH ;Remove all ,,,,, .WORD RMVSPC ;Remove all , .WORD TRMPAR ;Trim parity bit CVT$$:: JSR R5,$SAVRG ;Save non-volatile registers MOV R1,R4 ;Save the pointer to the output string 1$: MOVB (R0)+,(R1)+ ;Move the input string to the output area BNE 1$ ;Do it all MOV #CVT$$-2,R5 ;R5 -> action routines 2$: CLC ;Clear the carry ROR R2 ;Shift out a bit BCC 3$ ;Branch if nothing to do MOV R4,R0 ;R0 -> string MOV R4,R1 ;R1 -> string JSR PC,@(R5) ;Call the routine 3$: TST -(R5) ;Point to next routine BEQ 4$ ;Branch if not TST R2 ;Anything left to do? BNE 2$ ;Branch if so 4$: RETURN .SBTTL Trim parity .ENABL LSB TRMPAR: BICB #200,(R0)+ ;Clear the parity bit BNE TRMPAR ;Branch if not end RETURN .SBTTL Remove all spaces and tabs RMVSPC: TSTB @R1 ;At end of string? BEQ 3$ ;Branch if so CMPB #SPACE,@R1 ;? BEQ 1$ ;Branch if so CMPB #TAB,@R1 ;? BNE 2$ ;Branch if not 1$: TSTB (R1)+ ;Skip it BR RMVSPC ;Go get next on 2$: MOVB (R1)+,(R0)+ ;Copy the character BR RMVSPC ;Get next character 3$: CLRB @R0 ;Make it ASCIZ RETURN .SBTTL Remove other strange characters ;+ ; ; The 'other strange characters' to be removed by this routine ; are LF, VT, FF, CR, ESC, RUB. ; ;- RMVOTH: TSTB @R1 ;Done? ;MG01+ BEQ 3$ ;Branch if so CMPB @R1,#LF ;Is character in range of LF-CR (12-15) BLO 6$ ;Nope...then move it CMPB @R1,#CR ;Maybe...check upper range BHIS 5$ ;Nope...check for and 4$: TSTB (R1)+ ;Get rid of the character BR RMVOTH ;Get next character 5$: CMPB @R1,#ESC ;? BEQ 4$ ;Yes... CMPB @R1,#RUB ;? BEQ 4$ ;Yes... ;MG01- 6$: MOVB (R1)+,(R0)+ ;Move the character BR RMVOTH ;Try for another .SBTTL Remove leading spaces and tabs RMVLSP: CMPB @R1,#SPACE ;? BEQ 7$ ;Branch if so CMPB @R1,#TAB ;? BNE 8$ ;Branch if not 7$: INC R1 ;Skip the byte BR RMVLSP ;Check for more 8$: MOVB (R1)+,(R0)+ ;Move the rest of the string BNE 8$ ;Loop until done RTS1: RETURN .DSABL LSB .SBTTL Replace multiple spaces and tabs with single space .ENABL LSB REPMSP: CMPB @R1,#TAB ;? BEQ 4$ ;Branch if so. Put in a space 1$: MOVB (R1)+,(R0)+ ;Move a byte BEQ RTS1 ;Branch if done 2$: CMPB @R1,#SPACE ;? BEQ 3$ ;Branch if so CMPB @R1,#TAB ;? BNE 1$ ;Branch if not 3$: CMPB -1(R0),#SPACE ;Last character a space? BEQ 5$ ;Branch if so 4$: MOVB #SPACE,(R0)+ ;Put in a space 5$: TSTB (R1)+ ;Skip the character BR 2$ ;Go check next character .SBTTL Convert lower case to upper case CVTUC: TSTB @R0 ;Done? BEQ RTS1 ;Branch if so CMPB @R0,#141 ;Lower case alpha? BLO 6$ ;Branch if not CMPB @R0,#172 ;In range? BHI 6$ ;Branch if not BICB #40,@R0 ;Clear the bit 6$: TSTB (R0)+ ;Copy character BR CVTUC ;Go get next character .SBTTL Remove trailing spaces and tabs RMVTSP: TSTB (R0)+ ;Get to end of string BNE RMVTSP ;Keep going DEC R0 ;Back up the character 7$: CMPB R0,R1 ;At the beginning of the string? BEQ RTS1 ;Branch if so. Done CMPB -(R0),#SPACE ;Is the last character a space? BEQ 8$ ;Branch if so. Remove it CMPB @R0,#TAB ;Is it a tab? BNE RTS1 ;Branch if not. Done 8$: CLRB @R0 ;Move the zero byte back BR 7$ ;Go check next character .DSABL LSB .END