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
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);
*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;
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;
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;
}
cursor++;
x++;
if (x >= width) {
- printf("\r\n");
+ eprintf("\r\n");
y++;
x = 0;
}
cursor++;
x++;
if (x >= width) {
- printf("\r\n\033[K");
+ eprintf("\r\n\033[K");
y++;
x = 0;
}
}
}
- printf("\033[?7h");
+ eprintf("\033[?7h");
/* Add the command to the history */
comm_counter = malloc(sizeof(struct cli_command));
extern void cat_help_file(int key);
+extern void eprintf(const char *filename, ...);
+
#endif /* __CONFIG_H__ */
--- /dev/null
+#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);
+}
{
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)
return -1;
while (fgets(line, sizeof(line), f) != NULL)
- printf("%s", line);
+ eprintf("%s", line);
fclose(f);
return 0;
return;
if (cm->fkeyhelp[fkey].textname) {
- printf("\n");
+ eprintf("\n");
cat_file(cm->fkeyhelp[fkey].textname);
}
}
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;
_p[len + new_len] = '\0';
PATH = _p;
} else
- printf("Failed to realloc PATH\n");
+ eprintf("Failed to realloc PATH\n");
}
}
}