diff --git a/Base/usr/share/man/man1/strings.md b/Base/usr/share/man/man1/strings.md index abcaf5284b2..8635584352e 100644 --- a/Base/usr/share/man/man1/strings.md +++ b/Base/usr/share/man/man1/strings.md @@ -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 ``` diff --git a/Userland/Utilities/strings.cpp b/Userland/Utilities/strings.cpp index 326b826df95..a3d14b77c8e 100644 --- a/Userland/Utilities/strings.cpp +++ b/Userland/Utilities/strings.cpp @@ -70,17 +70,15 @@ static ErrorOr 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 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,