home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
ENTERPRS
/
CPM
/
UTILS
/
S
/
ZCNFG21.LBR
/
CFGLIB.LBR
/
RJUSTIP.ZZ0
/
RJUSTIP.Z8°
Wrap
Text File
|
1991-10-25
|
2KB
|
78 lines
;RJUSTIP - Right JUStify Text In Place
;maves left justified text to the right end of
;the buffer at HL and move terminal spaces to
;the beginning of the buffer
;CALL WITH:
; HL -> fixed length buffer, left justified
; BC: B = field width, C = Number of spaces at end
;RETURN WITH:
; HL preserved
; BC, DE destroyed
public rjip,ntspcs
rjip: ld a,c
cp b
ret z ;all spaces - nothing to do
or a ;no spaces?
ret z ;ret if none - nothing to do
;set up pointers to move text to end of buffer
xor a ;reset cy, get zero
ld d,a
ld e,b
add hl,de ;->buffer end +1
dec hl ;-> last char
push hl
ld e,c
sbc hl,de ;->text end
pop de ;HL->text end, DE -> buffer end
;transfer text to end of buffer
push bc
ld a,b
sub c ;text length = b-c
ld c,a
ld b,0
lddr ;de ->start of spaces
pop bc ;recover # of spaces
ld b,c
ex de,hl ;hl->end of left fill portion
bfill: ld (hl),' '
dec hl
djnz bfill ;insert spaces until b=0
inc hl ;->first char of buffer
ret
NTSPCS:
;scan the field at (HL) whose length is given in BC
;or just C, counting trailing spaces.
;This routine may be used to provide input for RJIP
;CALL WITH:
; HL -> start of field containing text
; C = length of the field (1...255)
;RETURN WITH:
; DE, HL are preserved
; BC = field length in B, number of trailing spaces in C
push hl
ld b,0
add hl,bc ;->field end + 1
ld a,c ;save for exit
ex af,af'
ld b,c ;for max field count
ld a,' ' ;spaces to count
ld c,0 ;initialize counter
ntspc1: dec hl
cp (hl)
jr nz,ntspcx
inc c ;count a space
djnz ntspc1 ;look for another
ntspcx: pop hl ;-> start of field
ex af,af' ;recover field size
ld b,a
ret ;b=length, c=# terminal spaces
end