home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / BASIC / POWBASIC / LIBRARY2 / PTOUCH.ZIP / TOUCH.BAS < prev   
BASIC Source File  |  1990-04-07  |  4KB  |  115 lines

  1. ' this program is being used to develop the ability to read, save and
  2. ' re-write the file date back to the directory. in this way, the
  3. ' program will apear un-altered. When used, we will first get the
  4. ' date and time, and then close the file. when done altering and
  5. ' closing the file, we will re-open and replace the current date and time
  6. ' with the original date and time.
  7. ' PowerBASIC version
  8. ' TOUCH.PBU
  9. $Compile UNIT
  10. Defint a-z
  11.  
  12. EXTERNAL FILEDate&,FileTime&,ErrorCode
  13. %True = -1
  14. %False = 0
  15. '┌───────────────────────────────────────────────────────────────────────────┐
  16. '│                  REGNAMES.INC                     │
  17. '│                                         │
  18. '│ This file is to be used as a $INCLUDE file whenever you use the CALL      │
  19. '│ INTERRUPT statement in your PowerBASIC program. The file contains         │
  20. '│ named constants that represent the registers the CALL INTERRUPT statement │
  21. '│ can manipulate.                                 │
  22. '│                                         │
  23. '│ In order to use this file include it in your programs using the $INCLUDE  │
  24. '│ metastatement:                                                       │
  25. '│                                                                         │
  26. '│   $INCLUDE "REGNAMES.INC"                             │
  27. '│                                                           │
  28. '└───────────────────────────────────────────────────────────────────────────┘
  29.  
  30. %FLAGS = 0
  31. %AX    = 1
  32. %BX    = 2
  33. %CX    = 3
  34. %DX    = 4
  35. %SI    = 5
  36. %DI    = 6
  37. %BP    = 7
  38. %DS    = 8
  39. %ES    = 9
  40. SUB Touch(FileName$,WayToGo$) PUBLIC
  41.  
  42.     '*********************************************************
  43.         '*                                                       *
  44.     '* Name: Touch                                           *
  45.         '* Purpose: To get the current file time and date, and   *
  46.         '*          save it. It will then be used to rewrite     *
  47.         '*          back to the directory.                       *
  48.     '* Application: PowerBasic  file invisible file updates  *
  49.         '* By: Barry Erick                                       *
  50.     '* Date: June 1, 1987, Jan 20,1990                       *
  51.     '* Altered: Registers 0,1,2,3,4,8 (Flags,AX,BX,CX,DX,DS) *
  52.         '*                                                       *
  53.         '*********************************************************
  54.  
  55.  
  56.   SHARED  FileDate&,FileTime&,ErrorCode    'Pass them on for later use
  57.   DirectionError = %False
  58.   IF UCase$(WayToGo$) = "SET" THEN
  59.     WayToGo = Asc(">")
  60.   ELSE
  61.     WayToGo = ASC("<")
  62.   END IF
  63.   FileName$=FileName$ +CHR$(0)    ' Tag on a Zero to make it a ASCIIZ
  64.  '
  65.   REG %AX,&H3D00    'open the file for read to then get date and time
  66.           ' ah = 3d, al = 0..read only
  67.   REG %DX,StrPtr(Filename$)
  68.   REG %DS,StrSeg(FileName$)
  69.   CALL INTERRUPT &H21
  70.   CarryFlag = REG(%FLAGS)MOD &HFFFE
  71.   Handle = REG(1) MOD 256
  72.  
  73.   IF WayToGo = asc(">") then  goto SetFileTimeDate
  74.   IF WayToGo = asc("<") Then  goto GetFileTimeDate
  75.   DirectionError = %True    ' Parameter wrong
  76.   Goto CloseIt          ' so tell and close it...delete once working
  77.  
  78. GetFileTimeDate:
  79.   REG %AX,&H5700 ' get date,time ah=57, al = 0
  80.   REG %BX,Handle
  81.   CALL INTERRUPT &H21
  82.  FileTime& = REG(%CX)
  83.  FileDate& = REG(%DX)
  84.  GOTO CloseIt
  85.  
  86. SetFileTimeDate:
  87.  'set file date
  88.   REG %AX,&H5701 ' set date,time ah=57, al = 1
  89.   REG %BX,Handle
  90.   REG %CX,FileTime&
  91.   REG %DX,FileDate&
  92.   CALL INTERRUPT &H21
  93.   IF REG(%FLAGS) MOD &HFFFE = 1 then goto setError
  94.   GOTO CloseIt
  95.  SetError:
  96.   errcode = REG(1) MOD 256 'AL
  97.   if ErrCode = 1 then print "Bad Function Code (not 1 or 0)":goto CloseIt
  98.   if ErrCode = 6 then print "Bad handle passed": GoTO CloseIt
  99.   ? "I got and error on setting, but I don't know what it is..";errCode
  100.   GOTO CloseIt
  101.  
  102.  
  103.  
  104. CloseIt:
  105.  If DirectionError then
  106.     ? " Parameter Error.... must be GET or SET "
  107.  end if
  108.  ' file is open.... close it for now
  109.  REG %AX,&H3E00
  110.  REG %BX,Handle
  111.  CALL INTERRUPT &H21
  112.  
  113. END SUB
  114.  
  115.