add term_printf()

This commit is contained in:
Babz 2021-09-08 22:15:46 +02:00
parent 8f4b3ddb72
commit aee32ef007
3 changed files with 8 additions and 17 deletions

View File

@ -50,7 +50,7 @@ static fe_Object *fefn(fe_Context *ctx, fe_Object *arg) {
return fe_number(ctx, 1);
}
int main(void) {
int main(int isappli, int optnum) {
char febuf[128 * 1024];
void *femem = (void *)febuf;
fe_Context *fectx = fe_open(femem, sizeof(febuf));

View File

@ -138,20 +138,11 @@ void term_append(const char *str) {
}
}
int term_consume_stdio(void) {
int i = 0;
int term_printf(const char *restrict format, ...) {
va_list argp;
char chunk[128 + 1];
while (1) {
int n = read((int)stdout, (void *)chunk, sizeof(chunk) - 1);
if (n < 0)
break;
chunk[n] = '\0';
term_append(chunk);
i += n;
}
return i;
char buf[1024];
const int n = sprintf(buf, format, argp);
term_append(buf);
return n;
}

View File

@ -10,6 +10,6 @@ void tgrid_display(void);
int term_writeat(int row, int col, int fg, int bg, const char *s);
void term_scroll_down(void);
void term_append(const char *str);
int term_consume_stdio(void);
int term_printf(const char *restrict format, ...);
#endif // #ifndef UNS_TERM_H