Refactor output modes to use enum (#489)#929
Refactor output modes to use enum (#489)#929valdaarhun wants to merge 7 commits intorizinorg:devfrom valdaarhun:Refactor_Output_Modes
Conversation
|
|
||
| RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 size, int rad, PJ *pj, bool show_full) { | ||
| rz_return_if_fail(!(rad == 'j' && !pj)); // rad == 'j' => pj != NULL | ||
| RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 size, RzOutputMode rad, PJ *pj, bool show_full) { |
There was a problem hiding this comment.
I suggest to rename variable too rad -> mode. And everywhere else you meet unclear name for the mode.
There was a problem hiding this comment.
I have changed rad to mode wherever output modes are involved.
| @@ -339,7 +339,7 @@ RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 | |||
| break; | |||
| case 0: | |||
| case 1: | |||
| case 0: | ||
| case 1: | ||
| case '*': | ||
| case RZ_OUTPUT_MODE_RIZIN: |
There was a problem hiding this comment.
no need to define this if it goes into the default switch case.
There was a problem hiding this comment.
Ok, so I will remove all the three cases.
| case 'j': print_types_json(pdb, pj, tpi_stream->types); return; | ||
| case 'r': print_types_format(pdb, tpi_stream->types); return; | ||
| case RZ_OUTPUT_MODE_JSON: print_types_json(pdb, pj, tpi_stream->types); return; | ||
| case RZ_OUTPUT_MODE_RIZIN: print_types_format(pdb, tpi_stream->types); return; |
There was a problem hiding this comment.
i'm not sure about this switch. what currently does the 'd' command?
| rz_analysis_var_list_show(core->analysis, fcn, 'r', 0, NULL); | ||
| rz_analysis_var_list_show(core->analysis, fcn, 'b', RZ_OUTPUT_MODE_QUIET, NULL); | ||
| rz_analysis_var_list_show(core->analysis, fcn, 's', RZ_OUTPUT_MODE_QUIET, NULL); | ||
| rz_analysis_var_list_show(core->analysis, fcn, 'r', RZ_OUTPUT_MODE_QUIET, NULL); |
There was a problem hiding this comment.
i think this should be RZ_OUTPUT_MODE_STANDARD
| } | ||
| break; | ||
| case 'r': | ||
| case RZ_OUTPUT_MODE_RIZIN: |
There was a problem hiding this comment.
i'm not sure this change is correct. that 'r' is a command, not a mode.
| } | ||
| } | ||
| return 0; | ||
| return RZ_OUTPUT_MODE_QUIET; |
There was a problem hiding this comment.
not sure about this change either.
| case ':': | ||
| case '*': | ||
| if (mode == '*' || (mode == ':' && addr >= map->addr && addr < map->addr_end)) { | ||
| case 'RZ_OUTPUT_MODE_RIZIN': |
There was a problem hiding this comment.
this change doesn't make sense. the command requires to be splitted.
There was a problem hiding this comment.
@wargio I am sorry but I haven't understood what you mean by "command should be split". Do you mean I should have a separate case for mode == ':'? Also, I noticed that I have accidentally put RZ_OUTPUT_MODE_RIZIN in single quotes. I'll change that as well.
| RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 size, int rad, PJ *pj, bool show_full) { | ||
| rz_return_if_fail(!(rad == 'j' && !pj)); // rad == 'j' => pj != NULL | ||
| RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 size, RzOutputMode mode, PJ *pj, bool show_full) { | ||
| rz_return_if_fail(!(mode == RZ_OUTPUT_MODE_JSON && !pj)); // mode == 'j' => pj != NULL |
There was a problem hiding this comment.
Please also update the commentary or just remove it.
| s = strdup(pstr); | ||
| } | ||
| if (rad) { | ||
| if (mode) { |
There was a problem hiding this comment.
I don't think this should be if (mode), code doesn't make sense in JSON mode, for example. Lets just use some specific mode here.
There was a problem hiding this comment.
@XVilka Do you mean I should change it to something more specific like if (mode == RZ_OUTPUT_MODE_STANDARD)?
| } break; | ||
| case RZ_META_TYPE_STRING: | ||
| if (rad) { | ||
| if (mode) { |
| pj_ks(pj, "cond", rz_str_get(b->cond)); | ||
| pj_end(pj); | ||
| } else if (rad) { | ||
| } else if (mode) { |
There was a problem hiding this comment.
Same here, better to use a switch instead of if/else and use specific modes.
| break; | ||
| case 's': | ||
| flag_space_stack_list(core->flags, input[2]); | ||
| RzOutputMode mode; |
There was a problem hiding this comment.
You could extract this in a separate function
There was a problem hiding this comment.
@XVilka I just wanted to confirm one thing. Should I create an RZ_API defined function in this file that I can then call in every other file as well?
| } | ||
| } else { | ||
| rz_flag_list(core->flags, *input, input[0] ? input + 1 : ""); | ||
| RzOutputMode mode; |
There was a problem hiding this comment.
Same here, will also avoid duplication.
| RzAnalysisMetaItem *mi = rz_meta_get_at(core->analysis, addr, type, &size); | ||
| if (mi) { | ||
| rz_meta_print(core->analysis, mi, addr, size, input[3], NULL, false); | ||
| switch(input[3]){ |
|
ok, here is what i would do, because this PR is quite messy and big even to comment.
you can open a new PR and reference that one to this. |
|
if you prefer, we can go function by function, so we can guide you towards the resolution of the issue. |
|
I agree about step-by-step approach, but instead of one function would do one/two files per PR. This way export from this PR is easy - just use |
|
i'll close this to discuss on the other PR. |
Your checklist for this pull request
Detailed description
Refactored output modes to use enum.
int modeandchar modepatterns in the code have been replaced withRzOutputModeenum type.Refactoring is still in progress.
Test plan
...
Closing issues
closes #489