libos+apps: Use os::*print* instead of (f)printf
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
a2303665fc
commit
48df90e636
@ -18,16 +18,13 @@ Result<int> luna_main(int argc, char** argv)
|
||||
|
||||
auto file = TRY(os::File::open_input_file(path));
|
||||
|
||||
auto output = os::File::standard_output();
|
||||
|
||||
if (!decode)
|
||||
{
|
||||
auto data = TRY(file->read_all());
|
||||
|
||||
auto encoded = TRY(Base64::encode(data));
|
||||
|
||||
output->write(encoded.view());
|
||||
output->write("\n"_sv);
|
||||
os::println("%s", encoded.chars());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -35,7 +32,7 @@ Result<int> luna_main(int argc, char** argv)
|
||||
|
||||
auto decoded = TRY(Base64::decode(data.view(), allow_garbage));
|
||||
|
||||
output->write(decoded);
|
||||
os::File::standard_output()->write(decoded);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1,11 +1,11 @@
|
||||
#include <os/ArgumentParser.h>
|
||||
#include <os/File.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
Result<int> luna_main(int argc, char** argv)
|
||||
{
|
||||
StringView date;
|
||||
|
||||
@ -20,5 +20,7 @@ int main(int argc, char** argv)
|
||||
if (date.is_empty()) { now = time(NULL); }
|
||||
else { now = strtol(date.chars(), nullptr, 10); }
|
||||
|
||||
fputs(ctime(&now), stdout);
|
||||
os::print("%s", ctime(&now));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
14
apps/ls.cpp
14
apps/ls.cpp
@ -1,8 +1,6 @@
|
||||
#include <os/ArgumentParser.h>
|
||||
#include <os/Directory.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <os/File.h>
|
||||
|
||||
Result<int> luna_main(int argc, char** argv)
|
||||
{
|
||||
@ -27,14 +25,8 @@ Result<int> luna_main(int argc, char** argv)
|
||||
|
||||
auto files = TRY(dir->list(filter));
|
||||
|
||||
int first_ent = 1;
|
||||
for (const auto& file : files)
|
||||
{
|
||||
printf(first_ent ? "%s" : " %s", file.chars());
|
||||
first_ent = 0;
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
auto list = TRY(String::join(files, " "_sv));
|
||||
os::println("%s", list.chars());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ Result<int> luna_main(int argc, char** argv)
|
||||
if (interactive)
|
||||
{
|
||||
auto cwd = TRY(os::FileSystem::working_directory());
|
||||
printf("%s@%s:%s%c ", username, hostname, cwd.chars(), prompt_end);
|
||||
os::print("%s@%s:%s%c ", username, hostname, cwd.chars(), prompt_end);
|
||||
}
|
||||
|
||||
auto cmd = TRY(input_file->read_line());
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <luna/StringBuilder.h>
|
||||
#include <os/ArgumentParser.h>
|
||||
#include <os/File.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/utsname.h>
|
||||
@ -165,7 +166,7 @@ namespace os
|
||||
|
||||
if (found) continue;
|
||||
|
||||
fprintf(stderr, "%s: unrecognized option '%s'\n", program_name.chars(), arg.chars());
|
||||
os::eprintln("%s: unrecognized option '%s'", program_name.chars(), arg.chars());
|
||||
short_usage(program_name);
|
||||
}
|
||||
else if (looks_like_short_flag(arg))
|
||||
@ -213,7 +214,7 @@ namespace os
|
||||
|
||||
if (found) continue;
|
||||
|
||||
fprintf(stderr, "%s: invalid option -- '%c'\n", program_name.chars(), c);
|
||||
os::eprintln("%s: invalid option -- '%c'", program_name.chars(), c);
|
||||
short_usage(program_name);
|
||||
}
|
||||
|
||||
@ -235,7 +236,7 @@ namespace os
|
||||
{
|
||||
if (current_value_argument->required)
|
||||
{
|
||||
fprintf(stderr, "%s: option '--%s' requires an argument\n", program_name.chars(),
|
||||
os::eprintln("%s: option '--%s' requires an argument", program_name.chars(),
|
||||
current_value_argument->long_flag.chars());
|
||||
short_usage(program_name);
|
||||
}
|
||||
@ -247,7 +248,7 @@ namespace os
|
||||
{
|
||||
if (arg.required)
|
||||
{
|
||||
fprintf(stderr, "%s: required argument '%s' not provided\n", program_name.chars(), arg.name.chars());
|
||||
os::eprintln("%s: required argument '%s' not provided", program_name.chars(), arg.name.chars());
|
||||
short_usage(program_name);
|
||||
}
|
||||
else { *arg.out = arg.fallback; }
|
||||
@ -354,7 +355,7 @@ namespace os
|
||||
void ArgumentParser::short_usage(StringView program_name)
|
||||
{
|
||||
if (m_add_short_help_flag || m_add_long_help_flag)
|
||||
fprintf(stderr, "Try running '%s %s' for more information.\n", program_name.chars(),
|
||||
os::eprintln("Try running '%s %s' for more information.", program_name.chars(),
|
||||
m_add_long_help_flag ? "--help" : "-h");
|
||||
|
||||
exit(1);
|
||||
|
Loading…
Reference in New Issue
Block a user