mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
strings: Replace the -p
option with the more commonly used -f
Previously, the `-p` option printed the path of the file being processed before any strings for that file. The `-f` prints the file path before each string . This matches the behavior of strings on Linux and FreeBSD.
This commit is contained in:
parent
3de4cd0ba9
commit
ab1e8a7b91
Notes:
sideshowbarker
2024-07-17 20:33:50 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/ab1e8a7b91 Pull-request: https://github.com/SerenityOS/serenity/pull/19515
2 changed files with 7 additions and 9 deletions
|
@ -5,7 +5,7 @@ strings - find printable strings in files
|
|||
## Synopsis
|
||||
|
||||
```**sh
|
||||
$ strings [-n NUMBER] [-p] [-t FORMAT] [PATHS...]
|
||||
$ strings [-n NUMBER] [--print-file-name] [-t FORMAT] [PATHS...]
|
||||
```
|
||||
|
||||
## Description
|
||||
|
@ -15,7 +15,7 @@ $ strings [-n NUMBER] [-p] [-t FORMAT] [PATHS...]
|
|||
## Options
|
||||
|
||||
* `-n NUMBER`: Specify the minimum string length (4 is default).
|
||||
* `-p`: Write the pathname for each file specified in `PATHS` to standard output.
|
||||
* `-f`, `--print-file-name`: Print the name of the file before each string.
|
||||
* `-t FORMAT`: Write each string preceded by its byte offset from the start of the file in the specified `FORMAT`, where `FORMAT` matches one of the following: `d` (decimal), `o` (octal), or `x` (hexidecimal).
|
||||
|
||||
## Examples
|
||||
|
@ -35,5 +35,5 @@ $ strings -t x ~/Videos/test.webm
|
|||
Display the printable strings in all .txt files in the current directory, preceded by their pathname:
|
||||
|
||||
```sh
|
||||
$ strings -p *.txt
|
||||
$ strings -f *.txt
|
||||
```
|
||||
|
|
|
@ -70,17 +70,15 @@ static ErrorOr<void> process_strings_in_file(StringView path, bool show_paths, S
|
|||
auto file = TRY(Core::File::open_file_or_standard_stream(path, Core::File::OpenMode::Read));
|
||||
size_t processed_characters = 0;
|
||||
size_t string_offset_position = 0;
|
||||
bool did_show_path = false;
|
||||
while (!file->is_eof()) {
|
||||
auto buffer_span = TRY(file->read_some(buffer));
|
||||
while (!buffer_span.is_empty()) {
|
||||
string_offset_position += processed_characters;
|
||||
processed_characters = process_characters_in_span(output_characters, buffer_span);
|
||||
if (show_paths && !did_show_path) {
|
||||
outln("path {}:", path);
|
||||
did_show_path = true;
|
||||
}
|
||||
if (output_characters.size() >= minimum_string_length && should_print_characters(output_characters)) {
|
||||
if (show_paths)
|
||||
out("{}:", path);
|
||||
|
||||
print_characters(output_characters, string_offset_format, string_offset_position);
|
||||
}
|
||||
buffer_span = buffer_span.slice(processed_characters);
|
||||
|
@ -102,7 +100,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_option(minimum_string_length, "Specify the minimum string length.", nullptr, 'n', "number");
|
||||
args_parser.add_option(show_paths, "Display the path for each matched file.", nullptr, 'p');
|
||||
args_parser.add_option(show_paths, "Print the name of the file before each string.", "print-file-name", 'f');
|
||||
args_parser.add_option({ Core::ArgsParser::OptionArgumentMode::Required,
|
||||
"Write offset relative to start of each file in (d)ec, (o)ct, or he(x) format.",
|
||||
nullptr,
|
||||
|
|
Loading…
Reference in a new issue