Fix #16389 - r2r -qv and r2 -v to show version and quiet versions (#16472) ##tools

This commit is contained in:
pancake 2020-04-08 13:56:52 +02:00 committed by GitHub
parent f9864efc09
commit 57c68c752c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 56 additions and 36 deletions

View File

@ -36,11 +36,12 @@ static void print_state(R2RState *state, ut64 prev_completed);
static void print_log(R2RState *state, ut64 prev_completed, ut64 prev_paths_completed);
static int help(bool verbose) {
printf ("Usage: r2r [-vh] [-j threads] [test file/dir | @test-type]\n");
printf ("Usage: r2r [-qvVnL] [-j threads] [test file/dir | @test-type]\n");
if (verbose) {
printf (
" -h print this help\n"
" -v show version\n"
" -q quiet\n"
" -V verbose\n"
" -n do nothing (don't run any test, just load/parse them)\n"
" -L log mode (better printing for CI, logfiles, etc.)"
@ -133,6 +134,7 @@ int main(int argc, char **argv) {
int workers_count = WORKERS_DEFAULT;
bool verbose = false;
bool nothing = false;
bool quiet = false;
bool log_mode = false;
char *radare2_cmd = NULL;
char *rasm2_cmd = NULL;
@ -143,7 +145,7 @@ int main(int argc, char **argv) {
int ret = 0;
RGetopt opt;
r_getopt_init (&opt, argc, (const char **)argv, "hvj:r:m:f:C:LnVt:F:");
r_getopt_init (&opt, argc, (const char **)argv, "hqvj:r:m:f:C:LnVt:F:");
int c;
while ((c = r_getopt_next (&opt)) != -1) {
@ -151,8 +153,17 @@ int main(int argc, char **argv) {
case 'h':
ret = help (true);
goto beach;
case 'q':
quiet = true;
break;
case 'v':
printf (R2_VERSION "\n");
if (quiet) {
printf (R2_VERSION "\n");
} else {
char *s = r_str_version ("r2r");
printf ("%s\n", s);
free (s);
}
return 0;
case 'V':
verbose = true;

View File

@ -196,6 +196,8 @@ R_API char *r_str_list_join(RList *str, const char *sep);
R_API const char *r_str_sep(const char *base, const char *sep);
R_API const char *r_str_rsep(const char *base, const char *p, const char *sep);
R_API char *r_str_donut(int size);
R_API char *r_str_version(const char *program);
#ifdef __cplusplus
}
#endif

View File

@ -2,7 +2,6 @@ include ../config.mk
NAME=r_main
OBJS=version.o
OBJS+=main.o
OBJS+=rax2.o
OBJS+=rasm2.o

View File

@ -44,3 +44,10 @@ R_API int r_main_run(RMain *m, int argc, const char **argv) {
r_return_val_if_fail (m && m->main, -1);
return m->main (argc, argv);
}
R_API int r_main_version_print(const char *progname) {
char *s = r_str_version (progname);
printf ("%s\n", s);
free (s);
return 0;
}

View File

@ -9,8 +9,7 @@ r_main_sources = [
'rahash2.c',
'rarun2.c',
'rasm2.c',
'rax2.c',
'version.c',
'rax2.c'
]
r_main = library('r_main', r_main_sources,

View File

@ -1,30 +0,0 @@
/* copyright 2015-2020 radare2 by pancake */
#include <r_userconf.h>
#include <r_util.h>
#ifndef R2_GITTAP
#define R2_GITTAP ""
#endif
#ifndef R2_GITTIP
#define R2_GITTIP ""
#endif
#ifndef R2_BIRTH
#define R2_BIRTH "unknown"
#endif
R_API int r_main_version_print(const char *program) {
printf ("%s "R2_VERSION" %d @ "
R_SYS_OS"-"
R_SYS_ARCH"-%d git.%s\n",
program, R2_VERSION_COMMIT,
(R_SYS_BITS & 8)? 64: 32,
*R2_GITTAP ? R2_GITTAP: "");
if (*R2_GITTIP) {
printf ("commit: "R2_GITTIP" build: "R2_BIRTH"\n");
}
return 0;
}

View File

@ -3645,3 +3645,32 @@ R_API char *r_str_scale(const char *s, int w, int h) {
free (str);
return r_str_list_join (out, "\n");
}
// version.c
#include <r_userconf.h>
#include <r_util.h>
#ifndef R2_GITTAP
#define R2_GITTAP ""
#endif
#ifndef R2_GITTIP
#define R2_GITTIP ""
#endif
#ifndef R2_BIRTH
#define R2_BIRTH "unknown"
#endif
R_API char *r_str_version(const char *program) {
char *s = r_str_newf ("%s "R2_VERSION" %d @ "
R_SYS_OS"-"
R_SYS_ARCH"-%d git.%s\n",
program, R2_VERSION_COMMIT,
(R_SYS_BITS & 8)? 64: 32,
*R2_GITTAP ? R2_GITTAP: "");
if (*R2_GITTIP) {
s = r_str_appendf (s, "commit: "R2_GITTIP" build: "R2_BIRTH"\n");
}
return s;
}

View File

@ -7,6 +7,7 @@
.Nm r2r
.Op Fl h
.Op Fl n
.Op Fl q
.Op Fl v
.Op Fl V
.Op Fl j Ar threads
@ -27,6 +28,8 @@ You need radare2 to be available in $PATH.
Show the help/usage message
.It Fl n
Do not run any test, just load/parse them
.It Fl q
Quiet mode (use like this: r2r -qv)
.It Fl v
Show version number
.It Fl V