summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2018-02-13 20:52:50 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2018-02-13 20:52:50 (GMT)
commit1f31f222a0131a1bcdcb9318da16d938f39839e0 (patch) (side-by-side diff)
tree3d0e638bc4108d4114911549284ca5ea6fe09f6d
parente8d8cbf292c9fbc041c346859916db9e7367d4bb (diff)
downloadfileserv-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.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--mimetypes/eval.c7
-rw-r--r--src/defidx.html6
-rw-r--r--src/idx.c11
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 @@
#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);
@@ -404,7 +405,13 @@ 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)
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 @@
{% 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">
diff --git a/src/idx.c b/src/idx.c
index 096e0ee..63b89bb 100644
--- a/src/idx.c
+++ b/src/idx.c
@@ -597,6 +597,16 @@ exp_filetime(char **ret, EVAL_ENV *env)
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 *);
@@ -607,6 +617,7 @@ static struct var_dcl var_dcl[] = {
{ "FILENAME", exp_filename },
{ "FILESIZE", exp_filesize },
{ "FILETIME", exp_filetime },
+ { "FILETYPE", exp_filetype },
{ "MIMETYPE", exp_mimetype },
{ NULL }
};

Return to:

Send suggestions and report system problems to the System administrator.