dos.inc 6.9 KB

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