Make rz_diff_buffers_unified() use the Subprocess API
Some checks failed
CI / changes (push) Has been cancelled
CI / Build on CentOS 7 (push) Has been cancelled
CI / Build on old Debian debian:jessie (push) Has been cancelled
CI / Build on old Debian debian:stretch (push) Has been cancelled
CI / Build on old Debian debian:wheezy (push) Has been cancelled
CI / Build static (push) Has been cancelled
CI / Create source tarball (push) Has been cancelled
Code scanning / changes (push) Has been cancelled
Mixed linter and checks / changes (push) Has been cancelled
CI / linux-meson-gcc-tests (push) Has been cancelled
CI / capstone-next (push) Has been cancelled
CI / capstone-v3 (push) Has been cancelled
CI / linux-gcc-tests-codecov (push) Has been cancelled
CI / linux-meson-clang-tests (push) Has been cancelled
CI / macos-meson-clang-tests (push) Has been cancelled
CI / linux-gcc-tests-asan (push) Has been cancelled
CI / Test source tarball (push) Has been cancelled
CI / Build OSX package (push) Has been cancelled
CI / Build Windows zip/installer clang_cl_x86 (push) Has been cancelled
CI / Build Windows zip/installer vs2019_static (push) Has been cancelled
CI / Build Windows zip/installer clang_cl (push) Has been cancelled
CI / Build Android aarch64 package (push) Has been cancelled
CI / Build Android arm package (push) Has been cancelled
CI / Build Android x86_64 package (push) Has been cancelled
CI / Build rizin rzpipe (push) Has been cancelled
CI / Test OSX pkg (push) Has been cancelled
CI / Test Windows installer built with clang_cl_x86 (push) Has been cancelled
CI / Test Windows installer built with clang_cl (push) Has been cancelled
CI / Create draft release and upload artifacts (push) Has been cancelled
CI / Publish Docker image on Docker Hub (push) Has been cancelled
Code scanning / (push) Has been cancelled
Mixed linter and checks / cmd_descs_yaml_check (push) Has been cancelled
Mixed linter and checks / clang-format (push) Has been cancelled
Mixed linter and checks / prettier (push) Has been cancelled
Mixed linter and checks / python (push) Has been cancelled
Some checks failed
CI / changes (push) Has been cancelled
CI / Build on CentOS 7 (push) Has been cancelled
CI / Build on old Debian debian:jessie (push) Has been cancelled
CI / Build on old Debian debian:stretch (push) Has been cancelled
CI / Build on old Debian debian:wheezy (push) Has been cancelled
CI / Build static (push) Has been cancelled
CI / Create source tarball (push) Has been cancelled
Code scanning / changes (push) Has been cancelled
Mixed linter and checks / changes (push) Has been cancelled
CI / linux-meson-gcc-tests (push) Has been cancelled
CI / capstone-next (push) Has been cancelled
CI / capstone-v3 (push) Has been cancelled
CI / linux-gcc-tests-codecov (push) Has been cancelled
CI / linux-meson-clang-tests (push) Has been cancelled
CI / macos-meson-clang-tests (push) Has been cancelled
CI / linux-gcc-tests-asan (push) Has been cancelled
CI / Test source tarball (push) Has been cancelled
CI / Build OSX package (push) Has been cancelled
CI / Build Windows zip/installer clang_cl_x86 (push) Has been cancelled
CI / Build Windows zip/installer vs2019_static (push) Has been cancelled
CI / Build Windows zip/installer clang_cl (push) Has been cancelled
CI / Build Android aarch64 package (push) Has been cancelled
CI / Build Android arm package (push) Has been cancelled
CI / Build Android x86_64 package (push) Has been cancelled
CI / Build rizin rzpipe (push) Has been cancelled
CI / Test OSX pkg (push) Has been cancelled
CI / Test Windows installer built with clang_cl_x86 (push) Has been cancelled
CI / Test Windows installer built with clang_cl (push) Has been cancelled
CI / Create draft release and upload artifacts (push) Has been cancelled
CI / Publish Docker image on Docker Hub (push) Has been cancelled
Code scanning / (push) Has been cancelled
Mixed linter and checks / cmd_descs_yaml_check (push) Has been cancelled
Mixed linter and checks / clang-format (push) Has been cancelled
Mixed linter and checks / prettier (push) Has been cancelled
Mixed linter and checks / python (push) Has been cancelled
This commit is contained in:
parent
a93665189d
commit
be6198fc64
4 changed files with 39 additions and 21 deletions
|
|
@ -606,7 +606,10 @@ static RzThreadFunctionRet worker_th(RzThread *th) {
|
||||||
static void print_diff(const char *actual, const char *expected, bool diffchar, const char *regexp) {
|
static void print_diff(const char *actual, const char *expected, bool diffchar, const char *regexp) {
|
||||||
RzDiff *d = rz_diff_new();
|
RzDiff *d = rz_diff_new();
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
d->diff_cmd = "git diff --no-index";
|
static const char *diff_cmd[] = {
|
||||||
|
"git", "diff", "--no-index", NULL
|
||||||
|
};
|
||||||
|
d->diff_cmd = diff_cmd;
|
||||||
#endif
|
#endif
|
||||||
const char *output = actual;
|
const char *output = actual;
|
||||||
if (regexp) {
|
if (regexp) {
|
||||||
|
|
@ -623,7 +626,10 @@ static void print_diff(const char *actual, const char *expected, bool diffchar,
|
||||||
rz_diffchar_free(diff);
|
rz_diffchar_free(diff);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
d->diff_cmd = "git diff --no-index --word-diff=porcelain --word-diff-regex=.";
|
static const char *diff_cmd_char[] = {
|
||||||
|
"git", "diff", "--no-index", "--word-diff=porcelain", "--word-diff-regex=.", NULL
|
||||||
|
};
|
||||||
|
d->diff_cmd = diff_cmd_char;
|
||||||
}
|
}
|
||||||
char *uni = rz_diff_buffers_to_string(d, (const ut8 *)expected, (int)strlen(expected),
|
char *uni = rz_diff_buffers_to_string(d, (const ut8 *)expected, (int)strlen(expected),
|
||||||
(const ut8 *)output, (int)strlen(output));
|
(const ut8 *)output, (int)strlen(output));
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ typedef struct rz_diff_t {
|
||||||
void *user;
|
void *user;
|
||||||
bool verbose;
|
bool verbose;
|
||||||
int type;
|
int type;
|
||||||
const char *diff_cmd;
|
const char **diff_cmd; // null-terminated array of cmd+args
|
||||||
int (*callback)(struct rz_diff_t *diff, void *user, RzDiffOp *op);
|
int (*callback)(struct rz_diff_t *diff, void *user, RzDiffOp *op);
|
||||||
} RzDiff;
|
} RzDiff;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -957,6 +957,9 @@ RZ_API int rz_main_rz_diff(int argc, const char **argv) {
|
||||||
RzDiff *d;
|
RzDiff *d;
|
||||||
RzGetopt opt;
|
RzGetopt opt;
|
||||||
|
|
||||||
|
rz_subprocess_init();
|
||||||
|
atexit(rz_subprocess_fini);
|
||||||
|
|
||||||
rzdiff_options_init(&ro);
|
rzdiff_options_init(&ro);
|
||||||
rz_getopt_init(&opt, argc, argv, "Aa:b:BCDe:npg:m:G:OijrhcdsS:uUvVxXt:zqZ");
|
rz_getopt_init(&opt, argc, argv, "Aa:b:BCDe:npg:m:G:OijrhcdsS:uUvVxXt:zqZ");
|
||||||
while ((o = rz_getopt_next(&opt)) != -1) {
|
while ((o = rz_getopt_next(&opt)) != -1) {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,10 @@
|
||||||
// the non-system-diff doesnt work well
|
// the non-system-diff doesnt work well
|
||||||
#define USE_SYSTEM_DIFF 1
|
#define USE_SYSTEM_DIFF 1
|
||||||
|
|
||||||
|
static const char *diff_cmd_default[] = {
|
||||||
|
"diff", "-u", NULL
|
||||||
|
};
|
||||||
|
|
||||||
RZ_API RzDiff *rz_diff_new_from(ut64 off_a, ut64 off_b) {
|
RZ_API RzDiff *rz_diff_new_from(ut64 off_a, ut64 off_b) {
|
||||||
RzDiff *d = RZ_NEW0(RzDiff);
|
RzDiff *d = RZ_NEW0(RzDiff);
|
||||||
if (d) {
|
if (d) {
|
||||||
|
|
@ -14,7 +18,7 @@ RZ_API RzDiff *rz_diff_new_from(ut64 off_a, ut64 off_b) {
|
||||||
d->user = NULL;
|
d->user = NULL;
|
||||||
d->off_a = off_a;
|
d->off_a = off_a;
|
||||||
d->off_b = off_b;
|
d->off_b = off_b;
|
||||||
d->diff_cmd = "diff -u";
|
d->diff_cmd = diff_cmd_default;
|
||||||
}
|
}
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
@ -135,30 +139,35 @@ RZ_API int rz_diff_buffers_static(RzDiff *d, const ut8 *a, int la, const ut8 *b,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: temporary files are
|
// XXX: temporary files are bad
|
||||||
RZ_API char *rz_diff_buffers_unified(RzDiff *d, const ut8 *a, int la, const ut8 *b, int lb) {
|
RZ_API char *rz_diff_buffers_unified(RzDiff *d, const ut8 *a, int la, const ut8 *b, int lb) {
|
||||||
|
rz_return_val_if_fail(d && d->diff_cmd && *d->diff_cmd && a && b, NULL);
|
||||||
rz_file_dump(".a", a, la, 0);
|
rz_file_dump(".a", a, la, 0);
|
||||||
rz_file_dump(".b", b, lb, 0);
|
rz_file_dump(".b", b, lb, 0);
|
||||||
#if 0
|
|
||||||
if (rz_mem_is_printable (a, RZ_MIN (5, la))) {
|
|
||||||
rz_file_dump (".a", a, la, 0);
|
|
||||||
rz_file_dump (".b", b, lb, 0);
|
|
||||||
} else {
|
|
||||||
rz_file_hexdump (".a", a, la, 0);
|
|
||||||
rz_file_hexdump (".b", b, lb, 0);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
char *err = NULL;
|
|
||||||
char *out = NULL;
|
char *out = NULL;
|
||||||
int out_len;
|
RzPVector args;
|
||||||
char *diff_cmdline = rz_str_newf("%s .a .b", d->diff_cmd);
|
rz_pvector_init(&args, NULL);
|
||||||
if (diff_cmdline) {
|
for (const char **i = d->diff_cmd; *i; i++) {
|
||||||
(void)rz_sys_cmd_str_full(diff_cmdline, NULL, &out, &out_len, &err);
|
rz_pvector_push(&args, (void *)*i);
|
||||||
free(diff_cmdline);
|
|
||||||
}
|
}
|
||||||
|
rz_pvector_push(&args, ".a");
|
||||||
|
rz_pvector_push(&args, ".b");
|
||||||
|
RzSubprocess *proc = rz_subprocess_start(rz_pvector_at(&args, 0),
|
||||||
|
(const char **)rz_pvector_index_ptr(&args, 1), rz_pvector_len(&args) - 1, NULL, NULL, 0);
|
||||||
|
if (!proc) {
|
||||||
|
goto terria;
|
||||||
|
}
|
||||||
|
rz_subprocess_wait(proc, 500);
|
||||||
|
RzSubprocessOutput *pout = rz_subprocess_drain(proc);
|
||||||
|
rz_subprocess_free(proc);
|
||||||
|
if (pout) {
|
||||||
|
out = pout->out;
|
||||||
|
pout->out = NULL;
|
||||||
|
rz_subprocess_output_free(pout);
|
||||||
|
}
|
||||||
|
terria:
|
||||||
rz_file_rm(".a");
|
rz_file_rm(".a");
|
||||||
rz_file_rm(".b");
|
rz_file_rm(".b");
|
||||||
free(err);
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue