Move shared code to command_enum.h and avoid duplicating code.
#include "tools.h"
#endif /* MAN_PAGE_GENERATOR */
-#include "command.h" /* defines struct command */
-#include "command-count.h" /* defines COMMAND_COUNT */
/* see cmd_names[] below, one for each unique "ID" in command-lines.in */
--- /dev/null
+/*
+ * Copyright (C) 2024 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _LVM_COMMAND_ENUMS_H
+#define _LVM_COMMAND_ENUMS_H
+
+/*
+ * cmd_enum.h uses the generated cmds.h to create the enum with an ID
+ * for each command definition in command-lines.in.
+ */
+#include "lib/commands/cmd_enum.h"
+
+/* define the enums for the command line --options, foo_ARG */
+enum {
+#define arg(a, b, c, d, e, f, g) a ,
+#include "args.h"
+#undef arg
+};
+
+/* define the enums for the values accepted by command line --options, foo_VAL */
+enum {
+#define val(a, b, c, d) a ,
+#include "vals.h"
+#undef val
+};
+
+/* define enums for LV properties, foo_LVP */
+enum {
+#define lvp(a, b, c) a ,
+#include "lv_props.h"
+#undef lvp
+};
+
+/* define enums for LV types, foo_LVT */
+enum {
+#define lvt(a, b, c) a ,
+#include "lv_types.h"
+#undef lvt
+};
+
+#define PERMITTED_READ_ONLY 0x00000002
+/* Process all VGs if none specified on the command line. */
+#define ALL_VGS_IS_DEFAULT 0x00000004
+/* Process all devices with --all if none are specified on the command line. */
+#define ENABLE_ALL_DEVS 0x00000008
+/* Command may try to interpret a vgname arg as a uuid. */
+#define ALLOW_UUID_AS_NAME 0x00000010
+/* Command needs a shared lock on a VG; it only reads the VG. */
+#define LOCKD_VG_SH 0x00000020
+/* Command does not process any metadata. */
+#define NO_METADATA_PROCESSING 0x00000040
+/* Command must use all specified arg names and fail if all cannot be used. */
+#define MUST_USE_ALL_ARGS 0x00000100
+/* Command should process unused duplicate devices. */
+#define ENABLE_DUPLICATE_DEVS 0x00000400
+/* Command does not accept tags as args. */
+#define DISALLOW_TAG_ARGS 0x00000800
+/* Command may need to find VG name in an option value. */
+#define GET_VGNAME_FROM_OPTIONS 0x00001000
+/* The data read from disk by label scan can be used for vg_read. */
+#define CAN_USE_ONE_SCAN 0x00002000
+/* Command can use hints file */
+#define ALLOW_HINTS 0x00004000
+/* Command can access exported vg. */
+#define ALLOW_EXPORTED 0x00008000
+/* Command checks and reports warning if devs used by LV are incorrect. */
+#define CHECK_DEVS_USED 0x00010000
+/* Command prints devices file entries that were not found. */
+#define DEVICE_ID_NOT_FOUND 0x00020000
+
+#include "command.h" /* defines struct command */
+#include "command-count.h" /* defines COMMAND_COUNT */
+
+#endif /* _LVM_COMMAND_ENUMS_H */
static inline int dumptype_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av) { return 0; }
static inline int headings_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av) { return 0; }
-/* needed to include commands.h when building man page generator */
-#define CACHE_VGMETADATA 0x00000001
-#define PERMITTED_READ_ONLY 0x00000002
-#define ALL_VGS_IS_DEFAULT 0x00000004
-#define ENABLE_ALL_DEVS 0x00000008
-#define ALLOW_UUID_AS_NAME 0x00000010
-#define LOCKD_VG_SH 0x00000020
-#define NO_METADATA_PROCESSING 0x00000040
-#define MUST_USE_ALL_ARGS 0x00000100
-#define ENABLE_DUPLICATE_DEVS 0x00000400
-#define DISALLOW_TAG_ARGS 0x00000800
-#define GET_VGNAME_FROM_OPTIONS 0x00001000
-#define CAN_USE_ONE_SCAN 0x00002000
-#define ALLOW_HINTS 0x00004000
-#define ALLOW_EXPORTED 0x00008000
-#define CHECK_DEVS_USED 0x00010000
-#define DEVICE_ID_NOT_FOUND 0x00020000
-
-/* create foo_CMD enums for command def ID's in command-lines.in */
-
-enum {
-#define cmd(a, b) a ,
-#include "../include/cmds.h"
-#undef cmd
-};
-
-/* create foo_VAL enums for option and position values */
-
-enum {
-#define val(a, b, c, d) a ,
-#include "vals.h"
-#undef val
-};
-
-/* create foo_ARG enums for --option's */
-
-enum {
-#define arg(a, b, c, d, e, f, g) a ,
-#include "args.h"
-#undef arg
-};
-
-/* create foo_LVP enums for LV properties */
-
-enum {
-#define lvp(a, b, c) a,
-#include "lv_props.h"
-#undef lvp
-};
-
-/* create foo_LVT enums for LV types */
-
-enum {
-#define lvt(a, b, c) a,
-#include "lv_types.h"
-#undef lvt
-};
-
#define MAN_PAGE_GENERATOR
+#include "command_enums.h"
#include "command.c"
static const size_t _LONG_LINE = 42; /* length of line that neededs .nh .. .hy */
#include "lib/notify/lvmnotify.h"
#include "lib/label/hints.h"
-/*
- * cmd_enum.h uses the generated cmds.h to create the enum with an ID
- * for each command definition in command-lines.in.
- */
-#include "lib/commands/cmd_enum.h"
-
#include <ctype.h>
#include <sys/types.h>
#define CMD_LEN 256
#define MAX_ARGS 64
-/* define the enums for the values accepted by command line --options, foo_VAL */
-enum {
-#define val(a, b, c, d) a ,
-#include "vals.h"
-#undef val
-};
-
-/* define the enums for the command line --options, foo_ARG */
-enum {
-#define arg(a, b, c, d, e, f, g) a ,
-#include "args.h"
-#undef arg
-};
+#include "command_enums.h"
/* command functions */
#define xx(a, b...) int a(struct cmd_context *cmd, int argc, char **argv);
#include "commands.h"
#undef xx
-/* define enums for LV properties, foo_LVP */
-enum {
-#define lvp(a, b, c) a ,
-#include "lv_props.h"
-#undef lvp
-};
-
-/* define enums for LV types, foo_LVT */
-enum {
-#define lvt(a, b, c) a ,
-#include "lv_types.h"
-#undef lvt
-};
-
-#include "command.h"
-#include "command-count.h"
-
#define ARG_COUNTABLE 0x00000001 /* E.g. -vvvv */
#define ARG_GROUPABLE 0x00000002 /* E.g. --addtag */
#define ARG_NONINTERACTIVE 0x00000004 /* only for use in noninteractive mode */
struct arg_values arg_values[];
};
-#define PERMITTED_READ_ONLY 0x00000002
-/* Process all VGs if none specified on the command line. */
-#define ALL_VGS_IS_DEFAULT 0x00000004
-/* Process all devices with --all if none are specified on the command line. */
-#define ENABLE_ALL_DEVS 0x00000008
-/* Command may try to interpret a vgname arg as a uuid. */
-#define ALLOW_UUID_AS_NAME 0x00000010
-/* Command needs a shared lock on a VG; it only reads the VG. */
-#define LOCKD_VG_SH 0x00000020
-/* Command does not process any metadata. */
-#define NO_METADATA_PROCESSING 0x00000040
-/* Command must use all specified arg names and fail if all cannot be used. */
-#define MUST_USE_ALL_ARGS 0x00000100
-/* Command should process unused duplicate devices. */
-#define ENABLE_DUPLICATE_DEVS 0x00000400
-/* Command does not accept tags as args. */
-#define DISALLOW_TAG_ARGS 0x00000800
-/* Command may need to find VG name in an option value. */
-#define GET_VGNAME_FROM_OPTIONS 0x00001000
-/* The data read from disk by label scan can be used for vg_read. */
-#define CAN_USE_ONE_SCAN 0x00002000
-/* Command can use hints file */
-#define ALLOW_HINTS 0x00004000
-/* Command can access exported vg. */
-#define ALLOW_EXPORTED 0x00008000
-/* Command checks and reports warning if devs used by LV are incorrect. */
-#define CHECK_DEVS_USED 0x00010000
-/* Command prints devices file entries that were not found. */
-#define DEVICE_ID_NOT_FOUND 0x00020000
-
-
void usage(const char *name);
/* the argument verify/normalise functions */