Commit Graph

18 Commits

Author SHA1 Message Date
Tim Ledbetter
12d6845c4e shuf: Add -r option to allow output lines to be repeated
This commit also modifies the behavior of the `-z` option, so that a
'\0' character now delimits output lines, as well as input lines. This
matches the behavior of the GNU coreutils and FreeBSD implementations
of shuf.
2023-05-18 21:06:37 -06:00
Ben Wiederhake
560133a0c6 Everywhere: Remove unused DeprecatedString includes 2023-04-09 22:00:54 +02:00
Tim Schumacher
874c7bba28 LibCore: Remove Stream.h 2023-02-13 00:50:07 +00:00
Tim Schumacher
606a3982f3 LibCore: Move Stream-based file into the Core namespace 2023-02-13 00:50:07 +00:00
Ben Wiederhake
6b7ce19161 Everywhere: Remove unused includes of LibC/stdlib.h
These instances were detected by searching for files that include
stdlib.h, but don't match the regex:

\\b(_abort|abort|abs|aligned_alloc|arc4random|arc4random_buf|arc4random_
uniform|atexit|atof|atoi|atol|atoll|bsearch|calloc|clearenv|div|div_t|ex
it|_Exit|EXIT_FAILURE|EXIT_SUCCESS|free|getenv|getprogname|grantpt|labs|
ldiv|ldiv_t|llabs|lldiv|lldiv_t|malloc|malloc_good_size|malloc_size|mble
n|mbstowcs|mbtowc|mkdtemp|mkstemp|mkstemps|mktemp|posix_memalign|posix_o
penpt|ptsname|ptsname_r|putenv|qsort|qsort_r|rand|RAND_MAX|random|reallo
c|realpath|secure_getenv|serenity_dump_malloc_stats|serenity_setenv|sete
nv|setprogname|srand|srandom|strtod|strtof|strtol|strtold|strtoll|strtou
l|strtoull|system|unlockpt|unsetenv|wcstombs|wctomb)\\b

(Without the linebreaks.)

This regex is pessimistic, so there might be more files that don't
actually use anything from the stdlib.

In theory, one might use LibCPP to detect things like this
automatically, but let's do this one step after another.
2023-01-02 20:27:20 -05:00
Arda Cinar
a559e26f68 shuf: Use the newly introduced AK::shuffle function 2022-12-12 16:23:03 +00:00
Tim Schumacher
ed4c2f2f8e LibCore: Rename Stream::read_all to read_until_eof
This generally seems like a better name, especially if we somehow also
need a better name for "read the entire buffer, but not the entire file"
somewhere down the line.
2022-12-12 14:16:42 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Baitinq
44ef0ac41c shuf: Support the output of a limited number of lines
This patch adds the "-n"/"--head-count" optional argument to specifiy
the maximum number of shuffled lines to output.

Idea from Andreas' FIXME roulette :^)
2022-11-29 11:44:05 +01:00
Eli Youngs
c92f450ff0 shuf: Support splitting on null bytes with -z 2022-11-25 22:59:27 +01:00
Eli Youngs
b2fd87950a shuf: Support reading input from a file
Previously, shuf exclusively read input from stdin. This PR adds an
option to read from a file using Core::Stream::File. Since a file might
contain arbitrary bytes, including null bytes, this PR represents lines
as Spans of Bytes instead of Strings.
2022-11-25 22:59:27 +01:00
Michel Hermier
176de579f2 shuf: Port to LibMain 2022-01-24 05:38:30 +00:00
SeekingBlues
c63bdba955 shuf: Fix division by zero when no lines are read 2021-10-17 12:07:09 -07:00
Jean-Baptiste Boric
5a0468c21f Userland: Migrate from arc4random_uniform() to get_random_uniform() 2021-05-14 22:24:02 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Andreas Kling
ef1e5db1d0 Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)
Good-bye LogStream. Long live AK::Format!
2021-03-12 17:29:37 +01:00
Andrew Kaster
c2d8b8ec14 Userland: Don't leak buffer from getline in shuf program
Probably doesn't matter too too much since the program exits almost
immediately after, but there's the principle of the thing to consider.
2021-02-28 18:19:37 +01:00
Ben Wiederhake
de98f69bfe Userland: Implement shuf for basic shuffling 2021-01-20 19:19:34 +01:00