X-Git-Url: http://www.dolda2000.com/gitweb/?p=ashd.git;a=blobdiff_plain;f=src%2Fhtls.c;h=f51da938daf87cc87b598382e45cc26aae495e01;hp=e16004d2a063c7f1fc9073a182571176b36e9c72;hb=595adb9922885c2a05bc6917ee8f8f02f496e618;hpb=121d8be9d4bdeea6a083d9bf791677e9150e6324 diff --git a/src/htls.c b/src/htls.c index e16004d..f51da93 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) { @@ -74,12 +75,26 @@ static void head(char *name, struct charbuf *dst) { char *title; + 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(stylesheet)); + } else { + bprintf(dst, "\n"); + } bprintf(dst, "\n"); bprintf(dst, "\n"); bprintf(dst, "

Index of %s

\n", title); @@ -123,32 +138,38 @@ 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); + bprintf(dst, ""); + 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", htmlquote(urlquote(dirbuf.b[i].name))); + bprintf(dst, "%s", htmlquote(dirbuf.b[i].name)); + bprintf(dst, ""); + 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 +181,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 +192,9 @@ int main(int argc, char **argv) case 's': dispsize = 1; break; + case 'c': + stylesheet = optarg; + break; default: usage(); exit(1);