sysdir.inc 3.2 KB

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