tlist polls and fix install target - vote - simple cgi voting system for web and gopher
(HTM) git clone git://src.adamsgaard.dk/vote
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 524a5c649d588c13e3ec21a599765bb55bee2501
(DIR) parent 56220268f3d1ce5110b6a3b2a3281a9d6e21f401
(HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Mon, 28 Sep 2020 00:15:40 +0200
list polls and fix install target
Diffstat:
M Makefile | 2 +-
M vote.c | 47 +++++++++++++++++++++++++++----
2 files changed, 43 insertions(+), 6 deletions(-)
---
(DIR) diff --git a/Makefile b/Makefile
t@@ -17,7 +17,7 @@ ${NAME}: ${OBJ}
${CC} -o $@ ${OBJ} ${HERE_LDFLAGS}
install: ${NAME}
- mkdir -p
+ mkdir -p ${PREFIX}/${NAME}
chmod 775 ${PREFIX}/${NAME}
chgrp www ${PREFIX}/${NAME}
cp -f ${NAME} ${PREFIX}/${NAME}/
(DIR) diff --git a/vote.c b/vote.c
t@@ -11,6 +11,7 @@
#include "util.h"
+#define LEN(s) (sizeof(s) / sizeof(s[0]))
#define OUT(s) (fputs((s), stdout))
#define POLLS_DIR "polls"
t@@ -199,13 +200,48 @@ show_poll(const char *poll_name)
void
list_polls()
{
- /* something with fts_open, fts_read */
- puts("listing polls");
+ FTS *ftsp;
+ FTSENT *p;
+ int fts_options = FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOCHDIR;
+ /* int fts_options = FTS_NOCHDIR | FTS_PHYSICAL; */
+ /* char *path = POLLS_DIR; */
+ char *paths[] = { (char*)POLLS_DIR, NULL };
+
+ if ((ftsp = fts_open(paths, fts_options, NULL)) == NULL) {
+ fprintf(stderr, "could not fts_open");
+ err(1, "list_polls: fts_open");
+ }
+
+ puts("<h2>Poll listing</h2>");
+
+ while ((p = fts_read(ftsp)) != NULL) {
+ switch (p->fts_info) {
+ case FTS_F:
+ printf("<a href=\"?poll=%s\">%s</a>\n",
+ p->fts_path + LEN(POLLS_DIR),
+ p->fts_path + LEN(POLLS_DIR));
+ break;
+ default:
+ break;
+ }
+ }
+ fts_close(ftsp);
}
+/*
+ while ((ch = fgetc(ft)) != EOF) {
+ if (ch == 'i') {
+ fseek(ft, -1, SEEK_CUR);
+ fputc('a',ft);
+ fseek(ft, 0, SEEK_CUR);
+ }
+ }
+*/
+
void
print_poll_create_form()
{
+ OUT("<h2>Create new poll</h2>");
OUT("<form method=\"get\" action=\"\">\n"
"<input type=\"hidden\" name=\"create\" value=\"1\" />\n"
"<table class=\"create\" width=\"100%\" border=\"0\" "
t@@ -305,11 +341,12 @@ main()
if (*create) {
if (create_poll_file(poll, question, options) == 0)
show_poll(poll);
- } else if (*poll)
+ } else if (*poll) {
show_poll(poll);
- else
+ } else {
+ list_polls();
print_poll_create_form();
- /* list_polls(); */
+ }
print_html_foot();