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
.\" 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
}
/** @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);
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;
}
}
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;
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,
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"
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);