• R/O
  • SSH
  • HTTPS

dprojfilter: Commit


Commit MetaInfo

Revision3 (tree)
Time2018-07-26 18:42:06
Authordummzeuch

Log Message

initial check in of working version

Change Summary

Incremental Difference

--- trunk/src/DprojFilter.dpr (nonexistent)
+++ trunk/src/DprojFilter.dpr (revision 3)
@@ -0,0 +1,18 @@
1+program DprojFilter;
2+
3+{$APPTYPE CONSOLE}
4+
5+uses
6+ SysUtils,
7+ u_DprojFilterMain in 'u_DprojFilterMain.pas',
8+ u_dzDefaultMain in '..\libs\dzlib\src\u_dzDefaultMain.pas';
9+
10+begin
11+ try
12+ MainClass := TDprojFilterMain;
13+ System.ExitCode := Main;
14+ except
15+ on e: Exception do
16+ Writeln(e.Classname, ': ', e.Message);
17+ end;
18+end.
--- trunk/src/DprojFilter.dproj (nonexistent)
+++ trunk/src/DprojFilter.dproj (revision 3)
@@ -0,0 +1,88 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+ <PropertyGroup>
4+ <ProjectGuid>{29985e20-7aa0-4356-91d8-bb4bc8b57893}</ProjectGuid>
5+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+ <DCC_DCCCompiler>DCC32</DCC_DCCCompiler>
8+ <DCC_DependencyCheckOutputName>..\DprojFilter.exe</DCC_DependencyCheckOutputName>
9+ <MainSource>DprojFilter.dpr</MainSource>
10+ </PropertyGroup>
11+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
12+ <Version>7.0</Version>
13+ <DCC_DebugInformation>False</DCC_DebugInformation>
14+ <DCC_LocalDebugSymbols>False</DCC_LocalDebugSymbols>
15+ <DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
16+ <DCC_Define>RELEASE</DCC_Define>
17+ </PropertyGroup>
18+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+ <Version>7.0</Version>
20+ <DCC_Define>DEBUG;no_translation</DCC_Define>
21+ <DCC_ExeOutput>..</DCC_ExeOutput>
22+ <DCC_DcuOutput>..\dcu</DCC_DcuOutput>
23+ <DCC_ObjOutput>..\dcu</DCC_ObjOutput>
24+ <DCC_HppOutput>..\dcu</DCC_HppOutput>
25+ <DCC_UnitSearchPath>$(BDS)\lib\Debug;D:\Source\VCLDelphiInstall\libs\JCL\lib\d11\debug;..\libs\dzlib\src;..\libs\dzlib\templates;..\libs\dzlib\forms;..\libs\dzlib\jedi_inc</DCC_UnitSearchPath>
26+ <DCC_ResourcePath>$(BDS)\lib\Debug;D:\Source\VCLDelphiInstall\libs\JCL\lib\d11\debug;..\libs\dzlib\src;..\libs\dzlib\templates;..\libs\dzlib\forms;..\libs\dzlib\jedi_inc</DCC_ResourcePath>
27+ <DCC_ObjPath>$(BDS)\lib\Debug;D:\Source\VCLDelphiInstall\libs\JCL\lib\d11\debug;..\libs\dzlib\src;..\libs\dzlib\templates;..\libs\dzlib\forms;..\libs\dzlib\jedi_inc</DCC_ObjPath>
28+ <DCC_IncludePath>$(BDS)\lib\Debug;D:\Source\VCLDelphiInstall\libs\JCL\lib\d11\debug;..\libs\dzlib\src;..\libs\dzlib\templates;..\libs\dzlib\forms;..\libs\dzlib\jedi_inc</DCC_IncludePath>
29+ <DCC_Optimize>False</DCC_Optimize>
30+ <DCC_SYMBOL_PLATFORM>False</DCC_SYMBOL_PLATFORM>
31+ <DCC_UNIT_PLATFORM>False</DCC_UNIT_PLATFORM>
32+ </PropertyGroup>
33+ <ProjectExtensions>
34+ <Borland.Personality>Delphi.Personality</Borland.Personality>
35+ <Borland.ProjectType />
36+ <BorlandProject>
37+<BorlandProject> <Delphi.Personality> <Parameters>
38+ <Parameters Name="UseLauncher">False</Parameters>
39+ <Parameters Name="LoadAllSymbols">True</Parameters>
40+ <Parameters Name="LoadUnspecifiedSymbols">False</Parameters>
41+ <Parameters Name="RunParams"></Parameters>
42+ </Parameters>
43+ <VersionInfo>
44+ <VersionInfo Name="IncludeVerInfo">False</VersionInfo>
45+ <VersionInfo Name="AutoIncBuild">False</VersionInfo>
46+ <VersionInfo Name="MajorVer">1</VersionInfo>
47+ <VersionInfo Name="MinorVer">0</VersionInfo>
48+ <VersionInfo Name="Release">0</VersionInfo>
49+ <VersionInfo Name="Build">0</VersionInfo>
50+ <VersionInfo Name="Debug">False</VersionInfo>
51+ <VersionInfo Name="PreRelease">False</VersionInfo>
52+ <VersionInfo Name="Special">False</VersionInfo>
53+ <VersionInfo Name="Private">False</VersionInfo>
54+ <VersionInfo Name="DLL">False</VersionInfo>
55+ <VersionInfo Name="Locale">1031</VersionInfo>
56+ <VersionInfo Name="CodePage">1252</VersionInfo>
57+ </VersionInfo>
58+ <VersionInfoKeys>
59+ <VersionInfoKeys Name="CompanyName"></VersionInfoKeys>
60+ <VersionInfoKeys Name="FileDescription"></VersionInfoKeys>
61+ <VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
62+ <VersionInfoKeys Name="InternalName"></VersionInfoKeys>
63+ <VersionInfoKeys Name="LegalCopyright"></VersionInfoKeys>
64+ <VersionInfoKeys Name="LegalTrademarks"></VersionInfoKeys>
65+ <VersionInfoKeys Name="OriginalFilename"></VersionInfoKeys>
66+ <VersionInfoKeys Name="ProductName"></VersionInfoKeys>
67+ <VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
68+ <VersionInfoKeys Name="Comments"></VersionInfoKeys>
69+ </VersionInfoKeys>
70+ <Excluded_Packages>
71+ <Excluded_Packages Name="C:\Users\Public\Documents\RAD Studio\5.0\Bpl\SIGComponents110.bpl">SIG internal components</Excluded_Packages>
72+ <Excluded_Packages Name="$(BDS)\bin\dcloffice2k100.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
73+ <Excluded_Packages Name="$(BDS)\bin\dclofficexp100.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
74+ </Excluded_Packages>
75+ <Source>
76+ <Source Name="MainSource">DprojFilter.dpr</Source>
77+ </Source>
78+ </Delphi.Personality> </BorlandProject></BorlandProject>
79+ </ProjectExtensions>
80+ <Import Project="$(MSBuildBinPath)\Borland.Delphi.Targets" />
81+ <ItemGroup>
82+ <DelphiCompile Include="DprojFilter.dpr">
83+ <MainSource>MainSource</MainSource>
84+ </DelphiCompile>
85+ <DCCReference Include="..\libs\dzlib\src\u_dzDefaultMain.pas" />
86+ <DCCReference Include="u_DprojFilterMain.pas" />
87+ </ItemGroup>
88+</Project>
--- trunk/src/u_DprojFilterMain.pas (nonexistent)
+++ trunk/src/u_DprojFilterMain.pas (revision 3)
@@ -0,0 +1,122 @@
1+unit u_DprojFilterMain;
2+
3+interface
4+
5+uses
6+ SysUtils,
7+ Classes,
8+ u_dzDefaultMain;
9+
10+type
11+ TDprojFilterMain = class(TDefaultMain)
12+ private
13+ procedure HandleParam(const _Parameter, _DeleteLine: string);
14+ procedure HandleFile(const _fn, _DeleteLine: string);
15+ protected
16+ procedure InitCmdLineParser; override;
17+ function doExecute: Integer; override;
18+ end;
19+
20+implementation
21+
22+uses
23+ u_dzFileUtils,
24+ u_dzStringUtils,
25+ u_dzMiscUtils;
26+
27+{ TDprojFilterMain }
28+
29+procedure TDprojFilterMain.HandleFile(const _fn: string; const _DeleteLine: string);
30+var
31+ Orig: TStringList;
32+ Changed: TStringList;
33+ i: Integer;
34+ s: string;
35+ bakfn: string;
36+ DelCnt: Integer;
37+begin
38+ WriteLn('processing file ', _fn);
39+ InitializeNil(Orig, Changed);
40+ try
41+ Orig := TStringList.Create;
42+ Changed := TStringList.Create;
43+ try
44+ Orig.LoadFromFile(_fn);
45+ DelCnt := 0;
46+ for i := 0 to Orig.Count - 1 do begin
47+ s := Trim(Orig[i]);
48+ if SameText(s, _DeleteLine) then begin
49+ Inc(DelCnt);
50+ end else begin
51+ Changed.Add(Orig[i]);
52+ end;
53+ end;
54+ if DelCnt > 0 then begin
55+ bakfn := _fn + '.bak';
56+ if TFileSystem.FileExists(bakfn) then
57+ WriteLn(bakfn, ' already exists, will not overwrite it.')
58+ else begin
59+ WriteLn('Writing backup to ', bakfn);
60+ Orig.SaveToFile(bakfn);
61+ end;
62+ end;
63+ Changed.SaveToFile(_fn);
64+ WriteLn(Format('Deleted %d lines.', [DelCnt]));
65+ except
66+ on e: Exception do begin
67+ WriteLn(Format('Error processing "%s": %s (%s)', [_fn, e.Message, e.ClassName]));
68+ end;
69+ end;
70+ finally
71+ FreeAndNil(Orig, Changed);
72+ end;
73+end;
74+
75+procedure TDprojFilterMain.HandleParam(const _Parameter: string; const _DeleteLine: string);
76+var
77+ FileIdx: Integer;
78+ Files: TStringList;
79+begin
80+ WriteLn('Handling parameter ', _Parameter);
81+ Files := TStringList.Create;
82+ try
83+ TSimpleDirEnumerator.EnumFilesOnly(_Parameter, Files, True);
84+ WriteLn(Format('Found %d files matching %s', [Files.Count, _Parameter]));
85+ for FileIdx := 0 to TSimpleDirEnumerator.EnumFilesOnly(_Parameter, Files, True) - 1 do begin
86+ HandleFile(Files[FileIdx], _DeleteLine);
87+ end;
88+ finally
89+ FreeAndNil(Files);
90+ end;
91+end;
92+
93+function TDprojFilterMain.doExecute: Integer;
94+var
95+ Parameters: TStringList;
96+ DeleteLine: string;
97+ ParamIdx: Integer;
98+begin
99+ Parameters := TStringList.Create;
100+ try
101+ FGetOpt.ParamPassed('DprojFile', Parameters);
102+ if not FGetOpt.OptionPassed('DeleteLine', DeleteLine) then
103+ raise Exception.Create('You must pass one of the options: --DeleteLine');
104+ DeleteLine := UnquoteString(DeleteLine);
105+ for ParamIdx := 0 to Parameters.Count - 1 do begin
106+ HandleParam(Parameters[ParamIdx], DeleteLine);
107+ end;
108+ finally
109+ FreeAndNil(Parameters);
110+ end;
111+ Result := 0;
112+end;
113+
114+procedure TDprojFilterMain.InitCmdLineParser;
115+begin
116+ inherited;
117+ FGetOpt.RegisterParam('DprojFile', 'Dproj file(s) to process wildcards are allowed', 1, MaxInt);
118+ FGetOpt.RegisterOption('DeleteLine', 'Delete a line matching the parameter, wildcards are not allowed. E.g. --DeleteLine="<DCC_DcpOutput>..\..\lib\16</DCC_DcpOutput>"', True);
119+// FGetOpt.RegisterOption('DeleteLineRegEx', 'Delete a line matching the parameter, regular expressions are allowed. E.g. --DeleteLine="<DCC_DcpOutput>..\..\lib\16</DCC_DcpOutput>"', 1)
120+end;
121+
122+end.
Show on old repository browser