/** @file lib/macros-builtin.c
* @brief Built-in expansions
*
- * This is a grab-bag of non-domain-specific expansions. Documentation will be
- * generated from the comments at the head of each function.
+ * This is a grab-bag of non-domain-specific expansions
+ *
+ * Documentation is generated from the comments at the head of each function.
+ * The comment should have a '$' and the expansion name on the first line and
+ * should have a blank line between each paragraph.
+ *
+ * To make a bulleted list, put a '-' at the start of each line.
+ *
+ * You can currently get away with troff markup but this is horribly ugly and
+ * might be changed.
*/
#include "common.h"
if(name[0] == '/') {
if(access(name, O_RDONLY) < 0) {
if(report)
- error(errno, "cannot read %s", name);
+ disorder_error(errno, "cannot read %s", name);
return 0;
}
path = xstrdup(name);
}
if(n >= include_path.nvec) {
if(report)
- error(0, "cannot find '%s' in search path", name);
+ disorder_error(0, "cannot find '%s' in search path", name);
return 0;
}
}
return path;
}
-/*! @include{TEMPLATE}@
+/*$ @include{TEMPLATE}
*
* Includes TEMPLATE.
*
/* Read the raw file. As with mx_expand_file() we insist that the file is a
* regular file. */
if((fd = open(path, O_RDONLY)) < 0)
- fatal(errno, "error opening %s", path);
+ disorder_fatal(errno, "error opening %s", path);
if(fstat(fd, &sb) < 0)
- fatal(errno, "error statting %s", path);
+ disorder_fatal(errno, "error statting %s", path);
if(!S_ISREG(sb.st_mode))
- fatal(0, "%s: not a regular file", path);
+ disorder_fatal(0, "%s: not a regular file", path);
while((n = read(fd, buffer, sizeof buffer)) > 0) {
if(sink_write(output, buffer, n) < 0) {
xclose(fd);
}
}
if(n < 0)
- fatal(errno, "error reading %s", path);
+ disorder_fatal(errno, "error reading %s", path);
xclose(fd);
return 0;
}
-/*! @include{COMMAND}@
+/*$ @include{COMMAND}
*
- * Executes COMMAND via the shell (using "sh -c") and copies its
+ * Executes COMMAND via the shell (using "sh \-c") and copies its
* standard output to the template output. The shell command output
* is not expanded or modified in any other way.
*
xdup2(p[1], 1);
xclose(p[1]);
execlp("sh", "sh", "-c", args[0], (char *)0);
- fatal(errno, "error executing sh");
+ disorder_fatal(errno, "error executing sh");
}
xclose(p[1]);
while((n = read(p[0], buffer, sizeof buffer))) {
if(errno == EINTR)
continue;
else
- fatal(errno, "error reading from pipe");
+ disorder_fatal(errno, "error reading from pipe");
}
if(output->write(output, buffer, n) < 0)
return -1;
while((n = waitpid(pid, &w, 0)) < 0 && errno == EINTR)
;
if(n < 0)
- fatal(errno, "error calling waitpid");
+ disorder_fatal(errno, "error calling waitpid");
if(w)
- error(0, "shell command '%s' %s", args[0], wstat(w));
+ disorder_error(0, "shell command '%s' %s", args[0], wstat(w));
return 0;
}
-/*! @if{CONDITION}{IF-TRUE}{IF-FALSE}@
+/*$ @if{CONDITION}{IF-TRUE}{IF-FALSE}
*
* If CONDITION is "true" then evaluates to IF-TRUE. Otherwise
* evaluates to IF-FALSE. The IF-FALSE part is optional.
return 0;
}
-/*! @and{BRANCH}{BRANCH}...@
+/*$ @and{BRANCH}{BRANCH}...
*
* Expands to "true" if all the branches are "true" otherwise to "false". If
* there are no brances then the result is "true". Only as many branches as
return mx_bool_result(output, result);
}
-/*! @or{BRANCH}{BRANCH}...@
+/*$ @or{BRANCH}{BRANCH}...
*
* Expands to "true" if any of the branches are "true" otherwise to "false".
* If there are no brances then the result is "false". Only as many branches
return mx_bool_result(output, result);
}
-/*! @not{CONDITION}@
+/*$ @not{CONDITION}
*
* Expands to "true" unless CONDITION is "true" in which case "false".
*/
return mx_bool_result(output, !mx_str2bool(args[0]));
}
-/*! @#{...}@
+/*$ @#{...}
*
* Expands to nothing. The argument(s) are not fully evaluated, and no side
* effects occur.
return 0;
}
-/*! @urlquote{STRING}@
+/*$ @urlquote{STRING}
*
* URL-quotes a string, i.e. replaces any characters not safe to use unquoted
* in a URL with %-encoded form.
return 0;
}
-/*! @eq{S1}{S2}...@
+/*$ @eq{S1}{S2}...
*
* Expands to "true" if all the arguments are identical, otherwise to "false"
* (i.e. if any pair of arguments differs).
return mx_bool_result(output, result);
}
-/*! @ne{S1}{S2}...@
+/*$ @ne{S1}{S2}...
*
* Expands to "true" if all of the arguments differ from one another, otherwise
* to "false" (i.e. if any value appears more than once).
return mx_bool_result(output, result);
}
-/*! @discard{...}@
+/*$ @discard{...}
*
* Expands to nothing. Unlike the comment expansion @#{...}, side effects of
* arguments are not suppressed. So this can be used to surround a collection
return 0;
}
-/*! @define{NAME}{ARG1 ARG2...}{DEFINITION}@
+/*$ @define{NAME}{ARG1 ARG2...}{DEFINITION}
*
* Define a macro. The macro will be called NAME and will act like an
* expansion. When it is expanded, the expansion is replaced by DEFINITION,
return 0;
}
-/*! @basename{PATH}
+/*$ @basename{PATH}
*
* Expands to the UNQUOTED basename of PATH.
*/
return sink_writes(output, d_basename(args[0])) < 0 ? -1 : 0;
}
-/*! @dirname{PATH}
+/*$ @dirname{PATH}
*
* Expands to the UNQUOTED directory name of PATH.
*/
return sink_writes(output, d_dirname(args[0])) < 0 ? -1 : 0;
}
-/*! @q{STRING}
+/*$ @q{STRING}
*
* Expands to STRING.
*/