commit 9d2f50d1f09844c6f2a3863e281b44074de97114
parent 9cd765acd9c8cb41139dc26d68d4a2e428d92a18
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Wed, 23 Dec 2020 11:56:54 -0800
Make sgoto more simple and logical
The arguments are no longer reordered depending on how many there
are and relative paths are taken as absolute paths.
Diffstat:
M | main.c | | | 38 | ++++++++------------------------------ |
1 file changed, 8 insertions(+), 30 deletions(-)
diff --git a/main.c b/main.c
@@ -149,20 +149,6 @@ strtorange(unsigned int *r, unsigned int min, unsigned int max, const char *s)
return 0;
}
-/* `path` old path, `newpath` new path. Result put into `path`. */
-void
-newpath(char *path, const char *newpath)
-{
- char tmp[MY_PATH_MAX];
-
- if (*newpath == '/') {
- strlcpy(path, newpath, MY_PATH_MAX);
- } else {
- snprintf(tmp, MY_PATH_MAX, "%s/%s", path, newpath);
- strlcpy(path, tmp, MY_PATH_MAX);
- }
-}
-
void
tr(char *s, int orig, int repl)
{
@@ -404,33 +390,25 @@ ftype(int argc, const char **argv, int index, const char **item, command *func)
return 0;
}
-/* If lacking arguments goes to root (`/'). If one argument is given
- * it is taken as a path, if multiple are given the first is the host,
- * the second the path, and the optional third the port.
- */
int
sgoto(int argc, const char **argv, int depth, const char **addr)
{
- char tmp[MY_PATH_MAX];
const char *newaddr[AR_NULL];
if (badargs(0, 3, argc, argv))
return 1;
- strcpy(tmp, addr[AR_PATH]);
newaddr[AR_HOST] = addr[AR_HOST];
+ newaddr[AR_PATH] = "/";
newaddr[AR_PORT] = addr[AR_PORT];
- newaddr[AR_PATH] = tmp;
- if (argc == 0)
- newpath(tmp, "/");
- else if (argc == 1)
- newpath(tmp, argv[0]);
- else {
- newpath(tmp, argv[1]);
- newaddr[AR_HOST] = argv[0];
- if (argc == 3)
- newaddr[AR_PORT] = argv[2];
+ if (argc > 0) {
+ newaddr[AR_PATH] = argv[0];
+ if (argc > 1) {
+ newaddr[AR_HOST] = argv[1];
+ if (argc > 2)
+ newaddr[AR_PORT] = argv[2];
+ }
}
return gawk(newaddr);