sysdir.inc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. {*****************************************************************************
  2. Directory Handling
  3. *****************************************************************************}
  4. procedure DosDir(func:byte;s:rawbytestring);
  5. var
  6. buffer : array[0..255] of char;
  7. regs : trealregs;
  8. begin
  9. DoDirSeparators(s);
  10. if length(s)>255 then
  11. begin
  12. inoutres:=3;
  13. exit;
  14. end;
  15. move(s[1],buffer,length(s));
  16. buffer[length(s)]:=#0;
  17. { True DOS does not like backslashes at end
  18. Win95 DOS accepts this !!
  19. but "\" and "c:\" should still be kept and accepted hopefully PM }
  20. if (length(s)>0) and (buffer[length(s)-1]='\') and
  21. Not ((length(s)=1) or ((length(s)=3) and (s[2]=':'))) then
  22. buffer[length(s)-1]:=#0;
  23. syscopytodos(longint(@buffer),length(s)+1);
  24. regs.realedx:=tb_offset;
  25. regs.realds:=tb_segment;
  26. if LFNSupport then
  27. regs.realeax:=$7100+func
  28. else
  29. regs.realeax:=func shl 8;
  30. sysrealintr($21,regs);
  31. if (regs.realflags and carryflag) <> 0 then
  32. GetInOutRes(lo(regs.realeax));
  33. end;
  34. procedure do_mkdir(const s : rawbytestring);
  35. begin
  36. DosDir($39,s);
  37. end;
  38. procedure do_rmdir(const s : rawbytestring);
  39. begin
  40. if s = '.' then
  41. begin
  42. InOutRes := 16;
  43. exit;
  44. end;
  45. DosDir($3a,s);
  46. end;
  47. procedure do_chdir(const s : rawbytestring);
  48. var
  49. regs : trealregs;
  50. begin
  51. { First handle Drive changes }
  52. if (length(s)>=2) and (s[2]=':') then
  53. begin
  54. regs.realedx:=(ord(s[1]) and (not 32))-ord('A');
  55. regs.realeax:=$0e00;
  56. sysrealintr($21,regs);
  57. regs.realeax:=$1900;
  58. sysrealintr($21,regs);
  59. if byte(regs.realeax)<>byte(regs.realedx) then
  60. begin
  61. Inoutres:=15;
  62. exit;
  63. end;
  64. { DosDir($3b,'c:') give Path not found error on
  65. pure DOS PM }
  66. if length(s)=2 then
  67. exit;
  68. end;
  69. { do the normal dos chdir }
  70. DosDir($3b,s);
  71. end;
  72. procedure do_getdir(drivenr : byte;var dir : RawByteString);
  73. var
  74. temp : array[0..255] of char;
  75. i : longint;
  76. regs : trealregs;
  77. begin
  78. regs.realedx:=drivenr;
  79. regs.realesi:=tb_offset;
  80. regs.realds:=tb_segment;
  81. if LFNSupport then
  82. regs.realeax:=$7147
  83. else
  84. regs.realeax:=$4700;
  85. sysrealintr($21,regs);
  86. if (regs.realflags and carryflag) <> 0 then
  87. Begin
  88. GetInOutRes(lo(regs.realeax));
  89. Dir := char (DriveNr + 64) + ':\';
  90. SetCodePage(dir,DefaultFileSystemCodePage,false);
  91. exit;
  92. end
  93. else
  94. syscopyfromdos(longint(@temp),251);
  95. { conversion to Pascal string including slash conversion }
  96. i:=0;
  97. SetLength(Dir,255);
  98. while (temp[i]<>#0) do
  99. begin
  100. if temp[i] in AllowDirectorySeparators then
  101. temp[i]:=DirectorySeparator;
  102. dir[i+4]:=temp[i];
  103. inc(i);
  104. end;
  105. dir[2]:=':';
  106. dir[3]:='\';
  107. SetLength(Dir,i+3);
  108. SetCodePage(dir,DefaultFileSystemCodePage,false);
  109. { upcase the string }
  110. if not FileNameCasePreserving then
  111. dir:=upcase(dir);
  112. if drivenr<>0 then { Drive was supplied. We know it }
  113. dir[1]:=char(65+drivenr-1)
  114. else
  115. begin
  116. { We need to get the current drive from DOS function 19H }
  117. { because the drive was the default, which can be unknown }
  118. regs.realeax:=$1900;
  119. sysrealintr($21,regs);
  120. i:= (regs.realeax and $ff) + ord('A');
  121. dir[1]:=chr(i);
  122. end;
  123. end;