diff options
Diffstat (limited to 'com32/elflink/ldlinux')
-rw-r--r-- | com32/elflink/ldlinux/Makefile | 2 | ||||
-rw-r--r-- | com32/elflink/ldlinux/cli.c | 30 | ||||
-rw-r--r-- | com32/elflink/ldlinux/config.h | 2 | ||||
-rw-r--r-- | com32/elflink/ldlinux/eprintf.c | 35 | ||||
-rw-r--r-- | com32/elflink/ldlinux/readconfig.c | 14 |
5 files changed, 60 insertions, 23 deletions
diff --git a/com32/elflink/ldlinux/Makefile b/com32/elflink/ldlinux/Makefile index 32780c49..5927e500 100644 --- a/com32/elflink/ldlinux/Makefile +++ b/com32/elflink/ldlinux/Makefile @@ -20,7 +20,7 @@ all: ldlinux.c32 ldlinux_lnx.a ldlinux.c32 : ldlinux.o cli.o readconfig.o refstr.o colors.o getadv.o \ adv.o ipappend.o execute.o kernel.o get_key.o \ - advwrite.o setadv.o + advwrite.o setadv.o eprintf.o $(LD) $(LDFLAGS) -o $@ $^ LNXLIBOBJS = get_key.lo diff --git a/com32/elflink/ldlinux/cli.c b/com32/elflink/ldlinux/cli.c index 3bb7db4d..1ed3ea63 100644 --- a/com32/elflink/ldlinux/cli.c +++ b/com32/elflink/ldlinux/cli.c @@ -81,7 +81,7 @@ static const char * cmd_reverse_search(int *cursor) memset(buf, 0, MAX_CMDLINE_LEN); - printf("\033[1G\033[1;36m(reverse-i-search)`': \033[0m"); + eprintf("\033[1G\033[1;36m(reverse-i-search)`': \033[0m"); while (1) { key = mygetkey(0); @@ -115,11 +115,11 @@ static const char * cmd_reverse_search(int *cursor) *cursor = p - last_good->command; } - printf("\033[?7l\033[?25l"); + eprintf("\033[?7l\033[?25l"); /* Didn't handle the line wrap case here */ - printf("\033[1G\033[1;36m(reverse-i-search)\033[0m`%s': %s", + eprintf("\033[1G\033[1;36m(reverse-i-search)\033[0m`%s': %s", buf, last_good->command ? : ""); - printf("\033[K\r"); + eprintf("\033[K\r"); } return last_good ? last_good->command : NULL; @@ -171,10 +171,10 @@ const char *edit_cmdline(const char *input, int top /*, int width */ , prev_len = max(len, prev_len); /* Redraw the command line */ - printf("\033[?7l\033[?25l"); + eprintf("\033[?7l\033[?25l"); if (y) - printf("\033[%dA", y); - printf("\033[1G\033[1;36m%s \033[0m", input); + eprintf("\033[%dA", y); + eprintf("\033[1G\033[1;36m%s \033[0m", input); x = strlen(input); y = 0; @@ -184,23 +184,23 @@ const char *edit_cmdline(const char *input, int top /*, int width */ , at++; x++; if (x >= width) { - printf("\r\n"); + eprintf("\r\n"); x = 0; y++; } } - printf("\033[K\r"); + eprintf("\033[K\r"); dy = y - (cursor + strlen(input) + 1) / width; x = (cursor + strlen(input) + 1) % width; if (dy) { - printf("\033[%dA", dy); + eprintf("\033[%dA", dy); y -= dy; } if (x) - printf("\033[%dC", x); - printf("\033[?25h"); + eprintf("\033[%dC", x); + eprintf("\033[?25h"); prev_len = len; redraw = 0; } @@ -294,7 +294,7 @@ const char *edit_cmdline(const char *input, int top /*, int width */ , cursor++; x++; if (x >= width) { - printf("\r\n"); + eprintf("\r\n"); y++; x = 0; } @@ -423,7 +423,7 @@ const char *edit_cmdline(const char *input, int top /*, int width */ , cursor++; x++; if (x >= width) { - printf("\r\n\033[K"); + eprintf("\r\n\033[K"); y++; x = 0; } @@ -443,7 +443,7 @@ const char *edit_cmdline(const char *input, int top /*, int width */ , } } - printf("\033[?7h"); + eprintf("\033[?7h"); /* Add the command to the history */ comm_counter = malloc(sizeof(struct cli_command)); diff --git a/com32/elflink/ldlinux/config.h b/com32/elflink/ldlinux/config.h index 8f708f14..c34b2cc6 100644 --- a/com32/elflink/ldlinux/config.h +++ b/com32/elflink/ldlinux/config.h @@ -38,4 +38,6 @@ extern const char *onerror; //"onerror" command line extern void cat_help_file(int key); +extern void eprintf(const char *filename, ...); + #endif /* __CONFIG_H__ */ diff --git a/com32/elflink/ldlinux/eprintf.c b/com32/elflink/ldlinux/eprintf.c new file mode 100644 index 00000000..d8858ff9 --- /dev/null +++ b/com32/elflink/ldlinux/eprintf.c @@ -0,0 +1,35 @@ +#include <stdio.h> +#include <string.h> +#include <stdarg.h> + +#define BUFFER_SIZE 4096 + +static void veprintf(const char *format, va_list ap) +{ + int rv, _rv; + char buffer[BUFFER_SIZE]; + char *p; + + _rv = rv = vsnprintf(buffer, BUFFER_SIZE, format, ap); + + if (rv < 0) + return; + + if (rv > BUFFER_SIZE - 1) + rv = BUFFER_SIZE - 1; + + p = buffer; + while (rv--) + write_serial(*p++); + + _fwrite(buffer, _rv, stdout); +} + +void eprintf(const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + veprintf(format, ap); + va_end(ap); +} diff --git a/com32/elflink/ldlinux/readconfig.c b/com32/elflink/ldlinux/readconfig.c index 3a6a3677..564cbeff 100644 --- a/com32/elflink/ldlinux/readconfig.c +++ b/com32/elflink/ldlinux/readconfig.c @@ -423,12 +423,12 @@ void print_labels(const char *prefix, size_t len) { struct menu_entry *me; - printf("\n"); + eprintf("\n"); for (me = all_entries; me; me = me->next ) { if (!strncmp(prefix, me->label, len)) - printf(" %s", me->label); + eprintf(" %s", me->label); } - printf("\n"); + eprintf("\n"); } struct menu_entry *find_label(const char *str) @@ -628,7 +628,7 @@ static int cat_file(const char *filename) return -1; while (fgets(line, sizeof(line), f) != NULL) - printf("%s", line); + eprintf("%s", line); fclose(f); return 0; @@ -685,7 +685,7 @@ void cat_help_file(int key) return; if (cm->fkeyhelp[fkey].textname) { - printf("\n"); + eprintf("\n"); cat_file(cm->fkeyhelp[fkey].textname); } } @@ -1306,7 +1306,7 @@ do_include: write_serial_str(copyright_str); } } else if (looking_at(p, "say")) { - printf("%s\n", p + 4); + eprintf("%s\n", p+4); } else if (looking_at(p, "path")) { /* PATH-based lookup */ char *new_path, *_p; @@ -1323,7 +1323,7 @@ do_include: _p[len + new_len] = '\0'; PATH = _p; } else - printf("Failed to realloc PATH\n"); + eprintf("Failed to realloc PATH\n"); } } } |