dos.inc 6.4 KB

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