diff options
author | Andreas Kling <kling@serenityos.org> | 2021-04-29 11:28:01 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-29 11:28:01 +0200 |
commit | 39369f1da63e8949d00378824714b37aabac7db1 (patch) | |
tree | 684be83be103a1ae31edbc4245f96a8d607c2b0f /Userland | |
parent | 695cdf7bc054826b1abbf797b7c100fb26dad51c (diff) | |
download | serenity-39369f1da63e8949d00378824714b37aabac7db1.zip |
Utilities: Use Vector<String> positional arguments in some places
There are more places we can use these, I just picked some that felt
like they improved the code.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Utilities/cat.cpp | 12 | ||||
-rw-r--r-- | Userland/Utilities/checksum.cpp | 6 | ||||
-rw-r--r-- | Userland/Utilities/gunzip.cpp | 4 | ||||
-rw-r--r-- | Userland/Utilities/gzip.cpp | 4 | ||||
-rw-r--r-- | Userland/Utilities/tar.cpp | 2 | ||||
-rw-r--r-- | Userland/Utilities/zip.cpp | 4 |
6 files changed, 15 insertions, 17 deletions
diff --git a/Userland/Utilities/cat.cpp b/Userland/Utilities/cat.cpp index c683382c68..59c203d70f 100644 --- a/Userland/Utilities/cat.cpp +++ b/Userland/Utilities/cat.cpp @@ -6,13 +6,11 @@ #include <AK/Vector.h> #include <LibCore/ArgsParser.h> -#include <assert.h> #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/stat.h> #include <unistd.h> int main(int argc, char** argv) @@ -22,7 +20,7 @@ int main(int argc, char** argv) return 1; } - Vector<const char*> paths; + Vector<String> paths; Core::ArgsParser args_parser; args_parser.set_general_help("Concatenate files or pipes to stdout."); @@ -31,12 +29,12 @@ int main(int argc, char** argv) Vector<int> fds; if (!paths.is_empty()) { - for (const char* path : paths) { + for (auto const& path : paths) { int fd; - if (StringView { path } == "-") { + if (path == "-") { fd = 0; - } else if ((fd = open(path, O_RDONLY)) == -1) { - fprintf(stderr, "Failed to open %s: %s\n", path, strerror(errno)); + } else if ((fd = open(path.characters(), O_RDONLY)) == -1) { + warnln("Failed to open {}: {}", path, strerror(errno)); continue; } fds.append(fd); diff --git a/Userland/Utilities/checksum.cpp b/Userland/Utilities/checksum.cpp index 21d182e905..583269f51f 100644 --- a/Userland/Utilities/checksum.cpp +++ b/Userland/Utilities/checksum.cpp @@ -36,7 +36,7 @@ int main(int argc, char** argv) auto hash_name = program_name.substring_view(0, program_name.length() - 3).to_string().to_uppercase(); auto paths_help_string = String::formatted("File(s) to print {} checksum of", hash_name); - Vector<const char*> paths; + Vector<String> paths; Core::ArgsParser args_parser; args_parser.add_positional_argument(paths, paths_help_string.characters(), "path", Core::ArgsParser::Required::No); @@ -52,8 +52,8 @@ int main(int argc, char** argv) auto has_error = false; auto file = Core::File::construct(); - for (auto path : paths) { - if (StringView { path } == "-") { + for (auto const& path : paths) { + if (path == "-") { success = file->open(STDIN_FILENO, Core::IODevice::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::No); } else { file->set_filename(path); diff --git a/Userland/Utilities/gunzip.cpp b/Userland/Utilities/gunzip.cpp index c4826d9956..589e0ddd3d 100644 --- a/Userland/Utilities/gunzip.cpp +++ b/Userland/Utilities/gunzip.cpp @@ -25,7 +25,7 @@ static bool decompress_file(Buffered<Core::InputFileStream>& input_stream, Buffe int main(int argc, char** argv) { - Vector<const char*> filenames; + Vector<String> filenames; bool keep_input_files { false }; bool write_to_stdout { false }; @@ -38,7 +38,7 @@ int main(int argc, char** argv) if (write_to_stdout) keep_input_files = true; - for (String filename : filenames) { + for (auto filename : filenames) { if (!filename.ends_with(".gz")) filename = String::formatted("{}.gz", filename); diff --git a/Userland/Utilities/gzip.cpp b/Userland/Utilities/gzip.cpp index c386ce0f49..7de3827470 100644 --- a/Userland/Utilities/gzip.cpp +++ b/Userland/Utilities/gzip.cpp @@ -12,7 +12,7 @@ int main(int argc, char** argv) { - Vector<const char*> filenames; + Vector<String> filenames; bool keep_input_files { false }; bool write_to_stdout { false }; @@ -25,7 +25,7 @@ int main(int argc, char** argv) if (write_to_stdout) keep_input_files = true; - for (const String input_filename : filenames) { + for (auto const& input_filename : filenames) { auto output_filename = String::formatted("{}.gz", input_filename); // We map the whole file instead of streaming to reduce size overhead (gzip header) and increase the deflate block size (better compression) diff --git a/Userland/Utilities/tar.cpp b/Userland/Utilities/tar.cpp index 3f2ea95562..7877787b37 100644 --- a/Userland/Utilities/tar.cpp +++ b/Userland/Utilities/tar.cpp @@ -175,7 +175,7 @@ int main(int argc, char** argv) } }; - for (const String path : paths) { + for (auto const& path : paths) { if (Core::File::is_directory(path)) { add_directory(path, add_directory); } else { diff --git a/Userland/Utilities/zip.cpp b/Userland/Utilities/zip.cpp index c15fc8fda8..0824e7c80a 100644 --- a/Userland/Utilities/zip.cpp +++ b/Userland/Utilities/zip.cpp @@ -16,7 +16,7 @@ int main(int argc, char** argv) { const char* zip_path; - Vector<const char*> source_paths; + Vector<String> source_paths; bool recurse = false; bool force = false; @@ -104,7 +104,7 @@ int main(int argc, char** argv) } }; - for (const String source_path : source_paths) { + for (auto const& source_path : source_paths) { if (Core::File::is_directory(source_path)) { add_directory(source_path, add_directory); } else { |