X-Git-Url: https://gitweb.ps.run/ps-cgit/blobdiff_plain/6f92f332e6a9ee3e16051bda9fe148607af67f65..fbd254d54e28e002a0d56b81c192156599df1e6b:/ui-plain.c diff --git a/ui-plain.c b/ui-plain.c index da76406..733db4d 100644 --- a/ui-plain.c +++ b/ui-plain.c @@ -34,7 +34,7 @@ static void print_object(const unsigned char *sha1, const char *path) ctx.page.mimetype = NULL; ext = strrchr(path, '.'); if (ext && *(++ext)) { - mime = string_list_lookup(ext, &ctx.cfg.mimetypes); + mime = string_list_lookup(&ctx.cfg.mimetypes, ext); if (mime) ctx.page.mimetype = (char *)mime->util; } @@ -52,30 +52,57 @@ static void print_object(const unsigned char *sha1, const char *path) match = 1; } -static void print_dir(const unsigned char *sha1, const char *path, - const char *base) +static char *buildpath(const char *base, int baselen, const char *path) { - char *fullpath; - if (path[0] || base[0]) - fullpath = fmt("/%s%s/", base, path); + if (path[0]) + return fmt("%.*s%s/", baselen, base, path); else - fullpath = "/"; + return fmt("%.*s/", baselen, base); +} + +static void print_dir(const unsigned char *sha1, const char *base, + int baselen, const char *path) +{ + char *fullpath, *slash; + size_t len; + + fullpath = buildpath(base, baselen, path); + slash = (fullpath[0] == '/' ? "" : "/"); ctx.page.etag = sha1_to_hex(sha1); cgit_print_http_headers(&ctx); - htmlf("%s\n\n" - "

%s

\n