home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / MISCTI10.ZIP / TI360.ASC < prev    next >
Encoding:
Text File  |  1988-05-02  |  6.7 KB  |  184 lines

  1. PRODUCT  :  TURBO BASIC@>( )NUMBER  :  360
  2. VERSION  :  1.0
  3.      OS  :  PC-DOS
  4.    DATE  :  July 22, 1987@>( )PAGE  :  @value(page)/5
  5.  
  6. TITLE    :  FILE HANDLES
  7.  
  8. $INCLUDE "REGNAMES.INC"  ' This file should be on your Turbo
  9. Basic disk.
  10.  
  11. Begin:
  12.     CLS
  13.     OPEN "Test1" FOR OUTPUT AS #1
  14.  
  15.     CALL Get.File.Date.and.Time ( 1, Year%, Month%, Date%,_
  16.                                   Hour%, Minute%, Second% )
  17.     CALL Print.Stats
  18.     CALL Set.File.Date.and.Time ( 1, 1987, 6, 30,_
  19.                                   12, 30, 55 )
  20.     CALL Get.File.Date.and.Time ( 1, Year%, Month%, Date%,_
  21.                                   Hour%, Minute%, Second% )
  22.     PRINT
  23.     CALL Print.Stats
  24.  
  25.     CLOSE
  26.     KILL "Test1"
  27. END
  28.  
  29.  
  30. ZDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD?
  31. 3                                                               3
  32. 3  FNFileHandleAddress% :                                       3
  33. 3                                                               3
  34. 3  Returns a file handle based upon the number of the file      3
  35. 3  passed into the function. The function searches through Turbo3
  36. 3  Basic's linked list of file handles for the corresponding    3
  37. 3  file number passed in the function. You will know which file 3
  38. 3  number to pass in through the syntax of the OPEN statement   3
  39. 3  that you used on the file. See the program FILEEX.BAS for an 3
  40. 3  example of how to use this function along with DOS function  3
  41. 3  call 87 ( 57 hex ).                                          3
  42. 3                                                               3
  43. 3       Turbo Basic's linked list of file handles is stored in  3
  44. 3  the string data segment area.  Two bytes at offsets 6 & 7    3
  45. 3  are a pointer to the first node of the linked list.  Each    3
  46. 3  node in the linked list has the following format:            3
  47. 3                                                               3
  48. 3                                                               3
  49. 3      DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD                           3
  50. 3      | Pointer to next node       |    2 Bytes                3
  51. 3      DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD                           3
  52. 3      | Pointer to previous node   |    "   "                  3
  53. 3      DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD                           3
  54. 3      | File Number                |    "   "                  3
  55. 3      DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD                           3
  56. 3      | DOS File Handle            |    "   "                  3
  57. 3      DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD                           3
  58. 3                                                               3
  59. 3  Please keep in mind that the information is stored in        3
  60. 3  byte-reverse notation.  This was written on 6/4/87 for       3
  61. 3  Turbo Basic 1.00.                                            3
  62. 3                                                               3
  63. @DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDY
  64. DEF FNFileHandleAddress%(FileNumber%)
  65. LOCAL Segment%,Ofs%,Done%
  66.   DEF SEG
  67.   Segment% = PEEK(0) + (256 * PEEK(1))   ' Get the string
  68. segment.
  69.   DEF SEG  = Segment%
  70.   Ofs%     = PEEK(6) + (256 * PEEK(7))   ' Peek at the first file
  71.     number.
  72.   Done%    = 1
  73.   WHILE Done% = 1
  74.     IF (PEEK(Ofs%+4) + (256 * PEEK(Ofs%+5))) = FileNumber% THEN
  75.       FNFileHandleAddress% = PEEK(Ofs%+6) + (256 * PEEK(Ofs%+7))
  76.       Done% = 0
  77.     ELSEIF (PEEK(Ofs%) + (256 * PEEK(Ofs%+1))) = 0 THEN
  78.       FNFileHandleAddress% = 0                ' File number not
  79. found.
  80.       Done% = 0
  81.     ELSE
  82.       Ofs% = PEEK(Ofs%) + (256 * PEEK(Ofs%+1))   ' Traverse the
  83.      linked list.
  84.     END IF
  85.   WEND
  86. END DEF
  87.  
  88.  
  89. ZDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD?
  90. 3                                                               3
  91. 3  Get.File.Date.and.Time                                       3
  92. 3                                                               3
  93. 3  Uses DOS Function call 87 ( hex 57 ) to retrieve             3
  94. 3  a file's time and date statistics.  To accomplish this,      3
  95. 3  the file handle must be first retrieved from Turbo Basic's   3
  96. 3  linked list structure of file handles.  If the file handle   3
  97. 3  is present in the linked list, the statistics concerning it  3
  98. 3  are returned.  If not, all variables passed to the procedure 3
  99. 3  Get.File.Date.and.Time are set to zero.                      3
  100. 3                                                               3
  101. 3  Written on 6/4/87 for Turbo Basic version 1.00.              3
  102. 3                                                               3
  103. @DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDY
  104. SUB Get.File.Date.and.Time ( FileNumber%, Year%, Month%, Date%,_
  105.                              Hour%, Minute%, Second% )
  106.  
  107.     FH% = FNFileHandleAddress% ( FileNumber% )  ' Get the File
  108. Handle.
  109.     IF ( FH% ) THEN
  110.         REG %AX,&H5700 ' DOS Function Call 87 -- see p.319
  111.         REG %BX,FH%    ' of Peter Norton's Programmer's Guide to
  112.                ' the IBM PC.
  113.         REG %DX,0
  114.         REG %CX,0
  115.         CALL INTERRUPT &H21
  116.  
  117.         Year% = 1980 + FNShr% ( REG (%DX), 9 )
  118.         Month% =  ( REG(%DX) AND &HLE0 ) \ 32
  119.         Date% =  REG(%DX) AND &HLF
  120.         Weekday% =  REG(%DX) AND &H1F
  121.         Hour% =  FNShr% ( REG(%CX), 11 )
  122.         Minute% =  FNShr% ( REG(%CX), 5 ) AND &H3F
  123.         Second% =  FNShl% ( ( REG(%CX) AND &HLF ) , 1 )
  124.     ELSE
  125.         Year% = 0       ' If the File Handle was not found,
  126.         Month% = 0      ' set all variables to zero.
  127.         Date% = 0
  128.         Weekday% = 0
  129.         Hour% = 0
  130.         Minute% = 0
  131.         Second% = 0
  132.     END IF
  133.  
  134. END SUB
  135.  
  136.  
  137. SUB Set.File.Date.and.Time ( FileNumber%, Year%, Month%, Date%,_
  138.                              Hour%, Minute%, Second% )
  139.  
  140.     FH% = FNFileHandleAddress% ( FileNumber% )  ' Get the File
  141. Handle.
  142.     IF ( FH% ) THEN
  143.         REG %AX,&H5701
  144.         REG %BX,FH%
  145.         REG %DX, (Year% - 1980%) * 512% + Month% * 32% + Date%
  146.         REG %CX, FNShl% ( Hour%, 11 )
  147.         REG %CX, REG(%CX) + FNShl% ( Minute%, 5 )
  148.         REG %CX, REG(%CX) + ( Second% \ 2 )
  149.         CALL INTERRUPT &H21
  150.     ELSE
  151.         PRINT "File number: ";FileNumber%;" associated handle not
  152.     found."
  153.     END IF
  154.  
  155. END SUB
  156.  
  157.  
  158. SUB Print.Stats
  159.   SHARED Year%, Month%, Date%, Hour%, Minute%, Second%
  160.     PRINT "Year = "; Year%
  161.     PRINT "Month = "; Month%
  162.     PRINT "Day = "; Date%
  163.     PRINT "Hour = ";  Hour%
  164.     PRINT "Minute = "; Minute%
  165.     PRINT "Seconds = "; Second%
  166. END SUB
  167.  
  168.  
  169. DEF FNHi% ( AnyInt% )
  170.     FNHi% = AnyInt% AND &HFF00
  171. END DEF
  172.  
  173. DEF FNLow% ( AnyInt% )
  174.     FNLow% = AnyInt% AND &H00FF
  175. END DEF
  176.  
  177. DEF FNShl% ( AnyInt%, Bits% )
  178.     FNShl% = AnyInt% * ( 2% ^ Bits% )
  179. END DEF
  180.  
  181. DEF FNShr% ( AnyInt%, Bits% )
  182.     FNShr% = AnyInt% \ ( 2% ^ Bits% )
  183. END DEF
  184.