From 71eb1436115c312bc4cb397b01760c3153378ff4 Mon Sep 17 00:00:00 2001 From: czapek1337 Date: Sun, 11 Sep 2022 20:45:04 +0200 Subject: [PATCH] print: Specifier for printing URIs --- common/lib/print.s2.c | 19 +++++++++++++++++++ common/lib/uri.c | 2 +- common/protos/limine.c | 8 ++++---- common/protos/linux.c | 8 ++++---- common/protos/multiboot1.c | 8 ++++---- common/protos/multiboot2.c | 8 ++++---- 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/common/lib/print.s2.c b/common/lib/print.s2.c index deae50fc..0d728676 100644 --- a/common/lib/print.s2.c +++ b/common/lib/print.s2.c @@ -192,6 +192,25 @@ void vprint(const char *fmt, va_list args) { char c = (char)va_arg(args, int); prn_char(print_buf, &print_buf_i, c); } break; + case '#': { + bool printed = false; + char *str = (char *)va_arg(args, const char *); + for (int i = (int)strlen(str) - 1; i >= 0; i--) { + if (str[i] != '#') { + continue; + } + + prn_nstr(print_buf, &print_buf_i, str, i); + printed = true; + break; + } + + if (!printed) { + prn_str(print_buf, &print_buf_i, str); + } + + break; + } default: prn_char(print_buf, &print_buf_i, '?'); break; diff --git a/common/lib/uri.c b/common/lib/uri.c index dce0433a..e3517fff 100644 --- a/common/lib/uri.c +++ b/common/lib/uri.c @@ -194,7 +194,7 @@ struct file_handle *uri_open(char *uri) { uri_resolve(uri, &resource, &root, &path); if (resource == NULL) { - panic(true, "No resource specified for URI `%s`.", uri); + panic(true, "No resource specified for URI `%#`.", uri); } bool compressed = false; diff --git a/common/protos/limine.c b/common/protos/limine.c index 5a33ae55..d2c9d2f7 100644 --- a/common/protos/limine.c +++ b/common/protos/limine.c @@ -281,11 +281,11 @@ noreturn void limine_load(char *config, char *cmdline) { if (kernel_path == NULL) panic(true, "limine: KERNEL_PATH not specified"); - print("limine: Loading kernel `%s`...\n", kernel_path); + print("limine: Loading kernel `%#`...\n", kernel_path); struct file_handle *kernel_file; if ((kernel_file = uri_open(kernel_path)) == NULL) - panic(true, "limine: Failed to open kernel with path `%s`. Is the path correct?", kernel_path); + panic(true, "limine: Failed to open kernel with path `%#`. Is the path correct?", kernel_path); uint8_t *kernel = freadall(kernel_file, MEMMAP_BOOTLOADER_RECLAIMABLE); @@ -632,11 +632,11 @@ FEAT_START module_cmdline = ""; } - print("limine: Loading module `%s`...\n", module_path); + print("limine: Loading module `%#`...\n", module_path); struct file_handle *f; if ((f = uri_open(module_path)) == NULL) - panic(true, "limine: Failed to open module with path `%s`. Is the path correct?", module_path); + panic(true, "limine: Failed to open module with path `%#`. Is the path correct?", module_path); struct limine_file *l = &modules[i]; *l = get_file(f, module_cmdline); diff --git a/common/protos/linux.c b/common/protos/linux.c index 5671a395..1afcf38f 100644 --- a/common/protos/linux.c +++ b/common/protos/linux.c @@ -357,10 +357,10 @@ noreturn void linux_load(char *config, char *cmdline) { if (kernel_path == NULL) panic(true, "linux: KERNEL_PATH not specified"); - print("linux: Loading kernel `%s`...\n", kernel_path); + print("linux: Loading kernel `%#`...\n", kernel_path); if ((kernel_file = uri_open(kernel_path)) == NULL) - panic(true, "linux: Failed to open kernel with path `%s`. Is the path correct?", kernel_path); + panic(true, "linux: Failed to open kernel with path `%#`. Is the path correct?", kernel_path); uint32_t signature; fread(kernel_file, &signature, 0x202, sizeof(uint32_t)); @@ -475,11 +475,11 @@ noreturn void linux_load(char *config, char *cmdline) { if (module_path == NULL) break; - print("linux: Loading module `%s`...\n", module_path); + print("linux: Loading module `%#`...\n", module_path); struct file_handle *module; if ((module = uri_open(module_path)) == NULL) - panic(true, "linux: Could not open `%s`", module_path); + panic(true, "linux: Could not open `%#`", module_path); fread(module, (void *)_modules_mem_base, 0, module->size); diff --git a/common/protos/multiboot1.c b/common/protos/multiboot1.c index cd7ec2f7..6dc8946b 100644 --- a/common/protos/multiboot1.c +++ b/common/protos/multiboot1.c @@ -53,10 +53,10 @@ noreturn void multiboot1_load(char *config, char *cmdline) { if (kernel_path == NULL) panic(true, "multiboot1: KERNEL_PATH not specified"); - print("multiboot1: Loading kernel `%s`...\n", kernel_path); + print("multiboot1: Loading kernel `%#`...\n", kernel_path); if ((kernel_file = uri_open(kernel_path)) == NULL) - panic(true, "multiboot1: Failed to open kernel with path `%s`. Is the path correct?", kernel_path); + panic(true, "multiboot1: Failed to open kernel with path `%#`. Is the path correct?", kernel_path); uint8_t *kernel = freadall(kernel_file, MEMMAP_KERNEL_AND_MODULES); @@ -248,11 +248,11 @@ noreturn void multiboot1_load(char *config, char *cmdline) { if (module_path == NULL) panic(true, "multiboot1: Module disappeared unexpectedly"); - print("multiboot1: Loading module `%s`...\n", module_path); + print("multiboot1: Loading module `%#`...\n", module_path); struct file_handle *f; if ((f = uri_open(module_path)) == NULL) - panic(true, "multiboot1: Failed to open module with path `%s`. Is the path correct?", module_path); + panic(true, "multiboot1: Failed to open module with path `%#`. Is the path correct?", module_path); char *module_cmdline = conf_tuple.value2; if (module_cmdline == NULL) { diff --git a/common/protos/multiboot2.c b/common/protos/multiboot2.c index f01dc096..ccfb5e46 100644 --- a/common/protos/multiboot2.c +++ b/common/protos/multiboot2.c @@ -70,10 +70,10 @@ noreturn void multiboot2_load(char *config, char* cmdline) { if (kernel_path == NULL) panic(true, "multiboot2: KERNEL_PATH not specified"); - print("multiboot2: Loading kernel `%s`...\n", kernel_path); + print("multiboot2: Loading kernel `%#`...\n", kernel_path); if ((kernel_file = uri_open(kernel_path)) == NULL) - panic(true, "multiboot2: Failed to open kernel with path `%s`. Is the path correct?", kernel_path); + panic(true, "multiboot2: Failed to open kernel with path `%#`. Is the path correct?", kernel_path); uint8_t *kernel = freadall(kernel_file, MEMMAP_KERNEL_AND_MODULES); @@ -397,11 +397,11 @@ noreturn void multiboot2_load(char *config, char* cmdline) { char *module_path = conf_tuple.value1; if (!module_path) panic(true, "multiboot2: Module disappeared unexpectedly"); - print("multiboot2: Loading module `%s`...\n", module_path); + print("multiboot2: Loading module `%#`...\n", module_path); struct file_handle *f; if ((f = uri_open(module_path)) == NULL) - panic(true, "multiboot2: Failed to open module with path `%s`. Is the path correct?", module_path); + panic(true, "multiboot2: Failed to open module with path `%#`. Is the path correct?", module_path); // Module commandline can be null, so we guard against that and make the // string "".