mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:54:58 +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
2 changed files with 7 additions and 9 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue