From b8e5620be56aed113d59dcd6f9953cad53d58831 Mon Sep 17 00:00:00 2001 From: midipix Date: Wed, 18 Jun 2025 19:15:01 +0000 Subject: driver: pe_main(): refactor, internally use pe_cmd_common(). --- src/driver/pe_amain.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/driver/pe_amain.c b/src/driver/pe_amain.c index 2a977ad..5a925f5 100644 --- a/src/driver/pe_amain.c +++ b/src/driver/pe_amain.c @@ -57,13 +57,24 @@ static int pe_exit(struct pe_driver_ctx * dctx, int ret) return ret; } +typedef int (*pe_cmd)(const struct pe_driver_ctx *, const char *); + +static void pe_cmd_common( + const struct pe_driver_ctx * dctx, + pe_cmd cmdfn) +{ + const char ** unit; + + for (unit=dctx->units; *unit; unit++) + cmdfn(dctx,*unit); +} + int pe_main(char ** argv, char ** envp, const struct pe_fd_ctx * fdctx) { int ret; int fdout; uint64_t flags; struct pe_driver_ctx * dctx; - const char ** unit; const char * posname; const char * arname; const char ** arfiles; @@ -83,8 +94,7 @@ int pe_main(char ** argv, char ** envp, const struct pe_fd_ctx * fdctx) switch (dctx->cctx->cmd) { case PERK_CMD_PERK: - for (unit=dctx->units; *unit; unit++) - pe_cmd_perk(dctx,*unit); + pe_cmd_common(dctx,pe_cmd_perk); break; case PERK_CMD_AR: @@ -105,13 +115,11 @@ int pe_main(char ** argv, char ** envp, const struct pe_fd_ctx * fdctx) break; case PERK_CMD_NM: - for (unit=dctx->units; *unit; unit++) - pe_cmd_nm(dctx,*unit); + pe_cmd_common(dctx,pe_cmd_nm); break; case PERK_CMD_SIZE: - for (unit=dctx->units; *unit; unit++) - pe_cmd_size(dctx,*unit); + pe_cmd_common(dctx,pe_cmd_size); break; default: -- cgit v1.2.3