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 | |||
@@ -5,6 +5,7 @@ | |||
5 | #include <inttypes.h> | 5 | #include <inttypes.h> |
6 | #include <ctype.h> | 6 | #include <ctype.h> |
7 | #include <errno.h> | 7 | #include <errno.h> |
8 | #include <sys/stat.h> | ||
8 | #include "mtint.h" | 9 | #include "mtint.h" |
9 | 10 | ||
10 | static int eval_rule (struct node *root, struct filebuf const *file); | 11 | static int eval_rule (struct node *root, struct filebuf const *file); |
@@ -404,7 +405,13 @@ get_file_type (char const *filename) | |||
404 | struct rule *r; | 405 | struct rule *r; |
405 | struct rule *last = NULL; | 406 | struct rule *last = NULL; |
406 | struct filebuf fb; | 407 | struct filebuf fb; |
408 | struct stat st; | ||
407 | 409 | ||
410 | if (stat (filename, &st)) | ||
411 | mimetypes_error ("can't stat %s: %s", filename, strerror (errno)); | ||
412 | else if (S_ISDIR (st.st_mode)) | ||
413 | return "directory"; | ||
414 | |||
408 | fb.name = filename; | 415 | fb.name = filename; |
409 | fb.fp = fopen (filename, "r"); | 416 | fb.fp = fopen (filename, "r"); |
410 | if (fb.fp == NULL) | 417 | if (fb.fp == NULL) |
diff --git a/src/defidx.html b/src/defidx.html index fa3cc66..12bea9f 100644 --- a/src/defidx.html +++ b/src/defidx.html | |||
@@ -53,10 +53,10 @@ | |||
53 | {% loop %} | 53 | {% loop %} |
54 | <tr class="{% $ROWCLASS %}"> | 54 | <tr class="{% $ROWCLASS %}"> |
55 | <td class="indexcolicon"> | 55 | <td class="indexcolicon"> |
56 | {% if $(icon $FILETYPE) %} | 56 | {% if $(icon $MIMETYPE) %} |
57 | <img src="{% $(icon $FILETYPE) %}" alt="[{% $(alt $FILETYPE) %}]"> | 57 | <img src="{% $(icon $MIMETYPE) %}" alt="[{% $(alt $MIMETYPE) %}]"> |
58 | {% else %} | 58 | {% else %} |
59 | [{% $(alt $FILETYPE) %}] | 59 | [{% $FILETYPE %}] |
60 | {% endif %} | 60 | {% endif %} |
61 | </td> | 61 | </td> |
62 | <td class="indexcolname"> | 62 | <td class="indexcolname"> |
@@ -597,6 +597,16 @@ exp_filetime(char **ret, EVAL_ENV *env) | |||
597 | return WRDSE_UNDEF; | 597 | return WRDSE_UNDEF; |
598 | } | 598 | } |
599 | 599 | ||
600 | static int | ||
601 | exp_filetype(char **ret, EVAL_ENV *env) | ||
602 | { | ||
603 | char const *s = " "; | ||
604 | if (env->ent) | ||
605 | s = S_ISDIR(env->ent->st.st_mode) ? "DIR" : "FILE"; | ||
606 | *ret = xstrdup(s); | ||
607 | return WRDSE_OK; | ||
608 | } | ||
609 | |||
600 | struct var_dcl { | 610 | struct var_dcl { |
601 | char const *name; | 611 | char const *name; |
602 | int (*exp)(char **, EVAL_ENV *); | 612 | int (*exp)(char **, EVAL_ENV *); |
@@ -607,6 +617,7 @@ static struct var_dcl var_dcl[] = { | |||
607 | { "FILENAME", exp_filename }, | 617 | { "FILENAME", exp_filename }, |
608 | { "FILESIZE", exp_filesize }, | 618 | { "FILESIZE", exp_filesize }, |
609 | { "FILETIME", exp_filetime }, | 619 | { "FILETIME", exp_filetime }, |
620 | { "FILETYPE", exp_filetype }, | ||
610 | { "MIMETYPE", exp_mimetype }, | 621 | { "MIMETYPE", exp_mimetype }, |
611 | { NULL } | 622 | { NULL } |
612 | }; | 623 | }; |