diff options
-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 @@ -7,2 +7,3 @@ #include <errno.h> +#include <sys/stat.h> #include "mtint.h" @@ -406,3 +407,9 @@ get_file_type (char const *filename) 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; diff --git a/src/defidx.html b/src/defidx.html index fa3cc66..12bea9f 100644 --- a/src/defidx.html +++ b/src/defidx.html @@ -55,6 +55,6 @@ <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 %} @@ -599,2 +599,12 @@ 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 { @@ -609,2 +619,3 @@ static struct var_dcl var_dcl[] = { { "FILETIME", exp_filetime }, + { "FILETYPE", exp_filetype }, { "MIMETYPE", exp_mimetype }, |