1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
{ Copie un fichier source en enlevant les commentaires. }
{$APPTYPE CONSOLE}
{Outils}
function extractFileExt(const aFileName: string): string;
var X,P: integer;
begin
for X := Length(aFileName) to 1 do
if aFileName[X] = '.' then
begin
P := X;
Break;
end;
result := copy(aFileName, P-1, Length(aFileName)-P);
end;
function ChangeFileExt(const aFileName, aNewExt: string): string;
var X,P: integer;
begin
for X := Length(aFileName) to 1 do
if aFileName[X] = '.' then
begin
P := X;
Break;
end;
if aNewExt[1] = '.' then
dec(P);
ChangeFileExt := copy(aFileName, 1, P)+aNewExt;
end;
{/Outils}
procedure Uncomment(const aFileNameSrc, aFileNameDest: string);
var
tSrc,
tDst : file;
SBuffer,SOut : string;
Sz,N,P1,P2: integer;
begin
// Open Src and load in String
assign(tSrc, aFileNameSrc);
reset(tSrc);
Sz := fileSize(tSrc);
SetLength(SBuffer, Sz);
blockRead(tSrc, SBuffer[1], Sz);
close(tSrc);
SOut := '';
N := 1;
while N < Sz do
begin
case SBuffer[N] of
'''': // Check strings firs, because JSon := '{"": "", "": ""}'; Smiley := '(*.*)';
begin
SOut := SBuffer[N];
inc(N);
while (N<Sz) and ((SBuffer[N-1] <> '''') and (SBuffer[N] <> '''')) do // only if not "''" char
begin
SOut := SOut + SBuffer[N];
inc(N);
end;
end;
'(' : (* *)
if SBuffer[N+1] = '*' then // not an operation
begin
inc(N);
while (N<Sz) and ((SBuffer[N-1]+SBuffer[N]) <> '*)') do // to next "*)"
inc(N);
end
else
begin
SOut := Sout + SBuffer[N];
inc(N);
end;
'{' : { }
if SBuffer[N+1] <> '$' then // not a directive
begin
inc(N);
while (N<Sz) and (SBuffer[N] <> '}') do // to next "}"
inc(N);
end
else
begin
SOut := SOut + SBuffer[N];
inc(N);
end;
'/' : //
if SBuffer[N+1] = '/' then // is a comment
begin
inc(N);
while (N<Sz) and not (SBuffer[N] in [#13,#10]) do // to end of line
inc(N);
end
else
begin
SOut := SOut+SBuffer[N];
inc(N);
end;
else
begin
SOut := SOut+SBuffer[N];
inc(N);
end;
end;
end;
// Save Dest string in file
Sz := Length(SOut) * SizeOf(Char);
assign(tDst, aFileNameDest);
rewrite(tDst, sZ);
blockWrite(tDst, SOut[1], sZ);
close(tDst);
end;
procedure Help;
begin
writeln('Source Uncomment v 0.0.1');
writeln('=====================================================');
writeln(' Howto use :');
writeln(' C:\>Uncomment Source Dest');
writeln(' or');
writeln(' C:\>Uncomment Source');
writeln(' note: in this case "source".wocom."ext" is created');
writeln(' in the same folder of Source.');
end;
begin
case paramCount of
0 : help;
1 : Uncomment(paramStr(1), changeFileExt(paramStr(1), '.wocom'+extractFileExt(paramStr(2))));
2 : Uncomment(paramStr(1), paramStr(2));
end;
end. |
Partager