dos.inc 6.8 KB

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