2
0

dos.inc 6.6 KB

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