diff options
author | Erik Andersen | 2000-02-10 07:31:15 +0000 |
---|---|---|
committer | Erik Andersen | 2000-02-10 07:31:15 +0000 |
commit | 4d0543138ebb30aad55ba8083ea362eafb0aac33 (patch) | |
tree | 97c6724691dcbc940e410350b9f75d120d9f6d8b | |
parent | fb1793f03cbc51885678ee1ce9d0e81bd0e246f7 (diff) | |
download | busybox-4d0543138ebb30aad55ba8083ea362eafb0aac33.zip busybox-4d0543138ebb30aad55ba8083ea362eafb0aac33.tar.gz |
More minor touchups.
-Erik
-rw-r--r-- | Changelog | 4 | ||||
-rw-r--r-- | editors/sed.c | 250 | ||||
-rw-r--r-- | find.c | 8 | ||||
-rw-r--r-- | findutils/find.c | 8 | ||||
-rw-r--r-- | sed.c | 250 |
5 files changed, 258 insertions, 262 deletions
@@ -86,6 +86,10 @@ - added "skip" and "seek" to dd. * swapoff -a was not working. Now it is. * init did not cleanly unmount filesystems on reboot. Now it does. + * "sed -ne s/foo/bar/" worked but "sed -n -e s/foo/bar/" didn't. + Now both work. + * Some architectures (PowerPc) assume chars are unsigned, so they could + not distinguish between EOF and '\0xFF' in sed. Sed now uses ints. -Erik Andersen diff --git a/editors/sed.c b/editors/sed.c index 3a7737e..608f868 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -82,7 +82,7 @@ static inline int at_last(FILE * fp) if (feof(fp)) return 1; else { - char ch; + int ch; if ((ch = fgetc(fp)) == EOF) res++; @@ -183,129 +183,131 @@ extern int sed_main(int argc, char **argv) usage(sed_usage); } - if (**argv == '-') { - argc--; - cp = *argv++; - stopNow = FALSE; - - while (*++cp && stopNow == FALSE) { - switch (*cp) { - case 'n': - quietFlag = TRUE; - break; - case 'e': - if (*(cp + 1) == 0 && --argc < 0) { - usage(sed_usage); - } - if (*++cp != 's') - cp = *argv++; - - /* Read address if present */ - SKIPSPACES(cp); - if (*cp == '$') { - addr_line = LAST_LINE; - cp++; - } else { - if (isdigit(*cp)) { /* LINE ADDRESS */ - line_s = cp; - while (isdigit(*cp)) - cp++; - if (cp > line_s) { - /* numeric line */ - saved = *cp; - *cp = '\0'; - addr_line = atoi(line_s); - *cp = saved; - } - } else if (*cp == '/') { /* PATTERN ADDRESS */ - pos = addr_pattern = cp + 1; - pos = strchr(pos, '/'); - if (!pos) - usage(sed_usage); - *pos = '\0'; - cp = pos + 1; - } - } - - SKIPSPACES(cp); - if (*cp == '!') { - negated++; - cp++; - } - - /* Read command */ - - SKIPSPACES(cp); - switch (*cp) { - case 's': /* REPLACE */ - if (strlen(cp) <= 3 || *(cp + 1) != '/') - break; - sed_f = f_replace; - - pos = needle = cp + 2; - - for (;;) { - pos = strchr(pos, '/'); - if (pos == NULL) { - usage(sed_usage); - } - if (*(pos - 1) == '\\') { - pos++; - continue; - } - break; - } - *pos = 0; - newNeedle = ++pos; - for (;;) { - pos = strchr(pos, '/'); - if (pos == NULL) { - usage(sed_usage); - } - if (*(pos - 1) == '\\') { - pos++; - continue; - } - break; - } - *pos = 0; - if (pos + 2 != 0) { - while (*++pos) { - switch (*pos) { - case 'i': - ignoreCase = TRUE; - break; - case 'p': - printFlag = TRUE; - break; - case 'g': - break; - default: - usage(sed_usage); - } - } - } - cp = pos; - /* fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle); */ - break; - - case 'a': /* APPEND */ - if (strlen(cp) < 2) - break; - sed_f = f_append; - appendline = ++cp; - /* fprintf(stderr, "append '%s'\n", appendline); */ - break; - } - - stopNow = TRUE; - break; - - default: - usage(sed_usage); - } - } - } + while (argc > 1) { + if (**argv == '-') { + argc--; + cp = *argv++; + stopNow = FALSE; + + while (*++cp && stopNow == FALSE) { + switch (*cp) { + case 'n': + quietFlag = TRUE; + break; + case 'e': + if (*(cp + 1) == 0 && --argc < 0) { + usage(sed_usage); + } + if (*++cp != 's') + cp = *argv++; + + /* Read address if present */ + SKIPSPACES(cp); + if (*cp == '$') { + addr_line = LAST_LINE; + cp++; + } else { + if (isdigit(*cp)) { /* LINE ADDRESS */ + line_s = cp; + while (isdigit(*cp)) + cp++; + if (cp > line_s) { + /* numeric line */ + saved = *cp; + *cp = '\0'; + addr_line = atoi(line_s); + *cp = saved; + } + } else if (*cp == '/') { /* PATTERN ADDRESS */ + pos = addr_pattern = cp + 1; + pos = strchr(pos, '/'); + if (!pos) + usage(sed_usage); + *pos = '\0'; + cp = pos + 1; + } + } + + SKIPSPACES(cp); + if (*cp == '!') { + negated++; + cp++; + } + + /* Read command */ + + SKIPSPACES(cp); + switch (*cp) { + case 's': /* REPLACE */ + if (strlen(cp) <= 3 || *(cp + 1) != '/') + break; + sed_f = f_replace; + + pos = needle = cp + 2; + + for (;;) { + pos = strchr(pos, '/'); + if (pos == NULL) { + usage(sed_usage); + } + if (*(pos - 1) == '\\') { + pos++; + continue; + } + break; + } + *pos = 0; + newNeedle = ++pos; + for (;;) { + pos = strchr(pos, '/'); + if (pos == NULL) { + usage(sed_usage); + } + if (*(pos - 1) == '\\') { + pos++; + continue; + } + break; + } + *pos = 0; + if (pos + 2 != 0) { + while (*++pos) { + switch (*pos) { + case 'i': + ignoreCase = TRUE; + break; + case 'p': + printFlag = TRUE; + break; + case 'g': + break; + default: + usage(sed_usage); + } + } + } + cp = pos; + /* fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle); */ + break; + + case 'a': /* APPEND */ + if (strlen(cp) < 2) + break; + sed_f = f_append; + appendline = ++cp; + /* fprintf(stderr, "append '%s'\n", appendline); */ + break; + } + + stopNow = TRUE; + break; + + default: + usage(sed_usage); + } + } + } + } if (argc == 0) { switch (sed_f) { @@ -39,13 +39,7 @@ static const char find_usage[] = "find [PATH...] [EXPRESSION]\n\n" "\nEXPRESSION may consist of:\n" "\t-follow\n\t\tDereference symbolic links.\n" "\t-name PATTERN\n\t\tFile name (with leading directories removed) matches PATTERN.\n" - "\t-print\n\t\tprint the full file name followed by a newline to stdout.\n\n" -#if defined BB_REGEXP - "This version of find matches full regular expresions.\n"; -#else - "This version of find matches strings (not regular expresions).\n"; -#endif - + "\t-print\n\t\tprint the full file name followed by a newline to stdout.\n"; static int fileAction(const char *fileName, struct stat *statbuf) diff --git a/findutils/find.c b/findutils/find.c index 6346d45..2c1039b 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -39,13 +39,7 @@ static const char find_usage[] = "find [PATH...] [EXPRESSION]\n\n" "\nEXPRESSION may consist of:\n" "\t-follow\n\t\tDereference symbolic links.\n" "\t-name PATTERN\n\t\tFile name (with leading directories removed) matches PATTERN.\n" - "\t-print\n\t\tprint the full file name followed by a newline to stdout.\n\n" -#if defined BB_REGEXP - "This version of find matches full regular expresions.\n"; -#else - "This version of find matches strings (not regular expresions).\n"; -#endif - + "\t-print\n\t\tprint the full file name followed by a newline to stdout.\n"; static int fileAction(const char *fileName, struct stat *statbuf) @@ -82,7 +82,7 @@ static inline int at_last(FILE * fp) if (feof(fp)) return 1; else { - char ch; + int ch; if ((ch = fgetc(fp)) == EOF) res++; @@ -183,129 +183,131 @@ extern int sed_main(int argc, char **argv) usage(sed_usage); } - if (**argv == '-') { - argc--; - cp = *argv++; - stopNow = FALSE; - - while (*++cp && stopNow == FALSE) { - switch (*cp) { - case 'n': - quietFlag = TRUE; - break; - case 'e': - if (*(cp + 1) == 0 && --argc < 0) { - usage(sed_usage); - } - if (*++cp != 's') - cp = *argv++; - - /* Read address if present */ - SKIPSPACES(cp); - if (*cp == '$') { - addr_line = LAST_LINE; - cp++; - } else { - if (isdigit(*cp)) { /* LINE ADDRESS */ - line_s = cp; - while (isdigit(*cp)) - cp++; - if (cp > line_s) { - /* numeric line */ - saved = *cp; - *cp = '\0'; - addr_line = atoi(line_s); - *cp = saved; - } - } else if (*cp == '/') { /* PATTERN ADDRESS */ - pos = addr_pattern = cp + 1; - pos = strchr(pos, '/'); - if (!pos) - usage(sed_usage); - *pos = '\0'; - cp = pos + 1; - } - } - - SKIPSPACES(cp); - if (*cp == '!') { - negated++; - cp++; - } - - /* Read command */ - - SKIPSPACES(cp); - switch (*cp) { - case 's': /* REPLACE */ - if (strlen(cp) <= 3 || *(cp + 1) != '/') - break; - sed_f = f_replace; - - pos = needle = cp + 2; - - for (;;) { - pos = strchr(pos, '/'); - if (pos == NULL) { - usage(sed_usage); - } - if (*(pos - 1) == '\\') { - pos++; - continue; - } - break; - } - *pos = 0; - newNeedle = ++pos; - for (;;) { - pos = strchr(pos, '/'); - if (pos == NULL) { - usage(sed_usage); - } - if (*(pos - 1) == '\\') { - pos++; - continue; - } - break; - } - *pos = 0; - if (pos + 2 != 0) { - while (*++pos) { - switch (*pos) { - case 'i': - ignoreCase = TRUE; - break; - case 'p': - printFlag = TRUE; - break; - case 'g': - break; - default: - usage(sed_usage); - } - } - } - cp = pos; - /* fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle); */ - break; - - case 'a': /* APPEND */ - if (strlen(cp) < 2) - break; - sed_f = f_append; - appendline = ++cp; - /* fprintf(stderr, "append '%s'\n", appendline); */ - break; - } - - stopNow = TRUE; - break; - - default: - usage(sed_usage); - } - } - } + while (argc > 1) { + if (**argv == '-') { + argc--; + cp = *argv++; + stopNow = FALSE; + + while (*++cp && stopNow == FALSE) { + switch (*cp) { + case 'n': + quietFlag = TRUE; + break; + case 'e': + if (*(cp + 1) == 0 && --argc < 0) { + usage(sed_usage); + } + if (*++cp != 's') + cp = *argv++; + + /* Read address if present */ + SKIPSPACES(cp); + if (*cp == '$') { + addr_line = LAST_LINE; + cp++; + } else { + if (isdigit(*cp)) { /* LINE ADDRESS */ + line_s = cp; + while (isdigit(*cp)) + cp++; + if (cp > line_s) { + /* numeric line */ + saved = *cp; + *cp = '\0'; + addr_line = atoi(line_s); + *cp = saved; + } + } else if (*cp == '/') { /* PATTERN ADDRESS */ + pos = addr_pattern = cp + 1; + pos = strchr(pos, '/'); + if (!pos) + usage(sed_usage); + *pos = '\0'; + cp = pos + 1; + } + } + + SKIPSPACES(cp); + if (*cp == '!') { + negated++; + cp++; + } + + /* Read command */ + + SKIPSPACES(cp); + switch (*cp) { + case 's': /* REPLACE */ + if (strlen(cp) <= 3 || *(cp + 1) != '/') + break; + sed_f = f_replace; + + pos = needle = cp + 2; + + for (;;) { + pos = strchr(pos, '/'); + if (pos == NULL) { + usage(sed_usage); + } + if (*(pos - 1) == '\\') { + pos++; + continue; + } + break; + } + *pos = 0; + newNeedle = ++pos; + for (;;) { + pos = strchr(pos, '/'); + if (pos == NULL) { + usage(sed_usage); + } + if (*(pos - 1) == '\\') { + pos++; + continue; + } + break; + } + *pos = 0; + if (pos + 2 != 0) { + while (*++pos) { + switch (*pos) { + case 'i': + ignoreCase = TRUE; + break; + case 'p': + printFlag = TRUE; + break; + case 'g': + break; + default: + usage(sed_usage); + } + } + } + cp = pos; + /* fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle); */ + break; + + case 'a': /* APPEND */ + if (strlen(cp) < 2) + break; + sed_f = f_append; + appendline = ++cp; + /* fprintf(stderr, "append '%s'\n", appendline); */ + break; + } + + stopNow = TRUE; + break; + + default: + usage(sed_usage); + } + } + } + } if (argc == 0) { switch (sed_f) { |