]> git.armaanb.net Git - stagit.git/commitdiff
add README and LICENSE file-detection
authorHiltjo Posthuma <hiltjo@codemadness.org>
Sat, 5 Dec 2015 19:43:29 +0000 (20:43 +0100)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Sat, 5 Dec 2015 19:43:29 +0000 (20:43 +0100)
TODO
urmoms.c

diff --git a/TODO b/TODO
index 868678c2a174f6d1b3fba9fdffcffc26606825da..ce740a754668094f2c6b2fed766f89b07b7ed672 100644 (file)
--- a/TODO
+++ b/TODO
@@ -3,7 +3,7 @@
 - add raw link to latest files: raw/file...
 - add summary page?
 - add diffstat to diff page? + and - lines summary?
-- escape < > ' " etc, maybe even use CDATA ?
+- escape HTML: < > ' " etc, maybe even use CDATA ?
 - shorter date format for logs.html page.
 - speed up generating files.
 - for files link to the commit but make the filename a link anchor.
index c0d2ab39ecc0157368dff613593da10600555f81..2d385f10367039920c67d314bd97df0252b624ba 100644 (file)
--- a/urmoms.c
+++ b/urmoms.c
@@ -1,16 +1,20 @@
 #include <err.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "git2.h"
 
+static git_repository *repo;
+
 static const char *relpath = "";
 static const char *name = "";
 static const char *description = "";
 
 static const char *repodir = ".";
 
-static git_repository *repo;
+static int hasreadme, haslicense;
 
 FILE *
 efopen(const char *name, const char *flags)
@@ -102,8 +106,10 @@ writeheader(FILE *fp)
        fprintf(fp, "<a href=\"%slog.html\">Log</a> |", relpath);
        fprintf(fp, "<a href=\"%sfiles.html\">Files</a>| ", relpath);
        fprintf(fp, "<a href=\"%sstats.html\">Stats</a> | ", relpath);
-       fprintf(fp, "<a href=\"%sreadme.html\">README</a> | ", relpath);
-       fprintf(fp, "<a href=\"%slicense.html\">LICENSE</a>", relpath);
+       if (hasreadme)
+               fprintf(fp, "<a href=\"%sreadme.html\">README</a> | ", relpath);
+       if (haslicense)
+               fprintf(fp, "<a href=\"%slicense.html\">LICENSE</a>", relpath);
        fprintf(fp, "</center><hr/><pre>");
 
        return 0;
@@ -181,12 +187,27 @@ writebranches(FILE *fp)
 }
 #endif
 
+void
+concat(FILE *fp1, FILE *fp2)
+{
+       char buf[BUFSIZ];
+       size_t n;
+
+       while ((n = fread(buf, 1, sizeof(buf), fp1))) {
+               fwrite(buf, 1, n, fp2);
+
+               if (feof(fp1) || ferror(fp1) || ferror(fp2))
+                       break;
+       }
+}
+
 int
 main(int argc, char *argv[])
 {
-       int status;
        const git_error *e = NULL;
-       FILE *fp;
+       FILE *fp, *fpread;
+       char path[PATH_MAX];
+       int status;
 
        if (argc != 2) {
                fprintf(stderr, "%s <repodir>\n", argv[0]);
@@ -202,6 +223,37 @@ main(int argc, char *argv[])
                exit(status);
        }
 
+       snprintf(path, sizeof(path), "%s%s%s",
+               repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "LICENSE");
+       if ((fpread = fopen(path, "r+b"))) {
+               fp = efopen("license.html", "w+b");
+               writeheader(fp);
+               concat(fpread, fp);
+               if (ferror(fpread) || ferror(fp))
+                       err(1, "concat");
+               writefooter(fp);
+
+               fclose(fp);
+               fclose(fpread);
+
+               haslicense = 1;
+       }
+
+       snprintf(path, sizeof(path), "%s%s%s",
+               repodir, repodir[strlen(repodir)] == '/' ? "" : "/", "README");
+       if ((fpread = fopen(path, "r+b"))) {
+               fp = efopen("readme.html", "w+b");
+               writeheader(fp);
+               concat(fpread, fp);
+               if (ferror(fpread) || ferror(fp))
+                       err(1, "concat");
+               writefooter(fp);
+               fclose(fp);
+               fclose(fpread);
+
+               hasreadme = 1;
+       }
+
        fp = efopen("logs.html", "w+b");
        writeheader(fp);
        writelog(fp);