* what do we do elsewhere about _GNU_SOURCE?
- prepare a little in advance for a potential future Windows port:
- + store the separator character in the index file when writing
- it, and be prepared to cope on reading if it isn't a slash
+ + store the path separator character in the index file when
+ writing it, and load it back in when reading
+ store literal byte sizes in all the size fields, instead of
Unixoid 512-byte sectors
- http://msdn.microsoft.com/en-us/library/ms724290.aspx suggest
modern Windowses support atime-equivalents, so a Windows port is
- possible in principle. Would need to modify the current structure
- a lot, to abstract away (at least) memory-mapping of files,
- details of disk scan procedure, networking for httpd. Unclear
- what the right UI would be on Windows, too; command-line exactly
- as now might be considered just a _little_ unfriendly. Or perhaps
- not.
+ possible in principle.
+ + For a full Windows port, would need to modify the current
+ structure a lot, to abstract away (at least) memory-mapping of
+ files, details of disk scan procedure, networking for httpd.
+ Unclear what the right UI would be on Windows, too;
+ command-line exactly as now might be considered just a
+ _little_ unfriendly. Or perhaps not.
+ + Alternatively, a much easier approach would be to write a
+ Windows version of just the --scan-dump mode, which does a
+ filesystem scan via the Windows API and generates a valid
+ agedu dump file on standard output. Then one would simply feed
+ that over the network connection of one's choice to the rest
+ of agedu running on Unix as usual.
#define lenof(x) (sizeof((x))/sizeof(*(x)))
+/*
+ * Path separator. This global variable affects the behaviour of
+ * various parts of the code when they need to deal with path
+ * separators. The path separator appropriate to a particular data
+ * set is encoded in the index file storing that data set; data
+ * sets generated on Unix will of course have the default '/', but
+ * foreign data sets are conceivable and must be handled correctly.
+ */
+char pathsep = '/';
+
void fatal(const char *fmt, ...)
{
va_list ap;
* Filter based on wildcards.
*/
include = 1;
- filename = strrchr(pathname, '/');
+ filename = strrchr(pathname, pathsep);
if (!filename)
filename = pathname;
else
* Trim trailing slash, just in case.
*/
pathlen = strlen(querydir);
- if (pathlen > 0 && querydir[pathlen-1] == '/')
+ if (pathlen > 0 && querydir[pathlen-1] == pathsep)
querydir[--pathlen] = '\0';
text_query(mappedfile, querydir, textcutoff, 1);
* Trim trailing slash, just in case.
*/
pathlen = strlen(querydir);
- if (pathlen > 0 && querydir[pathlen-1] == '/')
+ if (pathlen > 0 && querydir[pathlen-1] == pathsep)
querydir[--pathlen] = '\0';
xi = trie_before(mappedfile, querydir);
#define MAXCOLOUR 511
+extern char pathsep;
+
struct html {
char *buf;
size_t buflen, bufsize;
*/
htprintf(ctx, "<p align=center>\n<code>");
q = path;
- for (p = strchr(path, '/'); p; p = strchr(p+1, '/')) {
+ for (p = strchr(path, pathsep); p; p = strchr(p+1, pathsep)) {
int doing_href = 0;
/*
* See if this path prefix exists in the trie. If so,
htprintf(ctx, "<a href=\"%s\">", href);
doing_href = 1;
}
- *p = '/';
+ *p = pathsep;
htescape(ctx, q, p - q, 1);
q = p + 1;
if (doing_href)
htprintf(ctx, "</a>");
- htprintf(ctx, "/");
+ htescape(ctx, q, p - q, 1);
}
htescape(ctx, q, strlen(q), 1);
htprintf(ctx, "</code>\n");
#define alignof(typ) ( offsetof(struct { char c; typ t; }, t) )
+extern char pathsep;
+
/*
* Compare functions for pathnames. Returns the relative order of
* the names, like strcmp; also passes back the offset of the
*/
static int trieccmp(unsigned char a, unsigned char b)
{
- a = (a == '\0' ? '\0' : a == '/' ? '\1' : a+1);
- b = (b == '\0' ? '\0' : b == '/' ? '\1' : b+1);
- return a - b;
+ a = (a == '\0' ? '\0' : a == pathsep ? '\1' : a+1);
+ b = (b == '\0' ? '\0' : b == pathsep ? '\1' : b+1);
+ return (int)a - (int)b;
}
static int triencmp(const char *a, size_t alen,