from rust
This commit is contained in:
parent
32203fadc0
commit
ef491965f6
4 changed files with 21 additions and 326 deletions
32
source/app.d
32
source/app.d
|
@ -1,25 +1,17 @@
|
|||
import std.stdio : writeln, stderr;
|
||||
import std.exception : collectException;
|
||||
import std.stdio;
|
||||
import libxdiff : MMFile;
|
||||
|
||||
import diff;
|
||||
|
||||
int main(string[] args)
|
||||
void main()
|
||||
{
|
||||
if (args.length != 3)
|
||||
{
|
||||
stderr.writeln("use: ", args[0], " OLD NEW");
|
||||
return 1;
|
||||
}
|
||||
auto a = MMFile.fromBytes(cast(ubyte[]) "hello world\n");
|
||||
auto b = MMFile.fromBytes(cast(ubyte[]) "hello world!\n");
|
||||
|
||||
auto eng = new DiffEngine(3);
|
||||
auto patch = a.computePatch(b);
|
||||
writeln("patch size: ", patch.size());
|
||||
|
||||
string result; // сюда положим результат
|
||||
auto ex = collectException(result = eng.diffFiles(args[1], args[2]));
|
||||
if (ex !is null)
|
||||
{
|
||||
stderr.writeln(ex.msg);
|
||||
return 2;
|
||||
}
|
||||
writeln(result);
|
||||
return 0;
|
||||
auto res = a.applyPatch(patch);
|
||||
writeln("apply success: ", res.success);
|
||||
writeln(res.patched.asSlice()); // печатаем результат
|
||||
// печатаем как есть (включая заголовок @@ и строки с '-'/'+' и '\n')
|
||||
write(cast(string) MMFile.fromBlocksMoved(patch).asSlice());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue