summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2021-08-12 12:31:17 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2021-08-12 12:31:17 +0000
commitd90e2001ca3c890f76b726413c3601f6cb4236b5 (patch)
tree98d0db2109b53c6f732577d72f4d6f3bb8e60e62 /sbin
parentf918755f0fecb4870f7e04602e248f78c23a56b1 (diff)
Further reduce cross-file confusion by adding USER_help() and
calling it from Xhelp(). Move declaration of struct cmd to nestle next to its only instantiation (cmd_table) and use nitems() when scanning cmd_table. No functional change.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/fdisk/cmd.c18
-rw-r--r--sbin/fdisk/cmd.h10
-rw-r--r--sbin/fdisk/misc.h6
-rw-r--r--sbin/fdisk/part.c6
-rw-r--r--sbin/fdisk/user.c32
-rw-r--r--sbin/fdisk/user.h3
6 files changed, 40 insertions, 35 deletions
diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c
index ba6c5f742b4..af2fd613b31 100644
--- a/sbin/fdisk/cmd.c
+++ b/sbin/fdisk/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.137 2021/08/07 13:37:50 krw Exp $ */
+/* $OpenBSD: cmd.c,v 1.138 2021/08/12 12:31:16 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -482,21 +482,7 @@ Xexit(char *args, struct mbr *mbr)
int
Xhelp(char *args, struct mbr *mbr)
{
- char help[80];
- char *mbrstr;
- int i;
-
- for (i = 0; cmd_table[i].cmd_name != NULL; i++) {
- strlcpy(help, cmd_table[i].cmd_help, sizeof(help));
- if (letoh64(gh.gh_sig) == GPTSIGNATURE) {
- if (cmd_table[i].cmd_gpt == 0)
- continue;
- mbrstr = strstr(help, "MBR");
- if (mbrstr)
- memcpy(mbrstr, "GPT", 3);
- }
- printf("\t%s\t\t%s\n", cmd_table[i].cmd_name, help);
- }
+ USER_help();
return CMD_CONT;
}
diff --git a/sbin/fdisk/cmd.h b/sbin/fdisk/cmd.h
index ffa270133fa..0997ba4ac6d 100644
--- a/sbin/fdisk/cmd.h
+++ b/sbin/fdisk/cmd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.h,v 1.23 2021/07/12 22:18:54 krw Exp $ */
+/* $OpenBSD: cmd.h,v 1.24 2021/08/12 12:31:16 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -25,14 +25,6 @@
#define CMD_CLEAN 0x0003
#define CMD_DIRTY 0x0004
-struct cmd {
- char *cmd_name;
- int cmd_gpt;
- int (*cmd_fcn)(char *, struct mbr *);
- char *cmd_help;
-};
-extern const struct cmd cmd_table[];
-
int Xreinit(char *, struct mbr *);
int Xdisk(char *, struct mbr *);
int Xmanual(char *, struct mbr *);
diff --git a/sbin/fdisk/misc.h b/sbin/fdisk/misc.h
index 9acfba50b6c..1b95e853716 100644
--- a/sbin/fdisk/misc.h
+++ b/sbin/fdisk/misc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.h,v 1.39 2021/07/12 22:18:54 krw Exp $ */
+/* $OpenBSD: misc.h,v 1.40 2021/08/12 12:31:16 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -27,6 +27,10 @@ struct unit_type {
extern struct unit_type unit_types[];
#define SECTORS 1
+#ifndef nitems
+#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
+#endif
+
/* Prototypes */
int unit_lookup(const char *);
int string_from_line(char *, const size_t);
diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c
index 3deaf7b030c..e2c09945296 100644
--- a/sbin/fdisk/part.c
+++ b/sbin/fdisk/part.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: part.c,v 1.102 2021/07/22 13:30:40 krw Exp $ */
+/* $OpenBSD: part.c,v 1.103 2021/08/12 12:31:16 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -152,10 +152,6 @@ static const struct protected_guid {
{ "2e54b353-1271-4842-806f-e436d6af6985" }, /* HiFive BBL */
};
-#ifndef nitems
-#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
-#endif
-
int
PRT_protected_guid(const struct uuid *uuid)
{
diff --git a/sbin/fdisk/user.c b/sbin/fdisk/user.c
index 05a644eaac0..3ea302e486d 100644
--- a/sbin/fdisk/user.c
+++ b/sbin/fdisk/user.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: user.c,v 1.70 2021/08/10 13:48:34 krw Exp $ */
+/* $OpenBSD: user.c,v 1.71 2021/08/12 12:31:16 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -31,6 +31,13 @@
#include "gpt.h"
#include "disk.h"
+struct cmd {
+ char *cmd_name;
+ int cmd_gpt;
+ int (*cmd_fcn)(char *, struct mbr *);
+ char *cmd_help;
+};
+
const struct cmd cmd_table[] = {
{"help", 1, Xhelp, "Command help list"},
{"manual", 1, Xmanual, "Show entire OpenBSD man page for fdisk"},
@@ -47,7 +54,6 @@ const struct cmd cmd_table[] = {
{"exit", 1, Xexit, "Exit edit of current MBR, without saving changes"},
{"quit", 1, Xquit, "Quit edit of current MBR, saving current changes"},
{"abort", 1, Xabort, "Abort program without saving current changes"},
- {NULL, 0, NULL, NULL}
};
@@ -86,7 +92,7 @@ again:
if (cmd[0] == '\0')
continue;
- for (i = 0; cmd_table[i].cmd_name != NULL; i++)
+ for (i = 0; i < nitems(cmd_table); i++)
if (strstr(cmd_table[i].cmd_name, cmd) == cmd_table[i].cmd_name)
break;
@@ -177,6 +183,26 @@ USER_print_disk(const int verbosity)
}
void
+USER_help(void)
+{
+ char help[80];
+ char *mbrstr;
+ int i;
+
+ for (i = 0; i < nitems(cmd_table); i++) {
+ strlcpy(help, cmd_table[i].cmd_help, sizeof(help));
+ if (letoh64(gh.gh_sig) == GPTSIGNATURE) {
+ if (cmd_table[i].cmd_gpt == 0)
+ continue;
+ mbrstr = strstr(help, "MBR");
+ if (mbrstr)
+ memcpy(mbrstr, "GPT", 3);
+ }
+ printf("\t%s\t\t%s\n", cmd_table[i].cmd_name, help);
+ }
+}
+
+void
ask_cmd(char **cmd, char **arg)
{
static char lbuf[100];
diff --git a/sbin/fdisk/user.h b/sbin/fdisk/user.h
index 522be670550..f560bd70633 100644
--- a/sbin/fdisk/user.h
+++ b/sbin/fdisk/user.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: user.h,v 1.19 2021/07/13 15:03:34 krw Exp $ */
+/* $OpenBSD: user.h,v 1.20 2021/08/12 12:31:16 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -22,5 +22,6 @@
/* Prototypes */
void USER_edit(const uint64_t, const uint64_t);
void USER_print_disk(const int);
+void USER_help(void);
#endif /* _USER_H */