summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-07-18 02:55:10 -0400
committerIan Moffett <ian@osmora.org>2025-07-18 02:56:32 -0400
commit03853799060b9e1cca5b9ffa9609aac3b74f94e0 (patch)
tree30025b0c2b9154221305819a8e2cdf3c33066917
parent125ac66c648b2c901c9d7c0a7bcef7929b85be63 (diff)
usr: nerve: Convert nerve name in nerve_to_def()
Add helper to convert nerve name into numeric nerve type so that peek_nerve() may be implemented while keeping things clean. Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--usr.bin/nerve/nerve.c56
1 files changed, 38 insertions, 18 deletions
diff --git a/usr.bin/nerve/nerve.c b/usr.bin/nerve/nerve.c
index a7d39d8..a2a95fc 100644
--- a/usr.bin/nerve/nerve.c
+++ b/usr.bin/nerve/nerve.c
@@ -57,6 +57,7 @@
struct verb_handler;
static int poke_nerve(const char *nerve, struct verb_handler *h);
+static int nerve_to_def(const char *nerve);
/*
* Contains verb handlers called when a verb
@@ -170,24 +171,18 @@ poke_nerve(const char *nerve, struct verb_handler *h)
return -EINVAL;
}
- /*
- * Now we need to parse the nerve string
- * and see if it matches with anything
- * that we know.
- */
- switch (*nerve) {
- case 'c':
- if (strcmp(nerve, SNERVE_CONSATTR) == 0) {
- nerve_idx = NERVE_CONSATTR;
- } else if (strcmp(nerve, SNERVE_CONSFEAT) == 0) {
- nerve_idx = NERVE_CONSFEAT;
- }
+ /* Grab the nerve table index */
+ nerve_idx = nerve_to_def(nerve);
+ if (nerve_idx == NERVE_UNKNOWN) {
+ printf("[&^]: This is not my nerve.\n");
+ return -1;
+ }
- error = get_nerve_payload(h->argc, h->argv, &payload);
- if (error < 0) {
- printf("[!] nerve error\n");
- return -1;
- }
+ /* Grab the payload passed by the user */
+ error = get_nerve_payload(h->argc, h->argv, &payload);
+ if (error < 0) {
+ printf("[!] nerve error\n");
+ return -1;
}
switch (nerve_idx) {
@@ -218,7 +213,6 @@ poke_nerve(const char *nerve, struct verb_handler *h)
break;
}
default:
- printf("[&^]: This is not my nerve.\n");
break;
}
@@ -226,6 +220,32 @@ poke_nerve(const char *nerve, struct verb_handler *h)
}
/*
+ * Convert a nerve name into a numeric nerve
+ * definition
+ *
+ * @nerve: Nerve name to convert
+ */
+static int
+nerve_to_def(const char *nerve)
+{
+ /*
+ * Now we need to parse the nerve string
+ * and see if it matches with anything
+ * that we know.
+ */
+ switch (*nerve) {
+ case 'c':
+ if (strcmp(nerve, SNERVE_CONSATTR) == 0) {
+ return NERVE_CONSATTR;
+ } else if (strcmp(nerve, SNERVE_CONSFEAT) == 0) {
+ return NERVE_CONSFEAT;
+ }
+ }
+
+ return NERVE_UNKNOWN;
+}
+
+/*
* Convert a string verb, passed in through the command
* line, into a numeric definition
*