print: Specifier for printing URIs

This commit is contained in:
czapek1337 2022-09-11 20:45:04 +02:00
parent a1bcf3c09b
commit 71eb143611
No known key found for this signature in database
GPG Key ID: 2F5F3AE42F4E7E2C
6 changed files with 36 additions and 17 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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) {

View File

@ -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 "".