]> Trent Huber's Code - thus.git/commitdiff
Clean up whitespace and pointer/array operations
authorTrent Huber <trentmhuber@gmail.com>
Sat, 20 Dec 2025 20:49:06 +0000 (15:49 -0500)
committerTrent Huber <trentmhuber@gmail.com>
Sat, 20 Dec 2025 20:49:06 +0000 (15:49 -0500)
12 files changed:
src/builtins/alias.c
src/builtins/bg.c
src/builtins/builtin.c
src/builtins/exec.c
src/builtins/exeunt.c
src/builtins/mode.c
src/builtins/set.c
src/builtins/unalias.c
src/builtins/unset.c
src/builtins/which.c
src/run.c
src/utils.c

index 42105a8aacda83554992817697c36f86254f0aff..c5229a6d1e800df17a084f5a598ef9ce5df34b0d 100644 (file)
@@ -29,6 +29,7 @@ char *getalias(char *name) {
    size_t i;
 
    if ((i = getindex(name)) == aliases.size) return NULL;
+
    return aliases.entries[i].value;
 }
 
@@ -54,7 +55,8 @@ int removealias(char *name) {
    struct entry *entry;
 
    if ((i = getindex(name)) == aliases.size) return 0;
-   entry = &aliases.entries[i];
+
+   entry = aliases.entries + i;
    memmove(entry, entry + 1, (--aliases.size - i) * sizeof*entry);
    for (; i < aliases.size; ++i, ++entry)
        entry->value = (void *)entry->value - sizeof*entry;
@@ -87,7 +89,7 @@ int alias(char **args, size_t numargs) {
            *end = '\0';
        }
 
-       entry = &aliases.entries[i = getindex(args[1])];
+       entry = aliases.entries + (i = getindex(args[1]));
        if (i == aliases.size) {
            strcpy(entry->name, args[1]);
            ++aliases.size;
index 028a51f8382147082d8a5e8c336f80353b310508..1191c24546c7d92c8cde8474e3bab4e287b209ca 100644 (file)
@@ -62,7 +62,7 @@ void initbg(void) {
    bgaction = (struct sigaction){.sa_handler = sigchldbghandler};
 
    for (i = 0; i < MAXBG - 1; ++i)
-       bgjobs.entries[i].next = &bgjobs.entries[i + 1];
+       bgjobs.entries[i].next = bgjobs.entries + i + 1;
    bgjobs.free = bgjobs.entries;
 }
 
@@ -89,7 +89,6 @@ int pushbgid(pid_t id) {
 
 int peekbg(struct bgjob *job) {
    if (bgjobs.active && job) *job = bgjobs.active->job;
-
    return bgjobs.active != NULL;
 }
 
index 1e005bfebff2180c46c050d05d2b55859ad1fe7f..870c22f419a7d035b42e131de27e3d68555871ad 100644 (file)
@@ -18,6 +18,5 @@ int usage(char *program, char *options) {
    fprintf(stderr, "usage: %s", program);
    if (options) fprintf(stderr, " %s", options);
    fputc('\n', stderr);
-
    return EXIT_FAILURE;
 }
index 4976c7071b02a1dcb2c14f175e917c3d6d72bf44..dd072071b986c1ce843dd7024a4dcb4b859427a5 100644 (file)
@@ -28,7 +28,7 @@ int exec(char **args, size_t numargs) {
    if (numargs < 2) return usage(args[0], "command [args ...]");
 
    clear(&c);
-   memcpy(c.tokens, &args[1], (numargs - 1) * sizeof*args);
+   memcpy(c.tokens, args + 1, (numargs - 1) * sizeof*args);
    strcpy(c.current.name, args[1]);
    if (!(c.current.builtin = getbuiltin(args[1]))
        && !(c.current.path = getpath(c.current.name))) {
@@ -40,5 +40,5 @@ int exec(char **args, size_t numargs) {
 
    /* execute() is guaranteed not to return, this statement just appeases the
     * compiler */
-   exit(EXIT_SUCCESS);
+   exit(EXIT_FAILURE);
 }
index 877ea348bf7c9f3ad19105588cb4bb2dd77e25e4..afaba439894ef9747f5eeafbf11baa465849afa7 100644 (file)
@@ -7,5 +7,6 @@ int exeunt(char **args, size_t numargs) {
    if (numargs != 1) return usage(args[0], NULL);
 
    deinit();
+
    exit(EXIT_SUCCESS);
 }
index fcbf67c6a9a498da32d6e419330502a9dce4a5cb..a875c279fa0b69f45125fcf9288153c717c8766f 100644 (file)
@@ -18,6 +18,5 @@ int mode(char **args, size_t numargs) {
        default:
            return usage(args[0], "[verbose | quiet]");
    }
-
    return EXIT_SUCCESS;
 }
index 49bdd967d77853567f682f4b2023fdd73025eb1c..fb8586607eb76414f422e1b5b3696f1b6cd7f6c4 100644 (file)
@@ -15,6 +15,5 @@ int set(char **args, size_t numargs) {
    default:
        return usage(args[0], "name [value]");
    }
-
    return EXIT_SUCCESS;
 }
index 55581ba617db83f1124a03326a3aa751d1903cb1..2e18ad07da97b9184c6aab146bba6f4a4c717da6 100644 (file)
@@ -5,6 +5,5 @@
 
 int unalias(char **args, size_t numargs) {
    if (numargs != 2) return usage(args[0], "name");
-
    return removealias(args[1]) ? EXIT_SUCCESS : EXIT_FAILURE;
 }
index 9d49f5d2805d03ebe1f8d16853ff822abf7d030d..f3b0061158a96cda62245f285d018a469426e937 100644 (file)
@@ -6,8 +6,10 @@
 int unset(char **args, size_t numargs) {
    if (numargs != 2) return usage(args[0], "name");
 
-   if (unsetenv(args[1]) != -1) return EXIT_SUCCESS;
+   if (unsetenv(args[1]) == -1) {
+       note("Unable to unset `%s'", args[1]);
+       return EXIT_FAILURE;
+   }
 
-   note("Unable to unset `%s'", args[1]);
-   return EXIT_FAILURE;
+   return EXIT_SUCCESS;
 }
index 242659b6a3795d259a8020e8ce25273cea8c5de0..3016d87677fe5989867eb64cb95d80cfd79c17d6 100644 (file)
@@ -46,9 +46,8 @@ char *getpath(char *file) {
        if (errno != ENOENT) note("Unable to expand `%s'", file); else errno = 0;
        return NULL;
    }
-   if (exists(path)) return path;
 
-   return NULL;
+   return exists(path) ? path : NULL;
 }
 
 int which(char **args, size_t numargs) {
index 9fd4e0cc89015d7285f94cbf49538caadb003227..ed0da59551d64e41b60cadca8f56696d24b7b4f7 100644 (file)
--- a/src/run.c
+++ b/src/run.c
@@ -92,7 +92,7 @@ int run(struct context *c) {
            putchar('&');
        default:
            putchar('\n');
-       }   
+       }
    }
 
    islist = c->previous.term > BG || c->current.term > BG;
@@ -167,7 +167,7 @@ int run(struct context *c) {
            return quit(c);
        }
        jobid = pipeid;
-   } else if (!c->r && (c->current.builtin = getbuiltin(c->current.name))) {
+   } else if (c->current.builtin && !c->r) {
        status = c->current.builtin(c->tokens, c->numtokens);
        cpid = 0;
    } else if ((jobid = cpid = fork()) == -1) {
index 6665eaa68fe4feec53f36e433f84aab4700716df..af3f85dcf2ceb42978cc172708c03c3b134a61c2 100644 (file)
@@ -73,8 +73,8 @@ void init(void) {
        note("Unable to append trailing slash to $PWD$");
 
    if (shlvl == 1
-       && setenv("PATH", "/usr/local/bin/:/usr/local/sbin/:"
-                         "/usr/bin/:/usr/sbin/:/bin/:/sbin/", 1) == -1)
+       && setenv("PATH", "/usr/local/bin/:/usr/local/sbin/"
+                         ":/usr/bin/:/usr/sbin/:/bin/:/sbin/", 1) == -1)
        note("Unable to initialize $PATH$");
 
    getcolumns();
@@ -113,7 +113,7 @@ char *quoted(char *token) {
    } degree;
    static char buffer[MAXCHARS + 1];
 
-   if (!*token) return "\"\"";
+   if (!token[0]) return "\"\"";
 
    degree = NONE;
    for (p = token; *p; ++p) switch(*p) {