dos.inc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2004 by Tomas Hajny,
  4. member of the Free Pascal development team.
  5. Common implementations of functions for unit Dos
  6. (including dummy implementation of some functions for platforms
  7. missing real implementation).
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************}
  14. (* Everywhere the same now, but prepared for potential difference. *)
  15. const
  16. ExtensionSeparator = '.';
  17. {$IFNDEF HAS_DOSEXITCODE}
  18. threadvar
  19. LastDosExitCode: longint;
  20. function DosExitCode: word;
  21. begin
  22. if LastDosExitCode > high (word) then
  23. DosExitCode := high (word)
  24. else
  25. DosExitCode := LastDosExitCode and $FFFF;
  26. end;
  27. {$ENDIF HAS_DOSEXITCODE}
  28. {$IFNDEF HAS_GETMSCOUNT}
  29. {$WARNING Real GetMsCount implementation missing, dummy version used}
  30. {Dummy implementation of GetMsCount for platforms missing anything better.}
  31. function GetMsCount: int64;
  32. var
  33. Y, Mo, D, WD, H, Mi, S, S100: word;
  34. const
  35. DayTable: array[Boolean, 1..12] of longint =
  36. ((0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334),
  37. (0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335));
  38. function Leap: boolean;
  39. begin
  40. if (Y mod 400) = 0 then
  41. Leap := true
  42. else
  43. if ((Y mod 100) = 0) or ((Y mod 4) <> 0) then
  44. Leap := false
  45. else
  46. Leap := true;
  47. end;
  48. begin
  49. GetDate (Y, Mo, D, WD);
  50. GetTime (H, Mi, S, S100);
  51. GetMsCount := S100 * 10 + S * 1000 + cardinal (Mi) * 60*1000
  52. + int64 (H) * 60*60*1000
  53. + int64 (D + DayTable [Leap, Mo]
  54. + (Y div 400) * 97 + ((Y mod 400) div 100) * 24 + (Y mod 100) div 4)
  55. * 24*60*60*1000
  56. + int64 (Y) * 365*24*60*60*1000;
  57. end;
  58. {$ENDIF HAS_GETMSCOUNT}
  59. {$IFNDEF HAS_GETCBREAK}
  60. procedure GetCBreak (var BreakValue: boolean);
  61. begin
  62. BreakValue := true;
  63. end;
  64. {$ENDIF HAS_GETCBREAK}
  65. {$IFNDEF HAS_SETCBREAK}
  66. procedure SetCBreak (BreakValue: boolean);
  67. begin
  68. end;
  69. {$ENDIF HAS_SETCBREAK}
  70. {$IFNDEF HAS_GETVERIFY}
  71. var
  72. VerifyValue: boolean;
  73. procedure GetVerify (var Verify: boolean);
  74. begin
  75. Verify := VerifyValue;
  76. end;
  77. {$ENDIF HAS_GETVERIFY}
  78. {$IFNDEF HAS_SETVERIFY}
  79. {$IFDEF HAS_GETVERIFY}
  80. var
  81. VerifyValue: boolean;
  82. {$ENDIF HAS_GETVERIFY}
  83. procedure SetVerify (Verify: boolean);
  84. begin
  85. VerifyValue := Verify;
  86. end;
  87. {$ENDIF HAS_SETVERIFY}
  88. {$IFDEF CPUI386}
  89. {$IFNDEF HAS_INTR}
  90. procedure Intr (IntNo: byte; var Regs: Registers);
  91. begin
  92. end;
  93. {$ENDIF HAS_INTR}
  94. {$IFNDEF HAS_MSDOS}
  95. procedure MSDos (var Regs: Registers);
  96. begin
  97. Intr ($21, Regs);
  98. end;
  99. {$ENDIF HAS_MSDOS}
  100. {$ENDIF CPUI386}
  101. {$IFNDEF HAS_SWAPVECTORS}
  102. procedure SwapVectors;
  103. begin
  104. end;
  105. {$ENDIF HAS_SWAPVECTORS}
  106. {$IFNDEF HAS_GETINTVEC}
  107. procedure GetIntVec (IntNo: byte; var Vector: pointer);
  108. begin
  109. Vector := nil;
  110. end;
  111. {$ENDIF HAS_GETINTVEC}
  112. {$IFNDEF HAS_SETINTVEC}
  113. procedure SetIntVec (IntNo: byte; Vector: pointer);
  114. begin
  115. end;
  116. {$ENDIF HAS_SETINTVEC}
  117. {$IFNDEF HAS_KEEP}
  118. procedure Keep (ExitCode: word);
  119. begin
  120. end;
  121. {$ENDIF HAS_KEEP}
  122. {$IFNDEF HAS_GETSHORTNAME}
  123. function GetShortName (var P: String): boolean;
  124. begin
  125. GetShortName := true;
  126. end;
  127. {$ENDIF HAS_GETSHORTNAME}
  128. {$IFNDEF HAS_GETLONGNAME}
  129. function GetLongName (var P: String): boolean;
  130. begin
  131. GetLongName := true;
  132. end;
  133. {$ENDIF HAS_GETLONGNAME}
  134. {PackTime is platform independent}
  135. procedure PackTime (var T: DateTime; var P: longint);
  136. var zs:longint;
  137. begin
  138. p:=-1980;
  139. p:=p+t.year and 127;
  140. p:=p shl 4;
  141. p:=p+t.month;
  142. p:=p shl 5;
  143. p:=p+t.day;
  144. p:=p shl 16;
  145. zs:=t.hour;
  146. zs:=zs shl 6;
  147. zs:=zs+t.min;
  148. zs:=zs shl 5;
  149. zs:=zs+t.sec div 2;
  150. p:=p+(zs and $ffff);
  151. end;
  152. {UnpackTime is platform-independent}
  153. procedure UnpackTime (P: longint; var T: DateTime);
  154. begin
  155. t.sec:=(p and 31) * 2;
  156. p:=p shr 5;
  157. t.min:=p and 63;
  158. p:=p shr 6;
  159. t.hour:=p and 31;
  160. p:=p shr 5;
  161. t.day:=p and 31;
  162. p:=p shr 5;
  163. t.month:=p and 15;
  164. p:=p shr 4;
  165. t.year:=p+1980;
  166. end;
  167. {****************************************************************************
  168. A platform independent implementation of FSplit
  169. ****************************************************************************}
  170. {$IFNDEF HAS_FSPLIT}
  171. {$warnings off}
  172. Procedure FSplit (Path: PathStr; var Dir: DirStr; var Name: NameStr; var Ext: ExtStr);
  173. var
  174. DirEnd, ExtStart: Longint;
  175. begin
  176. if DirectorySeparator = '/' then
  177. { allow backslash as slash }
  178. for DirEnd := 1 to Length (Path) do
  179. begin
  180. if Path [DirEnd] = '\' then Path [DirEnd] := DirectorySeparator
  181. end
  182. else
  183. if DirectorySeparator = '\' then
  184. { allow slash as backslash }
  185. for DirEnd := 1 to Length (Path) do
  186. if Path [DirEnd] = '/' then Path [DirEnd] := DirectorySeparator;
  187. { Find the first DirectorySeparator or DriveSeparator from the end. }
  188. DirEnd := Length (Path);
  189. { Avoid problems with platforms having DriveSeparator = DirectorySeparator. }
  190. if DirectorySeparator = DriveSeparator then
  191. while (DirEnd > 0) and (Path [DirEnd] <> DirectorySeparator) do
  192. Dec (DirEnd)
  193. else
  194. while (DirEnd > 0) and
  195. (Path [DirEnd] <> DirectorySeparator) and
  196. (Path [DirEnd] <> DriveSeparator) do
  197. Dec (DirEnd);
  198. { The first "extension" should be returned if LFN }
  199. { support not available, the last one otherwise. }
  200. if LFNSupport then
  201. begin
  202. ExtStart := Length (Path);
  203. while (ExtStart > DirEnd) and (Path [ExtStart] <> ExtensionSeparator) do
  204. Dec (ExtStart);
  205. if ExtStart = 0 then
  206. ExtStart := Length (Path) + 1
  207. else
  208. if Path [ExtStart] <> ExtensionSeparator then
  209. ExtStart := Length (Path) + 1;
  210. end
  211. else
  212. begin
  213. ExtStart := DirEnd + 1;
  214. while (ExtStart <= Length (Path)) and (Path [ExtStart] <> ExtensionSeparator) do
  215. Inc (ExtStart);
  216. end;
  217. Dir := Copy (Path, 1, DirEnd);
  218. Name := Copy (Path, DirEnd + 1, ExtStart - DirEnd - 1);
  219. Ext := Copy (Path, ExtStart, Length (Path) - ExtStart + 1);
  220. end;
  221. {$warnings on}
  222. {$ENDIF HAS_FSPLIT}
  223. {****************************************************************************
  224. A platform independent implementation of FExpand
  225. ****************************************************************************}
  226. {$IFNDEF HAS_FEXPAND}
  227. (* FExpand maintained in standalone include file for easier maintenance. *)
  228. {$I fexpand.inc}
  229. {$ENDIF HAS_FEXPAND}