from rust

This commit is contained in:
Alexander Zhirov 2025-08-31 16:47:55 +03:00
parent 32203fadc0
commit ef491965f6
Signed by: alexander
GPG key ID: C8D8BE544A27C511
4 changed files with 21 additions and 326 deletions

View file

@ -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());
}