diff options
author | Elliott Hughes <enh@google.com> | 2023-04-06 16:34:56 +0000 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2023-04-06 16:34:56 +0000 |
commit | 6cc4588ba6d8b2ecaca09c269456e006a1b6db0a (patch) | |
tree | af927fc96e921768c5234879ffe5a62847c7b682 | |
parent | d9909513e2aa031e0b16af2464695c8e8df237ce (diff) | |
parent | 9f683b843678048d6008bf26f3e6cdef085258db (diff) | |
download | toybox-6cc4588ba6d8b2ecaca09c269456e006a1b6db0a.tar.gz |
Upgrade toybox to 9f683b843678048d6008bf26f3e6cdef085258db
This project was upgraded with external_updater.
Usage: tools/external_updater/updater.sh update toybox
For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md
Test: TreeHugger
Change-Id: Ie2fcec8fa5653fcf90ab709c2001fea6a62fc316
-rw-r--r-- | METADATA | 6 | ||||
-rw-r--r-- | android/device/generated/flags.h | 14 | ||||
-rw-r--r-- | android/device/generated/globals.h | 2 | ||||
-rw-r--r-- | android/device/generated/help.h | 2 | ||||
-rw-r--r-- | android/device/generated/newtoys.h | 2 | ||||
-rw-r--r-- | android/linux/generated/flags.h | 14 | ||||
-rw-r--r-- | android/linux/generated/globals.h | 2 | ||||
-rw-r--r-- | android/linux/generated/help.h | 2 | ||||
-rw-r--r-- | android/linux/generated/newtoys.h | 2 | ||||
-rw-r--r-- | android/mac/generated/flags.h | 14 | ||||
-rw-r--r-- | android/mac/generated/globals.h | 2 | ||||
-rw-r--r-- | android/mac/generated/help.h | 2 | ||||
-rw-r--r-- | android/mac/generated/newtoys.h | 2 | ||||
-rw-r--r-- | lib/args.c | 5 | ||||
-rw-r--r-- | scripts/portability.sh | 2 | ||||
-rw-r--r-- | scripts/runtest.sh | 8 | ||||
-rwxr-xr-x | tests/ls.test | 104 | ||||
-rwxr-xr-x | tests/sed.test | 135 | ||||
-rwxr-xr-x | tests/tar.test | 5 | ||||
-rw-r--r-- | toys/lsb/seq.c | 32 | ||||
-rw-r--r-- | toys/other/lsusb.c | 33 | ||||
-rw-r--r-- | toys/posix/tar.c | 10 |
22 files changed, 203 insertions, 197 deletions
@@ -13,11 +13,11 @@ third_party { type: GIT value: "https://github.com/landley/toybox" } - version: "1819be919d0566e2d2130bf90d90483a4e2318b6" + version: "9f683b843678048d6008bf26f3e6cdef085258db" license_type: UNENCUMBERED last_upgrade_date { year: 2023 - month: 3 - day: 23 + month: 4 + day: 6 } } diff --git a/android/device/generated/flags.h b/android/device/generated/flags.h index cdfb271d..55672500 100644 --- a/android/device/generated/flags.h +++ b/android/device/generated/flags.h @@ -1904,13 +1904,14 @@ #undef FLAG_l #endif -// lspci emkn@i: emkn@i: +// lspci emkn@x@i: emkn@x@i: #undef OPTSTR_lspci -#define OPTSTR_lspci "emkn@i:" +#define OPTSTR_lspci "emkn@x@i:" #ifdef CLEANUP_lspci #undef CLEANUP_lspci #undef FOR_lspci #undef FLAG_i +#undef FLAG_x #undef FLAG_n #undef FLAG_k #undef FLAG_m @@ -5606,10 +5607,11 @@ #define TT this.lspci #endif #define FLAG_i (1LL<<0) -#define FLAG_n (1LL<<1) -#define FLAG_k (1LL<<2) -#define FLAG_m (1LL<<3) -#define FLAG_e (1LL<<4) +#define FLAG_x (1LL<<1) +#define FLAG_n (1LL<<2) +#define FLAG_k (1LL<<3) +#define FLAG_m (1LL<<4) +#define FLAG_e (1LL<<5) #endif #ifdef FOR_lsusb diff --git a/android/device/generated/globals.h b/android/device/generated/globals.h index 6dd8f98b..2b646d04 100644 --- a/android/device/generated/globals.h +++ b/android/device/generated/globals.h @@ -362,7 +362,7 @@ struct lsattr_data { struct lsusb_data { char *i; - long n; + long x, n; void *ids, *class; int count; diff --git a/android/device/generated/help.h b/android/device/generated/help.h index 6d485773..d771c2f7 100644 --- a/android/device/generated/help.h +++ b/android/device/generated/help.h @@ -252,7 +252,7 @@ #define HELP_lsusb "usage: lsusb [-i]\n\nList USB hosts/devices.\n\n-i ID database (default /etc/usb.ids[.gz])" -#define HELP_lspci "usage: lspci [-ekmn] [-i FILE]\n\nList PCI devices.\n\n-e Extended (6 digit) class\n-i ID database (default /etc/pci.ids[.gz])\n-k Show kernel driver\n-m Machine readable\n-n Numeric output (-nn for both)" +#define HELP_lspci "usage: lspci [-ekmn] [-i FILE]\n\nList PCI devices.\n\n-e Extended (6 digit) class\n-i ID database (default /etc/pci.ids[.gz])\n-k Show kernel driver\n-m Machine readable\n-n Numeric output (-nn for both)\n-x Hex dump of config space (64 bytes; -xxx for 256, -xxxx for 4096)" #define HELP_lsmod "usage: lsmod\n\nDisplay the currently loaded modules, their sizes and their dependencies." diff --git a/android/device/generated/newtoys.h b/android/device/generated/newtoys.h index 28aa322d..72091791 100644 --- a/android/device/generated/newtoys.h +++ b/android/device/generated/newtoys.h @@ -173,7 +173,7 @@ USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241\376ZgoACF USE_LSATTR(NEWTOY(lsattr, "ldapvR", TOYFLAG_BIN)) USE_LSMOD(NEWTOY(lsmod, NULL, TOYFLAG_SBIN)) USE_LSOF(NEWTOY(lsof, "lp*t", TOYFLAG_USR|TOYFLAG_BIN)) -USE_LSPCI(NEWTOY(lspci, "emkn@i:", TOYFLAG_USR|TOYFLAG_BIN)) +USE_LSPCI(NEWTOY(lspci, "emkn@x@i:", TOYFLAG_USR|TOYFLAG_BIN)) USE_LSUSB(NEWTOY(lsusb, "i:", TOYFLAG_USR|TOYFLAG_BIN)) USE_MAKEDEVS(NEWTOY(makedevs, "<1>1d:", TOYFLAG_USR|TOYFLAG_BIN)) USE_MAN(NEWTOY(man, "k:M:", TOYFLAG_USR|TOYFLAG_BIN)) diff --git a/android/linux/generated/flags.h b/android/linux/generated/flags.h index fd587ef3..f0a29d93 100644 --- a/android/linux/generated/flags.h +++ b/android/linux/generated/flags.h @@ -1904,13 +1904,14 @@ #undef FLAG_l #endif -// lspci emkn@i: +// lspci emkn@x@i: #undef OPTSTR_lspci -#define OPTSTR_lspci "emkn@i:" +#define OPTSTR_lspci "emkn@x@i:" #ifdef CLEANUP_lspci #undef CLEANUP_lspci #undef FOR_lspci #undef FLAG_i +#undef FLAG_x #undef FLAG_n #undef FLAG_k #undef FLAG_m @@ -5606,10 +5607,11 @@ #define TT this.lspci #endif #define FLAG_i (FORCED_FLAG<<0) -#define FLAG_n (FORCED_FLAG<<1) -#define FLAG_k (FORCED_FLAG<<2) -#define FLAG_m (FORCED_FLAG<<3) -#define FLAG_e (FORCED_FLAG<<4) +#define FLAG_x (FORCED_FLAG<<1) +#define FLAG_n (FORCED_FLAG<<2) +#define FLAG_k (FORCED_FLAG<<3) +#define FLAG_m (FORCED_FLAG<<4) +#define FLAG_e (FORCED_FLAG<<5) #endif #ifdef FOR_lsusb diff --git a/android/linux/generated/globals.h b/android/linux/generated/globals.h index 6dd8f98b..2b646d04 100644 --- a/android/linux/generated/globals.h +++ b/android/linux/generated/globals.h @@ -362,7 +362,7 @@ struct lsattr_data { struct lsusb_data { char *i; - long n; + long x, n; void *ids, *class; int count; diff --git a/android/linux/generated/help.h b/android/linux/generated/help.h index 751dd611..c95b74a1 100644 --- a/android/linux/generated/help.h +++ b/android/linux/generated/help.h @@ -254,7 +254,7 @@ #define HELP_lsusb "usage: lsusb [-i]\n\nList USB hosts/devices.\n\n-i ID database (default /etc/usb.ids[.gz])" -#define HELP_lspci "usage: lspci [-ekmn] [-i FILE]\n\nList PCI devices.\n\n-e Extended (6 digit) class\n-i ID database (default /etc/pci.ids[.gz])\n-k Show kernel driver\n-m Machine readable\n-n Numeric output (-nn for both)" +#define HELP_lspci "usage: lspci [-ekmn] [-i FILE]\n\nList PCI devices.\n\n-e Extended (6 digit) class\n-i ID database (default /etc/pci.ids[.gz])\n-k Show kernel driver\n-m Machine readable\n-n Numeric output (-nn for both)\n-x Hex dump of config space (64 bytes; -xxx for 256, -xxxx for 4096)" #define HELP_lsmod "usage: lsmod\n\nDisplay the currently loaded modules, their sizes and their dependencies." diff --git a/android/linux/generated/newtoys.h b/android/linux/generated/newtoys.h index 28aa322d..72091791 100644 --- a/android/linux/generated/newtoys.h +++ b/android/linux/generated/newtoys.h @@ -173,7 +173,7 @@ USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241\376ZgoACF USE_LSATTR(NEWTOY(lsattr, "ldapvR", TOYFLAG_BIN)) USE_LSMOD(NEWTOY(lsmod, NULL, TOYFLAG_SBIN)) USE_LSOF(NEWTOY(lsof, "lp*t", TOYFLAG_USR|TOYFLAG_BIN)) -USE_LSPCI(NEWTOY(lspci, "emkn@i:", TOYFLAG_USR|TOYFLAG_BIN)) +USE_LSPCI(NEWTOY(lspci, "emkn@x@i:", TOYFLAG_USR|TOYFLAG_BIN)) USE_LSUSB(NEWTOY(lsusb, "i:", TOYFLAG_USR|TOYFLAG_BIN)) USE_MAKEDEVS(NEWTOY(makedevs, "<1>1d:", TOYFLAG_USR|TOYFLAG_BIN)) USE_MAN(NEWTOY(man, "k:M:", TOYFLAG_USR|TOYFLAG_BIN)) diff --git a/android/mac/generated/flags.h b/android/mac/generated/flags.h index 80264cb0..8993979c 100644 --- a/android/mac/generated/flags.h +++ b/android/mac/generated/flags.h @@ -1904,13 +1904,14 @@ #undef FLAG_l #endif -// lspci emkn@i: +// lspci emkn@x@i: #undef OPTSTR_lspci -#define OPTSTR_lspci "emkn@i:" +#define OPTSTR_lspci "emkn@x@i:" #ifdef CLEANUP_lspci #undef CLEANUP_lspci #undef FOR_lspci #undef FLAG_i +#undef FLAG_x #undef FLAG_n #undef FLAG_k #undef FLAG_m @@ -5606,10 +5607,11 @@ #define TT this.lspci #endif #define FLAG_i (FORCED_FLAG<<0) -#define FLAG_n (FORCED_FLAG<<1) -#define FLAG_k (FORCED_FLAG<<2) -#define FLAG_m (FORCED_FLAG<<3) -#define FLAG_e (FORCED_FLAG<<4) +#define FLAG_x (FORCED_FLAG<<1) +#define FLAG_n (FORCED_FLAG<<2) +#define FLAG_k (FORCED_FLAG<<3) +#define FLAG_m (FORCED_FLAG<<4) +#define FLAG_e (FORCED_FLAG<<5) #endif #ifdef FOR_lsusb diff --git a/android/mac/generated/globals.h b/android/mac/generated/globals.h index 6dd8f98b..2b646d04 100644 --- a/android/mac/generated/globals.h +++ b/android/mac/generated/globals.h @@ -362,7 +362,7 @@ struct lsattr_data { struct lsusb_data { char *i; - long n; + long x, n; void *ids, *class; int count; diff --git a/android/mac/generated/help.h b/android/mac/generated/help.h index 751dd611..c95b74a1 100644 --- a/android/mac/generated/help.h +++ b/android/mac/generated/help.h @@ -254,7 +254,7 @@ #define HELP_lsusb "usage: lsusb [-i]\n\nList USB hosts/devices.\n\n-i ID database (default /etc/usb.ids[.gz])" -#define HELP_lspci "usage: lspci [-ekmn] [-i FILE]\n\nList PCI devices.\n\n-e Extended (6 digit) class\n-i ID database (default /etc/pci.ids[.gz])\n-k Show kernel driver\n-m Machine readable\n-n Numeric output (-nn for both)" +#define HELP_lspci "usage: lspci [-ekmn] [-i FILE]\n\nList PCI devices.\n\n-e Extended (6 digit) class\n-i ID database (default /etc/pci.ids[.gz])\n-k Show kernel driver\n-m Machine readable\n-n Numeric output (-nn for both)\n-x Hex dump of config space (64 bytes; -xxx for 256, -xxxx for 4096)" #define HELP_lsmod "usage: lsmod\n\nDisplay the currently loaded modules, their sizes and their dependencies." diff --git a/android/mac/generated/newtoys.h b/android/mac/generated/newtoys.h index 28aa322d..72091791 100644 --- a/android/mac/generated/newtoys.h +++ b/android/mac/generated/newtoys.h @@ -173,7 +173,7 @@ USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241\376ZgoACF USE_LSATTR(NEWTOY(lsattr, "ldapvR", TOYFLAG_BIN)) USE_LSMOD(NEWTOY(lsmod, NULL, TOYFLAG_SBIN)) USE_LSOF(NEWTOY(lsof, "lp*t", TOYFLAG_USR|TOYFLAG_BIN)) -USE_LSPCI(NEWTOY(lspci, "emkn@i:", TOYFLAG_USR|TOYFLAG_BIN)) +USE_LSPCI(NEWTOY(lspci, "emkn@x@i:", TOYFLAG_USR|TOYFLAG_BIN)) USE_LSUSB(NEWTOY(lsusb, "i:", TOYFLAG_USR|TOYFLAG_BIN)) USE_MAKEDEVS(NEWTOY(makedevs, "<1>1d:", TOYFLAG_USR|TOYFLAG_BIN)) USE_MAN(NEWTOY(man, "k:M:", TOYFLAG_USR|TOYFLAG_BIN)) @@ -85,7 +85,7 @@ // ! More than one in group is error [!abc] means -ab calls error_exit() // primarily useful if you can switch things back off again. // -// You may use octal escapes with the high bit (127) set to use a control +// You may use octal escapes with the high bit (128) set to use a control // character as an option flag. For example, \300 would be the option -@ // Notes from getopt man page @@ -318,7 +318,7 @@ static int parse_optflaglist(struct getoptflagstate *gof) continue; // Claim this option, loop to see what's after it. - } else new->c = 127&*options; + } else new->c = *options; options++; } @@ -330,6 +330,7 @@ static int parse_optflaglist(struct getoptflagstate *gof) unsigned long long u = 1LL<<idx++; if (new->c == 1 || new->c=='~') new->c = 0; + else new->c &= 127; new->dex[1] = u; if (new->flags & 1) gof->requires |= u; if (new->type) { diff --git a/scripts/portability.sh b/scripts/portability.sh index 9c5153e1..4241916a 100644 --- a/scripts/portability.sh +++ b/scripts/portability.sh @@ -24,7 +24,7 @@ fi # Disable a pointless warning only clang produces [ -n "$("$CROSS_COMPILE$CC" --version | grep -w clang)" ] && - CFLAGS+=" -Wno-string-plus-int" + CFLAGS+=" -Wno-string-plus-int -Wno-invalid-source-encoding" # Address Sanitizer if [ -n "$ASAN" ]; then diff --git a/scripts/runtest.sh b/scripts/runtest.sh index cffedef0..ce6e0fd0 100644 --- a/scripts/runtest.sh +++ b/scripts/runtest.sh @@ -117,10 +117,10 @@ toyonly() # Takes five arguments: "name" "command" "result" "infile" "stdin" testing() { - NAME="$CMDNAME $1" wrong_args "$@" - [ -z "$1" ] && NAME=$2 + [ -z "$1" ] && NAME="$2" || NAME="$1" + [ "${NAME#$CMDNAME }" == "$NAME" ] && NAME="$CMDNAME $1" [ -n "$DEBUG" ] && set -x @@ -162,9 +162,7 @@ testcmd() { wrong_args "$@" - X="$1" - [ -z "$X" ] && X="$CMDNAME $2" - testing "$X" "\"$C\" $2" "$3" "$4" "$5" + testing "${1:-$CMDNAME $2}" "\"$C\" $2" "$3" "$4" "$5" } # Simple implementation of "expect" written in shell. diff --git a/tests/ls.test b/tests/ls.test index 96bb1d2b..fad27d3b 100755 --- a/tests/ls.test +++ b/tests/ls.test @@ -9,70 +9,72 @@ #set -x # Creating test-file/dir for testing ls -mkdir -p lstest/dir1 lstest/dir2 || exit 1 -echo "test file1" > lstest/file1.txt -echo "test file2" > lstest/file2.txt -echo "hidden file1" > lstest/.hfile1 +mkdir -p dir1 dir2 || exit 1 +echo "test file1" > file1.txt +echo "test file2" > file2.txt +echo "hidden file1" > .hfile1 -cd lstest -testing "no argument" "ls" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" -testing "with -C: test column spacing equals 2" "ls -C" "dir1 dir2 file1.txt file2.txt\n" "" "" -testing "with -x: test column spacing equals 2" "ls -x" "dir1 dir2 file1.txt file2.txt\n" "" "" -testing "with wild char" "ls file*" "file1.txt\nfile2.txt\n" "" "" -testing "with wild char - long listing" "ls -1 file*" "file1.txt\nfile2.txt\n" "" "" -testing "with -p" "ls -p" "dir1/\ndir2/\nfile1.txt\nfile2.txt\n" "" "" -testing "with -a" "ls -a" \ - ".\n..\n.hfile1\ndir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" -testing "with -A" "ls -A" \ - ".hfile1\ndir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" -testing "with -d" "ls -d" ".\n" "" "" -testing "with wild char and -d *" "ls -d *" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" -testing "with -k" "ls -k" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" -testing "with -m" "ls -m" "dir1, dir2, file1.txt, file2.txt\n" "" "" -testing "with -F" "ls -F" "dir1/\ndir2/\nfile1.txt\nfile2.txt\n" "" "" -testing "with -dk *" "ls -dk *" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" -testing "with -Z" "ls -Z file1.txt | egrep -q '^[^ ]+ file1.txt' || echo fail" "" "" "" -testing "with -lZ" "ls --full-time -lZ file1.txt | egrep -q '^-[rwx-]+ +[0-9]+ +[^ ]+ +[^ ]+ +[^ ]+ +[0-9]+ [0-9][0-9][0-9][0-9]-[0-9][0-9]-.* file1.txt' || echo fail" "" "" "" +testcmd "no argument" "" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" +testcmd "-C column spacing equals 2" "-C" "dir1 dir2 file1.txt file2.txt\n" \ + "" "" +testcmd "-x column spacing equals 2" "-x" "dir1 dir2 file1.txt file2.txt\n" \ + "" "" +testcmd "explicit files" "file*" "file1.txt\nfile2.txt\n" "" "" +testcmd "explicit -1" "-1 file*" "file1.txt\nfile2.txt\n" "" "" +testcmd "" "-p" "dir1/\ndir2/\nfile1.txt\nfile2.txt\n" "" "" +testcmd "" "-a" ".\n..\n.hfile1\ndir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" +testcmd "" "-A" ".hfile1\ndir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" +testcmd "" "-d" ".\n" "" "" +testcmd "" "-d *" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" +testcmd "" "-k" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" +testcmd "-m" "-m" "dir1, dir2, file1.txt, file2.txt\n" "" "" +testcmd "-F" "-F" "dir1/\ndir2/\nfile1.txt\nfile2.txt\n" "" "" +testcmd "-dk *" "-dk *" "dir1\ndir2\nfile1.txt\nfile2.txt\n" "" "" +testcmd "-Z" "-Z file1.txt | egrep -q '^[^ ]+ file1.txt' || echo fail" "" "" "" +testcmd "-lZ" "--full-time -lZ file1.txt | egrep -q '^-[rwx-]+ +[0-9]+ +[^ ]+ +[^ ]+ +[^ ]+ +[0-9]+ [0-9][0-9][0-9][0-9]-[0-9][0-9]-.* file1.txt' || echo fail" "" "" "" ln -s file1.txt slink -testing "-l symlink" \ - "ls -l slink | grep -q -- ' slink -> file1.txt' && echo ok" "ok\n" "" "" +testcmd "-l symlink" "-l slink | grep -q -- ' slink -> file1.txt' && echo ok" \ + "ok\n" "" "" rm -f slink ln -s /dev/null/nosuchfile nosuchfile -testing "with -d - broken softlink" "ls -d nosuchfile" "nosuchfile\n" "" "" +testcmd "-d broken symlink" "-d nosuchfile" "nosuchfile\n" "" "" rm -f nosuchfile -cd .. && rm -rf lstest/* && cd lstest && mkdir -p dir1 && touch file1.txt -testing "nested recursively" "ls -R" ".:\ndir1\nfile1.txt\n\n./dir1:\n" "" "" +rm -rf file{1,2}.txt .hfile dir1 dir2 -cd .. && rm -rf lstest/* && cd lstest && touch file1.txt -testing "with -i" "ls -i" "$(stat -c %i file1.txt) file1.txt\n" "" "" +mkdir -p dir1 && touch file1.txt dir1/file2 +testcmd "" "-R" ".:\ndir1\nfile1.txt\n\n./dir1:\nfile2\n" "" "" +rm -rf dir1 file1.txt -testing "missing" "ls does-not-exist 2>&1 >/dev/null | grep -o does-not-exist" "does-not-exist\n" "" "" +touch file1.txt +testcmd "-i" "-i" "$(stat -c %i file1.txt) file1.txt\n" "" "" +testcmd "missing" "does-not-exist 2>&1 >/dev/null | grep -o does-not-exist" \ + "does-not-exist\n" "" "" +rm -f file1.txt -cd .. && rm -f lstest/{file1.txt,err} && cd lstest && -touch one two three four five six seven eight nine ten -testing "-w test 1" "ls -Cw 20" \ - "eight one three\nfive seven two\nfour six\nnine ten\n" "" "" -testing "-w test 2" "ls -Cw 19" \ - "eight seven\nfive six\nfour ten\nnine three\none two\n" "" "" +# sort tests TIME=1234567890 -for i in one two three four five six seven eight +for i in one two three four five six seven eight nine ten do touch -d @$((TIME++)) $i done -testing "-r" "ls -r" \ - "two\nthree\nten\nsix\nseven\none\nnine\nfour\nfive\neight\n" "" "" - -cd .. && rm -rf lstest/* && cd lstest && touch a b c d e f -testing "-w test 3" "ls -Cw 3" "a\nb\nc\nd\ne\nf\n" "" "" -testing "-w test 4" "ls -Cw 4" "a d\nb e\nc f\n" "" "" +testcmd "" "-r" "two\nthree\nten\nsix\nseven\none\nnine\nfour\nfive\neight\n" \ + "" "" +testcmd "-w test 1" "-Cw 20" \ + "eight one three\nfive seven two\nfour six\nnine ten\n" "" "" +testcmd "-w test 2" "-Cw 19" \ + "eight seven\nfive six\nfour ten\nnine three\none two\n" "" "" +rm -f one two three four five six seven eight nine ten -cd .. && rm -rf lstest/* && cd lstest && touch 'hello
world' -testing "default escaping" "ls" "hello
world\n" "" "" -testing "-b" "ls -b" 'hello\\ \\rworld\n' "" "" -testing "-q" "ls -q" 'hello ?world\n' "" "" -testing "-N" "ls -q" 'hello ?world\n' "" "" +touch a b c d e f +testcmd "-w test 3" "-Cw 3" "a\nb\nc\nd\ne\nf\n" "" "" +testcmd "-w test 4" "-Cw 4" "a d\nb e\nc f\n" "" "" +rm -f a b c d e f -# Removing test dir for cleanup purpose -rm -rf lstest +touch 'hello
world' +testcmd "default escaping" "" "hello
world\n" "" "" +testcmd "-b" "-b" 'hello\\ \\rworld\n' "" "" +testcmd "-q" "-q" 'hello ?world\n' "" "" +testcmd "-N" "-N" 'hello
world\n' "" "" +rm hello* diff --git a/tests/sed.test b/tests/sed.test index 59e80fa1..ce35161f 100755 --- a/tests/sed.test +++ b/tests/sed.test @@ -2,86 +2,82 @@ #testing "name" "command" "result" "infile" "stdin" -testing 'as cat' 'sed ""' "one\ntwo\nthree" "" "one\ntwo\nthree" +testcmd 'as cat' '""' "one\ntwo\nthree" "" "one\ntwo\nthree" # This segfaults ubuntu 12.04's sed. No really. -testing 'sed - - twice' 'sed "" - -' "hello\n" "" "hello\n" -testing '-n' 'sed -n ""' "" "" "one\ntwo\nthree" -testing '-n p' 'sed -n p' "one\ntwo\nthree" "" "one\ntwo\nthree" -testing 'explicit pattern' 'sed -e p -n' "one\ntwo\nthree" "" \ - "one\ntwo\nthree" +testcmd '- - twice' '"" - -' "hello\n" "" "hello\n" +testcmd '-n' '-n ""' "" "" "one\ntwo\nthree" +testcmd '-n p' '-n p' "one\ntwo\nthree" "" "one\ntwo\nthree" +testcmd 'explicit pattern' '-e p -n' "one\ntwo\nthree" "" "one\ntwo\nthree" # Exploring the wonders of sed addressing modes -testing '' 'sed -n 1p' "one\n" "" "one\ntwo\nthree" -testing '' 'sed 2p' "one\ntwo\ntwo\nthree" "" "one\ntwo\nthree" -testing '' 'sed -n 2p' "two\n" "" "one\ntwo\nthree" -testing '-n $p' 'sed -n \$p' "three" "" "one\ntwo\nthree" -testing 'as cat #2' "sed -n '1,\$p'" "one\ntwo\nthree" "" "one\ntwo\nthree" -testing 'no input means no last line' "sed '\$a boing'" "" "" "" -testing '-n $,$p' 'sed -n \$,\$p' 'three' '' 'one\ntwo\nthree' -testing '' 'sed -n 1,2p' "one\ntwo\n" "" "one\ntwo\nthree" -testing '' 'sed -n 2,3p' "two\nthree" "" "one\ntwo\nthree" -testing '' 'sed -n 2,1p' "two\n" "" "one\ntwo\nthree" -testing '$ with 2 inputs' 'sed -n \$p - input' "four\n" "four\n" \ - "one\ntwo\nthree" -testing '' 'sed -n /two/p' "two\n" "" "one\ntwo\nthree" -testing '' 'sed -n 1,/two/p' 'one\ntwo\n' '' 'one\ntwo\nthree' -testing '' 'sed -n /one/,2p' 'one\ntwo\n' '' 'one\ntwo\nthree' -testing '' 'sed -n 1,/one/p' 'one\ntwo\nthree' '' 'one\ntwo\nthree' -testing '' 'sed -n /one/,1p' 'one\n' '' 'one\ntwo\nthree' -testing 'sed -n /two/,$p' 'sed -n /two/,\$p' 'two\nthree' '' 'one\ntwo\nthree' - +testcmd '' '-n 1p' "one\n" "" "one\ntwo\nthree" +testcmd '' '2p' "one\ntwo\ntwo\nthree" "" "one\ntwo\nthree" +testcmd '' '-n 2p' "two\n" "" "one\ntwo\nthree" +testcmd '-n $p' '-n \$p' "three" "" "one\ntwo\nthree" +testcmd 'as cat #2' "-n '1,\$p'" "one\ntwo\nthree" "" "one\ntwo\nthree" +testcmd 'no input means no last line' "'\$a boing'" "" "" "" +testcmd '-n $,$p' '-n \$,\$p' 'three' '' 'one\ntwo\nthree' +testcmd '' '-n 1,2p' "one\ntwo\n" "" "one\ntwo\nthree" +testcmd '' '-n 2,3p' "two\nthree" "" "one\ntwo\nthree" +testcmd '' '-n 2,1p' "two\n" "" "one\ntwo\nthree" +testcmd '$ with 2 inputs' '-n \$p - input' "four\n" "four\n" "one\ntwo\nthree" +testcmd '' '-n /two/p' "two\n" "" "one\ntwo\nthree" +testcmd '' '-n 1,/two/p' 'one\ntwo\n' '' 'one\ntwo\nthree' +testcmd '' '-n /one/,2p' 'one\ntwo\n' '' 'one\ntwo\nthree' +testcmd '' '-n 1,/one/p' 'one\ntwo\nthree' '' 'one\ntwo\nthree' +testcmd '' '-n /one/,1p' 'one\n' '' 'one\ntwo\nthree' +testcmd '-n /two/,$p' '-n /two/,\$p' 'two\nthree' '' 'one\ntwo\nthree' # Fun with newlines! -testing '' 'sed -n 3p' "three" "" "one\ntwo\nthree" -testing 'prodigal newline' "sed -n '1,\$p' - input" \ +testcmd '' '-n 3p' "three" "" "one\ntwo\nthree" +testcmd 'prodigal newline' "-n '1,\$p' - input" \ "one\ntwo\nthree\nfour\n" "four\n" "one\ntwo\nthree" -testing 'Newline only added if further output' "sed -n 3p - input" "three" \ +testcmd 'Newline only added if further output' "-n 3p - input" "three" \ "four\n" "one\ntwo\nthree" # Fun with match delimiters and escapes -testing 'match \t tab' "sed -n '/\t/p'" "\tx\n" "" "\tx\n" -testing 'match t delim disables \t tab' "sed -n '\t\txtp'" "" "" "\tx\n" -testing 'match t delim makes \t literal t' \ - "sed -n '\t\txtp'" "tx\n" "" "tx\n" -testing 'match n delim' "sed -n '\n\txnp'" "\tx\n" "" "\tx\n" -testing 'match n delim disables \n newline' "sed -n '\n\nxnp'" "" "" "\nx\n" -toyonly testing 'match \n literal n' "sed -n '\n\nxnp'" "nx\n" "" "nx\n" -testing 'end match does not check starting match line' \ - "sed -n '/two/,/two/p'" "two\nthree" "" "one\ntwo\nthree" -testing 'end match/start match mixing number/letter' \ - "sed -n '2,/two/p'" "two\nthree" "" "one\ntwo\nthree" -testing 'num then regex' 'sed -n 2,/d/p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n' -testing 'regex then num' 'sed -n /b/,4p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n' -testing 'multiple regex address match' 'sed -n /on/,/off/p' \ +testcmd 'match \t tab' "-n '/\t/p'" "\tx\n" "" "\tx\n" +testcmd 'match t delim disables \t tab' "-n '\t\txtp'" "" "" "\tx\n" +testcmd 'match t delim makes \t literal t' "-n '\t\txtp'" "tx\n" "" "tx\n" +testcmd 'match n delim' "-n '\n\txnp'" "\tx\n" "" "\tx\n" +testcmd 'match n delim disables \n newline' "-n '\n\nxnp'" "" "" "\nx\n" +toyonly testcmd 'match \n literal n' "-n '\n\nxnp'" "nx\n" "" "nx\n" +testcmd 'end match does not check starting match line' \ + "-n '/two/,/two/p'" "two\nthree" "" "one\ntwo\nthree" +testcmd 'end match/start match mixing number/letter' \ + "-n '2,/two/p'" "two\nthree" "" "one\ntwo\nthree" +testcmd 'num then regex' '-n 2,/d/p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n' +testcmd 'regex then num' '-n /b/,4p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n' +testcmd 'multiple regex address match' '-n /on/,/off/p' \ 'bone\nturtle\scoff\ntron\nlurid\noffer\n' "" \ 'zap\nbone\nturtle\scoff\nfred\ntron\nlurid\noffer\nbecause\n' -testing 'regex address overlap' 'sed -n /on/,/off/p' "on\nzap\noffon\n" "" \ +testcmd 'regex address overlap' '-n /on/,/off/p' "on\nzap\noffon\n" "" \ 'on\nzap\noffon\nping\noff\n' -testing 'getdelim with nested [:blah:]' 'sed -n "sa\a[a[:space:]bc]*aXXagp"' \ +testcmd 'getdelim with nested [:blah:]' '-n "sa\a[a[:space:]bc]*aXXagp"' \ "ABXXCDXXEFXXGHXXIXX" "" "ABaaCDa EFaa aGHa a Ia " -testing '[ in [[]' "sed 's@[[]@X@g'" "X" "" "[" -testing '[[] with ] as delimiter' "sed 's][[]]X]g'" "X" "" "[" -testing '[[] with [ as delimiter' "sed 's[\[\[][X['" "X" "" "[" +testcmd '[ in [[]' "'s@[[]@X@g'" "X" "" "[" +testcmd '[[] with ] as delimiter' "'s][[]]X]g'" "X" "" "[" +testcmd '[[] with [ as delimiter' "'s[\[\[][X['" "X" "" "[" # gGhHlnNpPqrstwxy:= # s///#comment # abcdDi -testing 'prodigaler newline' 'sed -e a\\ -e woo' 'one\nwoo\n' '' 'one' -testing "aci" \ - "sed -e '3a boom' -e '/hre/i bang' -e '3a whack' -e '3c bong'" \ +testcmd 'prodigaler newline' '-e a\\ -e woo' 'one\nwoo\n' '' 'one' +testcmd "aci" "-e '3a boom' -e '/hre/i bang' -e '3a whack' -e '3c bong'" \ "one\ntwo\nbang\nbong\nboom\nwhack\nfour\n" "" \ "one\ntwo\nthree\nfour\n" -testing "b loop" "sed ':woo;=;b woo' | head -n 5" '1\n1\n1\n1\n1\n' "" "X" -testing "b skip" "sed -n '2b zap;d;:zap;p'" "two\n" "" "one\ntwo\nthree" -testing "b end" "sed -n '2b;p'" "one\nthree" "" "one\ntwo\nthree" -testing "c range" "sed '2,4c blah'" "one\nblah\nfive\nsix" "" \ +testcmd "b loop" "':woo;=;b woo' | head -n 5" '1\n1\n1\n1\n1\n' "" "X" +testcmd "b skip" "-n '2b zap;d;:zap;p'" "two\n" "" "one\ntwo\nthree" +testcmd "b end" "-n '2b;p'" "one\nthree" "" "one\ntwo\nthree" +testcmd "c range" "'2,4c blah'" "one\nblah\nfive\nsix" "" \ "one\ntwo\nthree\nfour\nfive\nsix" -testing "c {range}" "sed -e '2,4{c blah' -e '}'" \ - "one\nblah\nblah\nblah\nfive\nsix" \ +testcmd "c {range}" "-e '2,4{c blah' -e '}'" "one\nblah\nblah\nblah\nfive\nsix"\ "" "one\ntwo\nthree\nfour\nfive\nsix" -testing "c multiple continuation" \ - "sed -e 'c\\' -e 'two\\' -e ''" "two\n\n" "" "hello" +testcmd "c multiple continuation" "-e 'c\\' -e 'two\\' -e ''" "two\n\n" "" \ + "hello" +testcmd 'multiline continuations' '-e c\\ -e line1\\ -e line2' 'line1\nline2\n'\ + '' 'one\n' toyonly testing "c empty continuation" "sed -e 'c\\'" "\n" "" "hello" testing "D further processing depends on whether line is blank" \ "sed -e '/one/,/three/{' -e 'i meep' -e'N;2D;}'" \ @@ -187,14 +183,13 @@ testcmd '^ not trigger after NUL' 's/^t/x/' 'one\0two' '' 'one\0two' # toybox handling of empty capturing groups broke minjail. Check that we # correctly replace an empty capturing group with the empty string: -testing '\n with empty capture' \ - 'sed -E "s/(ARM_)?(NR_)([a-z]*) (.*)/\1\2\3/"' "NR_read" "" "NR_read foo" +testcmd '\n with empty capture' \ + '-E "s/(ARM_)?(NR_)([a-z]*) (.*)/\1\2\3/"' "NR_read" "" "NR_read foo" # ...but also that we report an error for a backreference to a group that # isn't in the pattern: -testing '\n too high' \ - 'sed -E "s/(.*)/\2/p" 2>/dev/null || echo OK' "OK\n" "" "foo" +testcmd '\n too high' '-E "s/(.*)/\2/p" 2>/dev/null || echo OK' "OK\n" "" "foo" -toyonly testing 's///x' 'sed "s/(hello )?(world)/\2/x"' "world" "" "hello world" +toyonly testcmd 's///x' '"s/(hello )?(world)/\2/x"' "world" "" "hello world" # Performance test X=x; Y=20; while [ $Y -gt 0 ]; do X=$X$X; Y=$(($Y-1)); done @@ -203,15 +198,15 @@ testing 'megabyte s/x/y/g (20 sec timeout)' \ '138c1fa7c3f64186203b0192fb4abdb33cb4e98a -\n' '' "$X\n" unset X Y -testing "w doesn't blank" "sed -e 'w one' -e 'w one' -e d; cat one" \ - 'hello\nhello\n' '' 'hello\n' +testcmd "w doesn't blank" "-e 'w one' -e 'w one' -e d; cat one" \ + 'hello\nhello\n' '' 'hello\n' -testing 's i and I' 'sed s/o/0/ig' "f00l F00L" "" "fool FOOL" +testcmd 's i and I' 's/o/0/ig' "f00l F00L" "" "fool FOOL" -testing 's l ignores posix' "sed -n 'N;l'" 'one\\ntwo$\n' '' 'one\ntwo\n' -testing 's l loses missing newline' "sed -n 'N;l'" 'one\\ntwo$\n' '' 'one\ntwo' -testing 's -z l' "sed -zn 'N;l'" 'one\\000two$\0' '' 'one\0two\0' -testing 's -z l missing newline' "sed -zn 'N;l'" 'one\\000two$\0' '' 'one\0two' +testcmd 's l ignores posix' "-n 'N;l'" 'one\\ntwo$\n' '' 'one\ntwo\n' +testcmd 's l loses missing newline' "-n 'N;l'" 'one\\ntwo$\n' '' 'one\ntwo' +testcmd 's -z l' "-zn 'N;l'" 'one\\000two$\0' '' 'one\0two\0' +testcmd 's -z l missing newline' "-zn 'N;l'" 'one\\000two$\0' '' 'one\0two' testcmd 'count match' '"s/./&X/4"' '0123X45\n' '' '012345\n' diff --git a/tests/tar.test b/tests/tar.test index fb26991f..e6487bd7 100755 --- a/tests/tar.test +++ b/tests/tar.test @@ -383,6 +383,7 @@ testing 'without -P' "$TAR --no-recursion -C / /// .. 2>/dev/null | SUM 3" \ # Wildcards: --exclude, include (create/extract * cmdline/recursive) # --anchored, --wildcards, --wildcards-match-slash +# --no-* versions of each. Span coverage, switching on/off... #pattern a.c # abcd dabc a/c da/c @@ -413,6 +414,10 @@ touch sub2/{ephebe,klatch,djelibeybi} testing 'tsort' '$TAR -c sub2 --sort=name | tar t' \ 'sub2/\nsub2/djelibeybi\nsub2/ephebe\nsub2/klatch\n' '' '' +touch file +testing './file bug' 'tar c ./file > tar.tar && tar t ./file < tar.tar' \ + './file\n' '' '' + if false then # Sequencing issues that leak implementation details out the interface diff --git a/toys/lsb/seq.c b/toys/lsb/seq.c index 7a931c64..b44d05c6 100644 --- a/toys/lsb/seq.c +++ b/toys/lsb/seq.c @@ -52,24 +52,6 @@ static double parsef(char *s) return xstrtod(s); } -// fast integer conversion to decimal string -// TODO move to lib? -static char *itoa(char *s, int i) -{ - char buf[16], *ff = buf; - unsigned n = i; - - if (i<0) { - *s++ = '-'; - n = -i; - } - do *ff++ = '0'+n%10; while ((n /= 10)); - do *s++ = *--ff; while (ff>buf); - *s++ = '\n'; - - return s; -} - static char *flush_toybuf(char *ss) { if (ss-toybuf<TT.buflen) return ss; @@ -80,9 +62,9 @@ static char *flush_toybuf(char *ss) void seq_main(void) { - char fbuf[32], *ss; + char fbuf[64], *ss; double first = 1, increment = 1, last, dd; - int ii, inc = 1, len, slen; + long ii, inc = 1, len, slen; // parse arguments if (!TT.s) TT.s = "\n"; @@ -101,20 +83,20 @@ void seq_main(void) slen = dd; if (dd != slen) inc = 0; } - if (!FLAG(f)) sprintf(TT.f = fbuf, "%%0%d.%df", len, TT.precision); - TT.buflen = sizeof(toybuf) - 32 - len - TT.precision - strlen(TT.s); + if (!FLAG(f)) sprintf(TT.f = fbuf, "%%0%ld.%df", len, TT.precision); + TT.buflen = sizeof(toybuf)-sizeof(fbuf)-len-TT.precision-strlen(TT.s); if (TT.buflen<0) error_exit("bad -s"); - // fast path: when everything fits in an int with no flags. + // fast path: when everything fits in a long with no flags. if (!toys.optflags && inc) { ii = first; len = last; inc = increment; ss = toybuf; if (inc>0) for (; ii<=len; ii += inc) - ss = flush_toybuf(itoa(ss, ii)); + ss = flush_toybuf(ss+sprintf(ss, "%ld\n", ii)); else if (inc<0) for (; ii>=len; ii += inc) - ss = flush_toybuf(itoa(ss, ii)); + ss = flush_toybuf(ss+sprintf(ss, "%ld\n", ii)); if (ss != toybuf) xwrite(1, toybuf, ss-toybuf); return; diff --git a/toys/other/lsusb.c b/toys/other/lsusb.c index 3ca7703a..c4f64529 100644 --- a/toys/other/lsusb.c +++ b/toys/other/lsusb.c @@ -4,7 +4,7 @@ * Copyright 2013 Isaac Dunham <ibid.ag@gmail.com> USE_LSUSB(NEWTOY(lsusb, "i:", TOYFLAG_USR|TOYFLAG_BIN)) -USE_LSPCI(NEWTOY(lspci, "emkn@i:", TOYFLAG_USR|TOYFLAG_BIN)) +USE_LSPCI(NEWTOY(lspci, "emkn@x@i:", TOYFLAG_USR|TOYFLAG_BIN)) config LSPCI bool "lspci" @@ -14,11 +14,12 @@ config LSPCI List PCI devices. - -e Extended (6 digit) class - -i ID database (default /etc/pci.ids[.gz]) - -k Show kernel driver - -m Machine readable - -n Numeric output (-nn for both) + -e Extended (6 digit) class + -i ID database (default /etc/pci.ids[.gz]) + -k Show kernel driver + -m Machine readable + -n Numeric output (-nn for both) + -x Hex dump of config space (64 bytes; -xxx for 256, -xxxx for 4096) config LSUSB bool "lsusb" @@ -36,7 +37,7 @@ config LSUSB GLOBALS( char *i; - long n; + long x, n; void *ids, *class; int count; @@ -229,6 +230,24 @@ static int list_pci(struct dirtree *new) if (FLAG(k)) printf(FLAG(m) ? " \"%s\"" : " %s", driver); xputc('\n'); + if (TT.x) { + FILE *fp; + int b, col = 0, max = (TT.x >= 4) ? 4096 : ((TT.x >= 3) ? 256 : 64); + + // TODO: where does the "0000:" come from? + snprintf(toybuf, sizeof(toybuf), "/sys/bus/pci/devices/0000:%s/config", + new->name+5); + fp = xfopen(toybuf, "r"); + while ((b = fgetc(fp)) != EOF) { + if ((col % 16) == 0) printf("%02x: ", col & 0xf0); + printf("%02x ", (b & 0xff)); + if ((++col % 16) == 0) xputc('\n'); + if (col == max) break; + } + xputc('\n'); + fclose(fp); + } + return 0; } diff --git a/toys/posix/tar.c b/toys/posix/tar.c index 977ccf0f..5af32db8 100644 --- a/toys/posix/tar.c +++ b/toys/posix/tar.c @@ -194,7 +194,7 @@ static struct double_list *filter(struct double_list *lst, char *name) { struct double_list *end = lst; long long flags = toys.optflags; - char *ss, *last; + char *ss; if (!lst || !*name) return 0; @@ -211,13 +211,11 @@ static struct double_list *filter(struct double_list *lst, char *name) // The +1 instead of ++ is in case of conseutive slashes do { - for (ss = last = name; *ss; ss++) { + if (do_filter(lst->data, name, flags)) return lst; + if (!(flags & FLAG_anchored)) for (ss = name; *ss; ss++) { if (*ss!='/' || !ss[1]) continue; - if (!(flags & FLAG_anchored)) { - if (do_filter(lst->data, ss+1, flags)) return lst; - } else last = ss+1; + if (do_filter(lst->data, ss+1, flags)) return lst; } - if (do_filter(lst->data, last, flags)) return lst; } while (end != (lst = lst->next)); return 0; |