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 / TOUCH.ASM < prev    next >
Assembly Source File  |  1985-11-16  |  4KB  |  187 lines

  1. page 66,132
  2. ;compressed mode on prn.
  3.  
  4. ;---- touch.com ---------------------------------------------------
  5. ; Usage: touch file [file...]
  6. ; Sets creation time of file to now
  7. ; Wildcards allowed in filename 
  8. ; Patterned after rm by MCN
  9. ; DRK 30 Oct 85
  10. ;---------------------------------------------------------------
  11.     extrn    _args:near,argc:word,argv:word,_shift:near
  12.     extrn    ffirst:near,fnext:near,fnam:byte,finder:word
  13.  
  14. stderr    equ    2
  15.  
  16. code    segment    public 'CODE'
  17. assume cs:code,ds:code,es:code
  18.  
  19. f_attrib    equ    21        ; offset from DTA of file attrib
  20.  
  21.     org    100h
  22.  
  23. ; This is a .COM program.
  24. ; It takes one or more arguments - the names of files (wildcards ok).
  25. ; The argument is the first nonblank string of chars.
  26. ; Either backslashes or forward slashes may be used in a pathname.
  27.  
  28. exist    proc    near
  29.  
  30.     ; Get arguments.
  31.     call    _args
  32.  
  33.     ; Check # of arguments- if none, send usage message.
  34.     cmp    argc, 0
  35.     jnz    arglp
  36.         jmp    usage
  37.  
  38.                     
  39.     ; call DOS to see if file exists.
  40. arglp:    mov    dx, argv[2]    ; get pointer to first argument.
  41.     mov    cx, 0        ; no special attribute bits set
  42.     call    ffirst        ; FIND FIRST
  43.     jc    nofile        ; if carry set, no file found.
  44.  
  45. doit: 
  46.  
  47.     mov    ah, 3dh        ; open file for writing
  48.     mov    al, 1
  49.     lea    dx, fnam    ; 
  50.     int    21h
  51.     jnc    changem
  52.         call    denied        ; give whimpy access denied message
  53.         jmp    short next
  54. changem:
  55.     xchg    ax, bx
  56.  
  57.     ; Get current date/time
  58.     cli            ; stop system chronograph (no rollover, please)
  59.     mov    ah, 2ch
  60.     int    21h        ; hour=ch, min=cl, sec=dh
  61.     push    cx
  62.     push    dx
  63.     mov    ah, 2ah
  64.     int    21h        ; cx=year(1980..), dh=month(1-12), dl=day(1-31)
  65.     sti            ; restart chronograph, hope no serial I/O lost
  66.  
  67.     ; Convert to file timestamp format
  68.     ; dx=yyyyyyy mmmm ddddd (yyyyyyy = year-1980, mmmm=1..12, dddd=1..31)
  69.     sub    cx, 1980
  70.     shl    dh, 1
  71.     shl    dh, 1
  72.     shl    dh, 1
  73.     shl    dh, 1
  74.     shl    dh, 1        ; dh = mmm00000
  75.     rcl    cl, 1        ; cl = yyyyyyym
  76.     or    dl, dh        ; dl = mmmddddd
  77.     mov    dh, cl        ; dx = yyyyyyym mmmddddd
  78.     
  79.     ; cx=hhhhh mmmmmm sssss (sssss = seconds/2)
  80.     pop    ax        ; sec = ah
  81.     pop    cx        ; hour = ch, min=cl
  82.     shr    ah, 1        ; ah = 000sssss
  83.     shl    cl, 1
  84.     shl    cl, 1        ; cx = 000hhhhh mmmmmm00
  85.     shl    cx, 1
  86.     shl    cx, 1
  87.     shl    cx, 1
  88.     or    cl, ah        ; cx = hhhhhmmm mmmsssss
  89.  
  90.     ; Set file creation date/time
  91.     mov    ax, 5701h    ; cx=time, dx=date
  92.     int    21h
  93.     jnc    closem
  94.         call    denied        ; give whimpy access denied message
  95.         jmp    short next
  96. closem:
  97.     ; Close file
  98.     mov    ah, 3eh
  99.     int    21h
  100.  
  101. next:    mov    bx, finder
  102.     call    fnext        ; FIND NEXT
  103.     jnc    doit        ; again
  104.     
  105. narg:    call    _shift        ; more arguments?
  106.     dec    argc
  107.     jnz    arglp        ; nope
  108.  
  109.     mov    al, 0        ; errorlevel= 0 => file found
  110.     jmp    short exit
  111.  
  112. nlen    = 0
  113. nlen    = nend-noff
  114.  
  115. nofile:    mov    bx, stderr     ; error device
  116.     mov    cx,    nlen
  117.     mov    dx,    offset nmsg
  118.     mov    ah, 40h
  119.     int    21h
  120.     mov    al, 1        ; file not found error
  121.     jmp    short narg
  122.  
  123.     
  124.     
  125.  
  126. exit:    mov    ah, 4ch
  127.     int    21h        ; terminate process, return status in AL.
  128.  
  129. ulen    = 0
  130. ulen    =    uend-uoff
  131.  
  132. usage:    mov    bx, stderr    ; write to error device...
  133.     mov    cx, ulen
  134.     mov    dx, offset umsg
  135.     mov    ah, 40h
  136.     int    21h
  137.     mov    al, 2        ; error2 = syntax error
  138.     jmp    short exit
  139.  
  140. alen    = 0
  141. alen    =    aend-aoff
  142.  
  143. denied: cmp    ax, 5
  144.     jne    nfw        ; not access denied
  145.     mov    bx, stderr    ; error device
  146.     mov    cx, alen
  147.     mov    dx, offset amsg
  148.     mov    ah, 40h        ; write message
  149.     int    21h
  150.     mov    al, 1
  151.     ret
  152.  
  153. nfw:
  154.     mov    bx, stderr     ; error device
  155.     mov    cx,    nlen
  156.     mov    dx,    offset nmsg
  157.     mov    ah, 40h
  158.     int    21h
  159.     mov    al, 0ffh        ; file whiz error
  160.     jmp    short exit
  161.  
  162. exist    endp
  163.  
  164.  
  165. handle    dw    ?
  166.     
  167. umsg    db    'Usage: touch filespec [filespec ...]', 13, 10
  168. bugo    db    ?
  169. uoff    equ    offset umsg
  170. uend    equ    offset bugo
  171.  
  172. nmsg    db    "touch: Couldn't touch.", 13, 10
  173. nugo    db    ?
  174. noff    equ    offset nmsg
  175. nend    equ    offset nugo
  176.  
  177. amsg    db    'touch: access denied', 13, 10
  178. augo    db    ?
  179. aoff    equ    offset amsg
  180. aend    equ    offset augo
  181.  
  182.  
  183. code    ends
  184.  
  185.     end    exist
  186.