home *** CD-ROM | disk | FTP | other *** search
/ ftp.update.uu.se / ftp.update.uu.se.2014.03.zip / ftp.update.uu.se / pub / rainbow / msdos / misc / touch.lzh / TOUCH.ASM next >
Assembly Source File  |  1985-07-08  |  7KB  |  135 lines

  1. title Touch - Reset the date and time of each file found.
  2. page 60,132
  3. cgroup  group   code_seg, data_seg
  4.         assume  cs:cgroup,ds:cgroup
  5. data_seg segment        public
  6. path_name       db      80 dup (0)      ; space for 64 char path name
  7.                                         ; and 13 char file name
  8. file_name       db      13 dup (0)      ; save room for full dos name
  9. file_handle     dw
  10. date            dw
  11. time            dw
  12. fnf             db      'File not found$'
  13. disk_area               db      21 dup(?)
  14.         attribute       db
  15.         file_time       dw
  16.         file_date       dw
  17.         file_size       dd
  18.         name_found      db      13 dup(?)
  19. disk_transfer_areas     label   byte    ; this starts at the end of the whereis
  20. data_seg        ends
  21. page
  22. code_seg        segment
  23.         org     100h
  24. touch           proc    near
  25.         mov     si,82H                  ; start of command line
  26.         mov     di,offset cgroup:path_name
  27. get_search_name:
  28.         lodsb                           ; get first character
  29.         cmp     al,0dh                  ; carriage return character?
  30.         je      done_reading_name       ; yes, end of name
  31.         stosb
  32.         jmp     get_search_name
  33. done_reading_name:
  34.         xor     al,al                   ; write a 0 at the end
  35.         stosb
  36.         mov     dx, offset cgroup:disk_area
  37.         mov     ah,1aH
  38.         int     21H                     ; set the dta
  39.         mov     dx, offset cgroup:path_name    ; point to the file name
  40.         mov     cx,0                    ; set for normal files only
  41.         mov     ah,4eH                  ; find first file
  42.         int     21H                     ; do it
  43.         cmp     ax, 12H                 ; another error ?
  44.         je      file_not_found
  45.         jmp     found_a_file            ; process it
  46. file_not_found:
  47.         mov     dx, offset cgroup:fnf   ; offset to error message
  48.         mov     ah, 9                   ; print string
  49.         int     21H                     ; dos call
  50.         mov     al, 1                   ; error code 1
  51.         mov     ah,4cH                  ; exit with error code
  52.         int     21h                     ; bye bye
  53. no_more_files:
  54.         mov     al, 0                   ; error code 0
  55.         mov     ah,4ch                  ; exit with error code
  56.         int     21h                     ; bye bye
  57. found_a_file:
  58.         mov     dx,offset cgroup:name_found ; found file name
  59.         mov     al, 2                   ; open for read/write
  60.         mov     ah, 3dH                 ; open file
  61.         int     21H                     ; do it
  62.         mov     file_handle, ax         ; mov file handle to mem
  63.  
  64.         mov     ah, 2aH                 ; get date
  65.         int     21h                     ; do it
  66.         sub     cx,1980                 ; get the date offset from 1980
  67.         shl     cx,1                    ; have the year set up
  68.         shl     cx,1                    ; have the year set up
  69.         shl     cx,1                    ; have the year set up
  70.         shl     cx,1                    ; have the year set up
  71.         shl     cx,1                    ; have the year set up
  72.         shl     cx,1                    ; have the year set up
  73.         shl     cx,1                    ; have the year set up
  74.         shl     cx,1                    ; have the year set up
  75.         shl     cx,1                    ; have the year set up
  76.         xor     bx,bx                   ; clear bx
  77.         mov     bl,dh                   ; move month to bl
  78.         shl     bx,1                    ; set up month
  79.         shl     bx,1                    ; set up month
  80.         shl     bx,1                    ; set up month
  81.         shl     bx,1                    ; set up month
  82.         shl     bx,1                    ; set up month
  83.         or      cx,bx                   ; mov month to date
  84.         xor     bx,bx                   ; clear bx
  85.         mov     bl,dl                   ; mov day to bl
  86.         or      cx,bx                   ; mov day to cx
  87.         mov     date, cx                ; mov to mem
  88.  
  89.         mov     ah, 2cH                 ; get time
  90.         int     21H                     ; do it
  91.         shl     ch,1                    ; shift left 3 bits
  92.         shl     ch,1                    ; shift left 3 bits
  93.         shl     ch,1                    ; shift left 3 bits
  94.         xor     bx,bx                   ; clear bx
  95.         mov     bl,cl                   ; mov minutes to bx
  96.         xor     cl,cl                   ; clear cl
  97.                                         ; now hours are in ch
  98.                                         ; and minutes in bx
  99.         shl     bx,1                    ; shift left 5 bits
  100.         shl     bx,1                    ; shift left 5 bits
  101.         shl     bx,1                    ; shift left 5 bits
  102.         shl     bx,1                    ; shift left 5 bits
  103.         shl     bx,1                    ; shift left 5 bits
  104.         or      cx,bx                   ; now hours are in bits 15-11
  105.                                         ; and mins  are in bits 10-5
  106.                                         ; now to work on seconds.
  107.         xor     bx,bx                   ; clear bx
  108.         shr     dh,1                    ; now we have 2 second value
  109.         mov     bl,dh                   ; mov to bl
  110.         or      cx,bx                   ; or with cx
  111.                                         ; now we have converted the
  112.                                         ; time to file format
  113.         mov     time, cx                ; mov to mem
  114.  
  115.         mov     al, 01                  ; set file date/time
  116.         mov     cx, time                ; mov time
  117.         mov     dx, date                ; mov date
  118.         mov     bx, file_handle         ; mov file_handle
  119.         mov     ah, 57H                 ; set/get file date/time
  120.         int     21H
  121.         mov     bx, file_handle         ; mov file_handle
  122.         mov     ah, 3eH                 ; close file
  123.         int     21H                     ; do it
  124.         ; check to see if there are more files
  125.         mov     ah, 4fH                 ; find next file
  126.         int     21H
  127.         cmp     al, 12H                 ; no more files?
  128.         jne     do_it_again             ; if not do it again
  129.         jmp     no_more_files           ; otherwise exit.
  130. do_it_again:
  131.         jmp     found_a_file
  132. touch   endp
  133. code_seg ends
  134. end     touch
  135.