mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:07:45 +00:00
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.
This commit is contained in:
parent
695cdf7bc0
commit
39369f1da6
6 changed files with 15 additions and 17 deletions
|
@ -6,13 +6,11 @@
|
||||||
|
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <assert.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
|
@ -22,7 +20,7 @@ int main(int argc, char** argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<const char*> paths;
|
Vector<String> paths;
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.set_general_help("Concatenate files or pipes to stdout.");
|
args_parser.set_general_help("Concatenate files or pipes to stdout.");
|
||||||
|
@ -31,12 +29,12 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
Vector<int> fds;
|
Vector<int> fds;
|
||||||
if (!paths.is_empty()) {
|
if (!paths.is_empty()) {
|
||||||
for (const char* path : paths) {
|
for (auto const& path : paths) {
|
||||||
int fd;
|
int fd;
|
||||||
if (StringView { path } == "-") {
|
if (path == "-") {
|
||||||
fd = 0;
|
fd = 0;
|
||||||
} else if ((fd = open(path, O_RDONLY)) == -1) {
|
} else if ((fd = open(path.characters(), O_RDONLY)) == -1) {
|
||||||
fprintf(stderr, "Failed to open %s: %s\n", path, strerror(errno));
|
warnln("Failed to open {}: {}", path, strerror(errno));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fds.append(fd);
|
fds.append(fd);
|
||||||
|
|
|
@ -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 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);
|
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;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.add_positional_argument(paths, paths_help_string.characters(), "path", Core::ArgsParser::Required::No);
|
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 has_error = false;
|
||||||
auto file = Core::File::construct();
|
auto file = Core::File::construct();
|
||||||
|
|
||||||
for (auto path : paths) {
|
for (auto const& path : paths) {
|
||||||
if (StringView { path } == "-") {
|
if (path == "-") {
|
||||||
success = file->open(STDIN_FILENO, Core::IODevice::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::No);
|
success = file->open(STDIN_FILENO, Core::IODevice::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::No);
|
||||||
} else {
|
} else {
|
||||||
file->set_filename(path);
|
file->set_filename(path);
|
||||||
|
|
|
@ -25,7 +25,7 @@ static bool decompress_file(Buffered<Core::InputFileStream>& input_stream, Buffe
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
Vector<const char*> filenames;
|
Vector<String> filenames;
|
||||||
bool keep_input_files { false };
|
bool keep_input_files { false };
|
||||||
bool write_to_stdout { false };
|
bool write_to_stdout { false };
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ int main(int argc, char** argv)
|
||||||
if (write_to_stdout)
|
if (write_to_stdout)
|
||||||
keep_input_files = true;
|
keep_input_files = true;
|
||||||
|
|
||||||
for (String filename : filenames) {
|
for (auto filename : filenames) {
|
||||||
if (!filename.ends_with(".gz"))
|
if (!filename.ends_with(".gz"))
|
||||||
filename = String::formatted("{}.gz", filename);
|
filename = String::formatted("{}.gz", filename);
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
Vector<const char*> filenames;
|
Vector<String> filenames;
|
||||||
bool keep_input_files { false };
|
bool keep_input_files { false };
|
||||||
bool write_to_stdout { false };
|
bool write_to_stdout { false };
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ int main(int argc, char** argv)
|
||||||
if (write_to_stdout)
|
if (write_to_stdout)
|
||||||
keep_input_files = true;
|
keep_input_files = true;
|
||||||
|
|
||||||
for (const String input_filename : filenames) {
|
for (auto const& input_filename : filenames) {
|
||||||
auto output_filename = String::formatted("{}.gz", input_filename);
|
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)
|
// We map the whole file instead of streaming to reduce size overhead (gzip header) and increase the deflate block size (better compression)
|
||||||
|
|
|
@ -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)) {
|
if (Core::File::is_directory(path)) {
|
||||||
add_directory(path, add_directory);
|
add_directory(path, add_directory);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
const char* zip_path;
|
const char* zip_path;
|
||||||
Vector<const char*> source_paths;
|
Vector<String> source_paths;
|
||||||
bool recurse = false;
|
bool recurse = false;
|
||||||
bool force = 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)) {
|
if (Core::File::is_directory(source_path)) {
|
||||||
add_directory(source_path, add_directory);
|
add_directory(source_path, add_directory);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue