From b6d231847a0541f545c2b64d84f71c58841d60ec Mon Sep 17 00:00:00 2001 From: katalx Date: Mon, 2 Feb 2026 04:12:07 -0500 Subject: more junk --- Makefile | 2 +- main.c | 35 +++++++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index d78fc6d..3ed0a95 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ clean: rm -fv ${EXE} ${OBJ} run: ${EXE} - ls | ./${EXE} + ./${EXE} ${EXE}: ${OBJ} ${CC} ${OBJ} -o ${EXE} ${LDFLAGS} diff --git a/main.c b/main.c index e883f29..f179c1b 100644 --- a/main.c +++ b/main.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -350,6 +351,15 @@ fetch(Str *buf, Request req, Arena *perm, Arena *scratch) } } +void +term_size(int *rows, int *cols) +{ + struct winsize sz = { 0 }; + ioctl(STDOUT_FILENO, TIOCGWINSZ, &sz); + if (rows) *rows = sz.ws_row; + if (cols) *cols = sz.ws_col; +} + int main(void) { @@ -357,21 +367,34 @@ main(void) Request req = { 0 }; addr_init(); - printf("parse_request() -> %d\n", parse_request(S("file://main.c"), &req)); + printf("parse_request() -> %d\n", parse_request(S("gopher://tilde.town"), &req)); printf("host = %.*s\n", (int)req.host.n, req.host.s); printf("path = %.*s\n", (int)req.path.n, req.path.s); printf("prot = %d\n", req.proto); printf("port = %d\n", req.port); Str buf = { 0 }; - printf("fetch() -> %d\n", fetch(&buf, req, &scratch, &scratch)); - Doc doc = { .arena = scratch, .src = buf }; + DocType t = fetch(&buf, req, &scratch, &scratch); + printf("fetch() -> %d\n", t); + Doc doc = { .arena = scratch, .src = buf, .type = t }; printf("parse() -> %d\n", parse_doc(&doc)); - int i = 0; - for (DocLine *l = doc.head; l && i < 10; (l = l->next), i++) { - printf("%d %.*s\n", i, (int)l->s.n, l->s.s); + + DocLine *l = doc.head; + while (l) { + int ln; + term_size(&ln, NULL); + for (int i = 0; l && i < ln - 1; i++) { + printf("%.*s\n", (int)l->s.n, l->s.s); + l = l->next; + } + char buf[1024] = { 0 }; + printf("* "); + fflush(stdout); + fgets(buf, 1023, stdin); + if (buf[0] == 'q') break; } + puts("Goodbye!"); addr_fini(); return 0; } -- cgit v1.2.3