From: Elliott Hughes
Date: Wed, 5 Jul 2017 19:51:55 +0000 (+0000)
Subject: Merge remote-tracking branch 'toybox/master' into HEAD am: a379d5ee15 am: a4f4fa78eb
X-Git-Tag: android-x86-8.1-r1^2~4^2^2
X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e1097aac542017126728135bbc6073963b247569;hp=edfa9dc9c6edfdd47d659166298bab56c7557547;p=android-x86%2Fexternal-toybox.git
Merge remote-tracking branch 'toybox/master' into HEAD am: a379d5ee15 am: a4f4fa78eb
am: cb13c3da93
Change-Id: I627d5f6fa77e1083ea1167ff8179c94c3046918e
---
diff --git a/generated/flags.h b/generated/flags.h
index a240db12..431b924a 100644
--- a/generated/flags.h
+++ b/generated/flags.h
@@ -1010,14 +1010,15 @@
#undef FLAG_c
#endif
-// head ?n#<0=10qv ?n#<0=10qv
+// head ?n#<0=10c#<0qv[-nc] ?n#<0=10c#<0qv[-nc]
#undef OPTSTR_head
-#define OPTSTR_head "?n#<0=10qv"
+#define OPTSTR_head "?n#<0=10c#<0qv[-nc]"
#ifdef CLEANUP_head
#undef CLEANUP_head
#undef FOR_head
#undef FLAG_v
#undef FLAG_q
+#undef FLAG_c
#undef FLAG_n
#endif
@@ -2410,9 +2411,9 @@
#undef FOR_stop
#endif
-// strings an#=4<1fo an#=4<1fo
+// strings t:an#=4<1fo t:an#=4<1fo
#undef OPTSTR_strings
-#define OPTSTR_strings "an#=4<1fo"
+#define OPTSTR_strings "t:an#=4<1fo"
#ifdef CLEANUP_strings
#undef CLEANUP_strings
#undef FOR_strings
@@ -2420,6 +2421,7 @@
#undef FLAG_f
#undef FLAG_n
#undef FLAG_a
+#undef FLAG_t
#endif
// su lmpc:s:
@@ -4078,7 +4080,8 @@
#endif
#define FLAG_v (1<<0)
#define FLAG_q (1<<1)
-#define FLAG_n (1<<2)
+#define FLAG_c (1<<2)
+#define FLAG_n (1<<3)
#endif
#ifdef FOR_hello
@@ -5248,6 +5251,7 @@
#define FLAG_f (1<<1)
#define FLAG_n (1<<2)
#define FLAG_a (1<<3)
+#define FLAG_t (1<<4)
#endif
#ifdef FOR_su
diff --git a/generated/globals.h b/generated/globals.h
index 00fcc16c..5e4f8ce5 100644
--- a/generated/globals.h
+++ b/generated/globals.h
@@ -1117,6 +1117,7 @@ struct grep_data {
// toys/posix/head.c
struct head_data {
+ long bytes;
long lines;
int file_no;
};
@@ -1326,6 +1327,7 @@ struct split_data {
struct strings_data {
long num;
+ char *t;
};
// toys/posix/tail.c
diff --git a/generated/help.h b/generated/help.h
index 49a14f95..811b5340 100644
--- a/generated/help.h
+++ b/generated/help.h
@@ -460,7 +460,7 @@
#define HELP_tail "usage: tail [-n|c NUMBER] [-f] [FILE...]\n\nCopy last lines from files to stdout. If no files listed, copy from\nstdin. Filename \"-\" is a synonym for stdin.\n\n-n output the last NUMBER lines (default 10), +X counts from start\n-c output the last NUMBER bytes, +NUMBER counts from start\n-f follow FILE(s), waiting for more data to be appended\n\n"
-#define HELP_strings "usage: strings [-fo] [-n LEN] [FILE...]\n\nDisplay printable strings in a binary file\n\n-f Precede strings with filenames\n-n At least LEN characters form a string (default 4)\n-o Precede strings with decimal offsets\n\n"
+#define HELP_strings "usage: strings [-fo] [-t oxd] [-n LEN] [FILE...]\n\nDisplay printable strings in a binary file\n\n-f Show filename\n-n At least LEN characters form a string (default 4)\n-o Show offset (ala -t d)\n-t Show offset type (o=octal, d=decimal, x=hexadecimal)\n\n"
#define HELP_split "usage: split [-a SUFFIX_LEN] [-b BYTES] [-l LINES] [INPUT [OUTPUT]]\n\nCopy INPUT (or stdin) data to a series of OUTPUT (or \"x\") files with\nalphabetically increasing suffix (aa, ab, ac... az, ba, bb...).\n\n-a Suffix length (default 2)\n-b BYTES/file (10, 10k, 10m, 10g...)\n-l LINES/file (default 1000)\n\n"
@@ -530,7 +530,7 @@
#define HELP_id "usage: id [-GZgnru] \n\nPrint user and group ID.\n-G Show only the group IDs\n-Z Show only security context\n-g Show only the effective group ID\n-n print names instead of numeric IDs (to be used with -Ggu)\n-r Show real ID instead of effective ID\n-u Show only the effective user ID\n"
-#define HELP_head "usage: head [-n number] [file...]\n\nCopy first lines from files to stdout. If no files listed, copy from\nstdin. Filename \"-\" is a synonym for stdin.\n\n-n Number of lines to copy\n-q Never print headers\n-v Always print headers\n\n"
+#define HELP_head "usage: head [-n number] [file...]\n\nCopy first lines from files to stdout. If no files listed, copy from\nstdin. Filename \"-\" is a synonym for stdin.\n\n-n Number of lines to copy\n-c Number of bytes to copy\n-q Never print headers\n-v Always print headers\n\n"
#define HELP_grep "usage: grep [-EFrivwcloqsHbhn] [-ABC NUM] [-m MAX] [-e REGEX]... [-MS PATTERN]... [-f REGFILE] [FILE]...\n\nShow lines matching regular expressions. If no -e, first argument is\nregular expression to match. With no files (or \"-\" filename) read stdin.\nReturns 0 if matched, 1 if no match found.\n\n-e Regex to match. (May be repeated.)\n-f File listing regular expressions to match.\n\nfile search:\n-r Recurse into subdirectories (defaults FILE to \".\")\n-M Match filename pattern (--include)\n-S Skip filename pattern (--exclude)\n\nmatch type:\n-A Show NUM lines after -B Show NUM lines before match\n-C NUM lines context (A+B) -E extended regex syntax\n-F fixed (literal match) -i case insensitive\n-m match MAX many lines -v invert match\n-w whole word (implies -E) -x whole line\n-z input NUL terminated\n\ndisplay modes: (default: matched line)\n-c count of matching lines -l show matching filenames\n-o only matching part -q quiet (errors only)\n-s silent (no error msg) -Z output NUL terminated\n\noutput prefix (default: filename if checking more than 1 file)\n-H force filename -b byte offset of match\n-h hide filename -n line number of match\n\n"
diff --git a/generated/newtoys.h b/generated/newtoys.h
index fc2811dc..3d62e0d1 100644
--- a/generated/newtoys.h
+++ b/generated/newtoys.h
@@ -89,7 +89,7 @@ USE_GROUPS(NEWTOY(groups, NULL, TOYFLAG_USR|TOYFLAG_BIN))
USE_GUNZIP(NEWTOY(gunzip, "cdfk123456789", TOYFLAG_USR|TOYFLAG_BIN))
USE_GZIP(NEWTOY(gzip, "cdfk123456789", TOYFLAG_USR|TOYFLAG_BIN))
USE_REBOOT(OLDTOY(halt, reboot, TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
-USE_HEAD(NEWTOY(head, "?n#<0=10qv", TOYFLAG_USR|TOYFLAG_BIN))
+USE_HEAD(NEWTOY(head, "?n#<0=10c#<0qv[-nc]", TOYFLAG_USR|TOYFLAG_BIN))
USE_HELLO(NEWTOY(hello, 0, TOYFLAG_USR|TOYFLAG_BIN))
USE_HELP(NEWTOY(help, ""USE_HELP_EXTRAS("ah"), TOYFLAG_BIN))
USE_HEXEDIT(NEWTOY(hexedit, "<1>1r", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))
@@ -217,7 +217,7 @@ USE_SPLIT(NEWTOY(split, ">2a#<1=2>9b#<1l#<1[!bl]", TOYFLAG_USR|TOYFLAG_BIN))
USE_START(NEWTOY(start, "", TOYFLAG_USR|TOYFLAG_SBIN))
USE_STAT(NEWTOY(stat, "<1c:fLt", TOYFLAG_BIN))
USE_STOP(NEWTOY(stop, "", TOYFLAG_USR|TOYFLAG_SBIN))
-USE_STRINGS(NEWTOY(strings, "an#=4<1fo", TOYFLAG_USR|TOYFLAG_BIN))
+USE_STRINGS(NEWTOY(strings, "t:an#=4<1fo", TOYFLAG_USR|TOYFLAG_BIN))
USE_SU(NEWTOY(su, "lmpc:s:", TOYFLAG_BIN|TOYFLAG_ROOTONLY))
USE_SULOGIN(NEWTOY(sulogin, "t#<0=0", TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
USE_SWAPOFF(NEWTOY(swapoff, "<1>1", TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
diff --git a/lib/lib.c b/lib/lib.c
index ceb1bc7d..6e88fd25 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -299,11 +299,12 @@ long long atolx(char *numstr)
val = xstrtol(numstr, &c, 0);
if (c != numstr && *c && (end = strchr(suffixes, tolower(*c)))) {
- int shift = end-suffixes-2;
+ int shift = end-suffixes-1;
- if (shift >= 0) {
- if (toupper(*++c)=='d') do val *= 1000; while (shift--);
- else val *= 1024LL<<(shift*10);
+ if (!shift) val *= 512;
+ else if (shift>0) {
+ if (toupper(*++c)=='d') while (shift--) val *= 1000;
+ else val *= 1LL<<(shift*10);
}
}
while (isspace(*c)) c++;
diff --git a/main.c b/main.c
index fcb87029..6025d43f 100644
--- a/main.c
+++ b/main.c
@@ -6,7 +6,7 @@
#include "toys.h"
#ifndef TOYBOX_VERSION
-#define TOYBOX_VERSION "0.7.3"
+#define TOYBOX_VERSION "0.7.4"
#endif
// Populate toy_list[].
diff --git a/tests/head.test b/tests/head.test
index 6ed027c4..4e4c01bd 100755
--- a/tests/head.test
+++ b/tests/head.test
@@ -27,3 +27,7 @@ testing "-q, multiple files" "head -q -n 2 input file1" "one\ntwo\nfoo\nbar\n" \
"one\ntwo\nthree\n" ""
rm file1
+testing "-c 3" "head -c 3" "one" "" "one\ntwo"
+testing "-c bigger than input" "head -c 3" "a" "" "a"
+testing "-c 3 -n 1" "head -c 3 -n 1" "one\n" "" "one\ntwo"
+testing "-n 1 -c 3" "head -n 1 -c 3" "one" "" "one\ntwo"
diff --git a/tests/strings.test b/tests/strings.test
new file mode 100644
index 00000000..8becc2f5
--- /dev/null
+++ b/tests/strings.test
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+[ -f testing.sh ] && . testing.sh
+
+#testing "name" "command" "result" "infile" "stdin"
+
+testing "stdin" "strings" "foobar\n" "" "foobar\n"
+testing "file" "strings input" "foobar\n" "foobar\n" ""
+testing "string to the end" "strings input" "foobar\n" "foobar" ""
+testing "short strings" "strings input" "" "foo\nbar\n" ""
+testing "-n6" "strings -n6 input" "foobar\n" "foobar\nbaz\n" ""
+testing "string and nulls" "strings input" "foobar\nbazfoo\n" \
+ "\0foobar\0\0bazfoo\0foo" ""
+testing "-f" "strings -f input" "input: foobar\n" "foobar\n" ""
+testing "-o" "strings -o input | sed 's/^ *//'" "6 foobar\n" \
+ "\0\0\0\0\0\0foobar\n" ""
+testing "-o, multiple strings" "strings -n3 -o input | sed 's/^ *//'" \
+ "1 foo\n7 bar\n" "\0foo\0b\0bar\n" ""
+testing "-fo" "strings -fo input | sed 's/: */: /'" "input: 6 foobar\n" \
+ "\0\0\0\0\0\0foobar\n" ""
diff --git a/toys/posix/head.c b/toys/posix/head.c
index 63eb85b0..ea4bbbc6 100644
--- a/toys/posix/head.c
+++ b/toys/posix/head.c
@@ -3,8 +3,10 @@
* Copyright 2006 Timothy Elliott
*
* See http://opengroup.org/onlinepubs/9699919799/utilities/head.html
+ *
+ * Deviations from posix: -c
-USE_HEAD(NEWTOY(head, "?n#<0=10qv", TOYFLAG_USR|TOYFLAG_BIN))
+USE_HEAD(NEWTOY(head, "?n#<0=10c#<0qv[-nc]", TOYFLAG_USR|TOYFLAG_BIN))
config HEAD
bool "head"
@@ -16,6 +18,7 @@ config HEAD
stdin. Filename "-" is a synonym for stdin.
-n Number of lines to copy
+ -c Number of bytes to copy
-q Never print headers
-v Always print headers
*/
@@ -24,13 +27,14 @@ config HEAD
#include "toys.h"
GLOBALS(
+ long bytes;
long lines;
int file_no;
)
static void do_head(int fd, char *name)
{
- int i, len, lines=TT.lines, size=sizeof(toybuf);
+ int i, len, lines=TT.lines, bytes=TT.bytes;
if ((toys.optc > 1 && !(toys.optflags & FLAG_q)) || toys.optflags & FLAG_v) {
// Print an extra newline for all but the first file
@@ -39,12 +43,15 @@ static void do_head(int fd, char *name)
xflush();
}
- while (lines) {
- len = read(fd, toybuf, size);
+ while ((toys.optflags&FLAG_c) ? bytes : lines) {
+ len = read(fd, toybuf, sizeof(toybuf));
if (len<0) perror_msg_raw(name);
if (len<1) break;
- for(i=0; i= len ? len : bytes;
+ bytes -= i;
+ } else for(i=0; i
* Copyright 2014 Kyungwan Han
*
- * No Standard
+ * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/strings.html
+ *
+ * Deviations from posix: we don't readahead to the end of the string to see
+ * if it ends with NUL or newline before printing. Add -o. We always do -a
+ * (and accept but don't document the flag), but that's sort of conformant.
+ * Posix' STDOUT section says things like "%o %s" and we support 64 bit offsets.
+ *
* TODO: utf8 strings
- * TODO: posix -t
-USE_STRINGS(NEWTOY(strings, "an#=4<1fo", TOYFLAG_USR|TOYFLAG_BIN))
+USE_STRINGS(NEWTOY(strings, "t:an#=4<1fo", TOYFLAG_USR|TOYFLAG_BIN))
config STRINGS
bool "strings"
default y
help
- usage: strings [-fo] [-n LEN] [FILE...]
+ usage: strings [-fo] [-t oxd] [-n LEN] [FILE...]
Display printable strings in a binary file
- -f Precede strings with filenames
+ -f Show filename
-n At least LEN characters form a string (default 4)
- -o Precede strings with decimal offsets
+ -o Show offset (ala -t d)
+ -t Show offset type (o=octal, d=decimal, x=hexadecimal)
*/
#define FOR_strings
@@ -27,35 +33,51 @@ config STRINGS
GLOBALS(
long num;
+ char *t;
)
static void do_strings(int fd, char *filename)
{
int nread, i, wlen = TT.num, count = 0;
off_t offset = 0;
- char *string = xzalloc(wlen + 1);
+ char *string = 0, pattern[8];
+
+ if (TT.t) if (!(string = strchr("oxd", *TT.t))) error_exit("-t needs oxd");
+ sprintf(pattern, "%%7ll%c ", string ? *string : 'd');
+
+ // input buffer can wrap before we have enough data to output, so
+ // copy start of string to temporary buffer until enough to output
+ string = xzalloc(wlen+1);
+
+ for (i = nread = 0; ;i++) {
+ if (i >= nread) {
+ nread = read(fd, toybuf, sizeof(toybuf));
+ i = 0;
+ if (nread < 0) perror_msg_raw(filename);
+ if (nread < 1) {
+ if (count) goto flush;
+ break;
+ }
+ }
- for (;;) {
- nread = read(fd, toybuf, sizeof(toybuf));
- if (nread < 0) perror_msg_raw(filename);
- if (nread < 1) break;
- for (i = 0; i < nread; i++, offset++) {
- if (((toybuf[i] >= 32) && (toybuf[i] <= 126)) || (toybuf[i] == '\t')) {
- if (count == wlen) fputc(toybuf[i], stdout);
- else {
- string[count++] = toybuf[i];
- if (count == wlen) {
- if (toys.optflags & FLAG_f) printf("%s: ", filename);
- if (toys.optflags & FLAG_o)
- printf("%7lld ",(long long)(offset - wlen));
- printf("%s", string);
- }
+ offset++;
+ if ((toybuf[i]>=32 && toybuf[i]<=126) || toybuf[i]=='\t') {
+ if (count == wlen) fputc(toybuf[i], stdout);
+ else {
+ string[count++] = toybuf[i];
+ if (count == wlen) {
+ if (toys.optflags & FLAG_f) printf("%s: ", filename);
+ if (toys.optflags & (FLAG_o|FLAG_t))
+ printf(pattern, (long long)(offset - wlen));
+ printf("%s", string);
}
- } else {
- if (count == wlen) xputc('\n');
- count = 0;
}
+ continue;
}
+flush:
+ // End of previous string
+ if (count == wlen) xputc('\n');
+ count = 0;
}
xclose(fd);
free(string);
diff --git a/www/news.html b/www/news.html
index 73516b0b..f2733a72 100755
--- a/www/news.html
+++ b/www/news.html
@@ -8,6 +8,93 @@ a development environment. See the links on the left for details.
News
+
June 19, 2017
+It is a well-known fact that those people who most want to rule people are, ipso facto, those least suited to do it.
+To summarize the summary: anyone who is capable of getting themselves made President should on no account be allowed to do the job.
+- The Hitchhiker's Guide to the Galaxy
+
+
+Toybox 0.7.4
+(git commit)
+is out. No new commands this time, but
+chrt and dmesg got promoted out of pending.
+
+New features:
+Rob rewrote paste, which should work much better now, and added grep
+-M and -S to match and skip wildcards respectively (useful with -r).
+Elliott's updated dmesg has -T and --color. The file
+command can recognize gzip now, uptime grew -s, date grew %N, env knows - as a first argument
+means -i (posix!) and grew -0, ls defaults to -b
+instead of -q now when there's a tty, and ls has a new -ll option (with
+--full-time as a compatibility synonym) showing nanoseconds and (for some
+reason) timezone. (Why do individual files have timezones?) Elliott added
+"uudecode -o -" support. Illya Kuzmich taught head -v and -q. The cpio
+code no longer adds the "TRAILER!!!" entry by default (initramfs extractor
+doesn't care) without which you can concatenate cpio archives with "cat".
+(Use the new --trailer option if you want the legacy behavior.)
+In pending, fdisk compiles now and tar understands bzip2.
+
+Build:
+The "make install_airlock" target now symlinks bc from the host because
+the kernel inexplicably
+needs that to build. This was motivated by
+mkroot, which builds under
+a toybox airlock directory.
+
+Lots of work on the test suite, mostly from the Android guys who are now
+running it under Android. This fixed several existing tests that didn't
+pass, made more tests run on a toybox-only system, and so on. The test suite
+infrastructure now has a second testing function,
+"testcmd", which supplies the command name being tested (bypassing
+shell builtins).
+
+Various android build and config fixes, getting closer to being able
+to let android someday use scripts/make.sh instead of generated/* snapshots.
+Also more work into building under android's NDK; not quite there yet
+but much closer.
+Use nproc in scripts/make.sh detect available processors (so you can control the SMP level with taskset).
+Removed the old uClibc compatibility glue, it's been 5 years since their
+last release.
+
+The new config option TOYBOX_PEDANTIC_ARGS checks arguments when there
+are no arguments, so things like "uptime" no longer silently ignore arguments
+you pass but instead refuse to run.
+
+Docs:
+The FAQ now has more than one entry. Commands no longer output the full
+help text for argument errors but instead just say "See %s --help" with the
+command name (in addition to the actual error message).
+Elliott did a big period-ectomy on all the --help text, and
+we cleaned up some tab/space inconsistency. The
+non-html help -a output now has separators with the command name.
+The top/iotop and pkill/pgrep help text now describe a lot more of what
+the commands can do. Twitter's code of conduct page went down so we
+mirrored the text locally.
+
+Bugfixes:
+Fixed a race condition in ps/top where a process that exited right as we
+read its data returned a different error value than we were expecting (which
+was causing long-running top instances to occasionally exit),
+mount now gives an error if it can't autodetect the filesystem
+type, ps no longer queries the terminal size when output isn't to a tty
+(so "ps -A | cat" doesn't vary), date's chkmktime() was replaced with
+simple range checks for fields (to avoid false positives from things like
+timezones and daylight savings time), removed %s from date's help (we
+didn't implement it, we have @seconds[.nanoseconds] instead), fixed
+zcat's buffer flush logic (which was always failing on files larger
+than 32k), and factor now detects requests for numbers >64 bits and fails
+loudly instead of producing incorrect answers.
+Elliott fixed touch -a/-m (they were backwards), and allowed ':' in
+setprop's property names. Grep now exits with 2 for errors (so -q can
+distinguish "didn't find" from "didn't work"), doesn't stop on symlinks
+that point nowhere (there was an error_exit() that should just be a warning),
+and provides error messages for files we could open but not read.
+
+Library:
+New library functions: strend() complements strstart(), minof()/maxof()
+are min/max macros that evalute arguments once and autodetect type (why
+isn't this in libc?), xmmap() checks MAP_FAILED (which is not NULL).
+
February 21, 2017
Only six people in the Galaxy knew that the job of the
Galactic President was not to wield power but to attract attention