]> git.armaanb.net Git - stagit.git/blobdiff - src/stagit-index.c
micro-optimization: fputc (function) -> putc (macro/inline function)
[stagit.git] / src / stagit-index.c
index 2b243ec15660ba042313d4317b2d33810f9300a3..5454edb0a2fbae91e7cb0aa9944b2c185e5bd2ec 100644 (file)
@@ -8,6 +8,8 @@
 
 #include <git2.h>
 
+#include "cp.h"
+
 static git_repository *repo;
 
 static const char *relpath = "";
@@ -41,7 +43,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);
                }
        }
 }
@@ -61,36 +63,42 @@ printtimeshort(FILE *fp, const git_time *intime)
 }
 
 void
-writeheader(FILE *fp)
+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.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><span class=\"desc\">", relpath);
+               "<td><h1>", relpath);
        xmlencode(fp, description, strlen(description));
-       fputs("</span></td></tr><tr><td></td><td>\n"
+       fputs("</h1></td></tr><tr><td></td><td>\n"
                "</td></tr>\n</table>\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>"
                "</thead><tbody>\n", fp);
+       fclose(fp);
 }
 
 void
-writefooter(FILE *fp)
+writefooter(char *path)
 {
+       FILE *fp = fopen(path, "a");
        fputs("</tbody>\n</table>\n</div>\n</body>\n</html>\n", fp);
+       fclose(fp);
 }
 
 int
-writelog(FILE *fp)
+writelog(char *path)
 {
+       FILE *fp = fopen(path, "a");
        git_commit *commit = NULL;
        const git_signature *author;
        git_revwalk *w = NULL;
@@ -134,6 +142,7 @@ writelog(FILE *fp)
 err:
        git_revwalk_free(w);
        free(stripped_name);
+       fclose(fp);
 
        return ret;
 }
@@ -162,7 +171,7 @@ main(int argc, char *argv[])
                err(1, "pledge");
 #endif
 
-       writeheader(stdout);
+       writeheader("index.html");
 
        for (i = 1; i < argc; i++) {
                repodir = argv[i];
@@ -208,9 +217,14 @@ main(int argc, char *argv[])
                        owner[strcspn(owner, "\n")] = '\0';
                        fclose(fp);
                }
-               writelog(stdout);
+               writelog("index.html");
        }
-       writefooter(stdout);
+       writefooter("index.html");
+
+       /* copy css */
+       char cwd[PATH_MAX];
+       strcpy(cwd, getcwd(cwd, sizeof(cwd)));
+       cp("/usr/local/share/stagit/style.css", strcat(cwd, "/style.css"));
 
        /* cleanup */
        git_repository_free(repo);