commit 01fc315f45395d60a11d852a241739070b00ee70
parent 709e957b51b9d7d1e4716b52adc5d2cadb49b5ca
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Wed, 6 Jan 2021 01:21:10 -0800
Revise const usage
Most `item` and `argv` are fully mutable now, it's too tough, or
dare I say impossable, to deal with ** and const and improve the
usage of const in other areas.
Move itemtoaddr() to command.c as it's only used there.
Diffstat:
5 files changed, 57 insertions(+), 59 deletions(-)
diff --git a/command.c b/command.c
@@ -26,6 +26,12 @@
#define LOCAL /* functions local to this file */
+char **
+itemtoaddr(char **request)
+{
+ return request + 1;
+}
+
LOCAL int
type(int c, char const *types, int want)
{
@@ -45,7 +51,7 @@ wtype(char const *argv0, int c, char const *types, int want)
}
LOCAL int
-warg(int min, int max, int argc, char const **ap)
+warg(int min, int max, int argc, char **ap)
{
if (max > 0 && argc > max)
warn(0, "'%s': '%s'... unused.", *ap, ap[max]);
@@ -57,7 +63,7 @@ warg(int min, int max, int argc, char const **ap)
}
int
-cextern(int argc, char const **argv, int ino, char const **item)
+cextern(int argc, char **argv, int ino, char **item)
{
char url[MY_URL_MAX];
int i;
@@ -84,7 +90,7 @@ cextern(int argc, char const **argv, int ino, char const **item)
}
LOCAL int
-timid_gopher(char const **addr, char const *path, int bin)
+timid_gopher(char **addr, char *path, int bin)
{
if (!exists(path))
return gopher(addr, path, bin);
@@ -93,9 +99,9 @@ timid_gopher(char const **addr, char const *path, int bin)
}
int
-cfetch(int argc, char const **argv, int ino, char const **item)
+cfetch(int argc, char **argv, int ino, char **item)
{
- char const *path;
+ char *path;
int bin;
if (warg(1, 2, argc, argv) || wtype(*argv, **item, "i3", 0))
@@ -119,7 +125,7 @@ cfetch(int argc, char const **argv, int ino, char const **item)
}
LOCAL int
-cgoto7(int argc, char const **argv, int ino, char const **item)
+cgoto7(int argc, char **argv, int ino, char **item)
{
char tmp[MY_PATH_MAX];
@@ -133,7 +139,7 @@ cgoto7(int argc, char const **argv, int ino, char const **item)
}
int
-cgoto(int argc, char const **argv, int ino, char const **item)
+cgoto(int argc, char **argv, int ino, char **item)
{
if (**item == '1') {
if (warg(1, 1, argc, argv))
@@ -144,7 +150,7 @@ cgoto(int argc, char const **argv, int ino, char const **item)
}
int
-cprint(int argc, char const **argv, int ino, char const **item)
+cprint(int argc, char **argv, int ino, char **item)
{
if (warg(1, 1, argc, argv))
return FAIL;
@@ -160,7 +166,7 @@ cprint(int argc, char const **argv, int ino, char const **item)
}
int
-cprintv(int argc, char const **argv, int ino, char const **item)
+cprintv(int argc, char **argv, int ino, char **item)
{
if (**item != 'i' && **item != '3')
printf("\n %s%s\n", item[GI_HOST], item[GI_PATH]);
@@ -168,7 +174,7 @@ cprintv(int argc, char const **argv, int ino, char const **item)
}
int
-findex(int argc, char const **argv, int ino, char const **item)
+findex(int argc, char **argv, int ino, char **item)
{
char const *err;
int i;
@@ -188,7 +194,7 @@ findex(int argc, char const **argv, int ino, char const **item)
}
int
-frange(int argc, char const **argv, int ino, char const **item)
+frange(int argc, char **argv, int ino, char **item)
{
char const *err;
int i, j;
@@ -220,7 +226,7 @@ frange(int argc, char const **argv, int ino, char const **item)
}
int
-fstring(int argc, char const **argv, int ino, char const **item)
+fstring(int argc, char **argv, int ino, char **item)
{
int i;
@@ -233,7 +239,7 @@ fstring(int argc, char const **argv, int ino, char const **item)
}
int
-ftype(int argc, char const **argv, int ino, char const **item)
+ftype(int argc, char **argv, int ino, char **item)
{
if (warg(2, 2, argc, argv))
return FAIL;
@@ -243,7 +249,7 @@ ftype(int argc, char const **argv, int ino, char const **item)
}
int
-sexit(int argc, char const **argv, int depth, char const **addr)
+sexit(int argc, char **argv, int depth, char **addr)
{
if (warg(1, 1, argc, argv))
return FAIL;
@@ -251,9 +257,9 @@ sexit(int argc, char const **argv, int depth, char const **addr)
}
int
-sgoto(int argc, char const **argv, int depth, char const **addr)
+sgoto(int argc, char **argv, int depth, char **addr)
{
- char const *newaddr[AR_NULL];
+ char *newaddr[AR_NULL];
int i;
if (warg(1, 4, argc, argv))
@@ -269,7 +275,7 @@ sgoto(int argc, char const **argv, int depth, char const **addr)
}
int
-sunwind(int argc, char const **argv, int depth, char const **addr)
+sunwind(int argc, char **argv, int depth, char **addr)
{
char const *err;
int n;
diff --git a/command.h b/command.h
@@ -1,17 +1,17 @@
#ifndef _command_h
#define _command_h
-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 cprintv(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 **);
+int cextern(int, char **, int, char **);
+int cfetch(int, char **, int, char **);
+int cgoto(int, char **, int, char **);
+int cprint(int, char **, int, char **);
+int cprintv(int, char **, int, char **);
+int findex(int, char **, int, char **);
+int frange(int, char **, int, char **);
+int fstring(int, char **, int, char **);
+int ftype(int, char **, int, char **);
+int sexit(int, char **, int, char **);
+int sgoto(int, char **, int, char **);
+int sunwind(int, char **, int, char **);
#endif /* _command_h */
diff --git a/config.def.h b/config.def.h
@@ -7,7 +7,7 @@ static int const timeout = 5 * 1000;
static char const cache_command[] = "p";
/* default address if arguments are ommited */
-static char const *default_address[] = {
+static char *default_address[] = {
/* path, host, port */
"/", "localhost", "70"
};
diff --git a/gawk.h b/gawk.h
@@ -22,10 +22,10 @@ enum gphitem { GI_INFO, GI_PATH, GI_HOST, GI_PORT, GI_PLUS, GI_NULL };
enum cstatus { ERROR = -1, OK, UNWIND }; /* command status */
enum pstatus { NEXT = -2, FAIL, PASS }; /* pipe status */
-typedef int (command)(int, char const **, int, char const **);
+typedef int (command)(int, char **, int, char **);
struct command {
- char const *argv[MY_ARGV_MAX];
+ char *argv[MY_ARGV_MAX];
command *f;
int argc;
};
@@ -35,8 +35,7 @@ struct bind {
command *f;
};
-char const **itemtoaddr(char const **);
-int gopher(char const **, char const *, int);
-int gawk(char const **);
+int gopher(char **, char const *, int);
+int gawk(char **);
#endif /* _gawk_h */
diff --git a/main.c b/main.c
@@ -34,14 +34,8 @@
static char tmpdir[] = "/tmp/gawk-XXXXXXXXXXX";
static int fatal;
-char const **
-itemtoaddr(char const **request)
-{
- return request + 1;
-}
-
int
-argsplit(char const **argv, int size, char *s, char const *const sep, int cat)
+argsplit(char **argv, int size, char *s, char const *sep, int cat)
{
int argc;
@@ -58,7 +52,7 @@ argsplit(char const **argv, int size, char *s, char const *const sep, int cat)
}
int
-resolve(char const *const host, char const *const port)
+resolve(char const *host, char const *port)
{
int error, s;
struct addrinfo hints;
@@ -93,7 +87,7 @@ resolve(char const *const host, char const *const port)
}
void
-putprompt(char const *const prompt)
+putprompt(char const *prompt)
{
if (isatty(STDIN_FILENO))
fputs(prompt, stderr);
@@ -102,8 +96,7 @@ putprompt(char const *const prompt)
}
int
-input(char *buf, int size, char const *const delims, char const *const prompt,
- FILE *fp)
+input(char *buf, int size, char const *delims, char const *prompt, FILE *fp)
{
int next;
static unsigned int len;
@@ -138,7 +131,7 @@ too_big:
}
int
-gph_send(int sock, char const *const message)
+gph_send(int sock, char const *message)
{
char tmp[MY_PATH_MAX];
int n;
@@ -208,7 +201,7 @@ recvbin(int s, FILE *output)
}
int
-gph_recvto(int sock, char const *const path, int bin)
+gph_recvto(int sock, char const *path, int bin)
{
FILE *fp;
int status;
@@ -234,7 +227,7 @@ gph_recvto(int sock, char const *const path, int bin)
}
int
-gopher(char const **addr, char const *const path, int bin)
+gopher(char **addr, char const *path, int bin)
{
int sock;
@@ -251,7 +244,7 @@ gopher(char const **addr, char const *const path, int bin)
}
int
-gphsplit(char const **item, int size, char *buf)
+gphsplit(char **item, int size, char *buf)
{
int n;
@@ -262,7 +255,7 @@ gphsplit(char const **item, int size, char *buf)
}
command *
-getcom(char const *s, struct bind const *binds, int size)
+getcom(char const *s, struct bind const *const binds, int size)
{
int i;
@@ -275,14 +268,13 @@ getcom(char const *s, struct bind const *binds, int size)
}
int
-runpipe(struct command *cmds, int *indexes, int count, char const **item)
+runpipe(struct command *cmds, int *indexes, int count, char **item)
{
int i;
int r;
for (i = 0; i < count; ++i) {
- r = cmds[i].f(cmds[i].argc, cmds[i].argv,
- indexes[i]++, item);
+ r = cmds[i].f(cmds[i].argc, cmds[i].argv, indexes[i]++, item);
if (r != PASS)
return r;
}
@@ -294,7 +286,7 @@ runpipes(char const *cache, struct command *cmds, int count)
{
FILE *fp;
char buf[MY_LINE_MAX];
- char const *item[GI_NULL + 2];
+ char *item[GI_NULL + 2];
int error;
int indexes[count];
@@ -313,9 +305,10 @@ runpipes(char const *cache, struct command *cmds, int count)
}
int
-execute(char const *cache, char *input, int depth, char const **addr)
+execute(char const *cache, char *input, int depth, char **addr)
{
char *bufs[MY_PIPE_MAX];
+
int i;
int nbufs;
struct command cmds[MY_PIPE_MAX];
@@ -359,7 +352,7 @@ execute(char const *cache, char *input, int depth, char const **addr)
}
void
-tmp_mkpath(char *cache, char const **addr)
+tmp_mkpath(char *cache, char **addr)
{
char tmp[MY_PATH_MAX];
@@ -369,7 +362,7 @@ tmp_mkpath(char *cache, char const **addr)
}
int
-gawk(char const **addr)
+gawk(char **addr)
{
static int depth;
char cache[MY_PATH_MAX];
@@ -443,7 +436,7 @@ sighandler(int sig)
}
int
-main(int argc, char const *argv[])
+main(int argc, char *argv[])
{
int status;