"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Christian Weisgerber <naddy@mips.inka.de>
Subject:
const-ify tables
To:
gameoftrees@openbsd.org
Date:
Tue, 15 Feb 2022 19:39:07 +0100

Download raw body.

Thread
const-ify command and option tables

Did I miss any?  OK?

diff 28526235ae6336b37d0f79a3c266c3a92587f279 /home/naddy/got
blob - 7d8663fbddd35a7c2dca7773ddeda8f1c7abffa4
file + got/got.c
--- got/got.c
+++ got/got.c
@@ -145,7 +145,7 @@ static const struct got_error*		cmd_unstage(int, char 
 static const struct got_error*		cmd_cat(int, char *[]);
 static const struct got_error*		cmd_info(int, char *[]);
 
-static struct got_cmd got_commands[] = {
+static const struct got_cmd got_commands[] = {
 	{ "init",	cmd_init,	usage_init,	"" },
 	{ "import",	cmd_import,	usage_import,	"im" },
 	{ "clone",	cmd_clone,	usage_clone,	"cl" },
@@ -184,7 +184,7 @@ list_commands(FILE *fp)
 
 	fprintf(fp, "commands:");
 	for (i = 0; i < nitems(got_commands); i++) {
-		struct got_cmd *cmd = &got_commands[i];
+		const struct got_cmd *cmd = &got_commands[i];
 		fprintf(fp, " %s", cmd->cmd_name);
 	}
 	fputc('\n', fp);
@@ -199,11 +199,11 @@ option_conflict(char a, char b)
 int
 main(int argc, char *argv[])
 {
-	struct got_cmd *cmd;
+	const struct got_cmd *cmd;
 	size_t i;
 	int ch;
 	int hflag = 0, Vflag = 0;
-	static struct option longopts[] = {
+	static const struct option longopts[] = {
 	    { "version", no_argument, NULL, 'V' },
 	    { NULL, 0, NULL, 0 }
 	};
@@ -250,9 +250,9 @@ main(int argc, char *argv[])
 			continue;
 
 		if (hflag)
-			got_commands[i].cmd_usage();
+			cmd->cmd_usage();
 
-		error = got_commands[i].cmd_main(argc, argv);
+		error = cmd->cmd_main(argc, argv);
 		if (error && error->code != GOT_ERR_CANCELLED &&
 		    error->code != GOT_ERR_PRIVSEP_EXIT &&
 		    !(sigpipe_received &&
@@ -9374,7 +9374,7 @@ usage_histedit(void)
 #define GOT_HISTEDIT_DROP 'd'
 #define GOT_HISTEDIT_MESG 'm'
 
-static struct got_histedit_cmd {
+static const struct got_histedit_cmd {
 	unsigned char code;
 	const char *name;
 	const char *desc;
@@ -9493,7 +9493,7 @@ write_cmd_list(FILE *f, const char *branch_name,
 	}
 
 	for (i = 0; i < nitems(got_histedit_cmds); i++) {
-		struct got_histedit_cmd *cmd = &got_histedit_cmds[i];
+		const struct got_histedit_cmd *cmd = &got_histedit_cmds[i];
 		n = fprintf(f, "#   %s (%c): %s\n", cmd->name, cmd->code,
 		    cmd->desc);
 		if (n < 0) {
blob - 9bf9bdbfc8e7f58c5245c1b799e93299b67d828f
file + gotadmin/gotadmin.c
--- gotadmin/gotadmin.c
+++ gotadmin/gotadmin.c
@@ -91,7 +91,7 @@ static const struct got_error*		cmd_indexpack(int, cha
 static const struct got_error*		cmd_listpack(int, char *[]);
 static const struct got_error*		cmd_cleanup(int, char *[]);
 
-static struct gotadmin_cmd gotadmin_commands[] = {
+static const struct gotadmin_cmd gotadmin_commands[] = {
 	{ "info",	cmd_info,	usage_info,	"" },
 	{ "pack",	cmd_pack,	usage_pack,	"" },
 	{ "indexpack",	cmd_indexpack,	usage_indexpack,"ix" },
@@ -106,7 +106,7 @@ list_commands(FILE *fp)
 
 	fprintf(fp, "commands:");
 	for (i = 0; i < nitems(gotadmin_commands); i++) {
-		struct gotadmin_cmd *cmd = &gotadmin_commands[i];
+		const struct gotadmin_cmd *cmd = &gotadmin_commands[i];
 		fprintf(fp, " %s", cmd->cmd_name);
 	}
 	fputc('\n', fp);
@@ -115,11 +115,11 @@ list_commands(FILE *fp)
 int
 main(int argc, char *argv[])
 {
-	struct gotadmin_cmd *cmd;
+	const struct gotadmin_cmd *cmd;
 	size_t i;
 	int ch;
 	int hflag = 0, Vflag = 0;
-	static struct option longopts[] = {
+	static const struct option longopts[] = {
 	    { "version", no_argument, NULL, 'V' },
 	    { NULL, 0, NULL, 0 }
 	};
@@ -166,9 +166,9 @@ main(int argc, char *argv[])
 			continue;
 
 		if (hflag)
-			gotadmin_commands[i].cmd_usage();
+			cmd->cmd_usage();
 
-		error = gotadmin_commands[i].cmd_main(argc, argv);
+		error = cmd->cmd_main(argc, argv);
 		if (error && error->code != GOT_ERR_CANCELLED &&
 		    error->code != GOT_ERR_PRIVSEP_EXIT &&
 		    !(sigpipe_received &&
blob - 280413b8f66e5256382c5cabb2bf2dc5dbb4bfc5
file + tog/tog.c
--- tog/tog.c
+++ tog/tog.c
@@ -88,7 +88,7 @@ static const struct got_error*	cmd_blame(int, char *[]
 static const struct got_error*	cmd_tree(int, char *[]);
 static const struct got_error*	cmd_ref(int, char *[]);
 
-static struct tog_cmd tog_commands[] = {
+static const struct tog_cmd tog_commands[] = {
 	{ "log",	cmd_log,	usage_log },
 	{ "diff",	cmd_diff,	usage_diff },
 	{ "blame",	cmd_blame,	usage_blame },
@@ -6502,7 +6502,7 @@ list_commands(FILE *fp)
 
 	fprintf(fp, "commands:");
 	for (i = 0; i < nitems(tog_commands); i++) {
-		struct tog_cmd *cmd = &tog_commands[i];
+		const struct tog_cmd *cmd = &tog_commands[i];
 		fprintf(fp, " %s", cmd->name);
 	}
 	fputc('\n', fp);
@@ -6555,7 +6555,7 @@ static const struct got_error *
 tog_log_with_path(int argc, char *argv[])
 {
 	const struct got_error *error = NULL, *close_err;
-	struct tog_cmd *cmd = NULL;
+	const struct tog_cmd *cmd = NULL;
 	struct got_repository *repo = NULL;
 	struct got_worktree *worktree = NULL;
 	struct got_object_id *commit_id = NULL, *id = NULL;
@@ -6653,10 +6653,10 @@ int
 main(int argc, char *argv[])
 {
 	const struct got_error *error = NULL;
-	struct tog_cmd *cmd = NULL;
+	const struct tog_cmd *cmd = NULL;
 	int ch, hflag = 0, Vflag = 0;
 	char **cmd_argv = NULL;
-	static struct option longopts[] = {
+	static const struct option longopts[] = {
 	    { "version", no_argument, NULL, 'V' },
 	    { NULL, 0, NULL, 0}
 	};
-- 
Christian "naddy" Weisgerber                          naddy@mips.inka.de