FILE HANDLES








  PRODUCT  :  TURBO BASIC                            NUMBER  :  360
  VERSION  :  1.0
       OS  :  PC-DOS
     DATE  :  July 22, 1987                            PAGE  :  1/5

  TITLE    :  FILE HANDLES




  This program demonstrates how to retrieve a file handle from
  within a Turbo Basic program.

  $INCLUDE "REGNAMES.INC"  ' This file should be on your Turbo
  Basic disk.

  Begin:
      CLS
      OPEN "Test1" FOR OUTPUT AS #1

      CALL Get.File.Date.and.Time ( 1, Year%, Month%, Date%,_
                                    Hour%, Minute%, Second% )
      CALL Print.Stats
      CALL Set.File.Date.and.Time ( 1, 1987, 6, 30,_
                                    12, 30, 55 )
      CALL Get.File.Date.and.Time ( 1, Year%, Month%, Date%,_
                                    Hour%, Minute%, Second% )
      PRINT
      CALL Print.Stats

      CLOSE
      KILL "Test1"
  END

































  PRODUCT  :  TURBO BASIC                            NUMBER  :  360
  VERSION  :  1.0
       OS  :  PC-DOS
     DATE  :  July 22, 1987                            PAGE  :  2/5

  TITLE    :  FILE HANDLES




  ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³                                                               ³
  ³  FNFileHandleAddress% :                                       ³
  ³                                                               ³
  ³  Returns a file handle based upon the number of the file      ³
  ³  passed into the function. The function searches through Turbo³
  ³  Basic's linked list of file handles for the corresponding    ³
  ³  file number passed in the function. You will know which file ³
  ³  number to pass in through the syntax of the OPEN statement   ³
  ³  that you used on the file. See the program FILEEX.BAS for an ³
  ³  example of how to use this function along with DOS function  ³
  ³  call 87 ( 57 hex ).                                          ³
  ³                                                               ³
  ³       Turbo Basic's linked list of file handles is stored in  ³
  ³  the string data segment area.  Two bytes at offsets 6 & 7    ³
  ³  are a pointer to the first node of the linked list.  Each    ³
  ³  node in the linked list has the following format:            ³
  ³                                                               ³
  ³                                                               ³
  ³      ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ                           ³
  ³      | Pointer to next node       |    2 Bytes                ³
  ³      ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ                           ³
  ³      | Pointer to previous node   |    "   "                  ³
  ³      ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ                           ³
  ³      | File Number                |    "   "                  ³
  ³      ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ                           ³
  ³      | DOS File Handle            |    "   "                  ³
  ³      ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ                           ³
  ³                                                               ³
  ³  Please keep in mind that the information is stored in        ³
  ³  byte-reverse notation.  This was written on 6/4/87 for       ³
  ³  Turbo Basic 1.00.                                            ³
  ³                                                               ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ






















  PRODUCT  :  TURBO BASIC                            NUMBER  :  360
  VERSION  :  1.0
       OS  :  PC-DOS
     DATE  :  July 22, 1987                            PAGE  :  3/5

  TITLE    :  FILE HANDLES




  DEF FNFileHandleAddress%(FileNumber%)
  LOCAL Segment%,Ofs%,Done%
    DEF SEG
    Segment% = PEEK(0) + (256 * PEEK(1))   ' Get the string
  segment.
    DEF SEG  = Segment%
    Ofs%     = PEEK(6) + (256 * PEEK(7))   ' Peek at the first file
          number.
    Done%    = 1
    WHILE Done% = 1
      IF (PEEK(Ofs%+4) + (256 * PEEK(Ofs%+5))) = FileNumber% THEN
        FNFileHandleAddress% = PEEK(Ofs%+6) + (256 * PEEK(Ofs%+7))
        Done% = 0
      ELSEIF (PEEK(Ofs%) + (256 * PEEK(Ofs%+1))) = 0 THEN
        FNFileHandleAddress% = 0                ' File number not
  found.
        Done% = 0
      ELSE
        Ofs% = PEEK(Ofs%) + (256 * PEEK(Ofs%+1))   ' Traverse the
           linked list.
      END IF
    WEND
  END DEF


  ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  ³                                                               ³
  ³  Get.File.Date.and.Time                                       ³
  ³                                                               ³
  ³  Uses DOS Function call 87 ( hex 57 ) to retrieve             ³
  ³  a file's time and date statistics.  To accomplish this,      ³
  ³  the file handle must be first retrieved from Turbo Basic's   ³
  ³  linked list structure of file handles.  If the file handle   ³
  ³  is present in the linked list, the statistics concerning it  ³
  ³  are returned.  If not, all variables passed to the procedure ³
  ³  Get.File.Date.and.Time are set to zero.                      ³
  ³                                                               ³
  ³  Written on 6/4/87 for Turbo Basic version 1.00.              ³
  ³                                                               ³
  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
















  PRODUCT  :  TURBO BASIC                            NUMBER  :  360
  VERSION  :  1.0
       OS  :  PC-DOS
     DATE  :  July 22, 1987                            PAGE  :  4/5

  TITLE    :  FILE HANDLES




  SUB Get.File.Date.and.Time ( FileNumber%, Year%, Month%, Date%,_
                               Hour%, Minute%, Second% )

      FH% = FNFileHandleAddress% ( FileNumber% )  ' Get the File
  Handle.
      IF ( FH% ) THEN
          REG %AX,&H5700 ' DOS Function Call 87 -- see p.319
          REG %BX,FH%    ' of Peter Norton's Programmer's Guide to
                         ' the IBM PC.
          REG %DX,0
          REG %CX,0
          CALL INTERRUPT &H21

          Year% = 1980 + FNShr% ( REG (%DX), 9 )
          Month% =  ( REG(%DX) AND &HLE0 ) \ 32
          Date% =  REG(%DX) AND &HLF
          Weekday% =  REG(%DX) AND &H1F
          Hour% =  FNShr% ( REG(%CX), 11 )
          Minute% =  FNShr% ( REG(%CX), 5 ) AND &H3F
          Second% =  FNShl% ( ( REG(%CX) AND &HLF ) , 1 )
      ELSE
          Year% = 0       ' If the File Handle was not found,
          Month% = 0      ' set all variables to zero.
          Date% = 0
          Weekday% = 0
          Hour% = 0
          Minute% = 0
          Second% = 0
      END IF

  END SUB


  SUB Set.File.Date.and.Time ( FileNumber%, Year%, Month%, Date%,_
                               Hour%, Minute%, Second% )

      FH% = FNFileHandleAddress% ( FileNumber% )  ' Get the File
  Handle.
      IF ( FH% ) THEN
          REG %AX,&H5701
          REG %BX,FH%















  PRODUCT  :  TURBO BASIC                            NUMBER  :  360
  VERSION  :  1.0
       OS  :  PC-DOS
     DATE  :  July 22, 1987                            PAGE  :  5/5

  TITLE    :  FILE HANDLES




          REG %DX, (Year% - 1980%) * 512% + Month% * 32% + Date%
          REG %CX, FNShl% ( Hour%, 11 )
          REG %CX, REG(%CX) + FNShl% ( Minute%, 5 )
          REG %CX, REG(%CX) + ( Second% \ 2 )
          CALL INTERRUPT &H21
      ELSE
          PRINT "File number: ";FileNumber%;" associated handle not
          found."
      END IF

  END SUB


  SUB Print.Stats
    SHARED Year%, Month%, Date%, Hour%, Minute%, Second%
      PRINT "Year = "; Year%
      PRINT "Month = "; Month%
      PRINT "Day = "; Date%
      PRINT "Hour = ";  Hour%
      PRINT "Minute = "; Minute%
      PRINT "Seconds = "; Second%
  END SUB


  DEF FNHi% ( AnyInt% )
      FNHi% = AnyInt% AND &HFF00
  END DEF

  DEF FNLow% ( AnyInt% )
      FNLow% = AnyInt% AND &H00FF
  END DEF

  DEF FNShl% ( AnyInt%, Bits% )
      FNShl% = AnyInt% * ( 2% ^ Bits% )
  END DEF

  DEF FNShr% ( AnyInt%, Bits% )
      FNShr% = AnyInt% \ ( 2% ^ Bits% )
  END DEF










Comments

Popular posts from this blog

BOTTOM LIVE script

Fawlty Towers script for "A Touch of Class"