diff options
author | Eric Andersen <andersen@codepoet.org> | 2000-07-05 17:26:35 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2000-07-05 17:26:35 +0000 |
commit | f7cf2f7ef98077c59e4da4bc25de38c22174ac9d (patch) | |
tree | a2fa5e67df2ccd2881a21ed4d22c6f7453b793b2 | |
parent | 57ebebfb01a9a29378b2f0179724661bfc5402e9 (diff) | |
download | busybox-w32-f7cf2f7ef98077c59e4da4bc25de38c22174ac9d.tar.gz busybox-w32-f7cf2f7ef98077c59e4da4bc25de38c22174ac9d.tar.bz2 busybox-w32-f7cf2f7ef98077c59e4da4bc25de38c22174ac9d.zip |
* Fix to tr so it recognizes standard escape sequences. Merged common
escape seq. code from tr and echo into utility.c. Fix thanks to
Matt Kraai <kraai@alumni.carnegiemellon.edu>.
* This should close Bug #1015. Please test.
-Erik
-rw-r--r-- | Changelog | 3 | ||||
-rw-r--r-- | coreutils/echo.c | 28 | ||||
-rw-r--r-- | coreutils/tr.c | 12 | ||||
-rw-r--r-- | echo.c | 28 | ||||
-rw-r--r-- | internal.h | 1 | ||||
-rw-r--r-- | tr.c | 12 | ||||
-rw-r--r-- | utility.c | 45 |
7 files changed, 63 insertions, 66 deletions
@@ -24,6 +24,9 @@ | |||
24 | of thing. Patch thanks to David Vrabel <dvrabel@arcom.co.uk> | 24 | of thing. Patch thanks to David Vrabel <dvrabel@arcom.co.uk> |
25 | * Fix to init.c from Stuart Menefy <Stuart.Menefy@st.com> so that | 25 | * Fix to init.c from Stuart Menefy <Stuart.Menefy@st.com> so that |
26 | it always sets the controlling terminal before running any programs | 26 | it always sets the controlling terminal before running any programs |
27 | * Fix to tr so it recognizes standard escape sequences. Merged common | ||
28 | escape seq. code from tr and echo into utility.c. Fix thanks to | ||
29 | Matt Kraai <kraai@alumni.carnegiemellon.edu>. | ||
27 | 30 | ||
28 | -Erik Andersen | 31 | -Erik Andersen |
29 | 32 | ||
diff --git a/coreutils/echo.c b/coreutils/echo.c index 4659e4bc6..6e279d1c6 100644 --- a/coreutils/echo.c +++ b/coreutils/echo.c | |||
@@ -40,7 +40,7 @@ extern int | |||
40 | echo_main(int argc, char** argv) | 40 | echo_main(int argc, char** argv) |
41 | { | 41 | { |
42 | register char **ap; | 42 | register char **ap; |
43 | register char *p; | 43 | char *p; |
44 | register char c; | 44 | register char c; |
45 | int nflag = 0; | 45 | int nflag = 0; |
46 | int eflag = 0; | 46 | int eflag = 0; |
@@ -65,28 +65,10 @@ echo_main(int argc, char** argv) | |||
65 | while ((p = *ap++) != NULL) { | 65 | while ((p = *ap++) != NULL) { |
66 | while ((c = *p++) != '\0') { | 66 | while ((c = *p++) != '\0') { |
67 | if (c == '\\' && eflag) { | 67 | if (c == '\\' && eflag) { |
68 | switch (c = *p++) { | 68 | if (*p == 'c') |
69 | case 'a': c = '\007'; break; | 69 | exit(0); |
70 | case 'b': c = '\b'; break; | 70 | else |
71 | case 'c': exit( 0); /* exit */ | 71 | c = process_escape_sequence(&p); |
72 | case 'f': c = '\f'; break; | ||
73 | case 'n': c = '\n'; break; | ||
74 | case 'r': c = '\r'; break; | ||
75 | case 't': c = '\t'; break; | ||
76 | case 'v': c = '\v'; break; | ||
77 | case '\\': break; /* c = '\\' */ | ||
78 | case '0': case '1': case '2': case '3': | ||
79 | case '4': case '5': case '6': case '7': | ||
80 | c -= '0'; | ||
81 | if (*p >= '0' && *p <= '7') | ||
82 | c = c * 8 + (*p++ - '0'); | ||
83 | if (*p >= '0' && *p <= '7') | ||
84 | c = c * 8 + (*p++ - '0'); | ||
85 | break; | ||
86 | default: | ||
87 | p--; | ||
88 | break; | ||
89 | } | ||
90 | } | 72 | } |
91 | putchar(c); | 73 | putchar(c); |
92 | } | 74 | } |
diff --git a/coreutils/tr.c b/coreutils/tr.c index 3e7ba583c..48cdd47bd 100644 --- a/coreutils/tr.c +++ b/coreutils/tr.c | |||
@@ -111,22 +111,14 @@ static void map(register unsigned char *string1, register unsigned char *string2 | |||
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | static void expand(register char *arg, register unsigned char *buffer) | 114 | static void expand(char *arg, register unsigned char *buffer) |
115 | { | 115 | { |
116 | int i, ac; | 116 | int i, ac; |
117 | 117 | ||
118 | while (*arg) { | 118 | while (*arg) { |
119 | if (*arg == '\\') { | 119 | if (*arg == '\\') { |
120 | arg++; | 120 | arg++; |
121 | i = ac = 0; | 121 | *buffer++ = process_escape_sequence(&arg); |
122 | if (*arg >= '0' && *arg <= '7') { | ||
123 | do { | ||
124 | ac = (ac << 3) + *arg++ - '0'; | ||
125 | i++; | ||
126 | } while (i < 4 && *arg >= '0' && *arg <= '7'); | ||
127 | *buffer++ = ac; | ||
128 | } else if (*arg != '\0') | ||
129 | *buffer++ = *arg++; | ||
130 | } else if (*arg == '[') { | 122 | } else if (*arg == '[') { |
131 | arg++; | 123 | arg++; |
132 | i = *arg++; | 124 | i = *arg++; |
@@ -40,7 +40,7 @@ extern int | |||
40 | echo_main(int argc, char** argv) | 40 | echo_main(int argc, char** argv) |
41 | { | 41 | { |
42 | register char **ap; | 42 | register char **ap; |
43 | register char *p; | 43 | char *p; |
44 | register char c; | 44 | register char c; |
45 | int nflag = 0; | 45 | int nflag = 0; |
46 | int eflag = 0; | 46 | int eflag = 0; |
@@ -65,28 +65,10 @@ echo_main(int argc, char** argv) | |||
65 | while ((p = *ap++) != NULL) { | 65 | while ((p = *ap++) != NULL) { |
66 | while ((c = *p++) != '\0') { | 66 | while ((c = *p++) != '\0') { |
67 | if (c == '\\' && eflag) { | 67 | if (c == '\\' && eflag) { |
68 | switch (c = *p++) { | 68 | if (*p == 'c') |
69 | case 'a': c = '\007'; break; | 69 | exit(0); |
70 | case 'b': c = '\b'; break; | 70 | else |
71 | case 'c': exit( 0); /* exit */ | 71 | c = process_escape_sequence(&p); |
72 | case 'f': c = '\f'; break; | ||
73 | case 'n': c = '\n'; break; | ||
74 | case 'r': c = '\r'; break; | ||
75 | case 't': c = '\t'; break; | ||
76 | case 'v': c = '\v'; break; | ||
77 | case '\\': break; /* c = '\\' */ | ||
78 | case '0': case '1': case '2': case '3': | ||
79 | case '4': case '5': case '6': case '7': | ||
80 | c -= '0'; | ||
81 | if (*p >= '0' && *p <= '7') | ||
82 | c = c * 8 + (*p++ - '0'); | ||
83 | if (*p >= '0' && *p <= '7') | ||
84 | c = c * 8 + (*p++ - '0'); | ||
85 | break; | ||
86 | default: | ||
87 | p--; | ||
88 | break; | ||
89 | } | ||
90 | } | 72 | } |
91 | putchar(c); | 73 | putchar(c); |
92 | } | 74 | } |
diff --git a/internal.h b/internal.h index 41a72e18a..27be05ee2 100644 --- a/internal.h +++ b/internal.h | |||
@@ -259,6 +259,7 @@ extern pid_t* findPidByName( char* pidName); | |||
259 | extern void *xmalloc (size_t size); | 259 | extern void *xmalloc (size_t size); |
260 | extern int find_real_root_device_name(char* name); | 260 | extern int find_real_root_device_name(char* name); |
261 | extern char *get_line_from_file(FILE *file); | 261 | extern char *get_line_from_file(FILE *file); |
262 | extern char process_escape_sequence(char **ptr); | ||
262 | 263 | ||
263 | /* These parse entries in /etc/passwd and /etc/group. This is desirable | 264 | /* These parse entries in /etc/passwd and /etc/group. This is desirable |
264 | * for BusyBox since we want to avoid using the glibc NSS stuff, which | 265 | * for BusyBox since we want to avoid using the glibc NSS stuff, which |
@@ -111,22 +111,14 @@ static void map(register unsigned char *string1, register unsigned char *string2 | |||
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | static void expand(register char *arg, register unsigned char *buffer) | 114 | static void expand(char *arg, register unsigned char *buffer) |
115 | { | 115 | { |
116 | int i, ac; | 116 | int i, ac; |
117 | 117 | ||
118 | while (*arg) { | 118 | while (*arg) { |
119 | if (*arg == '\\') { | 119 | if (*arg == '\\') { |
120 | arg++; | 120 | arg++; |
121 | i = ac = 0; | 121 | *buffer++ = process_escape_sequence(&arg); |
122 | if (*arg >= '0' && *arg <= '7') { | ||
123 | do { | ||
124 | ac = (ac << 3) + *arg++ - '0'; | ||
125 | i++; | ||
126 | } while (i < 4 && *arg >= '0' && *arg <= '7'); | ||
127 | *buffer++ = ac; | ||
128 | } else if (*arg != '\0') | ||
129 | *buffer++ = *arg++; | ||
130 | } else if (*arg == '[') { | 122 | } else if (*arg == '[') { |
131 | arg++; | 123 | arg++; |
132 | i = *arg++; | 124 | i = *arg++; |
@@ -1617,6 +1617,51 @@ extern char *get_line_from_file(FILE *file) | |||
1617 | return linebuf; | 1617 | return linebuf; |
1618 | } | 1618 | } |
1619 | 1619 | ||
1620 | #if defined BB_ECHO || defined BB_TR | ||
1621 | char process_escape_sequence(char **ptr) | ||
1622 | { | ||
1623 | char c; | ||
1624 | |||
1625 | switch (c = *(*ptr)++) { | ||
1626 | case 'a': | ||
1627 | c = '\a'; | ||
1628 | break; | ||
1629 | case 'b': | ||
1630 | c = '\b'; | ||
1631 | break; | ||
1632 | case 'f': | ||
1633 | c = '\f'; | ||
1634 | break; | ||
1635 | case 'n': | ||
1636 | c = '\n'; | ||
1637 | break; | ||
1638 | case 't': | ||
1639 | c = '\t'; | ||
1640 | break; | ||
1641 | case 'v': | ||
1642 | c = '\v'; | ||
1643 | break; | ||
1644 | case '\\': | ||
1645 | c = '\\'; | ||
1646 | break; | ||
1647 | case '0': case '1': case '2': case '3': | ||
1648 | case '4': case '5': case '6': case '7': | ||
1649 | c -= '0'; | ||
1650 | if ('0' <= **ptr && **ptr <= '7') { | ||
1651 | c = c * 8 + (*(*ptr)++ - '0'); | ||
1652 | if ('0' <= **ptr && **ptr <= '7') | ||
1653 | c = c * 8 + (*(*ptr)++ - '0'); | ||
1654 | } | ||
1655 | break; | ||
1656 | default: | ||
1657 | (*ptr)--; | ||
1658 | c = '\\'; | ||
1659 | break; | ||
1660 | } | ||
1661 | return c; | ||
1662 | } | ||
1663 | #endif | ||
1664 | |||
1620 | /* END CODE */ | 1665 | /* END CODE */ |
1621 | /* | 1666 | /* |
1622 | Local Variables: | 1667 | Local Variables: |