sysdir.inc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 Amiga.
  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;const s:string);
  16. var
  17. buffer : array[0..255] of char;
  18. c : word;
  19. begin
  20. move(s[1],buffer,length(s));
  21. buffer[length(s)]:=#0;
  22. DoDirSeparators(pchar(@buffer));
  23. c:=word(func);
  24. asm
  25. move.l d2,d6 { save d2 }
  26. movem.l d3/a2/a3,-(sp)
  27. pea buffer
  28. move.w c,-(sp)
  29. trap #1
  30. add.l #6,sp
  31. move.l d6,d2 { restore d2 }
  32. movem.l (sp)+,d3/a2/a3
  33. tst.w d0
  34. beq @dosdirend
  35. move.w d0,errno
  36. @dosdirend:
  37. end;
  38. if errno <> 0 then
  39. Error2InOut;
  40. end;
  41. procedure mkdir(const s : string);[IOCheck];
  42. begin
  43. If InOutRes <> 0 then exit;
  44. DosDir($39,s);
  45. end;
  46. procedure rmdir(const s : string);[IOCheck];
  47. begin
  48. If InOutRes <> 0 then exit;
  49. DosDir($3a,s);
  50. end;
  51. procedure chdir(const s : string);[IOCheck];
  52. begin
  53. If InOutRes <> 0 then exit;
  54. DosDir($3b,s);
  55. end;
  56. function GetDirIO (DriveNr: byte; var Dir: ShortString): word;
  57. [public, alias: 'FPC_GETDIRIO'];
  58. var
  59. temp : array[0..255] of char;
  60. i : longint;
  61. j: byte;
  62. drv: word;
  63. begin
  64. GetDirIO := 0;
  65. drv:=word(drivenr);
  66. asm
  67. move.l d2,d6 { save d2 }
  68. movem.l d3/a2/a3,-(sp)
  69. { Get dir from drivenr : 0=default, 1=A etc... }
  70. move.w drv,-(sp)
  71. { put (previously saved) offset in si }
  72. { move.l temp,-(sp)}
  73. pea temp
  74. { call attos function 47H : Get dir }
  75. move.w #$47,-(sp)
  76. { make the call }
  77. trap #1
  78. add.l #8,sp
  79. move.l d6,d2 { restore d2 }
  80. movem.l (sp)+,d3/a2/a3
  81. end;
  82. { conversion to pascal string }
  83. i:=0;
  84. while (temp[i]<>#0) do
  85. begin
  86. if temp[i] in AllowDirectorySeparators then
  87. temp[i]:=DirectorySeparator;
  88. dir[i+3]:=temp[i];
  89. inc(i);
  90. end;
  91. dir[2]:=':';
  92. dir[3]:='\';
  93. dir[0]:=char(i+2);
  94. { upcase the string (FPC Pascal function) }
  95. dir:=upcase(dir);
  96. if drivenr<>0 then { Drive was supplied. We know it }
  97. dir[1]:=chr(65+drivenr-1)
  98. else
  99. begin
  100. asm
  101. move.l d2,d6 { save d2 }
  102. movem.l d3/a2/a3,-(sp)
  103. move.w #$19,-(sp)
  104. trap #1
  105. add.l #2,sp
  106. move.w d0,drv
  107. move.l d6,d2 { restore d2 }
  108. movem.l (sp)+,d3/a2/a3
  109. end;
  110. dir[1]:=chr(byte(drv)+ord('A'));
  111. end;
  112. end;
  113. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  114. begin
  115. end;
  116. procedure do_mkdir(const s : rawbytestring);
  117. var
  118. tmpStr : rawbytestring;
  119. tmpLock: LongInt;
  120. begin
  121. checkCTRLC;
  122. tmpStr:=PathConv(s);
  123. tmpLock:=dosCreateDir(pchar(tmpStr));
  124. if tmpLock=0 then begin
  125. dosError2InOut(IoErr);
  126. exit;
  127. end;
  128. UnLock(tmpLock);
  129. end;
  130. procedure do_rmdir(const s : rawbytestring);
  131. var
  132. tmpStr : rawbytestring;
  133. begin
  134. checkCTRLC;
  135. if (s='.') then
  136. begin
  137. InOutRes:=16;
  138. exit;
  139. end;
  140. tmpStr:=PathConv(s);
  141. if not dosDeleteFile(pchar(tmpStr)) then
  142. dosError2InOut(IoErr);
  143. end;
  144. procedure do_ChDir(const s: rawbytestring);
  145. var
  146. tmpStr : rawbytestring;
  147. tmpLock: LongInt;
  148. FIB : PFileInfoBlock;
  149. begin
  150. checkCTRLC;
  151. tmpStr:=PathConv(s);
  152. tmpLock:=0;
  153. { Changing the directory is a pretty complicated affair }
  154. { 1) Obtain a lock on the directory }
  155. { 2) CurrentDir the lock }
  156. tmpLock:=Lock(pchar(tmpStr),SHARED_LOCK);
  157. if tmpLock=0 then begin
  158. dosError2InOut(IoErr);
  159. exit;
  160. end;
  161. FIB:=nil;
  162. new(FIB);
  163. if (Examine(tmpLock,FIB)=True) and (FIB^.fib_DirEntryType>0) then begin
  164. tmpLock:=CurrentDir(tmpLock);
  165. if AOS_OrigDir=0 then begin
  166. AOS_OrigDir:=tmpLock;
  167. tmpLock:=0;
  168. end;
  169. end;
  170. if tmpLock<>0 then Unlock(tmpLock);
  171. if assigned(FIB) then dispose(FIB);
  172. end;
  173. procedure do_GetDir (DriveNr: byte; var Dir: RawByteString);
  174. var tmpbuf: array[0..255] of char;
  175. begin
  176. checkCTRLC;
  177. Dir:='';
  178. if not GetCurrentDirName(tmpbuf,256) then
  179. dosError2InOut(IoErr)
  180. else
  181. begin
  182. Dir:=tmpbuf;
  183. SetCodePage(Dir,DefaultFileSystemCodePage,false);
  184. end;
  185. end;