diff options
| author | Ron Yorston <rmy@pobox.com> | 2018-12-05 08:38:55 +0000 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2018-12-05 08:38:55 +0000 |
| commit | 2a34d6d4e3122df2f84eb1290221128be47dc36b (patch) | |
| tree | a7035842113f36823c4e7c16744416259f0a8bf6 | |
| parent | 5448a3893434a64d184055be81a58f47ea6af51b (diff) | |
| parent | d08206dce1291f512d7de9037d9ef1ffbf705cac (diff) | |
| download | busybox-w32-2a34d6d4e3122df2f84eb1290221128be47dc36b.tar.gz busybox-w32-2a34d6d4e3122df2f84eb1290221128be47dc36b.tar.bz2 busybox-w32-2a34d6d4e3122df2f84eb1290221128be47dc36b.zip | |
Merge branch 'busybox' into merge
| -rw-r--r-- | coreutils/cat.c | 6 | ||||
| -rw-r--r-- | coreutils/nl.c | 7 | ||||
| -rw-r--r-- | editors/awk.c | 2 | ||||
| -rw-r--r-- | editors/vi.c | 45 | ||||
| -rw-r--r-- | include/libbb.h | 2 | ||||
| -rw-r--r-- | libbb/print_numbered_lines.c | 10 | ||||
| -rw-r--r-- | libbb/process_escape_sequence.c | 16 |
7 files changed, 58 insertions, 30 deletions
diff --git a/coreutils/cat.c b/coreutils/cat.c index fb735f994..65f0648f9 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c | |||
| @@ -195,6 +195,7 @@ int cat_main(int argc UNUSED_PARAM, char **argv) | |||
| 195 | # define CAT_OPT_b (1<<1) | 195 | # define CAT_OPT_b (1<<1) |
| 196 | if (opts & (CAT_OPT_n|CAT_OPT_b)) { /* -n or -b */ | 196 | if (opts & (CAT_OPT_n|CAT_OPT_b)) { /* -n or -b */ |
| 197 | struct number_state ns; | 197 | struct number_state ns; |
| 198 | int exitcode; | ||
| 198 | 199 | ||
| 199 | ns.width = 6; | 200 | ns.width = 6; |
| 200 | ns.start = 1; | 201 | ns.start = 1; |
| @@ -203,10 +204,11 @@ int cat_main(int argc UNUSED_PARAM, char **argv) | |||
| 203 | ns.empty_str = "\n"; | 204 | ns.empty_str = "\n"; |
| 204 | ns.all = !(opts & CAT_OPT_b); /* -n without -b */ | 205 | ns.all = !(opts & CAT_OPT_b); /* -n without -b */ |
| 205 | ns.nonempty = (opts & CAT_OPT_b); /* -b (with or without -n) */ | 206 | ns.nonempty = (opts & CAT_OPT_b); /* -b (with or without -n) */ |
| 207 | exitcode = EXIT_SUCCESS; | ||
| 206 | do { | 208 | do { |
| 207 | print_numbered_lines(&ns, *argv); | 209 | exitcode |= print_numbered_lines(&ns, *argv); |
| 208 | } while (*++argv); | 210 | } while (*++argv); |
| 209 | fflush_stdout_and_exit(EXIT_SUCCESS); | 211 | fflush_stdout_and_exit(exitcode); |
| 210 | } | 212 | } |
| 211 | /*opts >>= 2;*/ | 213 | /*opts >>= 2;*/ |
| 212 | #endif | 214 | #endif |
diff --git a/coreutils/nl.c b/coreutils/nl.c index c2f8b1042..2fdc9d85e 100644 --- a/coreutils/nl.c +++ b/coreutils/nl.c | |||
| @@ -58,6 +58,8 @@ int nl_main(int argc UNUSED_PARAM, char **argv) | |||
| 58 | "number-width\0" Required_argument "w" | 58 | "number-width\0" Required_argument "w" |
| 59 | ; | 59 | ; |
| 60 | #endif | 60 | #endif |
| 61 | int exitcode; | ||
| 62 | |||
| 61 | ns.width = 6; | 63 | ns.width = 6; |
| 62 | ns.start = 1; | 64 | ns.start = 1; |
| 63 | ns.inc = 1; | 65 | ns.inc = 1; |
| @@ -72,9 +74,10 @@ int nl_main(int argc UNUSED_PARAM, char **argv) | |||
| 72 | if (!*argv) | 74 | if (!*argv) |
| 73 | *--argv = (char*)"-"; | 75 | *--argv = (char*)"-"; |
| 74 | 76 | ||
| 77 | exitcode = EXIT_SUCCESS; | ||
| 75 | do { | 78 | do { |
| 76 | print_numbered_lines(&ns, *argv); | 79 | exitcode |= print_numbered_lines(&ns, *argv); |
| 77 | } while (*++argv); | 80 | } while (*++argv); |
| 78 | 81 | ||
| 79 | fflush_stdout_and_exit(EXIT_SUCCESS); | 82 | fflush_stdout_and_exit(exitcode); |
| 80 | } | 83 | } |
diff --git a/editors/awk.c b/editors/awk.c index b9c8d2130..8e79d3159 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
| @@ -1853,6 +1853,8 @@ static void handle_special(var *v) | |||
| 1853 | 1853 | ||
| 1854 | if (v == intvar[NF]) { | 1854 | if (v == intvar[NF]) { |
| 1855 | n = (int)getvar_i(v); | 1855 | n = (int)getvar_i(v); |
| 1856 | if (n < 0) | ||
| 1857 | syntax_error("NF set to negative value"); | ||
| 1856 | fsrealloc(n); | 1858 | fsrealloc(n); |
| 1857 | 1859 | ||
| 1858 | /* recalculate $0 */ | 1860 | /* recalculate $0 */ |
diff --git a/editors/vi.c b/editors/vi.c index 05d30f2ff..57fac59ad 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
| @@ -255,8 +255,8 @@ enum { | |||
| 255 | YANKDEL = TRUE, | 255 | YANKDEL = TRUE, |
| 256 | FORWARD = 1, // code depends on "1" for array index | 256 | FORWARD = 1, // code depends on "1" for array index |
| 257 | BACK = -1, // code depends on "-1" for array index | 257 | BACK = -1, // code depends on "-1" for array index |
| 258 | LIMITED = 0, // how much of text[] in char_search | 258 | LIMITED = 0, // char_search() only current line |
| 259 | FULL = 1, // how much of text[] in char_search | 259 | FULL = 1, // char_search() to the end/beginning of entire text |
| 260 | 260 | ||
| 261 | S_BEFORE_WS = 1, // used in skip_thing() for moving "dot" | 261 | S_BEFORE_WS = 1, // used in skip_thing() for moving "dot" |
| 262 | S_TO_WS = 2, // used in skip_thing() for moving "dot" | 262 | S_TO_WS = 2, // used in skip_thing() for moving "dot" |
| @@ -563,7 +563,7 @@ static void indicate_error(void); // use flash or beep to indicate error | |||
| 563 | static void Hit_Return(void); | 563 | static void Hit_Return(void); |
| 564 | 564 | ||
| 565 | #if ENABLE_FEATURE_VI_SEARCH | 565 | #if ENABLE_FEATURE_VI_SEARCH |
| 566 | static char *char_search(char *, const char *, int, int); // search for pattern starting at p | 566 | static char *char_search(char *, const char *, int); // search for pattern starting at p |
| 567 | #endif | 567 | #endif |
| 568 | #if ENABLE_FEATURE_VI_COLON | 568 | #if ENABLE_FEATURE_VI_COLON |
| 569 | static char *get_one_address(char *, int *); // get colon addr, if present | 569 | static char *get_one_address(char *, int *); // get colon addr, if present |
| @@ -940,7 +940,7 @@ static char *get_one_address(char *p, int *addr) // get colon addr, if present | |||
| 940 | p = q; | 940 | p = q; |
| 941 | if (*p == '/') | 941 | if (*p == '/') |
| 942 | p++; | 942 | p++; |
| 943 | q = char_search(dot, pat, FORWARD, FULL); | 943 | q = char_search(dot, pat, (FORWARD << 1) | FULL); |
| 944 | if (q != NULL) { | 944 | if (q != NULL) { |
| 945 | *addr = count_lines(text, q); | 945 | *addr = count_lines(text, q); |
| 946 | } | 946 | } |
| @@ -1444,7 +1444,7 @@ static void colon(char *buf) | |||
| 1444 | char *ls = q; // orig line start | 1444 | char *ls = q; // orig line start |
| 1445 | char *found; | 1445 | char *found; |
| 1446 | vc4: | 1446 | vc4: |
| 1447 | found = char_search(q, F, FORWARD, LIMITED); // search cur line only for "find" | 1447 | found = char_search(q, F, (FORWARD << 1) | LIMITED); // search cur line only for "find" |
| 1448 | if (found) { | 1448 | if (found) { |
| 1449 | uintptr_t bias; | 1449 | uintptr_t bias; |
| 1450 | // we found the "find" pattern - delete it | 1450 | // we found the "find" pattern - delete it |
| @@ -1897,13 +1897,14 @@ static char *new_screen(int ro, int co) | |||
| 1897 | # if ENABLE_FEATURE_VI_REGEX_SEARCH | 1897 | # if ENABLE_FEATURE_VI_REGEX_SEARCH |
| 1898 | 1898 | ||
| 1899 | // search for pattern starting at p | 1899 | // search for pattern starting at p |
| 1900 | static char *char_search(char *p, const char *pat, int dir, int range) | 1900 | static char *char_search(char *p, const char *pat, int dir_and_range) |
| 1901 | { | 1901 | { |
| 1902 | struct re_pattern_buffer preg; | 1902 | struct re_pattern_buffer preg; |
| 1903 | const char *err; | 1903 | const char *err; |
| 1904 | char *q; | 1904 | char *q; |
| 1905 | int i; | 1905 | int i; |
| 1906 | int size; | 1906 | int size; |
| 1907 | int range; | ||
| 1907 | 1908 | ||
| 1908 | re_syntax_options = RE_SYNTAX_POSIX_EXTENDED; | 1909 | re_syntax_options = RE_SYNTAX_POSIX_EXTENDED; |
| 1909 | if (ignorecase) | 1910 | if (ignorecase) |
| @@ -1916,10 +1917,16 @@ static char *char_search(char *p, const char *pat, int dir, int range) | |||
| 1916 | return p; | 1917 | return p; |
| 1917 | } | 1918 | } |
| 1918 | 1919 | ||
| 1919 | // assume a LIMITED forward search | 1920 | range = (dir_and_range & 1); |
| 1920 | q = end - 1; | 1921 | q = end - 1; // if FULL |
| 1921 | if (dir == BACK) | 1922 | if (range == LIMITED) |
| 1923 | q = next_line(p); | ||
| 1924 | if (dir_and_range < 0) { // BACK? | ||
| 1922 | q = text; | 1925 | q = text; |
| 1926 | if (range == LIMITED) | ||
| 1927 | q = prev_line(p); | ||
| 1928 | } | ||
| 1929 | |||
| 1923 | // RANGE could be negative if we are searching backwards | 1930 | // RANGE could be negative if we are searching backwards |
| 1924 | range = q - p; | 1931 | range = q - p; |
| 1925 | q = p; | 1932 | q = p; |
| @@ -1942,7 +1949,7 @@ static char *char_search(char *p, const char *pat, int dir, int range) | |||
| 1942 | regfree(&preg); | 1949 | regfree(&preg); |
| 1943 | if (i < 0) | 1950 | if (i < 0) |
| 1944 | return NULL; | 1951 | return NULL; |
| 1945 | if (dir == FORWARD) | 1952 | if (dir_and_range > 0) // FORWARD? |
| 1946 | p = p + i; | 1953 | p = p + i; |
| 1947 | else | 1954 | else |
| 1948 | p = p - i; | 1955 | p = p - i; |
| @@ -1963,13 +1970,15 @@ static int mycmp(const char *s1, const char *s2, int len) | |||
| 1963 | # define mycmp strncmp | 1970 | # define mycmp strncmp |
| 1964 | # endif | 1971 | # endif |
| 1965 | 1972 | ||
| 1966 | static char *char_search(char *p, const char *pat, int dir, int range) | 1973 | static char *char_search(char *p, const char *pat, int dir_and_range) |
| 1967 | { | 1974 | { |
| 1968 | char *start, *stop; | 1975 | char *start, *stop; |
| 1969 | int len; | 1976 | int len; |
| 1977 | int range; | ||
| 1970 | 1978 | ||
| 1971 | len = strlen(pat); | 1979 | len = strlen(pat); |
| 1972 | if (dir == FORWARD) { | 1980 | range = (dir_and_range & 1); |
| 1981 | if (dir_and_range > 0) { //FORWARD? | ||
| 1973 | stop = end - 1; // assume range is p..end-1 | 1982 | stop = end - 1; // assume range is p..end-1 |
| 1974 | if (range == LIMITED) | 1983 | if (range == LIMITED) |
| 1975 | stop = next_line(p); // range is to next line | 1984 | stop = next_line(p); // range is to next line |
| @@ -1978,7 +1987,7 @@ static char *char_search(char *p, const char *pat, int dir, int range) | |||
| 1978 | return start; | 1987 | return start; |
| 1979 | } | 1988 | } |
| 1980 | } | 1989 | } |
| 1981 | } else if (dir == BACK) { | 1990 | } else { //BACK |
| 1982 | stop = text; // assume range is text..p | 1991 | stop = text; // assume range is text..p |
| 1983 | if (range == LIMITED) | 1992 | if (range == LIMITED) |
| 1984 | stop = prev_line(p); // range is to prev line | 1993 | stop = prev_line(p); // range is to prev line |
| @@ -2357,7 +2366,7 @@ static void undo_push(char *src, unsigned int length, uint8_t u_type) // Add to | |||
| 2357 | // Allocate a new undo object | 2366 | // Allocate a new undo object |
| 2358 | if (u_type == UNDO_DEL || u_type == UNDO_DEL_CHAIN) { | 2367 | if (u_type == UNDO_DEL || u_type == UNDO_DEL_CHAIN) { |
| 2359 | // For UNDO_DEL objects, save deleted text | 2368 | // For UNDO_DEL objects, save deleted text |
| 2360 | if ((src + length) == end) | 2369 | if ((text + length) == end) |
| 2361 | length--; | 2370 | length--; |
| 2362 | // If this deletion empties text[], strip the newline. When the buffer becomes | 2371 | // If this deletion empties text[], strip the newline. When the buffer becomes |
| 2363 | // zero-length, a newline is added back, which requires this to compensate. | 2372 | // zero-length, a newline is added back, which requires this to compensate. |
| @@ -3865,7 +3874,7 @@ static void do_cmd(int c) | |||
| 3865 | p = dot - 1; | 3874 | p = dot - 1; |
| 3866 | } | 3875 | } |
| 3867 | dc4: | 3876 | dc4: |
| 3868 | q = char_search(p, last_search_pattern + 1, dir, FULL); | 3877 | q = char_search(p, last_search_pattern + 1, (dir << 1) | FULL); |
| 3869 | if (q != NULL) { | 3878 | if (q != NULL) { |
| 3870 | dot = q; // good search, update "dot" | 3879 | dot = q; // good search, update "dot" |
| 3871 | msg = NULL; | 3880 | msg = NULL; |
| @@ -3876,7 +3885,7 @@ static void do_cmd(int c) | |||
| 3876 | if (dir == BACK) { | 3885 | if (dir == BACK) { |
| 3877 | p = end - 1; | 3886 | p = end - 1; |
| 3878 | } | 3887 | } |
| 3879 | q = char_search(p, last_search_pattern + 1, dir, FULL); | 3888 | q = char_search(p, last_search_pattern + 1, (dir << 1) | FULL); |
| 3880 | if (q != NULL) { // found something | 3889 | if (q != NULL) { // found something |
| 3881 | dot = q; // found new pattern- goto it | 3890 | dot = q; // found new pattern- goto it |
| 3882 | msg = "search hit BOTTOM, continuing at TOP"; | 3891 | msg = "search hit BOTTOM, continuing at TOP"; |
| @@ -3892,13 +3901,13 @@ static void do_cmd(int c) | |||
| 3892 | } while (--cmdcnt > 0); | 3901 | } while (--cmdcnt > 0); |
| 3893 | break; | 3902 | break; |
| 3894 | case '{': // {- move backward paragraph | 3903 | case '{': // {- move backward paragraph |
| 3895 | q = char_search(dot, "\n\n", BACK, FULL); | 3904 | q = char_search(dot, "\n\n", (BACK << 1) | FULL); |
| 3896 | if (q != NULL) { // found blank line | 3905 | if (q != NULL) { // found blank line |
| 3897 | dot = next_line(q); // move to next blank line | 3906 | dot = next_line(q); // move to next blank line |
| 3898 | } | 3907 | } |
| 3899 | break; | 3908 | break; |
| 3900 | case '}': // }- move forward paragraph | 3909 | case '}': // }- move forward paragraph |
| 3901 | q = char_search(dot, "\n\n", FORWARD, FULL); | 3910 | q = char_search(dot, "\n\n", (FORWARD << 1) | FULL); |
| 3902 | if (q != NULL) { // found blank line | 3911 | if (q != NULL) { // found blank line |
| 3903 | dot = next_line(q); // move to next blank line | 3912 | dot = next_line(q); // move to next blank line |
| 3904 | } | 3913 | } |
diff --git a/include/libbb.h b/include/libbb.h index 405c929a2..4ac749fd3 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
| @@ -1431,7 +1431,7 @@ struct number_state { | |||
| 1431 | const char *empty_str; | 1431 | const char *empty_str; |
| 1432 | smallint all, nonempty; | 1432 | smallint all, nonempty; |
| 1433 | }; | 1433 | }; |
| 1434 | void print_numbered_lines(struct number_state *ns, const char *filename) FAST_FUNC; | 1434 | int print_numbered_lines(struct number_state *ns, const char *filename) FAST_FUNC; |
| 1435 | 1435 | ||
| 1436 | 1436 | ||
| 1437 | /* Networking */ | 1437 | /* Networking */ |
diff --git a/libbb/print_numbered_lines.c b/libbb/print_numbered_lines.c index 9a8a51440..d6459d7c3 100644 --- a/libbb/print_numbered_lines.c +++ b/libbb/print_numbered_lines.c | |||
| @@ -8,12 +8,16 @@ | |||
| 8 | 8 | ||
| 9 | #include "libbb.h" | 9 | #include "libbb.h" |
| 10 | 10 | ||
| 11 | void FAST_FUNC print_numbered_lines(struct number_state *ns, const char *filename) | 11 | int FAST_FUNC print_numbered_lines(struct number_state *ns, const char *filename) |
| 12 | { | 12 | { |
| 13 | FILE *fp = fopen_or_warn_stdin(filename); | 13 | FILE *fp = fopen_or_warn_stdin(filename); |
| 14 | unsigned N = ns->start; | 14 | unsigned N; |
| 15 | char *line; | 15 | char *line; |
| 16 | 16 | ||
| 17 | if (!fp) | ||
| 18 | return EXIT_FAILURE; | ||
| 19 | |||
| 20 | N = ns->start; | ||
| 17 | while ((line = xmalloc_fgetline(fp)) != NULL) { | 21 | while ((line = xmalloc_fgetline(fp)) != NULL) { |
| 18 | if (ns->all | 22 | if (ns->all |
| 19 | || (ns->nonempty && line[0]) | 23 | || (ns->nonempty && line[0]) |
| @@ -27,4 +31,6 @@ void FAST_FUNC print_numbered_lines(struct number_state *ns, const char *filenam | |||
| 27 | ns->start = N; | 31 | ns->start = N; |
| 28 | 32 | ||
| 29 | fclose(fp); | 33 | fclose(fp); |
| 34 | |||
| 35 | return EXIT_SUCCESS; | ||
| 30 | } | 36 | } |
diff --git a/libbb/process_escape_sequence.c b/libbb/process_escape_sequence.c index 59d0d3ea8..13022b83e 100644 --- a/libbb/process_escape_sequence.c +++ b/libbb/process_escape_sequence.c | |||
| @@ -37,12 +37,18 @@ char FAST_FUNC bb_process_escape_sequence(const char **ptr) | |||
| 37 | * We treat \2 as a valid octal escape sequence. */ | 37 | * We treat \2 as a valid octal escape sequence. */ |
| 38 | do { | 38 | do { |
| 39 | unsigned r; | 39 | unsigned r; |
| 40 | #if !WANT_HEX_ESCAPES | ||
| 41 | unsigned d = (unsigned char)(*q) - '0'; | 40 | unsigned d = (unsigned char)(*q) - '0'; |
| 42 | #else | 41 | #if WANT_HEX_ESCAPES |
| 43 | unsigned d = (unsigned char)_tolower(*q) - '0'; | 42 | if (d >= 10) { |
| 44 | if (d >= 10) | 43 | d = (unsigned char)_tolower(*q) - 'a'; |
| 45 | d += ('0' - 'a' + 10); | 44 | //d += 10; |
| 45 | /* The above would map 'A'-'F' and 'a'-'f' to 10-15, | ||
| 46 | * however, some chars like '@' would map to 9 < base. | ||
| 47 | * Do not allow that, map invalid chars to N > base: | ||
| 48 | */ | ||
| 49 | if ((int)d >= 0) | ||
| 50 | d += 10; | ||
| 51 | } | ||
| 46 | #endif | 52 | #endif |
| 47 | if (d >= base) { | 53 | if (d >= base) { |
| 48 | if (WANT_HEX_ESCAPES && base == 16) { | 54 | if (WANT_HEX_ESCAPES && base == 16) { |
