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
@@ -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>&nbsp;</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>
diff --git a/src/idx.c b/src/idx.c
index 096e0ee..63b89bb 100644
--- a/src/idx.c
+++ b/src/idx.c
@@ -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)

Return to:

Send suggestions and report system problems to the System administrator.