home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / dirutl / zdel3001.arc / ZDEL.ASM < prev    next >
Assembly Source File  |  1987-05-04  |  17KB  |  332 lines

  1. Title  ZDEL: multiple file deletion utility
  2.  
  3. comment !
  4.    ZDEL v3.001 for the Public Domain
  5.  
  6.           Thomas Hanlin III
  7.         6812 Sydenstricker Rd
  8.         Springfield, VA 22152
  9.  
  10.    Update notes: v2.0 allows full path specs with filenames.
  11.                  v3.0 includes more information in the confirmation.
  12.                  v3.001 fixes a minor bug that caused the "days" portion
  13.                       of dates from months > 9 to be displayed incorrectly
  14.                       (Mike Pechnyo, 5-4-87)
  15. !
  16.  
  17.  
  18. Sseg           segment byte stack 'prog'    ; dummy stack segment
  19. Sseg           ends
  20.  
  21.  
  22. Cseg           segment byte public 'prog'
  23.                assume         cs:Cseg, ds:Cseg, ss:Sseg
  24.  
  25.                org            80h
  26.   CMDLEN       db  ?
  27.   CMDINFO      db 127 dup(?)
  28.  
  29.                org            100h
  30.  
  31. MAIN           proc           far
  32.                xor            cx,cx         ; clear parm length
  33.                mov            cl,CMDLEN
  34.                mov            PARMLEN,cl
  35.                jcxz           Inform
  36.                mov            si,offset CMDINFO
  37.                mov            di,offset PARMINFO
  38.                mov            PARMLOC,di
  39.  
  40.                cld
  41. SaveParms:     lodsb                        ; get a command-line char
  42.                cmp            al,"/"        ; is it a switch?
  43.                jne            NotSwitch     ;   no, skip switch handler
  44. Switches:      lodsb                        ; get the switch char
  45.                and            al,11011111b  ; convert to uppercase
  46.                cmp            al,"K"        ; K>ill without confirmation?
  47.                je             SwitchKill    ;   yes, set flags
  48.                cmp            al,"S"        ; S>hort confirm?
  49.                jne            Inform        ;   no, list valid parms
  50.                mov            byte ptr SHORTCNF,1
  51.                jmp            short SwitchDone
  52. SwitchKill:    mov            byte ptr CONFIRM,0 ; set confirmation off
  53. SwitchDone:    sub            byte ptr PARMLEN,2 ; remove "-K" from parms
  54.                loop           SP_loop
  55.                jmp            short Inform  ;   oops, no letter, so error!
  56. NotSwitch:     stosb                        ; save it as a parm chr
  57. SP_loop:       loop           SaveParms     ;    scan entire command line
  58.                cmp            byte ptr PARMLEN,0 ; doublecheck parms
  59.                jz             Inform        ;   Inform if switch w/o filespec
  60.                inc            byte ptr PARMLEN ; account for later decrement
  61.  
  62. GetParm:       xor            cx,cx
  63.                mov            cl,PARMLEN    ; get parm length
  64.                jcxz           Done          ;   exit if no more files to kill
  65.                dec            cx            ; factor in space between parms
  66.                jcxz           Done          ;   exit if no more files to kill
  67.                mov            si,PARMLOC    ; get parm location
  68.                cld                          ; search forward
  69. SeekParmStart: cmp            byte ptr [si]," "  ; is it a valid char?
  70.                jne            GotStart      ;   yes, go handle it
  71.                inc            si            ; move to next char
  72.                loop           SeekParmStart ;   loop until start of parm
  73.  
  74. Inform:        mov            dx,offset ZDELINFO
  75.                mov            ah,9
  76.                int            21h
  77. Done:          int            20h           ; exit program
  78.  
  79. GotStart:      mov            dx,si         ; point to start of parm
  80.                cld                          ; set direction forward
  81. SeekParmEnd:   lodsb                        ; get a parm char
  82.                cmp            al," "        ; is it a space?
  83.                je             GotParmEnd
  84.                loop           SeekParmEnd   ;   loop if not
  85. GotParmEnd:    mov            PARMLEN,cl    ; save new parm line length
  86.                jcxz           GotParm
  87.                mov            PARMLOC,si    ; and new location
  88.                dec            si            ; go back to space
  89. GotParm:       mov            [si],ch       ; put filespec in ASCIIZ format
  90.                mov            di,offset FILESPEC +65 ; end of path area
  91.                std                          ; set direction backwards
  92.                dec            si            ; move to last chr of filespec
  93.  
  94. SeekPath:      lodsb                        ; get a chr
  95.                cmp            al,":"        ; are we back at the drive spec?
  96.                je             SavePath      ;   yes, save it
  97.                cmp            al,"\"        ; are we back at the subdir spec?
  98.                je             SavePath      ;   yes, save it
  99.                cmp            al," "        ; are we back at the start?
  100.                je             GotPath       ;   yes, null path
  101.                or             al,al         ; are we back at the previous file?
  102.                jnz            SeekPath      ;   no, go until we find something
  103.                jmp            short GotPath ;   null path spec
  104.  
  105. SavePath:      cmp            al,"a"        ; is it lowercase?
  106.                jb             UpCase        ;   no
  107.                cmp            al,"z"        ; is it really lowercase?
  108.                ja             UpCase        ;   no
  109.                sub            al,32         ; convert it to uppercase
  110. UpCase:        stosb                        ; save path chr
  111.                lodsb                        ; get another path chr
  112.                or             al,al         ; are we back at the previous file?
  113.                jz             GotPath       ;   yes, we're done saving the path
  114.                cmp            al," "        ; are we back at the beginning?
  115.                jnz            SavePath      ;   no, keep saving path
  116.  
  117. GotPath:       inc            di            ; move to first chr of path spec
  118.                mov            FILELOC,di    ; save location
  119.                mov            ah,4Eh        ; find first file
  120.                xor            cx,cx         ; seek normal files
  121.                int            21h
  122.                or             ax,ax         ; was there an error?
  123.                jnz            GetParm       ;   yes, try next parm
  124.  
  125. XferName:      mov            si,offset CMDLEN +30 ; loc of filename
  126.                mov            di,offset FILESPEC +66 ; where to store it
  127.                cld                          ; move forward
  128.                mov            cx,12         ; max chars per filename
  129. SaveName:      lodsb                        ; get a chr of the filename
  130.                or             al,al         ; end of filename?
  131.                jz             EndFileName   ;   yes, handle it
  132.                stosb                        ; store chr
  133.                loop           SaveName      ;   transfer all of filename
  134.                jmp            short NoFill  ;   skip fill with blanks
  135. EndFileName:   mov            al," "
  136.                rep            stosb         ; left-justify filename in blanks
  137. NoFill:        xor            al,al
  138.                stosb
  139.  
  140.                cmp            byte ptr CONFIRM,1 ; confirm deletion?
  141.                je             ConfirmIt     ;   yes, go confirm deletion
  142.                jmp            DeleteIt      ;   go delete file
  143.  
  144. ConfirmIt:     mov            ah,9          ; display string
  145.                mov            dx,offset DELSTR1 ; "Delete "
  146.                int            21h
  147.  
  148.                mov            si,FILELOC    ; get start of filespec
  149. DispPath:      mov            dl,[si]       ; get a char
  150.                or             dl,dl         ; is it null?
  151.                jz             CheckConfirm  ;   yep, go see how to confirm it
  152.                mov            ah,2          ; display char
  153.                int            21h
  154.                inc            si
  155.                jmp            DispPath
  156.  
  157. CheckConfirm:  cmp            byte ptr SHORTCNF,1 ; short confirmation?
  158.                jne            LongConfirm   ;   no, do size/date/time stuff
  159.                jmp            DispDelStr2   ;   skip size/date/time...
  160.  
  161. LongConfirm:   mov            ax,word ptr CMDLEN +26 ; lsw of file size
  162.                mov            dx,word ptr CMDLEN +28 ; msw of file size
  163.                call           ASCFileSize   ; convert filesize to ASCII
  164.  
  165.                mov            ax,word ptr CMDLEN +24 ; get file date
  166.                mov            si,offset DISPBUF +18 ; ofs of year in buffer
  167.                mov            dx,ax         ; save date
  168.                mov            cl,9          ; shift for year
  169.                shr            ax,cl         ; get year
  170.                add            ax,80         ; add bias
  171.                cmp            ax,100        ; is it two digits (1900's) ?
  172.                jb             ConvYear      ;   yes, go convert it
  173.                sub            ax,100        ; make it two digits (2000's)
  174. ConvYear:      call           TwoDigit      ; convert to ASCII
  175.                and            dh,1          ; clear year from date
  176.                mov            ax,dx         ; restore date
  177.                mov            cl,5          ; shift for month
  178.                shr            ax,cl         ; get month
  179.                mov            si,offset DISPBUF +12 ; ofs of month in buffer
  180.                call           TwoDigit      ; convert to ASCII
  181.                mov            ax,dx         ; restore date
  182.  
  183. ;               and            al,1Fh        ; screen out month, leaving day
  184.                and            ax,1Fh        ; screen out month, leaving day
  185.                                             ; if AX is not masked, then there
  186.                                             ; can be a 1 as the low bit of AH
  187.                                             ; for months > 8, which screws up
  188.                                             ; the display of the days
  189.                                             ;  ... Mike Pechnyo 5-4-87
  190.  
  191.                mov            si,offset DISPBUF +15 ; ofs of day in buffer
  192.                call           TwoDigit      ; convert to ASCII
  193.  
  194.                mov            ax,word ptr CMDLEN +22 ; get file time
  195.                mov            dx,ax         ; save time
  196.                mov            cl,11         ; shift for hour
  197.                shr            ax,cl         ; get hour
  198.                mov            si,offset DISPBUF +22 ; ofs of hour in buffer
  199.                call           TwoDigit      ; convert to ASCII
  200.                mov            ax,dx         ; restore time
  201.                mov            cl,5          ; shift for minute
  202.                shr            ax,cl         ; get minute
  203.                and            ax,3Fh        ; screen out hour
  204.                mov            si,offset DISPBUF +25 ; ofs of minute in buffer
  205.                call           TwoDigit
  206.  
  207.                mov            dx,offset DISPBUF ; location of display buffer
  208.                mov            ah,9          ; display string
  209.                int            21h
  210.  
  211. DispDelStr2:   mov            dx,offset DELSTR2 ;   " [Y,N,Q] ? $"
  212.                mov            ah,9          ; display string
  213.                int            21h
  214.  
  215. GetKey:        mov            ah,8          ; keyboard input without echo
  216.                int            21h
  217.                or             al,al         ; extended ASCII?
  218.                jnz            GotKey        ;   no, process it
  219.                mov            ah,8          ; keyboard input (to junk extASCII)
  220.                int            21h
  221.                jmp            GetKey        ;   go get a valid key this time
  222. GotKey:        and            al,11011111b  ; convert key to uppercase
  223.                cmp            al,"Y"        ; delete file?
  224.                jne            NotY          ;   no
  225.                call           DispLine      ; display chr,CR,LF
  226.                jmp            short DeleteIt ;  go delete file
  227. NotY:          cmp            al,"N"        ; skip file?
  228.                jne            NotN          ;   no
  229.                call           DispLine      ; display chr,CR,LF
  230.                jmp            short NextFile ;  go skip file
  231. NotN:          cmp            al,"Q"        ; quit program?
  232.                jne            GetKey        ;   no, go get a valid key
  233.                call           DispLine      ; display chr,CR,LF
  234.                jmp            Done          ;   exit program
  235.  
  236. DeleteIt:      mov            ah,41h        ; delete file
  237.                mov            dx,FILELOC
  238.                int            21h
  239.  
  240. NextFile:      mov            ah,4Fh        ; find next file
  241.                int            21h
  242.                or             ax,ax         ; was there an error?
  243.                jnz            BadFile       ;   yes, ignore it
  244.                jmp            XferName      ;   go buffer the filename
  245. BadFile:       jmp            GetParm       ;   skip to the next parm
  246. MAIN           endp
  247.  
  248.  
  249. DispLine       proc           near
  250.                mov            bx,offset DELSTR3
  251.                mov            [bx],al
  252.                mov            dx,bx
  253.                mov            ah,9          ; display string
  254.                int            21h
  255.                ret
  256. DispLine       endp
  257.  
  258.  
  259. ASCFileSize    proc           near   ; file size in DX:AX --> ASCII number
  260.                mov            si,offset DISPBUF +1 ; where to put result
  261.                mov            di,offset CONVTABLE  ; table of powers of ten
  262.                mov            byte ptr SHOWZERO,0  ; don't show leading zeroes
  263. AFS1:          mov            byte ptr DIGIT,0     ; clear digit
  264.                mov            cx,2[di]             ; get table entry (msw)
  265.                cmp            cx,-1                ; at end of table?
  266.                je             AFSdone              ;   yes, we're done
  267.                mov            bx,[di]              ; get table entry (lsw)
  268. AFS2:          cmp            dx,cx                ; is number < table (msw)?
  269.                jb             AFS3                 ;   yes, got digit
  270.                ja             AFS2A                ;   ...get digit
  271.                cmp            ax,bx                ; is number < table (lsw)?
  272.                jb             AFS3                 ;   yes, got digit
  273. AFS2A:         inc            byte ptr DIGIT       ; increment digit
  274.                sub            ax,bx                ; reduce number accordingly
  275.                sbb            dx,cx
  276.                jmp            AFS2                 ;   keep going on this digit
  277. AFS3:          push           ax                   ; save AX, we need it
  278.                mov            al,DIGIT             ; get digit
  279.                add            al,"0"               ; convert to ASCII
  280.                cmp            al,"0"               ; is it zero?
  281.                jz             AFS5                 ;   yes, special case
  282.                mov            byte ptr SHOWZERO,1  ; show following zeroes
  283. AFS4:          mov            [si],al              ; store digit
  284.                pop            ax                   ; restore AX
  285.                inc            si                   ; move to next buffer loc
  286.                add            di,4                 ; move to next table loc
  287.                jmp            AFS1                 ;   convert until done
  288. AFSdone:       ret
  289. AFS5:          cmp            SHOWZERO,1           ; show zeroes?
  290.                je             AFS4                 ;   yes
  291.                mov            al," "               ; leading zeroes --> blanks
  292.                jmp            AFS4
  293. ASCFileSize    endp
  294.  
  295.  
  296. TwoDigit       proc           near   ; AX --> two-digit ASCII number
  297.                mov            cl,10         ; convert to base 10
  298.                div            cl
  299.                add            ax,3030h      ; convert digits to ASCII
  300.                mov            [si],ax       ; save result
  301.                ret
  302. TwoDigit       endp
  303.  
  304.  
  305.  
  306. CONFIRM   db 1               ; whether to confirm before deleting (default YES)
  307. SHORTCNF  db 0               ; whether to use short confirmation (default NO)
  308. PARMLEN   db 0               ; length of parms left to examine
  309. PARMLOC   dw ?               ; location of current parm item
  310. PARMINFO  db 127 dup(0)      ; cleaned-up command line storage
  311. FILELOC   dw ?               ; location of start of path spec in storage
  312. FILESPEC  db 79 dup(0)       ; full filespec storage
  313. DISPBUF   db 9 dup(" "),"b  00/00/00  00:00 $" ; long confirm display buffer
  314.  
  315. DELSTR1   db "Delete $"
  316. DELSTR2   db " [Y,N,Q]? $"
  317. DELSTR3   db "x",13,10,"$"
  318.  
  319. CONVTABLE dd 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1, -1
  320. DIGIT     db 0
  321. SHOWZERO  db 0
  322.  
  323. ZDELINFO  db 13,10,"ZDEL 3.0 by Tom Hanlin for the Public Domain",13,10,10
  324.           db "Purpose: multiple-file deletion utility with confirmation.",13,10
  325.           db "Format : ZDEL [/K] [/S] [filename] [..filename]",13,10
  326.           db "Options: Use /K to bypass confirmation before deletion.",13,10
  327.           db "         Use /S for short confirmation.",13,10
  328.           db "$"
  329.  
  330. Cseg           ends
  331.                end            MAIN
  332.