]> git.armaanb.net Git - stagit.git/blobdiff - src/stagit-index.c
Fix segfault by moving fclose
[stagit.git] / src / stagit-index.c
index 8a4d97418d617179e388030d568650d09dcc3492..2a23e8f943dd4de5df20c96ade90564193172515 100644 (file)
@@ -8,6 +8,10 @@
 
 #include <git2.h>
 
+#ifdef HAS_CMARK
+#include <cmark-gfm.h>
+#endif
+
 #include "cp.h"
 
 static git_repository *repo;
@@ -43,7 +47,7 @@ xmlencode(FILE *fp, const char *s, size_t len)
                case '\'': fputs("&#39;" , fp); break;
                case '&':  fputs("&amp;",  fp); break;
                case '"':  fputs("&quot;", fp); break;
-               default:   fputc(*s, fp);
+               default:   putc(*s, fp);
                }
        }
 }
@@ -67,18 +71,43 @@ writeheader(char *path)
 {
        FILE *fp = fopen(path, "w");
        fputs("<!DOCTYPE html>\n"
-               "<html>\n<head>\n"
+               "<html lang=\"en\">\n<head>\n"
                "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"
+               "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n"
                "<title>", fp);
        xmlencode(fp, description, strlen(description));
        fprintf(fp, "</title>\n<link rel=\"icon\" type=\"image/png\" href=\"%sfavicon.png\" />\n", relpath);
-       fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%sstyle.min.css\" />\n", relpath);
+       fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%sstyle.css\" />\n", relpath);
        fputs("</head>\n<body>\n", fp);
-       fprintf(fp, "<table>\n<tr><td><img src=\"%slogo.png\" alt=\"\" width=\"32\" height=\"32\" /></td>\n"
-               "<td><h1>", relpath);
+       fprintf(fp, "<img src=\"%slogo.png\" class=\"logo\" width=\"32\" height=\"32\" /></td>\n"
+               "<h1>", relpath);
        xmlencode(fp, description, strlen(description));
-       fputs("</h1></td></tr><tr><td></td><td>\n"
-               "</td></tr>\n</table>\n<hr/>\n<div id=\"content\">\n"
+       fputs("</h1>\n", fp);
+
+       FILE *longdesc = fopen("desc.md", "r");
+       if (longdesc == NULL) longdesc = fopen("desc", "r");
+       if (longdesc != NULL) {
+               char c = fgetc(longdesc);
+#ifdef HAS_CMARK
+               char buf[2048];
+               while (c != EOF) {
+                       strncat(buf, &c, 1);
+                       c = fgetc(longdesc);
+               }
+               char *md = cmark_markdown_to_html(buf, strlen(buf), CMARK_OPT_DEFAULT);
+               fprintf(fp, md, relpath);
+               free(md);
+#else
+               fputs("<p>\n", fp);
+               while (c != EOF) {
+                       fprintf(fp, &c, relpath);
+                       c = fgetc(longdesc);
+               }
+#endif
+               fclose(longdesc);
+       }
+
+       fputs("</p>\n<hr/>\n<div id=\"content\">\n"
                "<table id=\"index\"><thead>\n"
                "<tr><td><b>Name</b></td><td><b>Description</b></td><td><b>Owner</b></td>"
                "<td><b>Last commit</b></td></tr>"
@@ -223,7 +252,7 @@ main(int argc, char *argv[])
        /* copy css */
        char cwd[PATH_MAX];
        strcpy(cwd, getcwd(cwd, sizeof(cwd)));
-       cp("/usr/local/share/stagit/style.min.css", strcat(cwd, "/style.min.css"));
+       cp("/usr/local/share/stagit/style.css", strcat(cwd, "/style.css"));
 
        /* cleanup */
        git_repository_free(repo);