diff options
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/echo.c | 28 | ||||
-rw-r--r-- | coreutils/tr.c | 12 |
2 files changed, 7 insertions, 33 deletions
diff --git a/coreutils/echo.c b/coreutils/echo.c index 4659e4b..6e279d1 100644 --- a/coreutils/echo.c +++ b/coreutils/echo.c @@ -40,7 +40,7 @@ extern int echo_main(int argc, char** argv) { register char **ap; - register char *p; + char *p; register char c; int nflag = 0; int eflag = 0; @@ -65,28 +65,10 @@ echo_main(int argc, char** argv) while ((p = *ap++) != NULL) { while ((c = *p++) != '\0') { if (c == '\\' && eflag) { - switch (c = *p++) { - case 'a': c = '\007'; break; - case 'b': c = '\b'; break; - case 'c': exit( 0); /* exit */ - case 'f': c = '\f'; break; - case 'n': c = '\n'; break; - case 'r': c = '\r'; break; - case 't': c = '\t'; break; - case 'v': c = '\v'; break; - case '\\': break; /* c = '\\' */ - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - c -= '0'; - if (*p >= '0' && *p <= '7') - c = c * 8 + (*p++ - '0'); - if (*p >= '0' && *p <= '7') - c = c * 8 + (*p++ - '0'); - break; - default: - p--; - break; - } + if (*p == 'c') + exit(0); + else + c = process_escape_sequence(&p); } putchar(c); } diff --git a/coreutils/tr.c b/coreutils/tr.c index 3e7ba58..48cdd47 100644 --- a/coreutils/tr.c +++ b/coreutils/tr.c @@ -111,22 +111,14 @@ static void map(register unsigned char *string1, register unsigned char *string2 } } -static void expand(register char *arg, register unsigned char *buffer) +static void expand(char *arg, register unsigned char *buffer) { int i, ac; while (*arg) { if (*arg == '\\') { arg++; - i = ac = 0; - if (*arg >= '0' && *arg <= '7') { - do { - ac = (ac << 3) + *arg++ - '0'; - i++; - } while (i < 4 && *arg >= '0' && *arg <= '7'); - *buffer++ = ac; - } else if (*arg != '\0') - *buffer++ = *arg++; + *buffer++ = process_escape_sequence(&arg); } else if (*arg == '[') { arg++; i = *arg++; |