[Pdbg] [PATCH 0/8] Rework option parsing
Alistair Popple
alistair at popple.id.au
Wed Jun 20 15:34:01 AEST 2018
Option parsing is currently done in a very adhoc manner with each
individual command/action doing it's own parsing of arguments. This has
resulted in significant code duplication and several copy & paste errors
along with a lot of boilerplate code.
Some of this could be refactored to reduce duplication, however it would
still require tedious boilerplate functions to parse and pass arguments
through to the actual function calls. This can make it annoying to call a
series of pdbg commands/actions from within pdbg itself. It also makes
testing of command parsing logic hard as it becomes embedded in each
command.
Instead this series defines some individual argument parsers which can be
tested independently along with a general method of defining commands and
some tests.
Unfortunately this does rely on some macro magic. It is not strictly
neccessary but it does allow for type safety between command definitions
and function calls.
This series is functional but there are still a couple of items left TODO
depending on feedback from this series:
- HTM (will look at once all the fixes/refactoring has been completed)
- Help text generation. We could embed this in the general library?
- Short flag parsing
- Top-level/global/targetting flag parsing still uses the existing adhoc
methods. Should be relatively straight forward to fix when the above is
done.
Alistair Popple (8):
ccan: Add cppmagic
ccan/cppmagic: Fix NONEMPTY macro
ccan/cppmagic: Add CPPMAGIC_INC(x) macro
ccan/cppmaigc: Add CPPMAGIC_MAP_CNT(...) macro
pdbg: Add command/flag parsing definitions
pdbg: Define common command/flag argument parsers
optcmd: Add tests
pdbg: Use new command parsing
Makefile.am | 19 +++-
ccan/cppmagic/LICENSE | 1 +
ccan/cppmagic/_info | 30 ++++++
ccan/cppmagic/cppmagic.h | 257 +++++++++++++++++++++++++++++++++++++++++++++++
ccan/cppmagic/test/run.c | 92 +++++++++++++++++
src/cfam.c | 55 +++-------
src/cfam.h | 18 ----
src/main.c | 125 ++++++++++++++---------
src/mem.c | 124 ++++-------------------
src/mem.h | 20 ----
src/optcmd.c | 110 ++++++++++++++++++++
src/optcmd.h | 185 ++++++++++++++++++++++++++++++++++
src/parsers.c | 85 ++++++++++++++++
src/parsers.h | 21 ++++
src/reg.c | 164 ++++++++----------------------
src/reg.h | 20 ----
src/ring.c | 32 +-----
src/ring.h | 17 ----
src/scom.c | 54 +++-------
src/scom.h | 18 ----
src/tests/optcmd_test.c | 161 +++++++++++++++++++++++++++++
src/thread.c | 87 +++++++++++-----
src/thread.h | 23 -----
23 files changed, 1194 insertions(+), 524 deletions(-)
create mode 120000 ccan/cppmagic/LICENSE
create mode 100644 ccan/cppmagic/_info
create mode 100644 ccan/cppmagic/cppmagic.h
create mode 100644 ccan/cppmagic/test/run.c
delete mode 100644 src/cfam.h
delete mode 100644 src/mem.h
create mode 100644 src/optcmd.c
create mode 100644 src/optcmd.h
create mode 100644 src/parsers.c
create mode 100644 src/parsers.h
delete mode 100644 src/reg.h
delete mode 100644 src/ring.h
delete mode 100644 src/scom.h
create mode 100644 src/tests/optcmd_test.c
delete mode 100644 src/thread.h
--
2.11.0
More information about the Pdbg
mailing list