commit f934f7f636baa18b6d873e7d64e6ac3c3d10df1f
parent 300c803bc6c0534c5df6cf30bb895fa6257ab324
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Mon, 4 Jan 2021 23:48:30 -0800
Improve const usage
Change where const resides on most everything, remove const casting,
if it warns me I can ignore it, but not suppress it.
Diffstat:
7 files changed, 68 insertions(+), 67 deletions(-)
diff --git a/command.c b/command.c
@@ -12,7 +12,7 @@
#define LOCAL /* functions local to this file */
int
-cextern(int argc, const char **argv, int ino, char **item)
+cextern(int argc, char const **argv, int ino, char const **item)
{
char url[MY_URL_MAX];
int i;
@@ -30,7 +30,7 @@ cextern(int argc, const char **argv, int ino, char **item)
warn("unable to fork");
return FAIL;
case 0:
- execvp(*argv, (char *const *)argv);
+ execvp(*argv, argv);
warn("execvp '%s'", *argv);
_exit(1);
}
@@ -39,7 +39,7 @@ cextern(int argc, const char **argv, int ino, char **item)
}
LOCAL int
-timid_gopher(const char **addr, const char *path)
+timid_gopher(char const **addr, char const *path)
{
if (!exists(path))
return gopher(addr, path);
@@ -48,9 +48,9 @@ timid_gopher(const char **addr, const char *path)
}
int
-cfetch(int argc, const char **argv, int ino, char **item)
+cfetch(int argc, char const **argv, int ino, char const **item)
{
- const char *path;
+ char const *path;
if (warg(1, 2, argc, argv))
return FAIL;
@@ -72,7 +72,7 @@ cfetch(int argc, const char **argv, int ino, char **item)
}
int
-cgoto(int argc, const char **argv, int ino, char **item)
+cgoto(int argc, char const **argv, int ino, char const **item)
{
warg(1, 1, argc, argv);
/* TODO: implement 7 type support */
@@ -83,7 +83,7 @@ cgoto(int argc, const char **argv, int ino, char **item)
}
int
-cprint(int argc, const char **argv, int ino, char **item)
+cprint(int argc, char const **argv, int ino, char const **item)
{
warg(1, 2, argc, argv);
@@ -102,7 +102,7 @@ cprint(int argc, const char **argv, int ino, char **item)
}
int
-findex(int argc, const char **argv, int ino, char **item)
+findex(int argc, char const **argv, int ino, char const **item)
{
int i;
unsigned int n;
@@ -120,7 +120,7 @@ findex(int argc, const char **argv, int ino, char **item)
}
int
-frange(int argc, const char **argv, int ino, char **item)
+frange(int argc, char const **argv, int ino, char const **item)
{
int i, j;
unsigned int range[2];
@@ -148,7 +148,7 @@ frange(int argc, const char **argv, int ino, char **item)
}
int
-fstring(int argc, const char **argv, int ino, char **item)
+fstring(int argc, char const **argv, int ino, char const **item)
{
int i;
@@ -161,7 +161,7 @@ fstring(int argc, const char **argv, int ino, char **item)
}
int
-ftype(int argc, const char **argv, int ino, char **item)
+ftype(int argc, char const **argv, int ino, char const **item)
{
if (warg(2, 2, argc, argv))
return FAIL;
@@ -171,16 +171,16 @@ ftype(int argc, const char **argv, int ino, char **item)
}
int
-sexit(int argc, const char **argv, int depth, char **addr)
+sexit(int argc, char const **argv, int depth, char const **addr)
{
warg(1, 1, argc, argv);
return depth;
}
int
-sgoto(int argc, const char **argv, int depth, char **addr)
+sgoto(int argc, char const **argv, int depth, char const **addr)
{
- const char *newaddr[AR_NULL];
+ char const *newaddr[AR_NULL];
if (warg(1, 4, argc, argv))
return ERROR;
@@ -202,7 +202,7 @@ sgoto(int argc, const char **argv, int depth, char **addr)
}
int
-sunwind(int argc, const char **argv, int depth, char **addr)
+sunwind(int argc, char const **argv, int depth, char const **addr)
{
unsigned int n;
diff --git a/command.h b/command.h
@@ -1,16 +1,16 @@
#ifndef _command_h
#define _command_h
-int cextern(int, const char **, int, char **);
-int cfetch(int, const char **, int, char **);
-int cgoto(int, const char **, int, char **);
-int cprint(int, const char **, int, char **);
-int findex(int, const char **, int, char **);
-int frange(int, const char **, int, char **);
-int fstring(int, const char **, int, char **);
-int ftype(int, const char **, int, char **);
-int sexit(int, const char **, int, char **);
-int sgoto(int, const char **, int, char **);
-int sunwind(int, const char **, int, char **);
+int cextern(int, char const **, int, char const **);
+int cfetch(int, char const **, int, char const **);
+int cgoto(int, char const **, int, char const **);
+int cprint(int, char const **, int, char const **);
+int findex(int, char const **, int, char const **);
+int frange(int, char const **, int, char const **);
+int fstring(int, char const **, int, char const **);
+int ftype(int, char const **, int, char const **);
+int sexit(int, char const **, int, char const **);
+int sgoto(int, char const **, int, char const **);
+int sunwind(int, char const **, int, char const **);
#endif /* _command_h */
diff --git a/config.def.h b/config.def.h
@@ -2,7 +2,7 @@
#include "gawk.h"
/* default gopher hole (path, host, port): */
-static const char *default_address[] = { "/", "localhost", "70" };
+static char *const default_address[] = { "/", "localhost", "70" };
/* how long to wait for response */
static int timeout = 5 * 1000;
diff --git a/gawk.h b/gawk.h
@@ -8,15 +8,15 @@ enum gphitem { GI_INFO, GI_PATH, GI_HOST, GI_PORT, GI_PLUS, GI_NULL };
enum status { ERROR = -1, OK, UNWIND };
enum pipe_status { FAIL = -2, NEXT, PASS };
-typedef int (command)(int, const char **, int, char **);
+typedef int (command)(int, char const **, int, char const **);
struct command {
int c;
command *f;
};
-char **const itemtoaddr(char **const);
-int gopher(const char **, const char *);
-int gawk(const char **);
+char const **itemtoaddr(char const **);
+int gopher(char const **, char const *);
+int gawk(char const **);
#endif /* _gawk_h */
diff --git a/main.c b/main.c
@@ -37,14 +37,14 @@
static char tmpdir[] = "/tmp/gawk-XXXXXXXXXXX";
static int fatal;
-char **const
-itemtoaddr(char **const request)
+char const **
+itemtoaddr(char const **request)
{
return request + 1;
}
int
-argsplit(char **argv, int size, char *s, const char *sep, int concatenate)
+argsplit(char const **argv, int size, char *s, char const *const sep, int concatenate)
{
int argc;
@@ -61,7 +61,7 @@ argsplit(char **argv, int size, char *s, const char *sep, int concatenate)
}
int
-resolve(const char *host, const char *port)
+resolve(char const *const host, char const *const port)
{
int error, s;
struct addrinfo hints;
@@ -95,7 +95,7 @@ resolve(const char *host, const char *port)
}
void
-putprompt(const char *prompt)
+putprompt(char const *const prompt)
{
if (isatty(STDIN_FILENO))
fputs(prompt, stderr);
@@ -104,7 +104,8 @@ putprompt(const char *prompt)
}
int
-input(char *buf, int size, const char *delims, const char *prompt, FILE *fp)
+input(char *buf, int size, char const *const delims, char const *const prompt,
+ FILE *fp)
{
int next;
static unsigned int len;
@@ -139,7 +140,7 @@ too_big:
}
int
-gph_send(int sock, const char *message)
+gph_send(int sock, char const *const message)
{
char tmp[MY_PATH_MAX];
int n;
@@ -166,7 +167,7 @@ gph_send(int sock, const char *message)
}
int
-gph_recvto(int sock, const char *path)
+gph_recvto(int sock, char const *const path)
{
FILE *fp;
char buf[CHUNK_SIZE];
@@ -195,7 +196,7 @@ gph_recvto(int sock, const char *path)
}
int
-gopher(const char **addr, const char *path)
+gopher(char const **addr, char const *const path)
{
int sock;
@@ -212,7 +213,7 @@ gopher(const char **addr, const char *path)
}
int
-gphsplit(char **item, int size, char *buf)
+gphsplit(char const **item, int size, char *buf)
{
int n;
@@ -223,7 +224,7 @@ gphsplit(char **item, int size, char *buf)
}
command *
-get_command(const char *s, const struct command *commands, size_t size)
+get_command(char const *s, const struct command *commands, size_t size)
{
int i;
@@ -236,8 +237,8 @@ get_command(const char *s, const struct command *commands, size_t size)
}
int
-runpipe(int count, command **commands, int *indexes, const int *acs,
- const char *avs[MY_PIPE_MAX][MY_ARGV_MAX], char **item)
+runpipe(int count, command **commands, int *indexes, int *acs,
+ char const *avs[MY_PIPE_MAX][MY_ARGV_MAX], char const **item)
{
int i;
int r;
@@ -251,12 +252,12 @@ runpipe(int count, command **commands, int *indexes, const int *acs,
}
int
-pipeitems(const char *cache, int count, const command **commands,
- const int *acs, const char *avs[MY_PIPE_MAX][MY_ARGV_MAX])
+pipeitems(char const *cache, int count, command **const commands,
+ int *acs, char const *avs[MY_PIPE_MAX][MY_ARGV_MAX])
{
FILE *fp;
char buf[MY_LINE_MAX];
- char *item[GI_NULL + 2];
+ char const *item[GI_NULL + 2];
int error;
int indexes[count];
@@ -276,7 +277,7 @@ pipeitems(const char *cache, int count, const command **commands,
}
int
-run_command(int argc, const char **argv, int depth, const char **addr)
+run_command(int argc, char const **argv, int depth, char const **addr)
{
command *c;
@@ -289,9 +290,9 @@ run_command(int argc, const char **argv, int depth, const char **addr)
}
int
-execute(const char *cache, char *input, int depth, const char **addr)
+execute(char const *cache, char *input, int depth, char const **addr)
{
- char *avs[MY_PIPE_MAX][MY_ARGV_MAX];
+ char const *avs[MY_PIPE_MAX][MY_ARGV_MAX];
char *cbufs[MY_PIPE_MAX];
command *commands[MY_PIPE_MAX];
int acs[MY_PIPE_MAX];
@@ -329,7 +330,7 @@ execute(const char *cache, char *input, int depth, const char **addr)
}
void
-tmp_mkpath(char *cache, const char **addr)
+tmp_mkpath(char *cache, char const **addr)
{
char tmp[MY_PATH_MAX];
@@ -338,7 +339,7 @@ tmp_mkpath(char *cache, const char **addr)
}
int
-gawk(const char **addr)
+gawk(char const **addr)
{
static int depth;
char cache[MY_PATH_MAX];
@@ -413,7 +414,7 @@ sighandler(int sig)
}
int
-main(int argc, char *argv[])
+main(int argc, char const *argv[])
{
int status;
@@ -432,7 +433,7 @@ main(int argc, char *argv[])
if (mkdtemp(tmpdir) == NULL)
err(1, "mkdtemp '%s'", tmpdir);
- status = sgoto(argc, (const char **)argv, 0, default_address);
+ status = sgoto(argc, argv, 0, default_address);
if (wremove(tmpdir) == -1)
return 1;
diff --git a/util.c b/util.c
@@ -6,7 +6,7 @@
#include <unistd.h>
FILE *
-wfopen(const char *path, const char *mode)
+wfopen(char const *path, char const *mode)
{
FILE *fp;
@@ -17,7 +17,7 @@ wfopen(const char *path, const char *mode)
}
int
-exists(const char *path)
+exists(char const *path)
{
struct stat sb;
@@ -29,7 +29,7 @@ exists(const char *path)
}
int
-strtorange(unsigned int *r, unsigned int min, unsigned int max, const char *s)
+strtorange(unsigned int *r, unsigned int min, unsigned int max, char const *s)
{
char *ep;
unsigned long n;
@@ -48,7 +48,7 @@ strtorange(unsigned int *r, unsigned int min, unsigned int max, const char *s)
}
int
-warg(int min, int max, int argc, const char **ap)
+warg(int min, int max, int argc, char const **ap)
{
if (max > 0 && argc > max) {
warnx("%s: '%s' and %d more arguments unused.",
@@ -75,7 +75,7 @@ wfclose(FILE *fp)
}
int
-wremove(const char *path)
+wremove(char const *path)
{
if (remove(path)) {
warn("unable to remove '%s'", path);
@@ -85,7 +85,7 @@ wremove(const char *path)
}
void
-tr(char *r, const char *s, int orig, int repl)
+tr(char *r, char const *s, int orig, int repl)
{
for (; *s != '\0'; ++s, ++r)
if (*s == orig)
diff --git a/util.h b/util.h
@@ -3,12 +3,12 @@
#include <stdio.h>
-FILE *wfopen(const char *, const char *);
-int exists(const char *);
-int strtorange(unsigned int *r, unsigned int min, unsigned int max, const char *s);
-int warg(int, int, int, const char **);
-int wfclose(FILE *);
-int wremove(const char *);
-void tr(char *, const char *, int, int);
+FILE * wfopen(char const *, char const *);
+int exists(char const *);
+int strtorange(unsigned int *, unsigned int, unsigned int, char const *);
+int warg(int, int, int, char const **);
+int wfclose(FILE *);
+int wremove(char const *);
+void tr(char *, char const *, int, int);
#endif /* _util_h */