Skip to content

refactor: handle the argument parsing in a clearer way #3

@logic-finder

Description

@logic-finder

proofread/argparse.c

Lines 87 to 110 in 19a9d73

/*
FIXME: the following codes have this shape:
if (arg equals to opt_1) {
// tests to see if it is fine to take this arg
// sets the option
}
else if (arg equals to opt_2) { ... }
It seems it is possible to refactor like so:
opts = [opt_1, opt_2, ...]
handlers = [opt_1_handler, opt_2_handler, ...]
for (until the end of args) {
// checks whether arg is in opts; if exists, gets the index
// invokes the corresponding handler: handlers[index]()
}
void opt_n_handler(optflg_t *of) {
// tests to see if it is fine to take this arg
// sets the option
}
*/

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorThis code needs a refactoring

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions