delp.pp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. {
  2. $Id$
  3. Copyright (c) 1999-2000 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. begin
  41. Assign(f,Hstr);
  42. {$I-}
  43. Erase(f);
  44. {$I+}
  45. if ioresult<>0 then;
  46. end;
  47. function MatchesMask(What, Mask: string): boolean;
  48. function upper(const s : string) : string;
  49. var
  50. i : longint;
  51. begin
  52. for i:=1 to length(s) do
  53. if s[i] in ['a'..'z'] then
  54. upper[i]:=char(byte(s[i])-32)
  55. else
  56. upper[i]:=s[i];
  57. upper[0]:=s[0];
  58. end;
  59. Function CmpStr(const hstr1,hstr2:string):boolean;
  60. var
  61. found : boolean;
  62. i1,i2 : longint;
  63. begin
  64. i1:=0;
  65. i2:=0;
  66. found:=true;
  67. while found and (i1<length(hstr1)) and (i2<=length(hstr2)) do
  68. begin
  69. if found then
  70. inc(i2);
  71. inc(i1);
  72. case hstr1[i1] of
  73. '?' :
  74. found:=true;
  75. '*' :
  76. begin
  77. found:=true;
  78. if (i1=length(hstr1)) then
  79. i2:=length(hstr2)
  80. else
  81. if (i1<length(hstr1)) and (hstr1[i1+1]<>hstr2[i2]) then
  82. begin
  83. if i2<length(hstr2) then
  84. dec(i1)
  85. end
  86. else
  87. if i2>1 then
  88. dec(i2);
  89. end;
  90. else
  91. found:=(hstr1[i1]=hstr2[i2]) or (hstr2[i2]='?');
  92. end;
  93. end;
  94. if found then
  95. found:=(i1>=length(hstr1)) and (i2>=length(hstr2));
  96. CmpStr:=found;
  97. end;
  98. var
  99. D1,D2 : DirStr;
  100. N1,N2 : NameStr;
  101. E1,E2 : Extstr;
  102. begin
  103. {$ifdef linux}
  104. FSplit(What,D1,N1,E1);
  105. FSplit(Mask,D2,N2,E2);
  106. {$else}
  107. FSplit(Upper(What),D1,N1,E1);
  108. FSplit(Upper(Mask),D2,N2,E2);
  109. {$endif}
  110. MatchesMask:=CmpStr(N2,N1) and CmpStr(E2,E1);
  111. end;
  112. type
  113. PMaskItem=^TMaskItem;
  114. TMaskItem=record
  115. Mask : string[15];
  116. Files : longint;
  117. Size : longint;
  118. Next : PMaskItem;
  119. end;
  120. var
  121. masklist : pmaskitem;
  122. procedure AddMask(s:string);
  123. var
  124. maskitem : PMaskItem;
  125. i : longint;
  126. begin
  127. repeat
  128. i:=pos(' ',s);
  129. if i=0 then
  130. i:=length(s)+1;
  131. New(maskitem);
  132. fillchar(maskitem^,sizeof(tmaskitem),0);
  133. maskitem^.mask:=Copy(s,1,i-1);
  134. maskitem^.next:=masklist;
  135. masklist:=maskitem;
  136. Delete(s,1,i);
  137. until s='';
  138. end;
  139. var
  140. Dir : Searchrec;
  141. Total : longint;
  142. hp : pmaskitem;
  143. found : boolean;
  144. begin
  145. AddMask('*.exe *.so *.dll');
  146. AddMask('ppas.bat ppas.sh link.res fpcmaked fpcmade fpcmade.*');
  147. AddMask('*.tpu *.tpp *.tpw *.tr');
  148. AddMask('*.log *.bak');
  149. AddMask('*.ppu *.o *.a *.s');
  150. AddMask('*.ppw *.ow *.aw *.sw');
  151. AddMask('*.pp1 *.o1 *.a1 *.s1');
  152. AddMask('*.ppo *.oo *.ao *.so');
  153. WriteLn('DelPascal ',version,' (C) 1999 Peter Vreman');
  154. Writeln;
  155. FindFirst('*.*',$20,Dir);
  156. Total:=0;
  157. while (doserror=0) do
  158. begin
  159. hp:=masklist;
  160. while assigned(hp) do
  161. begin
  162. if MatchesMask(Dir.Name,hp^.mask) then
  163. begin
  164. EraseFile(Dir.Name);
  165. inc(hp^.Files);
  166. inc(hp^.Size,Dir.Size);
  167. break;
  168. end;
  169. hp:=hp^.next;
  170. end;
  171. FindNext(Dir);
  172. end;
  173. {Write Results}
  174. found:=false;
  175. hp:=masklist;
  176. while assigned(hp) do
  177. begin
  178. if hp^.Files>0 then
  179. begin
  180. WriteLn(' - Removed ',hp^.Files:2,' ',hp^.Mask,' (',DStr(hp^.Size)+' Bytes)');
  181. inc(Total,hp^.Size);
  182. found:=true;
  183. end;
  184. hp:=hp^.next;
  185. end;
  186. if not found then
  187. WriteLn(' - No Redundant Files Found!')
  188. else
  189. WriteLn(' - Total ',DStr(Total),' Bytes Freed');
  190. end.
  191. {
  192. $Log$
  193. Revision 1.4 2000-01-07 16:46:02 daniel
  194. * copyright 2000
  195. Revision 1.3 1999/12/19 17:12:10 peter
  196. * added fpcmade
  197. Revision 1.2 1999/12/02 11:31:11 peter
  198. * removed temp comment
  199. Revision 1.1 1999/12/01 22:45:04 peter
  200. + delp tool which deletes all generated pascal files
  201. }