summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--main.c35
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 <fcntl.h>
#include <limits.h>
#include <sys/socket.h>
+#include <sys/ioctl.h>
#include <netinet/in.h>
#include <netdb.h>
@@ -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;
}