From f2d306b4d82e76180b747a89fa7fd99cd5d253bc Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sun, 18 May 2008 19:46:53 +0100 Subject: [PATCH] Read user.tmpl after macros.tmpl Organization: Straylight/Edgeware From: Richard Kettlewell --- doc/disorder_templates.5.head | 28 ++++++++++++++++++++++------ doc/disorder_templates.5.tail | 14 +------------- lib/macros-builtin.c | 10 ++++++---- lib/macros.h | 2 +- server/actions.c | 6 ++++-- server/options.c | 2 +- 6 files changed, 35 insertions(+), 27 deletions(-) diff --git a/doc/disorder_templates.5.head b/doc/disorder_templates.5.head index 4170c32..5efeef0 100644 --- a/doc/disorder_templates.5.head +++ b/doc/disorder_templates.5.head @@ -84,15 +84,31 @@ In the case of a macro you can work around this by passing the value as an argument. Included files do not have arguments, so in this case you must rewrite the inclusion as a macro. -.SS macros.tmpl -Before any page is expanded, the CGI will process \fBmacros.tmpl\fR (and -discard any output). -This defines a collection of commonly used macros. .SS "Search Path" -Template files a first searched for in \fIpkgconfdir\fR and then in +All template files are first searched for in \fIpkgconfdir\fR and then in \fIpkgdatadir\fR. +.SS "macros.tmpl and user.tmpl" +Before any template is expanded, the CGI will process \fBmacros.tmpl\fR and +discard any output. +This defines a collection of commonly used macros. +.PP +Following this the CGI will process \fBuser.tmpl\fR, again discarding output. +This can be used to override the common macros without editing the installed +version of \fBmacros.tmpl\fR, or to define new ones. +.PP +It is not an error if \fBuser.tmpl\fR does not exist. +.SS "Character Encoding" +The CGI does not (currently) declare any character encoding. +This could be changed quite easily but in practice is not a pressing necessity. +.PP +The recommended approach is to treat the templates as ASCII files and if +non-ASCII characters are required, use HTML entities to represent them. +.PP +For example, to represent the copyright sign, use \fB©\fR or \fB©\fR. +.PP +If you know the decimal or hex unicode value for a character then you can use +\fB&#NNN;\fR or \fB&#xHHHH;\fR respectively. .SH EXPANSIONS -This section lists the supported expansions. .\" Local Variables: .\" mode:nroff .\" fill-column:79 diff --git a/doc/disorder_templates.5.tail b/doc/disorder_templates.5.tail index 0c88a6d..e43e86f 100644 --- a/doc/disorder_templates.5.tail +++ b/doc/disorder_templates.5.tail @@ -16,22 +16,10 @@ .\" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 .\" USA .\" -.SH "NOTES" -.SS "Character Encoding" -The CGI does not (currently) declare any character encoding. -This could be changed quite easily but in practice is not a pressing necessity. -.PP -The recommended approach is to treat the templates as ASCII files and if -non-ASCII characters are required, use HTML entities to represent them. -.PP -For example, to represent the copyright sign, use \fB©\fR or \fB©\fR. -.PP -If you know the decimal or hex unicode value for a character then you can use -\fB&#NNN;\fR or \fB&#xHHHH;\fR respectively. .SH "SEE ALSO" .BR disorder_actions (5), .BR disorder_options (5), -.BR disorder_config (5) (5), +.BR disorder_config (5), .BR disorder.cgi (8) .\" Local Variables: .\" mode:nroff diff --git a/lib/macros-builtin.c b/lib/macros-builtin.c index 24822bb..04ea490 100644 --- a/lib/macros-builtin.c +++ b/lib/macros-builtin.c @@ -71,13 +71,14 @@ int mx_bool_result(struct sink *output, int result) { } /** @brief Search the include path */ -char *mx_find(const char *name) { +char *mx_find(const char *name, int report) { char *path; int n; if(name[0] == '/') { if(access(name, O_RDONLY) < 0) { - error(errno, "cannot read %s", name); + if(report) + error(errno, "cannot read %s", name); return 0; } path = xstrdup(name); @@ -89,7 +90,8 @@ char *mx_find(const char *name) { break; } if(n >= include_path.nvec) { - error(0, "cannot find '%s' in search path", name); + if(report) + error(0, "cannot find '%s' in search path", name); return 0; } } @@ -123,7 +125,7 @@ static int exp_include(int attribute((unused)) nargs, char buffer[4096]; struct stat sb; - if(!(path = mx_find(args[0]))) { + if(!(path = mx_find(args[0], 1/*report*/))) { if(sink_printf(output, "[[cannot find '%s']]", args[0]) < 0) return 0; return 0; diff --git a/lib/macros.h b/lib/macros.h index 772873c..e9b0af5 100644 --- a/lib/macros.h +++ b/lib/macros.h @@ -106,7 +106,7 @@ int mx_register_macro(const char *name, void mx_register_builtin(void); void mx_search_path(const char *s); -char *mx_find(const char *name); +char *mx_find(const char *name, int report); int mx_expand_file(const char *path, struct sink *output, diff --git a/server/actions.c b/server/actions.c index 961fdec..1372733 100644 --- a/server/actions.c +++ b/server/actions.c @@ -731,13 +731,15 @@ void dcgi_expand(const char *name, int header) { const char *p, *found; /* Parse macros first */ - if((found = mx_find("macros.tmpl"))) + if((found = mx_find("macros.tmpl", 1/*report*/))) + mx_expand_file(found, sink_discard(), 0); + if((found = mx_find("user.tmpl", 0/*report*/))) mx_expand_file(found, sink_discard(), 0); /* For unknown actions check that they aren't evil */ if(!dcgi_valid_action(name)) fatal(0, "invalid action name '%s'", name); byte_xasprintf((char **)&p, "%s.tmpl", name); - if(!(found = mx_find(p))) + if(!(found = mx_find(p, 0/*report*/))) fatal(errno, "cannot find %s", p); if(header) { if(printf("Content-Type: text/html\n" diff --git a/server/options.c b/server/options.c index 0453cd7..68f8271 100644 --- a/server/options.c +++ b/server/options.c @@ -83,7 +83,7 @@ static void option__readfile(const char *name) { char **vec, *buffer; struct read_options_state cs; - if(!(cs.name = mx_find(name))) + if(!(cs.name = mx_find(name, 1/*report*/))) return; if(!(fp = fopen(cs.name, "r"))) fatal(errno, "error opening %s", cs.name); -- [mdw]