home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1995 December / SOFM_Dec1995.bin / pc / os2 / vpascal / source / rtl / dos.inc < prev    next >
Text File  |  1995-10-31  |  8KB  |  239 lines

  1. {█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█}
  2. {█                                                       █}
  3. {█      Virtual Pascal Runtime Library.  Version 1.0.    █}
  4. {█      Dos/WinDos common procedures and functions       █}
  5. {█      ─────────────────────────────────────────────────█}
  6. {█      Copyright (C) 1995 B&M&T Corporation             █}
  7. {█      ─────────────────────────────────────────────────█}
  8. {█      Written by Vitaly Miryanov                       █}
  9. {█                                                       █}
  10. {▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀}
  11.  
  12. { Returns the OS/2 version number. The low byte of the result is the    }
  13. { major version number, and the high byte is the minor version number.  }
  14. { For example, OS/2 2.10 returns $0A14, i.e. 20 in the low byte, and 10 }
  15. { in the high byte.                                                     }
  16.  
  17. function DosVersion: Word;
  18. var
  19.   Version: array [0..1] of Longint;
  20. begin
  21.   DosQuerySysInfo(qsv_Version_Major,qsv_Version_Minor,Version,SizeOf(Version));
  22.   DosVersion := Version[0] + Version[1] shl 8;
  23. end;
  24.  
  25. { Returns the current date set in the operating system. Ranges of the   }
  26. { values returned are: Year 1980-2099, Month 1-12, Day 1-31 and         }
  27. { DayOfWeek 0-6 (0 corresponds to Sunday).                              }
  28.  
  29. procedure GetDate(var Year,Month,Day,DayOfWeek: Word);
  30. var
  31.   DT: Os2Base.DateTime;
  32. begin
  33.   DosGetDateTime(DT);
  34.   Year      := DT.Year;
  35.   Month     := DT.Month;
  36.   Day       := DT.Day;
  37.   DayOfWeek := DT.WeekDay;
  38. end;
  39.  
  40. { Sets the current date set in the operating system. Valid parameter    }
  41. { ranges are: Year 1980-2099, Month 1-12 and Day 1-31. If the date is   }
  42. { not valid, the function call is ignored.                              }
  43.  
  44. procedure SetDate(Year,Month,Day: Word);
  45. var
  46.   DT: Os2Base.DateTime;
  47. begin
  48.   DosGetDateTime(DT);
  49.   DT.Year    := Year;
  50.   DT.Month   := Month;
  51.   DT.Day     := Day;
  52.   DosSetDateTime(DT);
  53. end;
  54.  
  55. { Returns the current time set in the operating system. Ranges of the   }
  56. { values returned are: Hour 0-23, Minute 0-59, Second 0-59 and Sec100   }
  57. { (hundredths of seconds) 0-99.                                         }
  58.  
  59. procedure GetTime(var Hour,Minute,Second,Sec100: Word);
  60. var
  61.   DT: Os2Base.DateTime;
  62. begin
  63.   DosGetDateTime(DT);
  64.   Hour   := DT.Hours;
  65.   Minute := DT.Minutes;
  66.   Second := DT.Seconds;
  67.   Sec100 := DT.Hundredths;
  68. end;
  69.  
  70. { Sets the time in the operating system. Valid parameter ranges are:    }
  71. { Hour 0-23, Minute 0-59, Second 0-59 and Sec100 (hundredths of seconds)}
  72. { 0-99. If the time is not valid, the function call is ignored.         }
  73.  
  74. procedure SetTime(Hour,Minute,Second,Sec100: Word);
  75. var
  76.   DT: Os2Base.DateTime;
  77. begin
  78.   DosGetDateTime(DT);
  79.   DT.Hours      := Hour;
  80.   DT.Minutes    := Minute;
  81.   DT.Seconds    := Second;
  82.   DT.Hundredths := Sec100;
  83.   DosSetDateTime(DT);
  84. end;
  85.  
  86. { GetVerify returns the state of the verify flag in OS/2. When off      }
  87. { (False), disk writes are not verified. When on (True), all disk       }
  88. { writes are verified to insure proper writing.                         }
  89.  
  90. procedure GetVerify(var Verify: Boolean);
  91. var
  92.   Flag: Bool;
  93. begin
  94.   DosQueryVerify(Flag);
  95.   Verify := Flag;
  96. end;
  97.  
  98. { SetVerify sets the state of the verify flag in OS/2.                  }
  99.  
  100. procedure SetVerify(Verify: Boolean);
  101. begin
  102.   DosSetVerify(Verify);
  103. end;
  104.  
  105. { Returns the number of free bytes on the specified drive number        }
  106. { (0=Default,1=A,2=B,..). Returns -1 if the drive number is invalid.    }
  107.  
  108. function DiskFree(Drive: Byte): Longint;
  109. var
  110.   Info: FsAllocate;
  111. begin
  112.   if DosQueryFSInfo(Drive, fsil_Alloc, Info, SizeOf(Info)) = 0
  113.     then DiskFree := Info.cUnitAvail * Info.cSectorUnit * Info.cbSector
  114.     else DiskFree := -1;
  115. end;
  116.  
  117. { Returns the size in bytes of the specified drive number (0=Default,   }
  118. { 1=A,2=B,..). Returns -1 if the drive number is invalid.               }
  119.  
  120. function DiskSize(Drive: Byte): Longint;
  121. var
  122.   Info: FsAllocate;
  123. begin
  124.   if DosQueryFSInfo(Drive, fsil_Alloc, Info, SizeOf(Info)) = 0
  125.     then DiskSize := Info.cUnit * Info.cSectorUnit * Info.cbSector
  126.     else DiskSize := -1;
  127. end;
  128.  
  129. { Returns the attributes of a file. F must be a file variable (typed,   }
  130. { untyped or textfile) which has been assigned a name. The attributes   }
  131. { are examined by ANDing with the attribute masks defined as constants  }
  132. { above. Errors are reported in DosError.                               }
  133.  
  134. procedure GetFAttr(var F; var Attr: Word);
  135. var
  136.   Info: FileStatus3;
  137. begin
  138.   DosError := DosQueryPathInfo(FileRec(F).Name,fil_Standard,Info,SizeOf(Info));
  139.   If DosError = 0 then Attr := Info.attrFile else Attr := 0;
  140. end;
  141.  
  142. { Sets the attributes of a file. F must be a file variable (typed,      }
  143. { untyped or textfile) which has been assigned a name. The attribute    }
  144. { value is formed by adding (or ORing) the appropriate attribute masks  }
  145. { defined as constants above. Errors are reported in DosError.          }
  146.  
  147. procedure SetFAttr(var F; Attr: Word);
  148. var
  149.   Info: FileStatus3;
  150. begin
  151.   DosError := DosQueryPathInfo(FileRec(F).Name,fil_Standard,Info,SizeOf(Info));
  152.   if DosError = 0 then
  153.   begin
  154.     Info.attrFile := Attr;
  155.     DosError := DosSetPathInfo(FileRec(F).Name,fil_Standard,Info,SizeOf(Info),dspi_WrtThru);
  156.   end;
  157. end;
  158.  
  159. { Type cast record }
  160.  
  161. type
  162.   DateTimeRec = record
  163.     FTime,FDate: SmallWord;
  164.   end;
  165.  
  166. { Returns the date and time a file was last written. F must be a file   }
  167. { variable (typed, untyped or textfile) which has been assigned and     }
  168. { opened. The Time parameter may be unpacked throgh a call to           }
  169. { UnpackTime. Errors are reported in DosError.                          }
  170.  
  171. procedure GetFTime(var F; var Time: Longint);
  172. var
  173.   Info: FileStatus3;
  174.   FDateTime: DateTimeRec absolute Time;
  175. begin
  176.   DosError := DosQueryFileInfo(FileRec(F).Handle,fil_Standard,Info,SizeOf(Info));
  177.   if DosError <> 0 then Time := 0
  178.  else
  179.   with FDateTime do
  180.   begin
  181.     FTime := Info.ftimeLastWrite;
  182.     FDate := Info.fdateLastWrite;
  183.   end
  184. end;
  185.  
  186. { Sets the date and time a file was last written. F must be a file      }
  187. { variable (typed, untyped or textfile) which has been assigned and     }
  188. { opened. The Time parameter may be created through a call to PackTime. }
  189. { Errors are reported in DosError.                                      }
  190.  
  191. procedure SetFTime(var F; Time: Longint);
  192. var
  193.   Info: FileStatus3;
  194.   FDateTime: DateTimeRec absolute Time;
  195. begin
  196.   DosError := DosQueryFileInfo(FileRec(F).Handle,fil_Standard,Info,SizeOf(Info));
  197.   if DosError <> 0 then Time := 0
  198.  else
  199.   with FDateTime do
  200.   begin
  201.     Info.ftimeLastWrite := FTime;
  202.     Info.fdateLastWrite := FDate;
  203.     DosError := DosSetFileInfo(FileRec(F).Handle,fil_Standard,Info,SizeOf(Info));
  204.   end
  205. end;
  206.  
  207. { Converts a 4-byte packed date/time returned by FindFirst, FindNext or }
  208. { GetFTime into a DateTime record.                                      }
  209.  
  210. procedure UnpackTime(P: Longint; var T: DateTime);
  211. var
  212.   FDateTime: DateTimeRec absolute P;
  213. begin
  214.   with T,FDateTime do
  215.   begin
  216.     Year  :=  (FDate and mfdYear   ) shr sfdYear + 1980;
  217.     Month :=  (FDate and mfdMonth  ) shr sfdMonth;
  218.     Day   :=  (FDate and mfdDay    ) shr sfdDay;
  219.     Hour  :=  (FTime and mftHours  ) shr sftHours;
  220.     Min   :=  (FTime and mftMinutes) shr sftMinutes;
  221.     Sec   := ((FTime and mftTwoSecs) shr sftTwoSecs) * 2;
  222.   end;
  223. end;
  224.  
  225. { Converts a DateTime record into a 4-byte packed date/time used by     }
  226. { SetFTime.                                                             }
  227.  
  228. procedure PackTime(var T: DateTime; var P: Longint);
  229. var
  230.   FDateTime: DateTimeRec absolute P;
  231. begin
  232.   with T,FDateTime do
  233.   begin
  234.     FDate := (Year - 1980) shl sfdYear + Month shl sfdMonth + Day shl sfdDay;
  235.     FTime := Hour shl sftHours + Min shl sftMinutes + (Sec div 2) shl sftTwoSecs;
  236.   end;
  237. end;
  238.  
  239.