(util_do_command): Accept traditional contracted
forms (`d*', `p9') Fix bug in handling conditional branches (bug introduced on 2005-08-11).
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"); |
106 | 104 | ||
107 | if (command != NULL) | 105 | if (!entry) |
108 | { | 106 | { |
109 | if (exec) | 107 | /* argv[0] might be a traditional /bin/mail contracted form, e.g. |
110 | status = command (argc, argv); | 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++; | ||
118 | |||
119 | if (strlen (p)) | ||
120 | { | ||
121 | argc++; | ||
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 | { |
... | @@ -117,7 +142,6 @@ util_do_command (const char *c, ...) | ... | @@ -117,7 +142,6 @@ util_do_command (const char *c, ...) |
117 | util_error (_("Invalid command")); | 142 | util_error (_("Invalid command")); |
118 | status = 1; | 143 | status = 1; |
119 | } | 144 | } |
120 | |||
121 | 145 | ||
122 | mu_argcv_free (argc, argv); | 146 | mu_argcv_free (argc, argv); |
123 | return status; | 147 | return status; | ... | ... |
-
Please register or sign in to post a comment