Userland: Use new format functions in some programs

This commit is contained in:
Andreas Kling 2020-10-20 17:28:17 +02:00
parent d1fe6a0b53
commit 633b6fbc48
4 changed files with 23 additions and 26 deletions

View file

@ -61,9 +61,9 @@ static void handle_sigint(int)
static void print_function_call(String function_name, size_t depth)
{
for (size_t i = 0; i < depth; ++i) {
printf(" ");
new_out(" ");
}
printf("=> %s\n", function_name.characters());
outln("=> {}", function_name);
}
static void print_syscall(PtraceRegisters& regs, size_t depth)
@ -73,10 +73,9 @@ static void print_syscall(PtraceRegisters& regs, size_t depth)
}
const char* begin_color = g_should_output_color ? "\033[34;1m" : "";
const char* end_color = g_should_output_color ? "\033[0m" : "";
printf("=> %sSC_%s(0x%x, 0x%x, 0x%x)%s\n",
outln("=> {}SC_{}(0x{:x}, 0x{:x}, 0x{:x}){}",
begin_color,
Syscall::to_string(
(Syscall::Function)regs.eax),
Syscall::to_string((Syscall::Function)regs.eax),
regs.edx,
regs.ecx,
regs.ebx,
@ -128,7 +127,7 @@ int main(int argc, char** argv)
auto result = Debug::DebugSession::exec_and_attach(command);
if (!result) {
fprintf(stderr, "Failed to start debugging session for: \"%s\"\n", command);
warnln("Failed to start debugging session for: \"{}\"", command);
exit(1);
}
g_debug_session = result.release_nonnull();
@ -145,7 +144,7 @@ int main(int argc, char** argv)
g_debug_session->run([&](Debug::DebugSession::DebugBreakReason reason, Optional<PtraceRegisters> regs) {
if (reason == Debug::DebugSession::DebugBreakReason::Exited) {
printf("Program exited.\n");
outln("Program exited.");
return Debug::DebugSession::DebugDecision::Detach;
}

View file

@ -55,7 +55,7 @@ int main(int argc, char** argv)
auto db = PCIDB::Database::open();
if (!db)
fprintf(stderr, "Couldn't open PCI ID database\n");
warnln("Couldn't open PCI ID database");
auto proc_pci = Core::File::construct("/proc/pci");
if (!proc_pci->open(Core::IODevice::ReadOnly)) {
@ -99,10 +99,7 @@ int main(int argc, char** argv)
if (class_name.is_empty())
class_name = String::format("%04x", class_id);
printf("%04x:%02x:%02x.%d %s: %s %s (rev %02x)\n",
seg, bus, slot, function,
class_name.characters(), vendor_name.characters(),
device_name.characters(), revision_id);
outln("{:04x}:{:02x}:{:02x}.{} {}: {} {} (rev {:02x})", seg, bus, slot, function, class_name, vendor_name, device_name, revision_id);
});
return 0;

View file

@ -52,13 +52,13 @@ int main(int argc, char* argv[])
URL url = URL::create_with_url_or_path(path);
if (url.protocol() == "file" && realpath_errno) {
fprintf(stderr, "Failed to open '%s': %s\n", url.path().characters(), strerror(realpath_errno));
warnln("Failed to open '{}': {}\n", url.path(), strerror(realpath_errno));
all_ok = false;
continue;
}
if (!Desktop::Launcher::open(url)) {
fprintf(stderr, "Failed to open '%s'\n", url.path().characters());
warnln("Failed to open '{}'", url.path());
all_ok = false;
}
}

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/LogStream.h>
#include <AK/LexicalPath.h>
#include <AK/QuickSort.h>
#include <AK/String.h>
@ -50,11 +51,11 @@ static void print_directory_tree(const String& root_path, int depth, const Strin
} else {
root_indent_string = "";
}
printf("%s|-- ", root_indent_string.characters());
new_out("{}|-- ", root_indent_string);
}
String root_dir_name = AK::LexicalPath(root_path).basename();
printf("\033[34;1m%s\033[0m\n", root_dir_name.characters());
new_out("\033[34;1m{}\033[0m\n", root_dir_name);
if (depth >= max_depth) {
return;
@ -62,7 +63,7 @@ static void print_directory_tree(const String& root_path, int depth, const Strin
Core::DirIterator di(root_path, flag_show_hidden_files ? Core::DirIterator::SkipParentAndBaseDir : Core::DirIterator::SkipDots);
if (di.has_error()) {
fprintf(stderr, "%s: %s\n", root_path.characters(), di.error_string());
warnln("{}: {}", root_path, di.error_string());
return;
}
@ -70,7 +71,7 @@ static void print_directory_tree(const String& root_path, int depth, const Strin
while (di.has_next()) {
String name = di.next_path();
if (di.has_error()) {
fprintf(stderr, "%s: %s\n", root_path.characters(), di.error_string());
warnln("{}: {}", root_path, di.error_string());
continue;
}
names.append(name);
@ -92,7 +93,7 @@ static void print_directory_tree(const String& root_path, int depth, const Strin
struct stat st;
int rc = lstat(full_path.characters(), &st);
if (rc == -1) {
fprintf(stderr, "lstat(%s) failed: %s\n", full_path.characters(), strerror(errno));
warnln("lstat({}) failed: {}", full_path, strerror(errno));
continue;
}
@ -102,16 +103,16 @@ static void print_directory_tree(const String& root_path, int depth, const Strin
bool at_last_entry = i == names.size() - 1;
String new_indent_string;
if (at_last_entry) {
new_indent_string = String::format("%s ", indent_string.characters());
new_indent_string = String::formatted("{} ", indent_string);
} else {
new_indent_string = String::format("%s| ", indent_string.characters());
new_indent_string = String::formatted("{}| ", indent_string);
}
print_directory_tree(full_path.characters(), depth + 1, new_indent_string);
} else if (!flag_show_only_directories) {
g_files_seen++;
printf("%s|-- %s\n", indent_string.characters(), name.characters());
outln("{}|-- {}", indent_string, name);
}
}
}
@ -133,21 +134,21 @@ int main(int argc, char** argv)
args_parser.parse(argc, argv);
if (max_depth < 1) {
fprintf(stderr, "%s: Invalid level, must be greater than 0.\n", argv[0]);
warnln("{}: Invalid level, must be greater than 0.", argv[0]);
return 1;
}
if (directories.is_empty()) {
print_directory_tree(".", 0, "");
printf("\n");
puts("");
} else {
for (const char* directory : directories) {
print_directory_tree(directory, 0, "");
printf("\n");
puts("");
}
}
printf("%d directories, %d files\n", g_directories_seen, g_files_seen);
outln("{} directories, {} files", g_directories_seen, g_files_seen);
return 0;
}