home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / ASMDLL.ZIP / TOUCH.ASM < prev    next >
Assembly Source File  |  1989-12-31  |  6KB  |  276 lines

  1. TITLE    OS/2 TOUCH -- update file last write date and time
  2. PAGE    66,80
  3.  
  4. COMMENT /**********************************************************************
  5.  
  6.     TOUCH.ASM
  7.  
  8.     Updates the named files' last write date and time to the current
  9.     date and time. Accepts wildcard filenames.
  10.  
  11.     Assemble with: masm -Mx touch;
  12.  
  13.     Link with: link touch,,,doscalls + djo,touch
  14.  
  15.     Usage: touch  pathname.ext
  16.  
  17.     Copyright (C)1989 David J Olson
  18.  
  19. ******************************************************************************/
  20.  
  21. .286
  22. .MODEL SMALL, PASCAL
  23.  
  24. INCL_DOSFILEMGR     EQU 1
  25. INCL_DOSDATETIME    EQU 1
  26.  
  27. INCLUDE     os2.inc
  28. INCLUDE     David's.inc
  29.  
  30. FindInfo    STRUC                ;search results structure
  31.     cdate    DW  (size FDATE)/2 dup (?)  ;creation date
  32.     ctime    DW  (size FTIME)/2 dup (?)  ;creation time
  33.     adate    DW  (size FDATE)/2 dup (?)  ;last access
  34.     atime    DW  (size FTIME)/2 dup (?)
  35.     wdate    DW  (size FDATE)/2 dup (?)  ;last written
  36.     wtime    DW  (size FTIME)/2 dup (?)
  37.     fsize    DD    ?            ;file size
  38.     allocated    DD    ?            ;file allocation
  39.     attributes    DW    ?            ;file attributes
  40.     fnamesize    DB    ?            ;filename count byte
  41.     fname    DB    13 dup(?)        ;ASCIIZ filename
  42. FindInfo    ENDS
  43.  
  44. FileInfo    STRUC                ;search results structure
  45.     create_d    DW  (size FDATE)/2 dup (?)  ;creation date
  46.     create_t    DW  (size FTIME)/2 dup (?)  ;creation time
  47.     access_d    DW  (size FDATE)/2 dup (?)  ;last access
  48.     access_t    DW  (size FTIME)/2 dup (?)
  49.     write_d    DW  (size FDATE)/2 dup (?)  ;last written
  50.     write_t    DW  (size FTIME)/2 dup (?)
  51.     filesize    DD    ?            ;file size
  52.     allocate    DD    ?            ;file allocation
  53.     attribute    DW    ?            ;file attributes
  54. FileInfo    ENDS
  55.  
  56. .DATA
  57.  
  58. arg_ptr     DD    ?
  59. subject     DB    64 dup(0)
  60. str_length    DW    0
  61. matches     DW    0
  62.  
  63. found        FindInfo<>            ; declare structure
  64. flength     EQU    TYPE found
  65.  
  66. touched     FileInfo<>
  67. Tlength     EQU    TYPE touched
  68.  
  69. present     DATETIME<>
  70.  
  71. here        DB    64 dup(?)
  72. hereLength    equ    $-here
  73.  
  74. WriteLength    DW    ?
  75.  
  76. newline     DB    cr, lf
  77. newlineLength    EQU    $-newline
  78.  
  79. notfound    DB    ': no matching files found.', cr, lf
  80. notfoundLength    EQU    $-notfound
  81.  
  82. usage        DB    cr, lf, 'USAGE: touch filename.ext', cr, lf
  83. usageLength    EQU    $-usage
  84.  
  85.  
  86.  
  87. .CODE
  88.  
  89. EXTRN       Argc:FAR
  90. EXTRN       Argv:FAR
  91.  
  92. touch      PROC      FAR
  93.  
  94. ;   Point ES to DGROUP
  95.  
  96.         push    ds
  97.         pop     es
  98.         assume  es:DGROUP
  99.  
  100. ;   Check for commandline argument
  101.  
  102.         push    SEG DGROUP
  103.         push    OFFSET DGROUP:str_length
  104.  
  105.         call    Argc
  106.  
  107.         cmp     WORD PTR str_length, 2
  108.         je      @F
  109.  
  110.         @DosWrite stderr, usage, usageLength, WriteLength
  111.  
  112.         @DosExit 1, 1
  113.  
  114. @@:
  115.         push    1
  116.         push    SEG DGROUP
  117.         push    OFFSET DGROUP:arg_ptr
  118.         push    SEG DGROUP
  119.         push    OFFSET DGROUP:str_length
  120.         call    Argv
  121.  
  122.         mov     cx, str_length           ;Number of characters
  123.         mov     di, OFFSET DGROUP:subject
  124.         lds     si, arg_ptr
  125.         cld
  126.     rep     movsb
  127.         xor     ax, ax
  128.         stosb                ;NULL terminated string
  129.         push    es
  130.         pop     ds
  131.  
  132.         @DosGetDateTime present
  133.  
  134.         call    FSearch
  135.  
  136.         mov     ax, matches
  137.         or        ax, ax
  138.         jnz     @F
  139.  
  140.         @DosWrite stdout, newline, newlineLength, WriteLength
  141.  
  142.         @DosWrite stdout, subject, [str_length], WriteLength
  143.  
  144.         @DosWrite stdout, notfound, notfoundLength, WriteLength
  145. @@:
  146.         @DosExit 1, 0
  147.  
  148. touch      ENDP
  149.  
  150.  
  151.  
  152.  
  153. COMMENT /**********************************************************************
  154.  
  155.     FSearch:    Scan current directory for filenames matching "subject".
  156.  
  157.     Arguments:    none
  158.  
  159.     Globals:    matches, subject, found.
  160.  
  161.     Locals:    shandle, scount.
  162.  
  163.     Returns:    none
  164.  
  165.     Registers:    ax.
  166.  
  167. ******************************************************************************/
  168.  
  169. FSearch     PROC    NEAR USES ax
  170.  
  171. LOCAL    shandle:WORD, scount:WORD
  172.  
  173.         mov     shandle, 0FFFFH        ;initialize search handle
  174.         mov     scount, 1            ;max matches to return
  175.  
  176.         @DosFindFirst subject shandle 0000H found flength scount 0
  177.  
  178.         or        ax, ax
  179.         jnz     FSdone            ;no match found
  180.  
  181. @@:
  182.         inc     matches            ;number of matches found
  183.         call    touchfile
  184.  
  185.         @DosFindNext [shandle] found flength scount
  186.  
  187.         or        ax, ax
  188.         jz        @B                ;Found another match
  189.  
  190. FSdone:
  191.         @DosFindClose [shandle]
  192.  
  193.         ret
  194.  
  195. FSearch     ENDP
  196.  
  197.  
  198.  
  199.  
  200. COMMENT /**********************************************************************
  201.  
  202.     touchfile:    Open file, get handle, get file info, change date & time,
  203.         set file info, close file.
  204.  
  205.     Arguments:    none
  206.  
  207.     Globals:    found, touched, seconds, minutes, hours, day, month, year
  208.  
  209.     Locals:    thandle
  210.  
  211.     Returns:    ERROR or NOERROR
  212.  
  213.     Registers:
  214.  
  215. ******************************************************************************/
  216.  
  217. touchfile   PROC    NEAR
  218.  
  219. LOCAL    thandle:WORD, action:WORD
  220.  
  221.         @DosOpen found.fname thandle action NULL NULL 0001H 0022H 0
  222.         or        ax, ax
  223.         jnz     @F
  224.  
  225.         @DosQFileInfo [thandle] 0001H touched Tlength
  226.         or        ax, ax
  227.         jnz     @F
  228.  
  229. ;touched.write_t =  (present.date_seconds >> 1) |
  230. ;           (present.date_minutes << 5) |
  231. ;           (present.date_hours << 11)
  232.  
  233.         xor     ax, ax
  234.         mov     al, present.date_seconds      ;seconds/2 to bits 0-4
  235.         shr     ax, 1
  236.         and     ax, 001FH
  237.         mov     touched.write_t, ax
  238.         mov     al, present.date_minutes     ;minutes to bits 5-10
  239.         and     ax, 003FH
  240.         shl     ax, 05H
  241.         or        touched.write_t, ax
  242.         xor     ah, ah
  243.         mov     al, present.date_hours       ;hours to bits 11-15
  244.         xchg    ah, al
  245.         shl     ax, 04H
  246.         or        touched.write_t, ax
  247.  
  248. ;touched.write_d =  (present.date_day & 001F) |
  249. ;           ((present.date_month & 000F) << 5) |
  250. ;           ((present.date_year - 1980) << 9)
  251.  
  252.         xor     ax, ax
  253.         mov     al, present.date_day
  254.         and     al, 1FH
  255.         mov     touched.write_d, ax     ;day to bits 0-4
  256.         mov     al, present.date_month
  257.         and     al, 0FH
  258.         shl     ax, 05H
  259.         or        touched.write_d, ax     ;month to bits 5-8
  260.         mov     ax, present.date_year
  261.         sub     ax, 1980
  262.         shl     ax, 09H
  263.         or        touched.write_d, ax     ;year to bits 9-15
  264.  
  265.         @DosSetFileInfo [thandle] 0001H touched Tlength
  266.         or        ax, ax
  267.         jnz     @F
  268.  
  269. @@:
  270.         @DosClose [Thandle]
  271.         ret
  272.  
  273. touchfile   ENDP
  274.  
  275. end touch
  276.