Commit 028f083a 028f083aca0695638cfb9304d684484d944bf0f4 by Sergey Poznyakoff

(util_do_command): Accept traditional contracted

forms (`d*', `p9')
Fix bug in handling conditional branches (bug introduced on
2005-08-11).
1 parent b1232b2f
Showing 1 changed file with 35 additions and 11 deletions
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
36 36
37 mu_list_t environment = NULL; 37 mu_list_t environment = NULL;
38 38
39 #define is_ascii_alpha(c) (isascii(c) && isalpha(c))
40
39 /* 41 /*
40 * expands command into its command and arguments, then runs command 42 * expands command into its command and arguments, then runs command
41 * cmd is the command to parse and run 43 * cmd is the command to parse and run
...@@ -47,8 +49,7 @@ util_do_command (const char *c, ...) ...@@ -47,8 +49,7 @@ util_do_command (const char *c, ...)
47 int argc = 0; 49 int argc = 0;
48 char **argv = NULL; 50 char **argv = NULL;
49 int status = 0; 51 int status = 0;
50 function_t *command = NULL; 52 struct mail_command_entry *entry = NULL;
51 int exec = 1;
52 char *cmd = NULL; 53 char *cmd = NULL;
53 va_list ap; 54 va_list ap;
54 static const char *delim = "="; 55 static const char *delim = "=";
...@@ -83,7 +84,6 @@ util_do_command (const char *c, ...) ...@@ -83,7 +84,6 @@ util_do_command (const char *c, ...)
83 84
84 if (mu_argcv_get (cmd, delim, NULL, &argc, &argv) == 0 && argc > 0) 85 if (mu_argcv_get (cmd, delim, NULL, &argc, &argv) == 0 && argc > 0)
85 { 86 {
86 struct mail_command_entry *entry;
87 char *p; 87 char *p;
88 88
89 /* Special case: a number alone implies "print" */ 89 /* Special case: a number alone implies "print" */
...@@ -95,19 +95,44 @@ util_do_command (const char *c, ...) ...@@ -95,19 +95,44 @@ util_do_command (const char *c, ...)
95 free (p); 95 free (p);
96 } 96 }
97 97
98 command = util_command_get (argv[0]); 98 entry = mail_find_command (argv[0]);
99 /* Make sure we are not in any if/else */
100 exec = !(if_cond () == 0 && (entry->flags & EF_FLOW) == 0);
101 } 99 }
102 free (cmd); 100 free (cmd);
103 } 101 }
104 else 102 else
105 command = util_command_get ("quit"); 103 entry = mail_find_command ("quit");
104
105 if (!entry)
106 {
107 /* argv[0] might be a traditional /bin/mail contracted form, e.g.
108 `d*' or `p4'. */
109
110 char *p;
111
112 for (p = argv[0] + strlen (argv[0]) - 1;
113 p > argv[0] && !is_ascii_alpha (*p);
114 p--)
115 ;
116
117 p++;
106 118
107 if (command != NULL) 119 if (strlen (p))
108 { 120 {
109 if (exec) 121 argc++;
110 status = command (argc, argv); 122 argv = xrealloc (argv, (argc + 1)*sizeof argv[0]);
123 memmove (argv + 2, argv + 1, argc*sizeof argv[0]);
124 argv[1] = xstrdup (p);
125 *p = 0;
126 }
127
128 entry = mail_find_command (argv[0]);
129 }
130
131 if (entry)
132 {
133 /* Make sure we are not in any if/else */
134 if (!(if_cond () == 0 && (entry->flags & EF_FLOW) == 0))
135 status = entry->func (argc, argv);
111 } 136 }
112 else 137 else
113 { 138 {
...@@ -118,7 +143,6 @@ util_do_command (const char *c, ...) ...@@ -118,7 +143,6 @@ util_do_command (const char *c, ...)
118 status = 1; 143 status = 1;
119 } 144 }
120 145
121
122 mu_argcv_free (argc, argv); 146 mu_argcv_free (argc, argv);
123 return status; 147 return status;
124 } 148 }
......