tvote.c: remove blank lines in options field - vote - simple cgi voting system for web and gopher
git clone git://src.adamsgaard.dk/vote
Log
Files
Refs
README
LICENSE
---
commit c214ae3ad448784c1da35ec3b14dec92fc92fccd
parent 524a5c649d588c13e3ec21a599765bb55bee2501
Author: Anders Damsgaard 
Date:   Mon, 28 Sep 2020 09:43:11 +0200

vote.c: remove blank lines in options field

Diffstat:
  M vote.c                              |      46 ++++++++++++++++---------------

1 file changed, 24 insertions(+), 22 deletions(-)
---
diff --git a/vote.c b/vote.c
t@@ -106,9 +106,9 @@ int
 create_poll_file(const char *name, const char *question, const char *options)
 {
         FILE *fp;
-        char fname[PATH_MAX];
-        char buf[PATH_MAX];
+        char fname[PATH_MAX], buf[PATH_MAX];
         struct stat sb;
+        size_t col;
 
         strlcpy(buf, name, sizeof(buf));
         escapechars(buf);
t@@ -139,35 +139,31 @@ create_poll_file(const char *name, const char *question, const char *options)
                         exit(1);
                 } else {
                         fputs(question, fp);
-                        fputs("\n0\t", fp);
-                        /*while (*question != '\0') {
-                                switch(*question) {
-                                case '<':
-                                case '>':
-                                        fputc(' ', fp);
-                                        break;
-                                default:
-                                        fputc(*question, fp);
-                                }
-                                (void)*question++;
-                        }*/
-                        while (*options != '\0') {
+                        fputc('\n', fp);
+
+                        for (col = 0; *options; (void)*options++) {
+
+                                if (++col == 1 && *options != '\n' && *options != '\r')
+                                        fputs("0\t", fp);
+
                                 switch(*options) {
-                                case '<':
-                                case '>':
                                 case '\t':
                                         fputc(' ', fp);
                                         break;
-                                case '\n':
-                                        fprintf(fp, "\n0\t");
+                                case '\r':
                                         break;
+                                case '\n':
+                                        if (col < 3) {
+                                                col = 0;
+                                                break;
+                                        }
+                                        col = 0;
                                 default:
                                         fputc(*options, fp);
                                         break;
                                 }
-                                (void)*options++;
                         }
-                        fputc('\n', fp);
+                        /* fputc('\n', fp); */
                         fclose(fp);
                 }
         }
t@@ -213,11 +209,12 @@ list_polls()
         }
 
         puts("

Poll listing

"); + puts("
    "); while ((p = fts_read(ftsp)) != NULL) { switch (p->fts_info) { case FTS_F: - printf("%s\n", + printf("
  • %s
  • \n", p->fts_path + LEN(POLLS_DIR), p->fts_path + LEN(POLLS_DIR)); break; t@@ -226,9 +223,13 @@ list_polls() } } fts_close(ftsp); + puts("
"); } /* +void +increment_option(FILE *fp) +{ while ((ch = fgetc(ft)) != EOF) { if (ch == 'i') { fseek(ft, -1, SEEK_CUR); t@@ -236,6 +237,7 @@ list_polls() fseek(ft, 0, SEEK_CUR); } } +} */ void