sysdir.inc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Florian Klaempfl and Pavel Ozerski
  4. member of the Free Pascal development team.
  5. FPC Pascal system unit for the Win32 API.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {*****************************************************************************
  13. Directory Handling
  14. *****************************************************************************}
  15. procedure DosDir(func:byte;s: rawbytestring);
  16. var
  17. regs : Registers;
  18. len : Integer;
  19. begin
  20. DoDirSeparators(s);
  21. { True DOS does not like backslashes at end
  22. Win95 DOS accepts this !!
  23. but "\" and "c:\" should still be kept and accepted hopefully PM }
  24. len:=length(s);
  25. if (len>0) and (s[len]='\') and
  26. Not ((len=1) or ((len=3) and (s[2]=':'))) then
  27. s[len]:=#0;
  28. regs.DX:=Ofs(s[1]);
  29. regs.DS:=Seg(s[1]);
  30. if LFNSupport then
  31. regs.AX:=$7100+func
  32. else
  33. regs.AX:=func shl 8;
  34. MsDos(regs);
  35. if (regs.Flags and fCarry) <> 0 then
  36. GetInOutRes(regs.AX);
  37. end;
  38. Procedure do_MkDir(const s: rawbytestring);
  39. begin
  40. DosDir($39,s);
  41. end;
  42. Procedure do_RmDir(const s: rawbytestring);
  43. begin
  44. if s='.' then
  45. begin
  46. InOutRes:=16;
  47. exit;
  48. end;
  49. DosDir($3a,s);
  50. end;
  51. Procedure do_ChDir(const s: rawbytestring);
  52. var
  53. regs : Registers;
  54. len : Integer;
  55. begin
  56. len:=Length(s);
  57. { First handle Drive changes }
  58. if (len>=2) and (s[2]=':') then
  59. begin
  60. regs.DX:=(ord(s[1]) and (not 32))-ord('A');
  61. regs.AX:=$0e00;
  62. MsDos(regs);
  63. regs.AX:=$1900;
  64. MsDos(regs);
  65. if regs.AL<>regs.DL then
  66. begin
  67. Inoutres:=15;
  68. exit;
  69. end;
  70. { DosDir($3b,'c:') give Path not found error on
  71. pure DOS PM }
  72. if len=2 then
  73. exit;
  74. end;
  75. { do the normal dos chdir }
  76. DosDir($3b,s);
  77. end;
  78. procedure do_GetDir (DriveNr: byte; var Dir: RawByteString);
  79. var
  80. temp : array[0..260] of char;
  81. i : integer;
  82. regs : Registers;
  83. begin
  84. regs.DX:=drivenr;
  85. regs.SI:=Ofs(temp);
  86. regs.DS:=Seg(temp);
  87. if LFNSupport then
  88. regs.AX:=$7147
  89. else
  90. regs.AX:=$4700;
  91. MsDos(regs);
  92. if (regs.Flags and fCarry) <> 0 then
  93. Begin
  94. GetInOutRes (regs.AX);
  95. Dir := char (DriveNr + 64) + ':\';
  96. SetCodePage (Dir,DefaultFileSystemCodePage,false);
  97. exit;
  98. end
  99. else
  100. temp[252] := #0; { to avoid shortstring buffer overflow }
  101. { conversion to Pascal string including slash conversion }
  102. i:=0;
  103. SetLength(dir,260);
  104. while (temp[i]<>#0) do
  105. begin
  106. if temp[i] in AllowDirectorySeparators then
  107. temp[i]:=DirectorySeparator;
  108. dir[i+4]:=temp[i];
  109. inc(i);
  110. end;
  111. dir[2]:=':';
  112. dir[3]:='\';
  113. SetLength(dir,i+3);
  114. SetCodePage (dir,DefaultFileSystemCodePage,false);
  115. { upcase the string }
  116. if not FileNameCasePreserving then
  117. dir:=upcase(dir);
  118. if drivenr<>0 then { Drive was supplied. We know it }
  119. dir[1]:=char(65+drivenr-1)
  120. else
  121. begin
  122. { We need to get the current drive from DOS function 19H }
  123. { because the drive was the default, which can be unknown }
  124. regs.AX:=$1900;
  125. MsDos(regs);
  126. i:= (regs.AX and $ff) + ord('A');
  127. dir[1]:=chr(i);
  128. end;
  129. end;