]> Trent Huber's Code - thus.git/commitdiff
Rename alias components
authorTrent Huber <trentmhuber@gmail.com>
Wed, 5 Nov 2025 06:31:18 +0000 (01:31 -0500)
committerTrent Huber <trentmhuber@gmail.com>
Wed, 5 Nov 2025 06:31:18 +0000 (01:31 -0500)
src/builtins/alias.c
src/builtins/alias.h
src/builtins/unalias.c
src/builtins/which.c

index 2eb2692ec440e090c0d73c2225a0139523afd1ea..3a1ea4c9fa08c59ddf2b73148a9a96afd30012b6 100644 (file)
 
 static struct {
    struct entry {
-       char lhs[MAXCHARS - 5], *rhs;
+       char name[MAXCHARS - 5], *value;
    } entries[MAXALIAS + 1];
    size_t size;
 } aliases;
 
-static size_t getindex(char *lhs) {
+static size_t getindex(char *name) {
    size_t i;
 
    for (i = 0; i < aliases.size; ++i)
-       if (strcmp(aliases.entries[i].lhs, lhs) == 0) break;
+       if (strcmp(aliases.entries[i].name, name) == 0) break;
 
    return i;
 }
 
-char *getaliasrhs(char *lhs) {
+char *getaliasvalue(char *name) {
    size_t i;
 
-   if ((i = getindex(lhs)) == aliases.size) return NULL;
-   return aliases.entries[i].rhs;
+   if ((i = getindex(name)) == aliases.size) return NULL;
+   return aliases.entries[i].value;
 }
 
-char **getalias(char *lhs) {
-   char *rhs;
+char **getalias(char *name) {
+   char *value;
    size_t l;
    static struct context context;
 
-   if (!(rhs = getaliasrhs(lhs))) return NULL;
+   if (!(value = getaliasvalue(name))) return NULL;
 
-   while (*rhs == ' ') ++rhs;
-   strcpy(context.buffer, rhs);
-   l = strlen(rhs);
+   while (*value == ' ') ++value;
+   strcpy(context.buffer, value);
+   l = strlen(value);
    context.buffer[l + 1] = '\0';
    context.buffer[l] = ';';
    context.alias = 1;
@@ -53,15 +53,15 @@ char **getalias(char *lhs) {
    return context.tokens;
 }
 
-int removealias(char *lhs) {
+int removealias(char *name) {
    size_t i;
    struct entry *entry;
 
-   if ((i = getindex(lhs)) == aliases.size) return 0;
+   if ((i = getindex(name)) == aliases.size) return 0;
    entry = &aliases.entries[i];
    memmove(entry, entry + 1, (--aliases.size - i) * sizeof(*entry));
    for (; i < aliases.size; ++i, ++entry)
-       entry->rhs = (void *)entry->rhs - sizeof(*entry);
+       entry->value = (void *)entry->value - sizeof(*entry);
 
    return 1;
 }
@@ -73,7 +73,7 @@ BUILTIN(alias) {
    switch (argc) {
    case 1:
        for (i = 0; i < aliases.size; ++i)
-           printf("%s = \"%s\"\n", aliases.entries[i].lhs, aliases.entries[i].rhs);
+           printf("%s = \"%s\"\n", aliases.entries[i].name, aliases.entries[i].value);
        break;
    case 3:
        if (aliases.size == MAXALIAS) {
@@ -83,14 +83,14 @@ BUILTIN(alias) {
 
        entry = &aliases.entries[i = getindex(argv[1])];
        if (i == aliases.size) {
-           strcpy(entry->lhs, argv[1]);
+           strcpy(entry->name, argv[1]);
            ++aliases.size;
        }
-       strcpy(entry->rhs = entry->lhs + strlen(entry->lhs) + 1, argv[2]);
+       strcpy(entry->value = entry->name + strlen(entry->name) + 1, argv[2]);
 
        break;
    default:
-       return usage(argv[0], "[lhs rhs]");
+       return usage(argv[0], "[name value]");
    }
 
    return EXIT_SUCCESS;
index 7f2411f3f030716ab4b695d29caa1eb52db803b6..ba5206541bcb41ad7fcd6a1061ca29e3f8a5bc01 100644 (file)
@@ -1,3 +1,3 @@
-char *getaliasrhs(char *lhs);
-char **getalias(char *lhs);
-int removealias(char *lhs);
+char *getaliasvalue(char *name);
+char **getalias(char *name);
+int removealias(char *name);
index 3024cbc67be136e64809a474485230c3383d1fd1..d906b8ec5bc62374079fa6c208039706b45b3e4b 100644 (file)
@@ -4,7 +4,7 @@
 #include "builtin.h"
 
 BUILTIN(unalias) {
-   if (argc != 2) return usage(argv[0], "lhs");
+   if (argc != 2) return usage(argv[0], "name");
 
    return removealias(argv[1]) ? EXIT_SUCCESS : EXIT_FAILURE;
 }
index 80a774be2bb5da539ff4fa1bfec29254548c96c1..841ca6052b2de172e0f473fd1b24f24f2a7b4b57 100644 (file)
@@ -39,7 +39,7 @@ char *getpath(char *file) {
 
    type = PATH;
    if (!(slash = strchr(file, '/'))) {
-       if ((entry = getaliasrhs(file))) {
+       if ((entry = getaliasvalue(file))) {
            type = ALIAS;
            return entry;
        }