* diff -u /tmp/std_find /tmp/bb_find && echo Identical
*/
+//applet:IF_FIND(APPLET_NOEXEC(find, find, _BB_DIR_USR_BIN, _BB_SUID_DROP, find))
+
//kbuild:lib-$(CONFIG_FIND) += find.o
-//config:
+
//config:config FIND
//config: bool "find"
//config: default y
#undef ALLOC_ACTION
}
+//usage:#define find_trivial_usage
+//usage: "[PATH]... [EXPRESSION]"
+//usage:#define find_full_usage "\n\n"
+//usage: "Search for files. The default PATH is the current directory,\n"
+//usage: "default EXPRESSION is '-print'\n"
+//usage: "\nEXPRESSION may consist of:"
+//usage: "\n -follow Follow symlinks"
+//usage: IF_FEATURE_FIND_XDEV(
+//usage: "\n -xdev Don't descend directories on other filesystems"
+//usage: )
+//usage: IF_FEATURE_FIND_MAXDEPTH(
+//usage: "\n -maxdepth N Descend at most N levels. -maxdepth 0 applies"
+//usage: "\n tests/actions to command line arguments only"
+//usage: )
+//usage: "\n -mindepth N Don't act on first N levels"
+//usage: "\n -name PATTERN File name (w/o directory name) matches PATTERN"
+//usage: "\n -iname PATTERN Case insensitive -name"
+//usage: IF_FEATURE_FIND_PATH(
+//usage: "\n -path PATTERN Path matches PATTERN"
+//usage: )
+//usage: IF_FEATURE_FIND_REGEX(
+//usage: "\n -regex PATTERN Path matches regex PATTERN"
+//usage: )
+//usage: IF_FEATURE_FIND_TYPE(
+//usage: "\n -type X File type is X (X is one of: f,d,l,b,c,...)"
+//usage: )
+//usage: IF_FEATURE_FIND_PERM(
+//usage: "\n -perm NNN Permissions match any of (+NNN), all of (-NNN),"
+//usage: "\n or exactly NNN"
+//usage: )
+//usage: IF_FEATURE_FIND_MTIME(
+//usage: "\n -mtime DAYS Modified time is greater than (+N), less than (-N),"
+//usage: "\n or exactly N days"
+//usage: )
+//usage: IF_FEATURE_FIND_MMIN(
+//usage: "\n -mmin MINS Modified time is greater than (+N), less than (-N),"
+//usage: "\n or exactly N minutes"
+//usage: )
+//usage: IF_FEATURE_FIND_NEWER(
+//usage: "\n -newer FILE Modified time is more recent than FILE's"
+//usage: )
+//usage: IF_FEATURE_FIND_INUM(
+//usage: "\n -inum N File has inode number N"
+//usage: )
+//usage: IF_FEATURE_FIND_USER(
+//usage: "\n -user NAME File is owned by user NAME (numeric user ID allowed)"
+//usage: )
+//usage: IF_FEATURE_FIND_GROUP(
+//usage: "\n -group NAME File belongs to group NAME (numeric group ID allowed)"
+//usage: )
+//usage: IF_FEATURE_FIND_DEPTH(
+//usage: "\n -depth Process directory name after traversing it"
+//usage: )
+//usage: IF_FEATURE_FIND_SIZE(
+//usage: "\n -size N[bck] File size is N (c:bytes,k:kbytes,b:512 bytes(def.))"
+//usage: "\n +/-N: file size is bigger/smaller than N"
+//usage: )
+//usage: IF_FEATURE_FIND_LINKS(
+//usage: "\n -links N Number of links is greater than (+N), less than (-N),"
+//usage: "\n or exactly N"
+//usage: )
+//usage: "\n -print Print (default and assumed)"
+//usage: IF_FEATURE_FIND_PRINT0(
+//usage: "\n -print0 Delimit output with null characters rather than"
+//usage: "\n newlines"
+//usage: )
+//usage: IF_FEATURE_FIND_CONTEXT(
+//usage: "\n -context File has specified security context"
+//usage: )
+//usage: IF_FEATURE_FIND_EXEC(
+//usage: "\n -exec CMD ARG ; Run CMD with all instances of {} replaced by the"
+//usage: "\n matching files"
+//usage: )
+//usage: IF_FEATURE_FIND_PRUNE(
+//usage: "\n -prune Stop traversing current subtree"
+//usage: )
+//usage: IF_FEATURE_FIND_DELETE(
+//usage: "\n -delete Delete files, turns on -depth option"
+//usage: )
+//usage: IF_FEATURE_FIND_PAREN(
+//usage: "\n (EXPR) Group an expression"
+//usage: )
+//usage:
+//usage:#define find_example_usage
+//usage: "$ find / -name passwd\n"
+//usage: "/etc/passwd\n"
int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int find_main(int argc UNUSED_PARAM, char **argv)
* 2004,2006 (C) Vladimir Oleynik <dzo@simtreas.ru> -
* correction "-e pattern1 -e pattern2" logic and more optimizations.
* precompiled regex
- */
-/*
+ *
* (C) 2006 Jac Goudsmit added -o option
*/
+//applet:IF_GREP(APPLET(grep, _BB_DIR_BIN, _BB_SUID_DROP))
+//applet:IF_FEATURE_GREP_EGREP_ALIAS(APPLET_ODDNAME(egrep, grep, _BB_DIR_BIN, _BB_SUID_DROP, egrep))
+//applet:IF_FEATURE_GREP_FGREP_ALIAS(APPLET_ODDNAME(fgrep, grep, _BB_DIR_BIN, _BB_SUID_DROP, fgrep))
+
//kbuild:lib-$(CONFIG_GREP) += grep.o
-//config:
+
//config:config GREP
//config: bool "grep"
//config: default y
#include "libbb.h"
#include "xregex.h"
+
/* options */
+//usage:#define grep_trivial_usage
+//usage: "[-HhnlLoqvsriw"
+//usage: "F"
+//usage: IF_FEATURE_GREP_EGREP_ALIAS("E")
+//usage: IF_EXTRA_COMPAT("z")
+//usage: "] [-m N] "
+//usage: IF_FEATURE_GREP_CONTEXT("[-A/B/C N] ")
+//usage: "PATTERN/-e PATTERN.../-f FILE [FILE]..."
+//usage:#define grep_full_usage "\n\n"
+//usage: "Search for PATTERN in FILEs (or stdin)\n"
+//usage: "\nOptions:"
+//usage: "\n -H Add 'filename:' prefix"
+//usage: "\n -h Do not add 'filename:' prefix"
+//usage: "\n -n Add 'line_no:' prefix"
+//usage: "\n -l Show only names of files that match"
+//usage: "\n -L Show only names of files that don't match"
+//usage: "\n -c Show only count of matching lines"
+//usage: "\n -o Show only the matching part of line"
+//usage: "\n -q Quiet. Return 0 if PATTERN is found, 1 otherwise"
+//usage: "\n -v Select non-matching lines"
+//usage: "\n -s Suppress open and read errors"
+//usage: "\n -r Recurse"
+//usage: "\n -i Ignore case"
+//usage: "\n -w Match whole words only"
+//usage: "\n -F PATTERN is a literal (not regexp)"
+//usage: IF_FEATURE_GREP_EGREP_ALIAS(
+//usage: "\n -E PATTERN is an extended regexp"
+//usage: )
+//usage: IF_EXTRA_COMPAT(
+//usage: "\n -z Input is NUL terminated"
+//usage: )
+//usage: "\n -m N Match up to N times per file"
+//usage: IF_FEATURE_GREP_CONTEXT(
+//usage: "\n -A N Print N lines of trailing context"
+//usage: "\n -B N Print N lines of leading context"
+//usage: "\n -C N Same as '-A N -B N'"
+//usage: )
+//usage: "\n -e PTRN Pattern to match"
+//usage: "\n -f FILE Read pattern from file"
+//usage:
+//usage:#define grep_example_usage
+//usage: "$ grep root /etc/passwd\n"
+//usage: "root:x:0:0:root:/root:/bin/bash\n"
+//usage: "$ grep ^[rR]oo. /etc/passwd\n"
+//usage: "root:x:0:0:root:/root:/bin/bash\n"
+//usage:
+//usage:#define egrep_trivial_usage NOUSAGE_STR
+//usage:#define egrep_full_usage ""
+//usage:#define fgrep_trivial_usage NOUSAGE_STR
+//usage:#define fgrep_full_usage ""
+
#define OPTSTR_GREP \
"lnqvscFiHhe:f:Lorm:w" \
IF_FEATURE_GREP_CONTEXT("A:B:C:") \
IF_FEATURE_GREP_EGREP_ALIAS("E") \
IF_EXTRA_COMPAT("z") \
"aI"
-
/* ignored: -a "assume all files to be text" */
/* ignored: -I "assume binary files have no matches" */
-
enum {
OPTBIT_l, /* list matched file names only */
OPTBIT_n, /* print line# */
/* vi: set sw=4 ts=4: */
/*
* Mini xargs implementation for busybox
- * Options are supported: "-prtx -n max_arg -s max_chars -e[ouf_str]"
*
* (C) 2002,2003 by Vladimir Oleynik <dzo@simtreas.ru>
*
*
* xargs is described in the Single Unix Specification v3 at
* http://www.opengroup.org/onlinepubs/007904975/utilities/xargs.html
- *
*/
+//applet:IF_XARGS(APPLET_NOEXEC(xargs, xargs, _BB_DIR_USR_BIN, _BB_SUID_DROP, xargs))
+
//kbuild:lib-$(CONFIG_XARGS) += xargs.o
//config:config XARGS
# define xargs_ask_confirmation() 1
#endif
+//usage:#define xargs_trivial_usage
+//usage: "[OPTIONS] [PROG ARGS]"
+//usage:#define xargs_full_usage "\n\n"
+//usage: "Run PROG on every item given by stdin\n"
+//usage: "\nOptions:"
+//usage: IF_FEATURE_XARGS_SUPPORT_CONFIRMATION(
+//usage: "\n -p Ask user whether to run each command"
+//usage: )
+//usage: "\n -r Don't run command if input is empty"
+//usage: IF_FEATURE_XARGS_SUPPORT_ZERO_TERM(
+//usage: "\n -0 Input is separated by NUL characters"
+//usage: )
+//usage: "\n -t Print the command on stderr before execution"
+//usage: "\n -e[STR] STR stops input processing"
+//usage: "\n -n N Pass no more than N args to PROG"
+//usage: "\n -s N Pass command line of no more than N bytes"
+//usage: IF_FEATURE_XARGS_SUPPORT_TERMOPT(
+//usage: "\n -x Exit if size is exceeded"
+//usage: )
+//usage:#define xargs_example_usage
+//usage: "$ ls | xargs gzip\n"
+//usage: "$ find . -name '*.c' -print | xargs rm\n"
+
/* Correct regardless of combination of CONFIG_xxx */
enum {
OPTBIT_VERBOSE = 0,
//IF_E2LABEL(APPLET_ODDNAME(e2label, tune2fs, _BB_DIR_SBIN, _BB_SUID_DROP, e2label))
IF_ECHO(APPLET_NOFORK(echo, echo, _BB_DIR_BIN, _BB_SUID_DROP, echo))
IF_ED(APPLET(ed, _BB_DIR_BIN, _BB_SUID_DROP))
-IF_FEATURE_GREP_EGREP_ALIAS(APPLET_ODDNAME(egrep, grep, _BB_DIR_BIN, _BB_SUID_DROP, egrep))
IF_EJECT(APPLET(eject, _BB_DIR_USR_BIN, _BB_SUID_DROP))
IF_ENV(APPLET_NOEXEC(env, env, _BB_DIR_USR_BIN, _BB_SUID_DROP, env))
IF_ENVDIR(APPLET_ODDNAME(envdir, chpst, _BB_DIR_USR_BIN, _BB_SUID_DROP, envdir))
IF_FDFORMAT(APPLET(fdformat, _BB_DIR_USR_BIN, _BB_SUID_DROP))
IF_FDISK(APPLET(fdisk, _BB_DIR_SBIN, _BB_SUID_DROP))
IF_FGCONSOLE(APPLET(fgconsole, _BB_DIR_USR_BIN, _BB_SUID_DROP))
-IF_FEATURE_GREP_FGREP_ALIAS(APPLET_ODDNAME(fgrep, grep, _BB_DIR_BIN, _BB_SUID_DROP, fgrep))
-IF_FIND(APPLET_NOEXEC(find, find, _BB_DIR_USR_BIN, _BB_SUID_DROP, find))
IF_FINDFS(APPLET(findfs, _BB_DIR_SBIN, _BB_SUID_MAYBE))
IF_FLASH_ERASEALL(APPLET(flash_eraseall, _BB_DIR_USR_SBIN, _BB_SUID_DROP))
IF_FLASH_LOCK(APPLET_ODDNAME(flash_lock, flash_lock_unlock, _BB_DIR_USR_SBIN, _BB_SUID_DROP, flash_lock))
IF_GETOPT(APPLET(getopt, _BB_DIR_BIN, _BB_SUID_DROP))
IF_GETSEBOOL(APPLET(getsebool, _BB_DIR_USR_SBIN, _BB_SUID_DROP))
IF_GETTY(APPLET(getty, _BB_DIR_SBIN, _BB_SUID_DROP))
-IF_GREP(APPLET(grep, _BB_DIR_BIN, _BB_SUID_DROP))
IF_GUNZIP(APPLET(gunzip, _BB_DIR_BIN, _BB_SUID_DROP))
IF_GZIP(APPLET(gzip, _BB_DIR_BIN, _BB_SUID_DROP))
IF_HALT(APPLET(halt, _BB_DIR_SBIN, _BB_SUID_DROP))
IF_WHICH(APPLET(which, _BB_DIR_USR_BIN, _BB_SUID_DROP))
IF_WHO(APPLET(who, _BB_DIR_USR_BIN, _BB_SUID_DROP))
IF_WHOAMI(APPLET_NOFORK(whoami, whoami, _BB_DIR_USR_BIN, _BB_SUID_DROP, whoami))
-IF_XARGS(APPLET_NOEXEC(xargs, xargs, _BB_DIR_USR_BIN, _BB_SUID_DROP, xargs))
IF_UNXZ(APPLET_ODDNAME(xzcat, unxz, _BB_DIR_USR_BIN, _BB_SUID_DROP, xzcat))
IF_XZ(APPLET_ODDNAME(xz, unxz, _BB_DIR_USR_BIN, _BB_SUID_DROP, xz))
IF_YES(APPLET_NOFORK(yes, yes, _BB_DIR_USR_BIN, _BB_SUID_DROP, yes))
#define findfs_example_usage \
"$ findfs LABEL=MyDevice"
-#define find_trivial_usage \
- "[PATH]... [EXPRESSION]"
-#define find_full_usage "\n\n" \
- "Search for files. The default PATH is the current directory,\n" \
- "default EXPRESSION is '-print'\n" \
- "\nEXPRESSION may consist of:" \
- "\n -follow Follow symlinks" \
- IF_FEATURE_FIND_XDEV( \
- "\n -xdev Don't descend directories on other filesystems") \
- IF_FEATURE_FIND_MAXDEPTH( \
- "\n -maxdepth N Descend at most N levels. -maxdepth 0 applies" \
- "\n tests/actions to command line arguments only") \
- "\n -mindepth N Don't act on first N levels" \
- "\n -name PATTERN File name (w/o directory name) matches PATTERN" \
- "\n -iname PATTERN Case insensitive -name" \
- IF_FEATURE_FIND_PATH( \
- "\n -path PATTERN Path matches PATTERN") \
- IF_FEATURE_FIND_REGEX( \
- "\n -regex PATTERN Path matches regex PATTERN") \
- IF_FEATURE_FIND_TYPE( \
- "\n -type X File type is X (X is one of: f,d,l,b,c,...)") \
- IF_FEATURE_FIND_PERM( \
- "\n -perm NNN Permissions match any of (+NNN), all of (-NNN)," \
- "\n or exactly NNN") \
- IF_FEATURE_FIND_MTIME( \
- "\n -mtime DAYS Modified time is greater than (+N), less than (-N)," \
- "\n or exactly N days") \
- IF_FEATURE_FIND_MMIN( \
- "\n -mmin MINS Modified time is greater than (+N), less than (-N)," \
- "\n or exactly N minutes") \
- IF_FEATURE_FIND_NEWER( \
- "\n -newer FILE Modified time is more recent than FILE's") \
- IF_FEATURE_FIND_INUM( \
- "\n -inum N File has inode number N") \
- IF_FEATURE_FIND_USER( \
- "\n -user NAME File is owned by user NAME (numeric user ID allowed)") \
- IF_FEATURE_FIND_GROUP( \
- "\n -group NAME File belongs to group NAME (numeric group ID allowed)") \
- IF_FEATURE_FIND_DEPTH( \
- "\n -depth Process directory name after traversing it") \
- IF_FEATURE_FIND_SIZE( \
- "\n -size N[bck] File size is N (c:bytes,k:kbytes,b:512 bytes(def.))" \
- "\n +/-N: file size is bigger/smaller than N") \
- IF_FEATURE_FIND_LINKS( \
- "\n -links N Number of links is greater than (+N), less than (-N)," \
- "\n or exactly N") \
- "\n -print Print (default and assumed)" \
- IF_FEATURE_FIND_PRINT0( \
- "\n -print0 Delimit output with null characters rather than" \
- "\n newlines") \
- IF_FEATURE_FIND_CONTEXT ( \
- "\n -context File has specified security context") \
- IF_FEATURE_FIND_EXEC( \
- "\n -exec CMD ARG ; Run CMD with all instances of {} replaced by the" \
- "\n matching files") \
- IF_FEATURE_FIND_PRUNE( \
- "\n -prune Stop traversing current subtree") \
- IF_FEATURE_FIND_DELETE( \
- "\n -delete Delete files, turns on -depth option") \
- IF_FEATURE_FIND_PAREN( \
- "\n (EXPR) Group an expression") \
-
-#define find_example_usage \
- "$ find / -name passwd\n" \
- "/etc/passwd\n"
-
#define flash_lock_trivial_usage \
"MTD_DEVICE OFFSET SECTORS"
#define flash_lock_full_usage "\n\n" \
"\n -I INITSTR Send INITSTR before anything else" \
"\n -H HOST Log HOST into the utmp file as the hostname" \
-#define grep_trivial_usage \
- "[-HhnlLoqvsriw" \
- "F" \
- IF_FEATURE_GREP_EGREP_ALIAS("E") \
- IF_EXTRA_COMPAT("z") \
- "] [-m N] " \
- IF_FEATURE_GREP_CONTEXT("[-A/B/C N] ") \
- "PATTERN/-e PATTERN.../-f FILE [FILE]..."
-#define grep_full_usage "\n\n" \
- "Search for PATTERN in FILEs (or stdin)\n" \
- "\nOptions:" \
- "\n -H Add 'filename:' prefix" \
- "\n -h Do not add 'filename:' prefix" \
- "\n -n Add 'line_no:' prefix" \
- "\n -l Show only names of files that match" \
- "\n -L Show only names of files that don't match" \
- "\n -c Show only count of matching lines" \
- "\n -o Show only the matching part of line" \
- "\n -q Quiet. Return 0 if PATTERN is found, 1 otherwise" \
- "\n -v Select non-matching lines" \
- "\n -s Suppress open and read errors" \
- "\n -r Recurse" \
- "\n -i Ignore case" \
- "\n -w Match whole words only" \
- "\n -F PATTERN is a literal (not regexp)" \
- IF_FEATURE_GREP_EGREP_ALIAS( \
- "\n -E PATTERN is an extended regexp" \
- ) \
- IF_EXTRA_COMPAT( \
- "\n -z Input is NUL terminated" \
- ) \
- "\n -m N Match up to N times per file" \
- IF_FEATURE_GREP_CONTEXT( \
- "\n -A N Print N lines of trailing context" \
- "\n -B N Print N lines of leading context" \
- "\n -C N Same as '-A N -B N'" \
- ) \
- "\n -e PTRN Pattern to match" \
- "\n -f FILE Read pattern from file" \
-
-#define grep_example_usage \
- "$ grep root /etc/passwd\n" \
- "root:x:0:0:root:/root:/bin/bash\n" \
- "$ grep ^[rR]oo. /etc/passwd\n" \
- "root:x:0:0:root:/root:/bin/bash\n"
-
-#define egrep_trivial_usage NOUSAGE_STR
-#define egrep_full_usage ""
-
-#define fgrep_trivial_usage NOUSAGE_STR
-#define fgrep_full_usage ""
-
#define gunzip_trivial_usage \
"[OPTIONS] [FILE]..."
#define gunzip_full_usage "\n\n" \
#define whoami_full_usage "\n\n" \
"Print the user name associated with the current effective user id"
-#define xargs_trivial_usage \
- "[OPTIONS] [PROG ARGS]"
-#define xargs_full_usage "\n\n" \
- "Run PROG on every item given by stdin\n" \
- "\nOptions:" \
- IF_FEATURE_XARGS_SUPPORT_CONFIRMATION( \
- "\n -p Ask user whether to run each command") \
- "\n -r Don't run command if input is empty" \
- IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( \
- "\n -0 Input is separated by NUL characters") \
- "\n -t Print the command on stderr before execution" \
- "\n -e[STR] STR stops input processing" \
- "\n -n N Pass no more than N args to PROG" \
- "\n -s N Pass command line of no more than N bytes" \
- IF_FEATURE_XARGS_SUPPORT_TERMOPT( \
- "\n -x Exit if size is exceeded") \
-
-#define xargs_example_usage \
- "$ ls | xargs gzip\n" \
- "$ find . -name '*.c' -print | xargs rm\n"
-
#define zcat_trivial_usage \
"FILE"
#define zcat_full_usage "\n\n" \