X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fhtls.c;h=060d1bf5a3b65a5086b34df0e10a0c33a46c7512;hb=3095582d21be4087f774f5a68a2a9abfa37dd1ff;hp=e16004d2a063c7f1fc9073a182571176b36e9c72;hpb=121d8be9d4bdeea6a083d9bf791677e9150e6324;p=ashd.git diff --git a/src/htls.c b/src/htls.c index e16004d..060d1bf 100644 --- a/src/htls.c +++ b/src/htls.c @@ -43,6 +43,7 @@ struct dentry { static int dispmtime = 0; static int dispsize = 0; +static char *stylesheet = NULL; static void checkcache(struct stat *sb) { @@ -72,14 +73,27 @@ static int dcmp(const void *ap, const void *bp) static void head(char *name, struct charbuf *dst) { - char *title; + char *title, *tmp; + title = sstrdup(htmlquote(name)); bprintf(dst, "\n"); bprintf(dst, "\n"); bprintf(dst, "\n"); bprintf(dst, "\n"); - title = htmlquote(name); bprintf(dst, "Index of %s\n", title); + if(stylesheet) { + bprintf(dst, "\n", htmlquote(tmp)); + } else { + bprintf(dst, "\n"); + } bprintf(dst, "\n"); bprintf(dst, "\n"); bprintf(dst, "

Index of %s

\n", title); @@ -123,32 +137,37 @@ static void mkindex(char *name, DIR *dir, struct charbuf *dst) bufadd(dirbuf, f); } qsort(dirbuf.b, dirbuf.d, sizeof(struct dentry), dcmp); - bprintf(dst, "\n"); + bprintf(dst, "
\n"); for(i = 0; i < dirbuf.d; i++) { bprintf(dst, ""); fn = htmlquote(dirbuf.b[i].name); bprintf(dst, "", fn, fn); - free(fn); - if(dispsize && !S_ISDIR(dirbuf.b[i].sb.st_mode)) - bprintf(dst, "", (intmax_t)dirbuf.b[i].sb.st_size); + if(dispsize) { + bprintf(dst, ""); + } if(dispmtime) bprintf(dst, "", fmthttpdate(dirbuf.b[i].sb.st_mtime)); bprintf(dst, "\n"); free(dirbuf.b[i].name); } - bprintf(dst, "
%s%ji"); + if(!S_ISDIR(dirbuf.b[i].sb.st_mode)) + bprintf(dst, "%ji", (intmax_t)dirbuf.b[i].sb.st_size); + bprintf(dst, "%s
\n"); + bprintf(dst, "\n"); } static void usage(void) { - flog(LOG_ERR, "usage: htls [-hms] METHOD URL REST"); + flog(LOG_ERR, "usage: htls [-hms] [-c STYLESHEET] METHOD URL REST"); } int main(int argc, char **argv) @@ -160,7 +179,7 @@ int main(int argc, char **argv) struct stat sb; setlocale(LC_ALL, ""); - while((c = getopt(argc, argv, "hms")) >= 0) { + while((c = getopt(argc, argv, "hmsc:")) >= 0) { switch(c) { case 'h': usage(); @@ -171,6 +190,9 @@ int main(int argc, char **argv) case 's': dispsize = 1; break; + case 'c': + stylesheet = optarg; + break; default: usage(); exit(1);