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 @@ -2,12 +2,13 @@ # include <config.h> #endif #include <fnmatch.h> #include <inttypes.h> #include <ctype.h> #include <errno.h> +#include <sys/stat.h> #include "mtint.h" static int eval_rule (struct node *root, struct filebuf const *file); /* match("pattern") Pattern match on filename @@ -401,13 +402,19 @@ rule_cmp (struct rule const *arule, struct rule const *brule) const char * get_file_type (char const *filename) { struct rule *r; 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"); if (fb.fp == NULL) { mimetypes_error ("can't open %s: %s", filename, strerror (errno)); return NULL; diff --git a/src/defidx.html b/src/defidx.html index fa3cc66..12bea9f 100644 --- a/src/defidx.html +++ b/src/defidx.html @@ -50,16 +50,16 @@ <td> </td> </tr> {% endif %} {% loop %} <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> <td class="indexcolname"> <a href="{% $FILENAME %}">{% $FILENAME %}</a> </td> <td class="indexcollastmod">{% $FILETIME %}</td> @@ -594,22 +594,33 @@ exp_filetime(char **ret, EVAL_ENV *env) *ret = xstrdup(buf); return WRDSE_OK; } else return WRDSE_UNDEF; } +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; int (*exp)(char **, EVAL_ENV *); }; static struct var_dcl var_dcl[] = { { "ROWCLASS", exp_rowclass }, { "FILENAME", exp_filename }, { "FILESIZE", exp_filesize }, { "FILETIME", exp_filetime }, + { "FILETYPE", exp_filetype }, { "MIMETYPE", exp_mimetype }, { NULL } }; static int template_getvar(char **ret, const char *var, size_t len, void *clos) |