diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2018-02-13 22:52:50 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2018-02-13 22:52:50 +0200 |
commit | 1f31f222a0131a1bcdcb9318da16d938f39839e0 (patch) | |
tree | 3d0e638bc4108d4114911549284ca5ea6fe09f6d | |
parent | e8d8cbf292c9fbc041c346859916db9e7367d4bb (diff) | |
download | fileserv-1f31f222a0131a1bcdcb9318da16d938f39839e0.tar.gz fileserv-1f31f222a0131a1bcdcb9318da16d938f39839e0.tar.bz2 |
Improve index generation
* mimetypes/eval.c (get_file_type): Return "directory",
for directories.
* src/defidx.html: Use $FILETYPE if no icon is available.
* src/idx.c: New variable $FILETYPE.
-rw-r--r-- | mimetypes/eval.c | 7 | ||||
-rw-r--r-- | src/defidx.html | 6 | ||||
-rw-r--r-- | src/idx.c | 11 |
3 files changed, 21 insertions, 3 deletions
diff --git a/mimetypes/eval.c b/mimetypes/eval.c index b2ad941..120d041 100644 --- a/mimetypes/eval.c +++ b/mimetypes/eval.c @@ -6,4 +6,5 @@ #include <ctype.h> #include <errno.h> +#include <sys/stat.h> #include "mtint.h" @@ -405,5 +406,11 @@ get_file_type (char const *filename) struct rule *last = NULL; struct filebuf fb; + struct stat st; + if (stat (filename, &st)) + mimetypes_error ("can't stat %s: %s", filename, strerror (errno)); + else if (S_ISDIR (st.st_mode)) + return "directory"; + fb.name = filename; fb.fp = fopen (filename, "r"); diff --git a/src/defidx.html b/src/defidx.html index fa3cc66..12bea9f 100644 --- a/src/defidx.html +++ b/src/defidx.html @@ -54,8 +54,8 @@ <tr class="{% $ROWCLASS %}"> <td class="indexcolicon"> - {% if $(icon $FILETYPE) %} - <img src="{% $(icon $FILETYPE) %}" alt="[{% $(alt $FILETYPE) %}]"> + {% if $(icon $MIMETYPE) %} + <img src="{% $(icon $MIMETYPE) %}" alt="[{% $(alt $MIMETYPE) %}]"> {% else %} - [{% $(alt $FILETYPE) %}] + [{% $FILETYPE %}] {% endif %} </td> @@ -598,4 +598,14 @@ exp_filetime(char **ret, EVAL_ENV *env) } +static int +exp_filetype(char **ret, EVAL_ENV *env) +{ + char const *s = " "; + if (env->ent) + s = S_ISDIR(env->ent->st.st_mode) ? "DIR" : "FILE"; + *ret = xstrdup(s); + return WRDSE_OK; +} + struct var_dcl { char const *name; @@ -608,4 +618,5 @@ static struct var_dcl var_dcl[] = { { "FILESIZE", exp_filesize }, { "FILETIME", exp_filetime }, + { "FILETYPE", exp_filetype }, { "MIMETYPE", exp_mimetype }, { NULL } |