home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / asm / OKTIMDAT.ZIP / FTD.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-10-29  |  17.7 KB  |  375 lines

  1. Page 60,120
  2. Title       FTD.ASM - File Time and Date stamper
  3. COMMENT ~   Ver 1.0
  4.             (c) 1988 Tom Gilbert's Heart&Mind
  5.             for NON-Commercial use ONLY!
  6.             Use and distribution without charge
  7.              IS authorized and encouraged!
  8.         ~
  9.         DOSSEG
  10.         .MODEL  small
  11.         .STACK  100h
  12.         .DATA
  13.         DB  10
  14. ArgV0   DB  'FTD',23 DUP (0),13,10,10
  15.         DB  'By: Heart&Mind - OCT 88',13,10
  16. InfoM   DB  10,'FTD file spec '
  17.         DB  '[mm/dd/yy[yy] [hh[:mm[:ss]]]]',13
  18.         DB  10,'stamps file(s) matching'
  19.         DB  ' "file spec"',13,10,10
  20. DayOW   DB  'DayOfWeek',13,10
  21. DateS   DB  'mm/dd/yyyy',13,10
  22. TimeS   DB  'hh:mm:ss',13,10,10
  23.         DB  'Optional date/time fields change',13,10
  24.         DB  'the date and/or time.  See FTD.DOC'
  25. CR_LF   DB  13,10,36
  26. NoFFM   DB  10,'No File(s) Found',13,10,36
  27. Press   DB  13,10,'Press any key to continue . . . $'
  28. Stamp   DB  13,10,'Stamping file: $'
  29.  
  30. LineC   DB  16                          ; Count of Display Lines
  31.  
  32. WrkFS   DB  'd:\',40 DUP (0),36         ; Drive:\DirPaths\filespec
  33. DTA4D   DB  21 DUP (0)                  ; DataTransferArea Reserved
  34. DTAFI   DB   9 DUP (0)                  ; DTA File Info: Atribs etc
  35. DTAFN   DB  12 DUP (0)                  ; DTA Filename.Ext
  36.  
  37. DayNT   Label   Byte                    ; Table of Day Names
  38.         DB      'Sunday   '
  39.         DB      'Monday   '
  40.         DB      'Tuesday  '
  41.         DB      'Wednesday'
  42.         DB      'Thursday '
  43.         DB      'Friday   '
  44.         DB      'Saturday '
  45.  
  46. CD_CX   DW  ?                           ; Current Date Year
  47. CD_DX   DW  ?                           ; Current Month/Day
  48.  
  49. DateW   DW  ?                           ; Bit-Mapped Date
  50. TimeW   DW  ?                           ; Bit-Mapped Time
  51.  
  52. WrkDI   DW  ?                           ; File Name Pointer
  53.  
  54. Count   DW  1                           ; Parameter Last Processed
  55. Pars    DW  ?                           ; Number of Parameters Found
  56.  
  57. PSP     DW  ?                           ; Segment of ProgramSegmentPrefix
  58.  
  59.         .CODE
  60. EXTRN   ArgC:Proc,ArgV:Proc
  61. EXTRN   B2Dec:Proc,SI2Val:Proc
  62. EXTRN   DateBits:Proc,TimeBits:Proc
  63. Main    Proc    Far
  64.         mov     ax,@data                ; Make data
  65.         mov     ds,ax                   ; Addressable
  66.         mov     PSP,es                  ; Store Segment of
  67.         mov     bx,80h                  ; Program Segment Prefix
  68.         call    ArgC                    ; Get and store
  69.         mov     Pars,ax                 ; Parameter Count
  70.         xor     ax,ax                   ; Get FTD
  71.         call    ArgV                    ; filespec
  72.         push    ds                      ; Exchange
  73.         push    es                      ; Data and
  74.         pop     ds                      ; Extra Segment
  75.         pop     es                      ; Registers
  76.         or      ax,ax                   ; If DOS Version < 3
  77.         jz      GetCL                   ; then Get Command Line
  78.         mov     si,bx                   ; else copy FTD
  79.         mov     di,OFFSET ArgV0         ; filespec to
  80.         mov     cx,ax                   ; bytes of
  81.         rep     movsb                   ; Message Area
  82.         mov     ds,es:PSP               ; Update SI Segment
  83. GetCL:  mov     si,80h                  ; Point to and
  84.         lodsb                           ; convert Command Line
  85.         cbw                             ; length to a WORD and
  86.         inc     ax                      ; include ending 0Dh=cr
  87.         mov     cx,ax                   ; Copy Command Line
  88.         mov     di,OFFSET DTA4D         ; into Data Area
  89.         rep     movsb
  90.         mov     ax,@data                ; Now, Data can be
  91.         mov     ds,ax                   ; addressed by ES or DS
  92.         mov     ah,19h                  ; Get and store
  93.         int     21h                     ; Current Drive
  94.         add     al,"A"                  ; Letter in
  95.         mov     di,OFFSET WrkFS         ; Drive and
  96.         stosb                           ; Directory
  97.         mov     si,OFFSET WrkFS+3       ; Path of
  98.         xor     dl,dl                   ; Default
  99.         mov     ah,47h                  ; Disk Device
  100.         int     21h
  101.         mov     ax,5C00h                ; Find Null Byte in
  102.         mov     cx,42                   ; Work FileSpec Area
  103.         repnz   scasb                   ; When Null at DI-1
  104.         mov     [di-1],ah               ; Store 5Ch = "\"
  105.         cmp     [di-2],ah               ; If NOT ROOT
  106.         jnz     SetDI                   ; then Set DI
  107.         dec     di                      ; else BackUp
  108. SetDI:  mov     WrkDI,di                ; Store FN Ptr
  109.         mov     ah,2Ah                  ; Get DOS
  110.         int     21h                     ; Date and
  111.         call    SetDOW                  ; Store Day of
  112.         mov     CD_CX,cx                ; Week and
  113.         mov     CD_DX,dx                ; Date Values
  114.         call    MovDatS                 ; Store Date String
  115.         call    DateBits                ; Bit-Map and
  116.         mov     DateW,dx                ; Date Word
  117.         mov     ah,2Ch                  ; Store
  118.         int     21h                     ; Time as a
  119.         call    TimeBits                ; Bit-Mapped
  120.         mov     TimeW,dx                ; Word Value
  121.         mov     ah,2Ch                  ; Store
  122.         int     21h                     ; Time
  123.         mov     bx,OFFSET TimeS         ; ASCII
  124.         mov     al,ch                   ; Hour
  125.         call    B2Dec                   ; Digits
  126.         add     bx,3                    ; plus
  127.         mov     al,cl                   ; Minutes
  128.         call    B2Dec                   ; Digits
  129.         add     bx,3                    ; plus
  130.         mov     al,dh                   ; Seconds
  131.         call    B2Dec                   ; Digits
  132.         mov     ax,Count                ; If File Spec
  133.         cmp     ax,Pars                 ; entry found
  134.         jc      CntIt                   ; then Count It
  135.         call    Message                 ; else Message Exit
  136.         jmp     MExit
  137. CntIt:  inc     Count                   ; Count and
  138.         mov     bx,OFFSET DTA4D         ; get the file
  139.         call    ArgV                    ; spec parameter
  140.         mov     di,bx                   ; Set Scan Pointer
  141.         xor     bp,bp                   ; Zero ":\" Flag
  142.         mov     cx,ax                   ; Get length
  143.         mov     dx,ax                   ; and copy
  144.         mov     ax,"\:"                 ; Scan first
  145.         repne   scasb                   ; for ":"
  146.         xchg    ah,al                   ; then scan
  147.         mov     di,bx                   ; for "\"
  148.         mov     cx,dx                   ; If had drive
  149.         je      SSlash                  ; then scan for path
  150.         or      bp,1                    ; else flag NO drive
  151. SSlash: repne   scasb                   ; If had path
  152.         je      CkFlag                  ; then Check Flag
  153.         or      bp,2                    ; else flag NO path
  154. CkFlag: mov     di,OFFSET WrkFS         ; Set Destination and
  155.         mov     si,bx                   ; Source Indices
  156.         or      bp,bp                   ; If Nothing Needed
  157.         jz      MovIt                   ; then move file spec
  158.         test    bp,1                    ; else if spec has drive
  159.         jz      CkPath                  ; then check Path Flag
  160.         add     di,2                    ; else use default drive
  161. CkPath: test    bp,2                    ; If file spec has path
  162.         jz      MovIt                   ; then add to drive
  163.         mov     di,WrkDI                ; else add to path
  164. MovIt:  mov     cx,dx                   ; Set length to
  165.         rep     movsb                   ; copy file spec
  166.         mov     BYTE PTR [di],0         ; Insure a Null
  167.         std                             ; Work Backward to
  168.         mov     al,"\"                  ; Find Last Path
  169.         mov     cx,dx                   ; Delimiter in
  170.         add     cx,2                    ; Filespec or
  171.         repne   scasb                   ; Old Path
  172.         cld                             ; Restore Direction
  173.         add     di,2                    ; Calculate FileName
  174.         mov     WrkDI,di                ; Starting Position
  175. GetVL:  mov     ax,Count                ; If NO More
  176.         cmp     ax,Pars                 ; Parameters
  177.         jnc     EndVL                   ; then done
  178.         inc     Count                   ; else count
  179.         mov     bx,OFFSET DTA4D         ;  and get
  180.         call    ArgV                    ; next one
  181.         mov     di,bx                   ; Scan the
  182.         mov     cx,ax                   ; length
  183.         push    ax                      ; preserved
  184.         mov     al,"/"                  ; for date
  185.         repne   scasb                   ; delimiter
  186.         pop     ax                      ; If NO "/"
  187.         jcxz    TimeR                   ; then Time Routine
  188.         call    SetDate                 ; else Date Routine
  189.         jmp     SHORT GetVL             ; and loop 'til done
  190. TimeR:  call    SetTime
  191.         jmp     SHORT GetVL
  192.  
  193. EndVL:  call    Message                 ; Display Message Area
  194.         mov     ah,1Ah                  ; Set
  195.         mov     dx,OFFSET DTA4D         ; DTA
  196.         int     21h                     ; Area
  197.         mov     ah,4Eh                  ; If First
  198.         xor     cx,cx                   ; Normal
  199.         mov     dx,OFFSET WrkFS         ; Matching
  200.         int     21h                     ; File Found
  201.         jnc     FTDSI                   ; then Stamp It
  202.         mov     ah,9                    ; else Display
  203.         mov     dx,OFFSET NoFFM         ; "No File(s)
  204.         int     21h                     ;  Found" and
  205.         jmp     SHORT MExit             ; Error Exit
  206. FNext:  mov     ah,4Fh                  ; If Another
  207.         int     21h                     ; File NOT Found
  208.         jc      ELine                   ; then End Line Exit
  209. FTDSI:  mov     si,OFFSET DTAFN         ; DTA Filename and
  210.         mov     di,WrkDI                ; Name to Open/Display
  211.         xor     ax,ax                   ; First Null
  212.         mov     cx,6                    ; Name area with
  213.         rep     stosw                   ; words and then
  214.         mov     di,WrkDI                ; Reset Destination
  215. FCopy:  lodsb                           ; If Byte
  216.         or      al,al                   ; is Null
  217.         jz      RData                   ; then done
  218.         stosb                           ; else copy
  219.         jmp     SHORT FCopy             ; until done
  220. RData:  mov     dx,OFFSET WrkFS         ; Open File
  221.         mov     ax,3D00h                ; Read Only
  222.         int     21h                     ; If Fails
  223.         jc      FNext                   ; then try Next
  224.         mov     dx,DateW                ; else Set Date
  225.         mov     cx,TimeW                ;  and Time for
  226.         mov     bx,ax                   ; file handle
  227.         mov     ax,5701h
  228.         int     21h                     ; If fails
  229.         jc      FNext                   ; then try Next
  230.         mov     ah,3Eh                  ; else close
  231.         int     21h                     ; the file
  232.  
  233.         cmp     LineC,25                ; If Lines Left
  234.         jc      Ok2Dis                  ; then Display
  235.         mov     LineC,0                 ; else zero line count
  236.         mov     ah,9                    ; Display "Press any
  237.         mov     dx,OFFSET Press         ; key to continue . . . "
  238.         int     21h
  239.         mov     ah,7                    ; Wait for
  240.         int     21h                     ; any key
  241. Ok2Dis: mov     ah,9                    ; Display
  242.         mov     dx,OFFSET Stamp         ; Stamping
  243.         int     21h                     ; and add
  244.         mov     dx,OFFSET WrkFS         ; filespec
  245.         int     21h
  246.         inc     LineC                   ; Increment Line Count and
  247.         jmp     SHORT FNext             ; Loop Until No More Matches
  248. ELine:  mov     ah,9
  249.         mov     dx,OFFSET CR_LF         ; End the
  250.         int     21h                     ; last line
  251.         xor     al,al                   ; Zero Error Level
  252. MExit:  mov     ah,4Ch                  ; Use Error Level
  253.         int     21h                     ; DOS Exit Function
  254. Main    EndP
  255.  
  256. SetDate Proc
  257.         mov     bp,ax                   ; Preserve Count
  258.         mov     si,bx                   ; Set Source Index
  259.         call    SI2Val                  ; Get Month
  260.         mov     dh,al                   ; Register
  261.         or      bp,bp                   ; If 0 Left
  262.         jz      SDExit                  ; then exit
  263.         call    SI2Val                  ; else Get
  264.         mov     dl,al                   ; Day Register
  265.         or      bp,bp                   ; If 0 Left
  266.         jz      SDExit                  ; then exit
  267.         call    SI2Val                  ; else Get Year
  268.         cmp     ax,1900                 ; If Century
  269.         jnc     SDY_Ok                  ; then value Ok
  270.         add     ax,1900                 ; else add Century
  271.         cmp     ax,1980                 ; If => 1980
  272.         jnc     SDY_Ok                  ; then value Ok
  273.         add     ax,100                  ; else make Ok
  274. SDY_Ok: mov     cx,ax                   ; Store Year
  275.         mov     ah,2Bh                  ; Set DOS Date
  276.         int     21h                     ; for Validity
  277.         mov     ah,2Ah                  ; Check and to
  278.         int     21h                     ; Get and Set
  279.         call    SetDOW                  ; Day of Week and
  280.         call    MovDatS                 ; Date String
  281.         call    DateBits                ; Bit-Map Date and
  282.         mov     DateW,dx                ; Store Date Word
  283.         mov     cx,CD_CX                ; Restore Current
  284.         mov     dx,CD_DX                ; Date Values
  285.         mov     ah,2Bh                  ; Set Current
  286.         int     21h                     ; DOS Date
  287. SDExit: ret
  288.  
  289. SetDate EndP
  290.  
  291. SetTime Proc
  292.         mov     bp,ax                   ; Preserve Count
  293.         mov     si,bx                   ; Set Source and
  294.         mov     bx,OFFSET TimeS         ; Set Destination
  295.         call    SI2Val                  ; Get and Store
  296.         mov     ch,al                   ; Hours Value
  297.         call    B2Dec                   ; Move ASCII
  298.         add     bx,3                    ; Skip ":"
  299.         or      bp,bp                   ; If More Left
  300.         jnz     STMins                  ; then do minutes
  301.         xor     ax,ax                   ; else zero
  302.         xor     cl,cl                   ; remaining
  303.         xor     dx,dx                   ; time values
  304.         call    B2Dec                   ; store zero
  305.         add     bx,3                    ; minutes
  306.         xor     ax,ax                   ; seconds
  307.         call    B2Dec                   ; and Bit-
  308.         jmp     SHORT ST2_MT            ; Map Time
  309. STMins: call    SI2Val                  ; Get and Store
  310.         mov     cl,al                   ; Minutes Value
  311.         call    B2Dec                   ; Move ASCII
  312.         add     bx,3                    ; Skip ":"
  313.         or      bp,bp                   ; If More Left
  314.         jnz     STSecs                  ; then do seconds
  315.         xor     ax,ax                   ; else zero
  316.         xor     dx,dx                   ; seconds value and
  317.         call    B2Dec                   ; ASCII seconds and
  318.         jmp     SHORT ST2_MT            ; Bit-Map Time
  319. STSecs: call    SI2Val                  ; Get and Store
  320.         mov     dx,ax                   ; seconds values
  321.         call    B2Dec                   ; Move ASCII
  322. ST2_MT: call    TimeBits                ; Bit-Map and
  323.         mov     TimeW,dx                ; store Time Word
  324.         ret
  325. SetTime EndP
  326.  
  327. SetDOW  Proc
  328.         push    cx                      ; Preserve Year
  329.         mov     cx,9                    ; Use as Multiplier
  330.         cbw                             ; for Day Code Word
  331.         mul     cl                      ; to Offset from
  332.         mov     si,OFFSET DayNT         ; Day Name Table
  333.         add     si,ax                   ; Copy Day Name
  334.         mov     di,OFFSET DayOW         ; into Message
  335.         rep     movsb                   ; Area DayName
  336.         pop     cx                      ; Return Date
  337.         ret                             ; Values
  338. SetDOW  EndP
  339.  
  340. MovDatS Proc
  341.         push    cx                      ; Preserve Year
  342.         mov     bx,OFFSET DateS         ; Set Destination
  343.         mov     al,dh                   ; Move Month
  344.         call    B2Dec                   ; ASCII Digits
  345.         add     bx,3                    ; Move Day of
  346.         mov     al,dl                   ; Month as
  347.         call    B2Dec                   ; ASCII Digits
  348.  
  349.         add     BX,3                    ; If Year
  350.         mov     al,20                   ; is in the
  351.         cmp     cx,2000                 ; 21st Century
  352.         ja      Cen21                   ; then (01 - 99)
  353.         jb      Cen20                   ; else (80 - 99)
  354.         xor     cx,cx                   ; else year is
  355.         jmp     SHORT YearS             ; equal "2000"
  356. Cen21:  sub     cx,2000                 ; Set (01 - 99)
  357.         jmp     SHORT YearS             ; for "20yy"
  358. Cen20:  sub     cx,1900                 ; Set (01 - 99)
  359.         dec     al                      ; for "19yy"
  360. YearS:  call    B2Dec                   ; Store Century,
  361.         add     bx,2                    ; Tens and Units
  362.         mov     al,cl                   ; Year ASCII Digits
  363.         call    B2Dec
  364.         pop     cx                      ; Restore Year
  365.         ret
  366. MovDatS EndP
  367.  
  368. Message Proc
  369.         mov     ah,9                    ; Display
  370.         mov     dx,OFFSET ArgV0-1       ; message
  371.         int     21h                     ; area
  372.         ret
  373. Message EndP
  374.         End     Main
  375.