chiark / gitweb /
General-purpose event distribution interface
[disorder] / lib / macros-builtin.c
index 6675dec518f1018d2e2f3c87db5de5229a826940..ec5628da145ff145ab2ba9fd785c5a821ab3f202 100644 (file)
  * generated from the comments at the head of each function.
  */
 
-#include <config.h>
-#include "types.h"
+#include "common.h"
 
-#include <stdio.h>
-#include <string.h>
 #include <errno.h>
-#include <assert.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/stat.h>
-#include <sys/wait.h>
 
 #include "hash.h"
 #include "mem.h"
@@ -71,13 +66,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,14 +85,15 @@ 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;
     }
   }
   return path;
 }
 
-/* @include{TEMPLATE}@
+/*! @include{TEMPLATE}@
  *
  * Includes TEMPLATE.
  *
@@ -123,7 +120,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;
@@ -151,7 +148,7 @@ static int exp_include(int attribute((unused)) nargs,
   return 0;
 }
 
-/* @include{COMMAND}@
+/*! @include{COMMAND}@
  *
  * Executes COMMAND via the shell (using "sh -c") and copies its
  * standard output to the template output.  The shell command output
@@ -200,7 +197,7 @@ static int exp_shell(int attribute((unused)) nargs,
   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.
@@ -222,7 +219,7 @@ static int exp_if(int nargs,
     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
@@ -248,7 +245,7 @@ static int exp_and(int nargs,
   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
@@ -274,7 +271,7 @@ static int exp_or(int nargs,
   return mx_bool_result(output, result);
 }
 
-/* @not{CONDITION}@
+/*! @not{CONDITION}@
  *
  * Expands to "true" unless CONDITION is "true" in which case "false".
  */
@@ -285,7 +282,7 @@ static int exp_not(int attribute((unused)) nargs,
   return mx_bool_result(output, !mx_str2bool(args[0]));
 }
 
-/* @#{...}@
+/*! @#{...}@
  *
  * Expands to nothing.  The argument(s) are not fully evaluated, and no side
  * effects occur.
@@ -297,7 +294,7 @@ static int exp_comment(int attribute((unused)) nargs,
   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.
@@ -312,7 +309,7 @@ static int exp_urlquote(int attribute((unused)) nargs,
     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).
@@ -336,7 +333,7 @@ static int exp_eq(int nargs,
   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).
@@ -360,7 +357,7 @@ static int exp_ne(int nargs,
   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
@@ -373,7 +370,7 @@ static int exp_discard(int attribute((unused)) nargs,
   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,
@@ -396,7 +393,7 @@ static int exp_define(int attribute((unused)) nargs,
   return 0;
 }
 
-/* @basename{PATH}
+/*! @basename{PATH}
  *
  * Expands to the UNQUOTED basename of PATH.
  */
@@ -407,7 +404,7 @@ static int exp_basename(int attribute((unused)) nargs,
   return sink_writes(output, d_basename(args[0])) < 0 ? -1 : 0;
 }
 
-/* @dirname{PATH}
+/*! @dirname{PATH}
  *
  * Expands to the UNQUOTED directory name of PATH.
  */
@@ -418,7 +415,7 @@ static int exp_dirname(int attribute((unused)) nargs,
   return sink_writes(output, d_dirname(args[0])) < 0 ? -1 : 0;
 }
 
-/* @q{STRING}
+/*! @q{STRING}
  *
  * Expands to STRING.
  */