Skip to content

Commit

Permalink
Use RzOutputMode for rz_core_file_print() (o cmd)
Browse files Browse the repository at this point in the history
  • Loading branch information
XVilka committed Sep 29, 2021
1 parent 300714c commit 4b7bce5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
13 changes: 6 additions & 7 deletions librz/core/cfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ RZ_API RzCoreFile *rz_core_file_get_by_fd(RzCore *core, int fd) {
return NULL;
}

RZ_API int rz_core_file_list(RzCore *core, int mode) {
RZ_API int rz_core_file_print(RzCore *core, RzOutputMode mode) {
int count = 0;
RzCoreFile *f;
RzIODesc *desc;
Expand All @@ -1294,7 +1294,7 @@ RZ_API int rz_core_file_list(RzCore *core, int mode) {
RzBinFile *bf;
RzListIter *iter;
PJ *pj = NULL;
if (mode == 'j') {
if (mode == RZ_OUTPUT_MODE_JSON) {
pj = pj_new();
if (!pj) {
return 0;
Expand All @@ -1309,7 +1309,7 @@ RZ_API int rz_core_file_list(RzCore *core, int mode) {
}
from = 0LL;
switch (mode) {
case 'j': { // "oij"
case RZ_OUTPUT_MODE_JSON: { // "oij"
pj_o(pj);
pj_kb(pj, "raised", core->io->desc->fd == f->fd);
pj_ki(pj, "fd", f->fd);
Expand All @@ -1320,8 +1320,7 @@ RZ_API int rz_core_file_list(RzCore *core, int mode) {
pj_end(pj);
break;
}
case '*':
case 'r':
case RZ_OUTPUT_MODE_RIZIN:
// TODO: use a getter
{
bool fileHaveBin = false;
Expand All @@ -1338,7 +1337,7 @@ RZ_API int rz_core_file_list(RzCore *core, int mode) {
free(absfile);
}
break;
case 'n': {
case RZ_OUTPUT_MODE_LONG: {
bool header_loaded = false;
rz_list_foreach (core->bin->binfiles, it, bf) {
if (bf->fd == f->fd) {
Expand Down Expand Up @@ -1378,7 +1377,7 @@ RZ_API int rz_core_file_list(RzCore *core, int mode) {
}
count++;
}
if (mode == 'j') {
if (mode == RZ_OUTPUT_MODE_JSON) {
pj_end(pj);
rz_cons_println(pj_string(pj));
pj_free(pj);
Expand Down
10 changes: 7 additions & 3 deletions librz/core/cmd_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ RZ_IPI int rz_cmd_open(void *data, const char *input) {
}
case 'n': // "on"
if (input[1] == '*') {
rz_core_file_list(core, 'n');
rz_core_file_print(core, RZ_OUTPUT_MODE_LONG);
return 0;
}
if (input[1] == '+') { // "on+"
Expand Down Expand Up @@ -1289,7 +1289,7 @@ RZ_IPI int rz_cmd_open(void *data, const char *input) {
rz_core_cmd_help(core, help_msg_o_star);
break;
}
rz_core_file_list(core, (int)(*input));
rz_core_file_print(core, RZ_OUTPUT_MODE_RIZIN);
break;
case 'j': // "oj"
if ('?' == input[1]) {
Expand Down Expand Up @@ -1352,10 +1352,14 @@ RZ_IPI int rz_cmd_open(void *data, const char *input) {
}
} break;
case 'j': // "oij"
rz_core_file_print(core, RZ_OUTPUT_MODE_JSON);
break;
case '*': // "oi*"
rz_core_file_print(core, RZ_OUTPUT_MODE_RIZIN);
break;
case 0: // "oi"
rz_core_file_list(core, input[1]);
break;
rz_core_file_print(core, RZ_OUTPUT_MODE_STANDARD);
}
break;
case 'u': { // "ou"
Expand Down
2 changes: 1 addition & 1 deletion librz/include/rz_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ RZ_API RzCoreFile *rz_core_file_get_by_fd(RzCore *core, int fd);
RZ_API void rz_core_file_close(RzCoreFile *fh);
RZ_API bool rz_core_file_close_fd(RzCore *core, int fd);
RZ_API bool rz_core_file_close_all_but(RzCore *core);
RZ_API int rz_core_file_list(RzCore *core, int mode);
RZ_API int rz_core_file_print(RzCore *core, RzOutputMode mode);
RZ_API int rz_core_file_binlist(RzCore *core);
RZ_API bool rz_core_file_bin_raise(RzCore *core, ut32 num);
RZ_API bool rz_core_extend_at(RzCore *core, ut64 addr, int size);
Expand Down

0 comments on commit 4b7bce5

Please sign in to comment.