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
/
BEEHIVE
/
UTILITYS
/
DWIM.ARC
/
DWIM.MAC
< prev
Wrap
Text File
|
1990-07-21
|
5KB
|
264 lines
;DWIM - Do What I Mean
;
;given a file name which doesn't match any known file name
;DWIM will attempt to automatically correct for
;the four most commonly occurring typographic errors -
; 1) single character substitution
; 2) single character omission
; 3) single character inclusion
; 4) adjacent character transposition
;
;as DWIM generates each possible alternative, it tests
;for validity against the "dictionary" of the cp/m file
;directory. When a (possibly empty) set of valid files
;has been generated, the user is prompted to choose from
;a menu of possible commands, one of which hopefully will
;be what the user meant to type.
;the file is assumed to have the correct extension (probably .COM)
;which gives 4n-3 possible corrections for a file length 8.
;This requires 29 searches of the directory which may make DWIM
;slower than just retyping the erroneous command
;this depends entirely upon the speed of your disk.
FCB equ 5Ch
FNAM equ FCB+1
FCBsize equ 36
namLen equ 12
BDOS equ 5
PSTR equ 9
srchFirst equ 17
srchNext equ 18
setDMA equ 26
;DDMA equ ???
start: ld (stSav),sp
ld hl,stack
ld sp,hl
ld c,setDMA
ld de,DDMA
call BDOS
call subst
ld sp,(stSav)
ret
;Substitute '?' for each character in turn, to catch the typo
; of substitution ie: "tha cut sitz un yhe met"
subst: ld hl,FCB ;point to file name
ld de,tFCB ;point to subsidiary file name
ld bc,FCBsize ;file name size
ldir ;duplicate file name
ld hl,tFCB+1 ;start of file name
ld a,9 ;only want first
ld (charCnt),a ; 8 characters
subNxt: dec a ;test
ld (charCnt),a ; end of
jr z,insrt ; name
ld a,(hl) ;store
ld (currChar),a ; current
and 7fh ;blank
cp ' ' ; terminates
jr z,insrt ; name
ld a,'?' ;substitute '?'
ld (hl),a ; for current
push hl
call srch
pop hl
ld a,(currChar) ;restore
ld (hl),a ; original
ld a,(charCnt) ;recover length
inc hl ;increment ptr
jr subNxt
;Insert '?' between each pair of characters to catch typos
; like eg "te ct st n th ma"
insrt: ld hl,FCB+1 ;shift
ld de,tFCB+2 ; name
ld bc,7 ; right
ldir ; one char
;overwrites to the right - hence no problem with garbage
ld hl,tFCB+1 ;point to file name
ld de,FCB+1
ld a,8 ;only 7 insertions
ld (charCnt),a ; possible
insNxt: dec a ;test
ld (charCnt),a ; end of
jr z,delet ; name
ld a,'?' ;simulate
ld (hl),a ; insertion
push hl
push de
call srch
pop de
pop hl
ld a,(de) ;restore original
ld (hl),a ; character
inc hl ;increment pointers
inc de ;/
ld a,(hl) ;test next char
and 7fh ; blank
cp ' ' ; terminates
jr z,delet ; file name
ld a,(charCnt) ;recover count
jr insNxt
delet: ld hl,FCB+2 ;point to file name
ld de,tFCB+1 ;point to subsidiary file name
ld bc,7 ;file name size
ldir ;duplicate file name
ld a,'?' ; garbage
ld (de),a ; to right
ld hl,tFCB+1 ;point to file name
ld de,FCB+1 ;point to original
ld a,8 ;only 7 deletions
ld (charCnt),a ; possible
delNxt: dec a ;test
ld (charCnt),a ; end of
jr z,transp ; name
push hl
push de
call srch
pop de
pop hl
ld a,(de) ;overwrite char
ld (hl),a ; to simulate deletion
and 7fh ;test char -
cp ' ' ; blank terminates
jr z,transp ; file name
inc hl ;increment pointer
inc de ;/
ld a,(charCnt) ;recover count
jr delNxt
transp: ld hl,FCB ;point to file name
ld de,tFCB ;point to subsidiary file name
ld bc,FCBsize ;file name size
ldir ;duplicate file name
ld hl,tFCB+1 ;start of file name
ld a,8 ;only want
ld (charCnt),a ; 7 transpositions
traNxt: dec a ;test
ld (charCnt),a ; end of
jr z,done ; name
ld a,(hl) ;store
ld (currChar),a ; current
;swap characters
ld b,(hl) ;get curr char
inc hl ;get next
ld a,(hl) ; char
ld (hl),b ;swap current char
dec hl ; and
ld (hl),a ; next char
and 7fh ;blank
cp ' ' ; terminates
jr z,done ; name
push hl
call srch
pop hl
;unswap chars
ld b,(hl) ;get curr char
inc hl ;get next
ld a,(hl) ; char
ld (hl),b ;swap current char
dec hl ; and
ld (hl),a ; next char
ld a,(charCnt) ;recover length
inc hl ;increment ptr
jr traNxt
;completed all variations
done: ret
;perform search - plug your favourite file search in here
srch: ld de,tFCB ;look for file
ld c,srchFirst ; in directory
call BDOS ;/
srch1: or a ;set status
ret M ;match not found
call action
ld de,tFCB ;look for
ld c,srchNext ; next
call BDOS ; match
jr srch1 ;keep looking
;print the attempted file name
action: ld hl,DDMA
add a,a
add a,a
add a,a
add a,a
add a,a
ld e,a
ld d,0
add hl,de
ld de,prtBlk
ld bc,namLen
ldir
ld a,10
ld (de),a
inc de
ld a,13
ld (de),a
inc de
ld a,'$'
ld (de),a
ld c,PSTR
ld de,prtBlk
call BDOS
ret
;Variable area
charCnt: defb 0
currChar: defb 0
stSav: defw 0
tFCB: defs FCBsize
prtBlk: defs FCBsize
DDMA: defs 128
defs 40
stack equ $
END