delp.pp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. {
  2. $Id$
  3. Copyright (c) 1999 by Peter Vreman
  4. Deletes all files generated for Pascal (*.exe,units,objects,libs)
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************}
  17. program Delp;
  18. uses
  19. dos;
  20. const
  21. version='v1.00';
  22. function DStr(l:longint):string;
  23. var
  24. TmpStr : string[32];
  25. i : byte;
  26. begin
  27. Str(l,tmpstr);
  28. i:=Length(TmpStr);
  29. while (i>3) do
  30. begin
  31. i:=i-3;
  32. if TmpStr[i]<>'-' then
  33. Insert('.',TmpStr,i+1);
  34. end;
  35. DStr:=TmpStr;
  36. end;
  37. Procedure EraseFile(Const HStr:String);
  38. var
  39. f : file;
  40. i : word;
  41. begin
  42. Assign(f,Hstr);
  43. {$I-}
  44. Erase(f);
  45. {$I+}
  46. i:=ioresult;
  47. end;
  48. function MatchesMask(What, Mask: string): boolean;
  49. function upper(const s : string) : string;
  50. var
  51. i : longint;
  52. begin
  53. for i:=1 to length(s) do
  54. if s[i] in ['a'..'z'] then
  55. upper[i]:=char(byte(s[i])-32)
  56. else
  57. upper[i]:=s[i];
  58. upper[0]:=s[0];
  59. end;
  60. Function CmpStr(const hstr1,hstr2:string):boolean;
  61. var
  62. found : boolean;
  63. i1,i2 : longint;
  64. begin
  65. i1:=0;
  66. i2:=0;
  67. found:=true;
  68. while found and (i1<length(hstr1)) and (i2<=length(hstr2)) do
  69. begin
  70. if found then
  71. inc(i2);
  72. inc(i1);
  73. case hstr1[i1] of
  74. '?' :
  75. found:=true;
  76. '*' :
  77. begin
  78. found:=true;
  79. if (i1=length(hstr1)) then
  80. i2:=length(hstr2)
  81. else
  82. if (i1<length(hstr1)) and (hstr1[i1+1]<>hstr2[i2]) then
  83. begin
  84. if i2<length(hstr2) then
  85. dec(i1)
  86. end
  87. else
  88. if i2>1 then
  89. dec(i2);
  90. end;
  91. else
  92. found:=(hstr1[i1]=hstr2[i2]) or (hstr2[i2]='?');
  93. end;
  94. end;
  95. if found then
  96. found:=(i1>=length(hstr1)) and (i2>=length(hstr2));
  97. CmpStr:=found;
  98. end;
  99. var
  100. D1,D2 : DirStr;
  101. N1,N2 : NameStr;
  102. E1,E2 : Extstr;
  103. begin
  104. {$ifdef linux}
  105. FSplit(What,D1,N1,E1);
  106. FSplit(Mask,D2,N2,E2);
  107. {$else}
  108. FSplit(Upper(What),D1,N1,E1);
  109. FSplit(Upper(Mask),D2,N2,E2);
  110. {$endif}
  111. MatchesMask:=CmpStr(N2,N1) and CmpStr(E2,E1);
  112. end;
  113. type
  114. PMaskItem=^TMaskItem;
  115. TMaskItem=record
  116. Mask : string[15];
  117. Files : longint;
  118. Size : longint;
  119. Next : PMaskItem;
  120. end;
  121. var
  122. masklist : pmaskitem;
  123. procedure AddMask(s:string);
  124. var
  125. maskitem : PMaskItem;
  126. i : longint;
  127. begin
  128. repeat
  129. i:=pos(' ',s);
  130. if i=0 then
  131. i:=length(s)+1;
  132. New(maskitem);
  133. fillchar(maskitem^,sizeof(tmaskitem),0);
  134. maskitem^.mask:=Copy(s,1,i-1);
  135. maskitem^.next:=masklist;
  136. masklist:=maskitem;
  137. Delete(s,1,i);
  138. until s='';
  139. end;
  140. var
  141. Dir : Searchrec;
  142. Total : longint;
  143. hp : pmaskitem;
  144. found : boolean;
  145. begin
  146. AddMask('*.exe *.so *.dll');
  147. AddMask('ppas.bat ppas.sh link.res fpcmaked');
  148. AddMask('*.tpu *.tpp *.tpw *.tr');
  149. AddMask('*.log *.bak');
  150. AddMask('*.ppu *.o *.a *.s');
  151. AddMask('*.ppw *.ow *.aw *.sw');
  152. AddMask('*.pp1 *.o1 *.a1 *.s1');
  153. AddMask('*.ppo *.oo *.ao *.so');
  154. WriteLn('DelPascal ',version,' (C) 1999 Peter Vreman');
  155. Writeln;
  156. FindFirst('*.*',$20,Dir);
  157. Total:=0;
  158. while (doserror=0) do
  159. begin
  160. hp:=masklist;
  161. while assigned(hp) do
  162. begin
  163. if MatchesMask(Dir.Name,hp^.mask) then
  164. begin
  165. EraseFile(Dir.Name);
  166. inc(hp^.Files);
  167. inc(hp^.Size,Dir.Size);
  168. break;
  169. end;
  170. hp:=hp^.next;
  171. end;
  172. FindNext(Dir);
  173. end;
  174. {Write Results}
  175. found:=false;
  176. hp:=masklist;
  177. while assigned(hp) do
  178. begin
  179. if hp^.Files>0 then
  180. begin
  181. WriteLn(' - Removed ',hp^.Files:2,' ',hp^.Mask,' (',DStr(hp^.Size)+' Bytes)');
  182. inc(Total,hp^.Size);
  183. found:=true;
  184. end;
  185. hp:=hp^.next;
  186. end;
  187. if not found then
  188. WriteLn(' - No Redundant Files Found!')
  189. else
  190. WriteLn(' - Total ',DStr(Total),' Bytes Freed');
  191. end.
  192. {
  193. $Log$
  194. Revision 1.2 1999-12-02 11:31:11 peter
  195. * removed temp comment
  196. Revision 1.1 1999/12/01 22:45:04 peter
  197. + delp tool which deletes all generated pascal files
  198. }