dos.inc 6.3 KB

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