home *** CD-ROM | disk | FTP | other *** search
/ ftp.shrubbery.net / 2015-02-07.ftp.shrubbery.net.tar / ftp.shrubbery.net / pub / pc / unix / unx.arc / RM.ASM < prev    next >
Assembly Source File  |  1986-05-07  |  4KB  |  171 lines

  1. page 66,132
  2. ;compressed mode on prn.
  3.  
  4. ;---- rm.com ---------------------------------------------------
  5. ; Usage: rm filespec
  6. ; Deletes filespec
  7. ; Wildcards allowed in filename 
  8. ; Uses standard DRK args, ffind
  9. ; MCN  16 Oct 84
  10. ; DRK  7 May 86 (yikes!) Added no-unix-wildcard check, cleaned up, added eputs
  11. ;---------------------------------------------------------------
  12.     extrn    _args:near,argc:word,argv:word,_shift:near
  13.     extrn    ffirst:near,fnext:near,fnam:byte,finder:word
  14.     extrn    strlen:near
  15.  
  16. stderr    equ    2
  17.  
  18. code    segment    public 'CODE'
  19. assume cs:code,ds:code,es:code
  20.  
  21. f_attrib    equ    21        ; offset from DTA of file attrib
  22.  
  23.     org    100h
  24.  
  25. origin    proc    near
  26.     jmp    main
  27. origin    endp
  28.  
  29.     db    27, '[2J'
  30.     db    'rm, May 1986, from Yoyodyne Aerospace (where the future',13,10
  31.     db    'begins Real Soon Now)', 13, 10
  32. umsg    db    'Usage: rm filespec [filespec ...]', 13, 10, 0
  33.     db    26        ; eof mark after hello and usage message
  34.  
  35. ;--- Error strings ---
  36. modname    db    "rm: '",0
  37. nommsg    db    "': no match", 13, 10, 0
  38. amsg    db    "': access denied", 13, 10, 0
  39. nadmsg    db    "': unable to remove", 13, 10, 0    ; shouldn't happen
  40. wcmsg    db    "': bad wildcarding", 13, 10, 0
  41.  
  42. ;--- eputs -----
  43. ; Print string at DX to stderr.
  44. ; Preserves DX.
  45. eputs    proc    near
  46.     mov    di, dx
  47.     call    strlen
  48.     mov    bx, stderr
  49.     mov    ah, 40h
  50.     int    21h
  51.     ret
  52. eputs    endp
  53.  
  54. ;--- prname ---
  55. ; Print rm:
  56. ; Preserves SI,DX.
  57. prname    proc    near
  58.     push    si
  59.     push    dx
  60.     mov    dx, offset modname
  61.     call    eputs
  62.     pop    dx
  63.     pop    si
  64.     ret
  65. prname    endp
  66.  
  67. ;--- Complain ----
  68. ; Filename in si has an invalid wildcard sequence;
  69. ; print an error message.
  70. complain    proc    near
  71.     call    prname
  72.     mov    dx, si
  73.     call    eputs
  74.     mov    dx, offset wcmsg
  75.     call    eputs
  76.     ret    
  77. complain    endp
  78.  
  79. ;--- Denied ----
  80. ; Filename in DX was un-removable; print "Access denied."
  81. ; (Error code in AX; if not "access denied", print something else.)
  82. denied    proc    near
  83.     call    prname
  84.     call    eputs        ; print filename
  85.     mov    dx, offset amsg
  86.     cmp    ax, 5
  87.     jne    nfw        ; not access denied
  88.     mov    dx, offset nadmsg
  89. nfw:    call    eputs
  90.     ret
  91. denied    endp
  92.  
  93. ;--- Star_no_dot ---
  94. ; Checks filename in SI for occurrence of * followed by anything but
  95. ; a null or a period.
  96. star_no_dot    proc    near
  97.     cld    
  98. snd_lp:        lodsb
  99.         or    al, al
  100.         jz    snd_ex
  101.         cmp    al, '*'
  102.         jnz    snd_lp
  103.         ; Found a *; is next char a 0 or '.'?
  104.         lodsb
  105.         or    al, al
  106.         jz    snd_ex
  107.         cmp    al, '.'
  108.         jz    snd_lp
  109.         ; fall thru to exit with NZ = error
  110. snd_ex:    ret
  111.         
  112. star_no_dot    endp
  113.  
  114. ;--- main -------
  115. main    proc    near
  116.     ; Get arguments.
  117.     call    _args
  118.  
  119.     ; Check # of arguments- if none, send usage message.
  120.     cmp    argc, 0
  121.     jnz    arglp
  122.         mov    dx, offset umsg
  123.         call    eputs
  124.         mov    al, 1
  125.         jmp    exit
  126.                     
  127. arglp:    ; Make sure file isn't a Unix wildcard with something following a *.
  128.     mov    si, argv[2]
  129.     call    star_no_dot    ; returns NZ if error
  130.     jz    argok
  131.         mov    si, argv[2]
  132.         call    complain    ; bad filespec in si
  133.         jmp    narg        ; and onwards
  134.  
  135. argok:
  136.     ; call DOS to see if file exists.
  137.     mov    dx, argv[2]    ; get pointer to first argument.
  138.     mov    cx, 0        ; no special attribute bits set
  139.     call    ffirst        ; FIND FIRST
  140.     jnc    doit        ; if carry set, no file found.
  141.         call    prname
  142.         mov    dx, argv[2]
  143.         call    eputs
  144.         mov    dx, offset nommsg
  145.         call    eputs
  146.         jmp    narg
  147.  
  148.     ; Inner loop
  149. doit:        lea    dx, fnam
  150.         mov    ah, 41h        ; unlink file
  151.         int    21h
  152.         jnc    next
  153.             lea    dx, fnam
  154.             call    denied    ; give whimpy access denied message
  155. next:        call    fnext        ; FIND NEXT
  156.         jnc    doit        ; again
  157.  
  158. narg:    call    _shift        ; more arguments?
  159.     dec    argc
  160.     jnz    arglp        ; nope
  161.  
  162.     mov    al, 0        ; errorlevel=0; ok.
  163. exit:    mov    ah, 4ch
  164.     int    21h        ; terminate process, return status in AL.
  165.  
  166. main    endp
  167.  
  168. code    ends
  169.  
  170.     end    origin
  171.