Added lastword
authorRobert Pengelly <robertapengelly@hotmail.com>
Wed, 15 Oct 2025 04:26:09 +0000 (05:26 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Wed, 15 Oct 2025 04:26:09 +0000 (05:26 +0100)
variable.c

index e52e5a246613967dcbd2c3ed5e96e41a54379e5d..8415c601faabf98ef6de916ea5d89273a4acd779 100644 (file)
@@ -137,6 +137,22 @@ static char *func_filter_out (const char *filename, unsigned long line_no, char
 
 }
 
+static char *func_lastword (const char *filename, unsigned long line_no, char *input) {
+
+    char *temp = xstrdup (input);
+    char *p;
+    
+    (void) filename;
+    (void) line_no;
+    
+    if ((p = strrchr (temp, ' '))) {
+        return p + 1;
+    }
+    
+    return temp;
+
+}
+
 static char *func_subst (const char *filename, unsigned long line_no, char *input) {
 
     char *src, *dst, *new_body, *old_body, *p;
@@ -145,7 +161,7 @@ static char *func_subst (const char *filename, unsigned long line_no, char *inpu
     (void) filename;
     (void) line_no;
     
-    src = input;
+    src = skip_whitespace (input);
     
     if (!(dst = strstr (src, ",")) || !dst[0]) {
         return 0;
@@ -159,6 +175,10 @@ static char *func_subst (const char *filename, unsigned long line_no, char *inpu
     
     *old_body++ = 0;
     
+    if (!*src) {
+        return xstrdup ("");
+    }
+    
     size = 16 + strlen (old_body);
     new_body = xmalloc (size);
     
@@ -777,6 +797,7 @@ static struct builtin_function builtin_functions[] ={
 
     {   "error",        &func_error         },
     {   "filter-out",   &func_filter_out    },
+    {   "lastword",     &func_lastword      },
     
 #if     defined (_WIN32) || defined (__WIN32__) || defined (unix) || defined (__unix) || defined (__unix__) || defined (__APPLE__)
     {   "shell",        &func_shell         },