static git_repository *repo;
+static const char *baseurl = ""; /* base URL to make absolute RSS/Atom URI */
static const char *relpath = "";
static const char *repodir;
static long long nlogcommits = -1; /* < 0 indicates not used */
bool htmlized; /* true if markdoown converted to HTML */
+static char oldfilename[PATH_MAX]; /* filename of the last file */
/* cache */
static git_oid lastoid;
}
}
+/* Escape characters below as HTML 2.0 / XML 1.0, ignore printing '\n', '\r' */
+void
+xmlencodeline(FILE *fp, const char *s, size_t len)
+{
+ size_t i;
+
+ for (i = 0; *s && i < len; s++, i++) {
+ switch(*s) {
+ case '<': fputs("<", fp); break;
+ case '>': fputs(">", fp); break;
+ case '\'': fputs("'", fp); break;
+ case '&': fputs("&", fp); break;
+ case '"': fputs(""", fp); break;
+ case '\r': break; /* ignore CR */
+ case '\n': break; /* ignore LF */
+ default: putc(*s, fp);
+ }
+ }
+}
+
+/* Escape characters below as HTML 2.0 / XML 1.0, ignore printing '\n', '\r' */
+void
+xmlencodeline(FILE *fp, const char *s, size_t len)
+{
+ size_t i;
+
+ for (i = 0; *s && i < len; s++, i++) {
+ switch(*s) {
+ case '<': fputs("<", fp); break;
+ case '>': fputs(">", fp); break;
+ case '\'': fputs("'", fp); break;
+ case '&': fputs("&", fp); break;
+ case '"': fputs(""", fp); break;
+ case '\r': break; /* ignore CR */
+ case '\n': break; /* ignore LF */
+ default: putc(*s, fp);
+ }
+ }
+}
+
+/* Escape characters below as HTML 2.0 / XML 1.0, ignore printing '\n', '\r' */
+void
+xmlencodeline(FILE *fp, const char *s, size_t len)
+{
+ size_t i;
+
+ for (i = 0; *s && i < len; s++, i++) {
+ switch(*s) {
+ case '<': fputs("<", fp); break;
+ case '>': fputs(">", fp); break;
+ case '\'': fputs("'", fp); break;
+ case '&': fputs("&", fp); break;
+ case '"': fputs(""", fp); break;
+<<<<<<< HEAD:src/stagit.c
+ case '\r': break; /* ignore CR */
+ case '\n': break; /* ignore LF */
+=======
+>>>>>>> 722f836 (micro-optimization: fputc (function) -> putc (macro/inline function)):stagit.c
+ default: putc(*s, fp);
+ }
+ }
+}
+
int
mkdirp(const char *path)
{
if (strcmp(get_ext(filename), "md") == 0) htmlized = true;
#endif
-
#ifdef HAS_CHROMA
if (!htmlized) {
// Copy STDOUT
xmlencode(fp, ci->author->email, strlen(ci->author->email));
fputs("</a>>\n<b>Date:</b> ", fp);
printtime(fp, &(ci->author->when));
- fputc('\n', fp);
+ putc('\n', fp);
}
if (ci->msg) {
- fputc('\n', fp);
+ putc('\n', fp);
xmlencode(fp, ci->msg, strlen(ci->msg));
- fputc('\n', fp);
+ putc('\n', fp);
}
}
fprintf(fp, "<a href=\"#h%zu-%zu-%zu\" id=\"h%zu-%zu-%zu\" class=\"d\">-",
i, j, k, i, j, k);
else
- fputc(' ', fp);
- xmlencode(fp, line->content, line->content_len);
+ putc(' ', fp);
+ xmlencodeline(fp, line->content, line->content_len);
+ putc('\n', fp);
if (line->old_lineno == -1 || line->new_lineno == -1)
fputs("</a>", fp);
}
xmlencode(fp, ci->summary, strlen(ci->summary));
fputs("</title>\n", fp);
}
- fprintf(fp, "<link rel=\"alternate\" type=\"text/html\" href=\"commit/%s.html\" />\n",
- ci->oid);
+ fprintf(fp, "<link rel=\"alternate\" type=\"text/html\" href=\"%scommit/%s.html\" />\n",
+ baseurl, ci->oid);
if (ci->author) {
fputs("<author>\n<name>", fp);
xmlencode(fp, ci->author->email, strlen(ci->author->email));
fputs(">\nDate: ", fp);
printtime(fp, &(ci->author->when));
- fputc('\n', fp);
+ putc('\n', fp);
}
if (ci->msg) {
- fputc('\n', fp);
+ putc('\n', fp);
xmlencode(fp, ci->msg, strlen(ci->msg));
}
fputs("\n</content>\n</entry>\n", fp);
fputs("<p> ", fp);
xmlencode(fp, filename, strlen(filename));
fprintf(fp, " (%s)", convertbytes((int)filesize));
- fputs("</p><hr/>", fp);
+
+#ifdef HAS_CMARK
+ char newfpath[PATH_MAX];
+ char newfilename[PATH_MAX];
+ if (strcmp(get_ext(filename), "md") == 0) {
+ fprintf(fp, " <a href=\"%s.html-raw\">View raw</a>", filename);
+ strcpy(newfpath, fpath);
+ strcat(newfpath, "-raw");
+
+ strcpy(newfilename, filename);
+ strcat(newfilename, "-raw");
+ strcpy(oldfilename, filename);
+
+ /* NOTE: recurses */
+ writeblob(obj, newfpath, newfilename, filesize);
+ } else if (strcmp(get_ext(filename), "md-raw" ) == 0) {
+ fprintf(fp, " <a href=\"%s.html\">View rendered</a>", oldfilename);
+ }
+#endif
+
+ fputs(".</p><hr/>", fp);
if (git_blob_is_binary((git_blob *)obj)) {
fputs("<p>Binary file.</p>\n", fp);
writeblobhtml(filename, fp, (git_blob *)obj);
if (ferror(fp))
err(1, "fwrite");
- else if (htmlized) {
- /* NOTE: recurses */
- char newfpath[PATH_MAX];
- strcat(newfpath, fpath);
- char newfilename[PATH_MAX];
- strcat(newfilename, filename);
- writeblob(obj, strcat(newfpath, "-raw"),
- strcat(newfilename, "-raw"), filesize);
- // TODO: Add view-raw button
- }
}
writefooter(fp);
void
usage(char *argv0)
{
- fprintf(stderr, "%s [-c cachefile | -l commits] repodir\n", argv0);
+ fprintf(stderr, "%s [-c cachefile | -l commits] "
+ "[-u baseurl] repodir\n", argv0);
exit(1);
}
if (argv[i][0] == '\0' || *p != '\0' ||
nlogcommits <= 0 || errno)
usage(argv[0]);
+ } else if (argv[i][1] == 'u') {
+ if (i + 1 >= argc)
+ usage(argv[0]);
+ baseurl = argv[++i];
}
}
if (!repodir)