diff --git a/zet.dpi.c b/zet.dpi.c index 2923140..fe12752 100644 --- a/zet.dpi.c +++ b/zet.dpi.c @@ -161,7 +161,10 @@ static int write_zet_link(int fd, const char *id, const char *title) { } static int write_topbar(int fd, enum page page, const char *id, const char *title) { - int rc = write_buf(fd, "
"); + int rc = write_buf(fd, + "" + ""); + rc |= write_buf(fd, ""); + } else { + rc |= write_buf(fd, ""); } - rc |= write_buf(fd, ""); + rc |= write_buf(fd, "
" + ""); rc |= write_buf(fd, " "); if (page == PAGE_ALL) rc |= write_buf(fd, ""); @@ -188,9 +191,14 @@ static int write_topbar(int fd, enum page page, const char *id, const char *titl if (page == PAGE_ZET) { rc |= write_zet_link(fd, id, title); + rc |= write_buf(fd, "" + "print
"); return rc; } @@ -828,27 +836,35 @@ static int dpi_serve_zet(int fd, char *path) { "" ""); - rc |= write_buf(fd, ""); - rc |= write_topbar(fd, PAGE_ZET, id, title); - rc |= dprintf(fd, - "" - "" - "
" - "
" - "" - " " - "
" - ); - if (rc < 0) { warn("dpi_send_header"); close(fd); return 0; } - if (note_fd >= 0) rc = lseek(note_fd, 0, SEEK_SET); - if (rc < 0) { - rc = dprintf(fd, "\nError: %s", strerror(errno)); - if (rc < 0) warnx("dprintf"); - close(fd); + // TODO: iterate + bool print = query != NULL && strncmp(query, "print", 5) == 0 + && (query[5] == '\0' || query[5] == '&' || + (query[5] == '=' && !(query[6] == '\0' || query[6] == '&'))); + if (!print) { + rc |= write_buf(fd, ""); + rc |= write_topbar(fd, PAGE_ZET, id, title); + rc |= dprintf(fd, + "" + "" + ""); - if (rc < 0) warn("dprintf"); + if (!print) { + rc = dprintf(fd, ""); + if (rc < 0) warn("dprintf"); - rc = dprintf(fd, ""); - if (rc < 0) warn("dprintf"); + if (!print) { + rc = dprintf(fd, ""); + if (rc < 0) warn("dprintf"); + } (void)zet_search_close(&zs); - rc = write_buf(fd, "
" + "
" + "" + " " + "
" + ); + if (rc < 0) { warn("dpi_send_header"); close(fd); return 0; } + if (note_fd >= 0) rc = lseek(note_fd, 0, SEEK_SET); + if (rc < 0) { + rc = dprintf(fd, "\nError: %s", strerror(errno)); + if (rc < 0) warnx("dprintf"); + close(fd); + } + } else { + rc |= write_buf(fd, ""); } char *text = note_fd >= 0 ? read_full(note_fd) : NULL; @@ -882,11 +898,16 @@ static int dpi_serve_zet(int fd, char *path) { rc = write_all(fd, ob->data, ob->size); if (rc < 0) warn("write_all"); bufrelease(ob); - rc = dprintf(fd, "
"); - if (rc < 0) warn("dprintf"); + rc = dprintf(fd, "
"); + if (rc < 0) warn("dprintf"); + } else { + rc = write_buf(fd, "
"); + if (rc < 0) warn("write_all"); + } struct zet_search zs; bool first = true; rc = zet_search_start(&zs, id, NULL); @@ -916,12 +937,16 @@ static int dpi_serve_zet(int fd, char *path) { rc |= write_buf(fd, ""); } while (1); if (!first) (void)dprintf(fd, ""); - rc = dprintf(fd, "
"); - if (rc < 0) warn("write_buf"); + if (!print) { + rc = write_buf(fd, "
"); + if (rc < 0) warn("write_buf"); + } rc = write_buf(fd, ""); if (rc < 0) warn("write_buf");