Commit c1a1d908 c1a1d90824a5ad28509c432f0879c29d36c0c1a8 by Sergey Poznyakoff

Expand \n only for 'echo'

1 parent 8ccd48fd
...@@ -96,7 +96,7 @@ backslash(int c) ...@@ -96,7 +96,7 @@ backslash(int c)
96 } 96 }
97 97
98 static int 98 static int
99 expand_escape (char **pp, message_t msg, const char *cr, struct obstack *stk) 99 expand_escape (char **pp, message_t msg, struct obstack *stk)
100 { 100 {
101 char *p = *pp; 101 char *p = *pp;
102 char *start, *sval, *namep; 102 char *start, *sval, *namep;
...@@ -182,11 +182,10 @@ expand_escape (char **pp, message_t msg, const char *cr, struct obstack *stk) ...@@ -182,11 +182,10 @@ expand_escape (char **pp, message_t msg, const char *cr, struct obstack *stk)
182 char *s = strchr (q, '\n'); 182 char *s = strchr (q, '\n');
183 if (!s) 183 if (!s)
184 break; 184 break;
185 size = s - q; 185 size += s - q + 1;
186 obstack_grow (stk, q, size);
187 obstack_grow (stk, cr, strlen (cr));
188 q = s + 1; 186 q = s + 1;
189 } 187 }
188 obstack_grow (stk, buf, size);
190 } 189 }
191 free (buf); 190 free (buf);
192 } 191 }
...@@ -197,7 +196,7 @@ expand_escape (char **pp, message_t msg, const char *cr, struct obstack *stk) ...@@ -197,7 +196,7 @@ expand_escape (char **pp, message_t msg, const char *cr, struct obstack *stk)
197 } 196 }
198 197
199 static char * 198 static char *
200 expand_line (const char *str, const char *cr, message_t msg) 199 expand_line (const char *str, message_t msg)
201 { 200 {
202 const char *p; 201 const char *p;
203 int c = 0, len; 202 int c = 0, len;
...@@ -210,32 +209,17 @@ expand_line (const char *str, const char *cr, message_t msg) ...@@ -210,32 +209,17 @@ expand_line (const char *str, const char *cr, message_t msg)
210 { 209 {
211 switch (*p) 210 switch (*p)
212 { 211 {
213 case '\n':
214 len = strlen (cr);
215 obstack_grow (&stk, cr, len);
216 break;
217
218 case '\\': 212 case '\\':
219 p++; 213 p++;
220 switch (*p) 214 if (*p)
221 { 215 {
222 case 0:
223 obstack_1grow (&stk, *p);
224 break;
225
226 case 'n':
227 len = strlen (cr);
228 obstack_grow (&stk, cr, len);
229 break;
230
231 default:
232 c = backslash (*p); 216 c = backslash (*p);
233 obstack_1grow (&stk, c); 217 obstack_1grow (&stk, c);
234 } 218 }
235 break; 219 break;
236 220
237 case '$': 221 case '$':
238 if (expand_escape (&p, msg, cr, &stk) == 0) 222 if (expand_escape ((char**)&p, msg, &stk) == 0)
239 break; 223 break;
240 224
241 /*FALLTHRU*/ 225 /*FALLTHRU*/
...@@ -268,15 +252,21 @@ action_beep (FILE *tty) ...@@ -268,15 +252,21 @@ action_beep (FILE *tty)
268 } 252 }
269 253
270 static void 254 static void
271 action_echo (FILE *tty, char *str) 255 action_echo (FILE *tty, const char *cr, char *str)
272 { 256 {
273 char *p;
274
275 if (!str) 257 if (!str)
276 return; 258 return;
277 for (p = str; *p; p++) 259 for (; *str; str++)
278 *p = LB (*p); 260 {
279 fprintf (tty, "%s", str); 261 if (*str == '\n')
262 fprintf (tty, "%s", cr);
263 else
264 {
265 char c = LB (*str);
266 putc (c, tty);
267 }
268 }
269 fflush (tty);
280 } 270 }
281 271
282 static void 272 static void
...@@ -374,7 +364,7 @@ run_user_action (FILE *tty, const char *cr, message_t msg) ...@@ -374,7 +364,7 @@ run_user_action (FILE *tty, const char *cr, message_t msg)
374 char **argv; 364 char **argv;
375 365
376 line++; 366 line++;
377 str = expand_line (stmt, cr, msg); 367 str = expand_line (stmt, msg);
378 if (!str) 368 if (!str)
379 continue; 369 continue;
380 if (argcv_get (str, "", &argc, &argv) 370 if (argcv_get (str, "", &argc, &argv)
...@@ -393,7 +383,7 @@ run_user_action (FILE *tty, const char *cr, message_t msg) ...@@ -393,7 +383,7 @@ run_user_action (FILE *tty, const char *cr, message_t msg)
393 } 383 }
394 else if (strcmp (argv[0], "echo") == 0) 384 else if (strcmp (argv[0], "echo") == 0)
395 { 385 {
396 action_echo (tty, argv[1]); 386 action_echo (tty, cr, argv[1]);
397 nact++; 387 nact++;
398 } 388 }
399 else if (strcmp (argv[0], "exec") == 0) 389 else if (strcmp (argv[0], "exec") == 0)
...@@ -413,8 +403,5 @@ run_user_action (FILE *tty, const char *cr, message_t msg) ...@@ -413,8 +403,5 @@ run_user_action (FILE *tty, const char *cr, message_t msg)
413 } 403 }
414 404
415 if (nact == 0) 405 if (nact == 0)
416 { 406 action_echo (tty, cr, expand_line (default_action, msg));
417 char *str = expand_line (default_action, cr, msg);
418 action_echo (tty, str);
419 }
420 } 407 }
......