home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol226 / delete.mac < prev   
Encoding:
Text File  |  1986-02-13  |  5.0 KB  |  268 lines

  1. ;DELETE.MAC v1.20 as of 08/08/84
  2. ;by S. Kluger
  3. ;styled after TurboDOS DELETE command
  4. ;
  5. ; Short documentation:
  6. ; DELETE can be used to delete (erase) any number of files in
  7. ; a given drive/user area. There are four options:
  8. ; 1. NO OPTION - program will ask whether or not to verify individual
  9. ;    files, R/O files are skipped
  10. ; 2. ;N OPTION - program will erase all files specified except R/O
  11. ; 3. ;Y OPTION - program will verify before erasure, skip R/O
  12. ; 4. ;R OPTION - R/O files are deleted without asking
  13. ; Options 2 and 3 are mutually exclusive. Examples:
  14. ; A0>delete b3:*.*
  15. ; B3>delete *.*;n
  16. ; A0>delete *.com;ry
  17. ; B0>delete foo.bar
  18. ;
  19. ; V1.20 now reports "not deleted" if BDOS returns FF in A
  20. ;
  21. ; If the filename is either UNAMBIGUOUS or expands into a single file,
  22. ; no verification is done.
  23. ;
  24. ; To reassemble, be sure to link SYSLIB last!
  25. ;
  26. cr    equ    0dh
  27. lf    equ    0ah
  28. ;
  29. dfcb    equ    5ch
  30. dbuf    equ    80h
  31. ;
  32. cmdsep    equ    ';'        ;command separator
  33.                 ;(change for ZCPR2)
  34. ;
  35.     extrn    bbline,print,cout,crlf
  36.     extrn    f$delete,fname,putud,getud,logud,retud
  37.     extrn    f$open,bdos,initfcb
  38.     extrn    codend
  39.     extrn    hmovb
  40.     extrn    wildex
  41. ;
  42. begin:    lxi    h,0
  43.     dad    sp
  44.     shld    stksav        ;save return stack
  45.     lxi    sp,stack
  46.     lda    dbuf
  47.     ora    a        ;any arg?
  48.     jz    help        ;no, give some help
  49.     call    putud        ;put away current DU:
  50.     lxi    h,dbuf+1    ;point to command line
  51.     call    skipnb        ;skip to next non-blank
  52.     lxi    d,curfcb
  53.     call    fname        ;parse the filename
  54.     jz    invdu
  55.     call    skipnb        ;skip to next nonblank
  56.     cpi    cmdsep        ;delimiter?
  57.     jnz    nodel        ;no, continue normally
  58.     inx    h
  59.     call    skipnb        ;go to next nonblank
  60.     ora    a
  61.     jz    nodel        ;nothing following the delimiter
  62. ynop:    sta    option        ;save as option
  63.     sta    optn2        ;twice in case only one option letter
  64.     inx    h
  65.     call    skipnb        ;check next character
  66.     ora    a
  67.     jz    nodel        ;if not eol...
  68.     sta    optn2        ;...then save it
  69.     cpi    'Y'        ;make optn2 the R/O option, so...
  70.     jz    swapo        ;...swap the two if ;ry or ;rn
  71.     cpi    'N'
  72.     jnz    nodel
  73. swapo:    push    psw
  74.     lda    option
  75.     sta    optn2
  76.     pop    psw
  77.     sta    option
  78. nodel:    push    b        ;save designated DU:
  79.     call    retud        ;get current DU:
  80.     pop    h
  81.     mov    a,h
  82.     dcr    a        ;if there, make 0..f
  83.     cpi    0feh
  84.     jz    skipdr        ;skip drive if current
  85.     mov    b,a
  86. skipdr:    mov    a,l        ;get user
  87.     cpi    '?'        ;if all users...
  88.     jz    invdu        ;...then complain
  89.     inr    a        ;if current...
  90.     jz    skipus        ;...then skip
  91.     mov    c,l
  92. skipus:    mov    h,b
  93.     mov    l,c
  94.     shld    filedu        ;save file DU:
  95.     call    logud        ;log into designated DU:
  96.     call    codend
  97.     lxi    d,curfcb
  98.     call    wildex        ;expand wildcards
  99.     shld    count        ;save file count
  100.     jz    nofile        ;abort if none or error
  101.     mov    a,h
  102.     ora    a
  103.     jnz    mult
  104.     mov    a,l
  105.     cpi    1        ;if only one file...
  106.     jnz    mult
  107.     mvi    a,'N'        ;then do not verify (but barf if R/O)
  108.     sta    option
  109. mult:    lda    option
  110.     cpi    'Y'
  111.     jz    goodop
  112.     cpi    'N'
  113.     jz    goodop
  114. conf:    call    print        ;ask for YN option if not yet specified
  115.     db    'Ambiguous filename. Confirm individual files (Y/N) ? ',0
  116.     mvi    a,1
  117.     call    bbline
  118.     call    crlf
  119.     mov    a,m
  120.     sta    option
  121.     cpi    'Y'
  122.     jz    goodop
  123.     cpi    'N'
  124.     jnz    conf
  125. goodop:    call    codend        ;get filename table pointer
  126.     shld    fptr
  127. loop:    lhld    fptr
  128.     lxi    d,curfcb    ;point to fcb area
  129.     push    d
  130.     mvi    b,16
  131.     call    hmovb        ;move the junk
  132.     shld    fptr        ;save pointer for next time
  133.     pop    d
  134.     call    initfcb
  135.     mov    h,d
  136.     mov    l,e
  137.     inx    h
  138.     call    pfn        ;print the filename
  139.     lda    option        ;get option letter
  140.     cpi    'N'
  141.     jz    noconf
  142.     call    print
  143.     db    ' delete (Y/N) ? ',0
  144.     mvi    a,1
  145.     call    bbline
  146.     call    crlf
  147.     mov    a,m
  148.     cpi    'Y'
  149.     jnz    nodl
  150.     mov    h,d
  151.     mov    l,e
  152.     inx    h
  153.     call    pfn
  154. noconf:    call    f$open
  155.     lda    curfcb+9
  156.     ani    80h
  157.     jz    noro
  158.     lda    optn2
  159.     cpi    'R'
  160.     jz    delro
  161.     call    print
  162.     db    ' R/O - not deleted.',cr,lf,0
  163.     jmp    nodl
  164. ;
  165. ; delete R/O file
  166. ;
  167. delro:    lda    curfcb+9
  168.     ani    7fh        ;reset R/O bit
  169.     sta    curfcb+9
  170.     push    d
  171.     mvi    c,30        ;set attribute call
  172.     call    bdos
  173.     pop    d
  174. noro:    call    f$delete    ;now delete file
  175.     ora    a
  176.     jz    didd
  177.     call    print
  178.     db    7,' not',0
  179. didd:    call    print
  180.     db    ' deleted.',cr,lf,0
  181. nodl:    lhld    count        ;decrement file count
  182.     dcx    h
  183.     shld    count
  184.     mov    a,h
  185.     ora    l
  186.     jnz    loop        ;loop if more files left
  187.     jmp    quit
  188. ;
  189. ; skip to next non-blank
  190. ;
  191. skipnb:    mov    a,m
  192.     cpi    ' '
  193.     rnz
  194.     inx    h
  195.     jmp    skipnb
  196. ;
  197. ; print DU:FN.FT
  198. ;
  199. pfn:    push    h        ;save filename pointer
  200.     lhld    filedu        ;get DU: of file
  201.     mov    a,h
  202.     adi    'A'
  203.     call    cout        ;print drive letter
  204.     mov    a,l        ;get user #
  205.     pop    h        ;restore HL while we're at it
  206.     cpi    10        ;if user < 10...
  207.     jc    punit        ;...then print units
  208.     mvi    b,0        ;else make and print tens
  209. tens:    sui    10
  210.     inr    b
  211.     cpi    10
  212.     jnc    tens
  213.     push    psw
  214.     mov    a,b
  215.     adi    '0'
  216.     call    cout
  217.     pop    psw
  218. punit:    adi    '0'
  219.     call    cout
  220.     mvi    a,':'        ;print a colon
  221.     call    cout
  222.     mvi    b,8        ;now print filename
  223.     call    phl
  224.     mvi    a,'.'
  225.     call    cout
  226.     mvi    b,3        ;print file type
  227. phl:    mov    a,m
  228.     call    cout
  229.     inx    h
  230.     dcr    b
  231.     jnz    phl
  232.     ret
  233. ;
  234. ; no file abort message
  235. ;
  236. nofile:    call    print
  237.     db    'No files deleted',cr,lf,0
  238.     jmp    quit
  239. ;
  240. ; invalid DU: message
  241. ;
  242. invdu:    call    print
  243.     db    'Invalid drive or user specified',cr,lf,0
  244.     jmp    quit
  245. ;
  246. help:    call    print
  247.     db    'Usage: ..>DELETE [du:]afn[;op]',cr,lf
  248.     db    '(du: = drive and/or user',cr,lf
  249.     db    ' ;op one of:',cr,lf
  250.     db    ' N = no individual verify',cr,lf
  251.     db    ' Y = individual verify',cr,lf
  252.     db    ' R = delete R/O files)',cr,lf,0
  253. quit:    call    getud
  254.     lhld    stksav
  255.     sphl
  256.     ret
  257. ;
  258. stksav:    dw    0
  259. option:    db    0
  260. optn2:    db    0
  261. filedu:    dw    0
  262. fptr:    dw    0
  263. count:    dw    0
  264. curfcb:    ds    36
  265.     ds    80
  266. stack    equ    $
  267.     end
  268.