chiark / gitweb /
Read user.tmpl after macros.tmpl
[disorder] / server / options.c
index 88fc9bfd8d091b463bd867f160e74380a58e7cbd..68f827157726d74d2c3229764a2a15bc8cd9048d 100644 (file)
  */
 /** @file server/options.c
  * @brief CGI options
+ *
+ * Options represent an additional configuration system private to the
+ * CGI program.
  */
 
-#include <config.h>
-#include "types.h"
-
-#include <stdio.h>
-
-#include "mem.h"
-#include "hash.h"
-#include "macros.h"
-#include "options.h"
-#include "split.h"
-#include "table.h"
+#include "disorder-cgi.h"
 
 struct column {
   int ncolumns;
   char **columns;
 };
 
+struct read_options_state {
+  const char *name;
+  int line;
+};
+
 static hash *labels;
 static hash *columns;
 
+static void option__readfile(const char *name);
+
 static void option__label(int attribute((unused)) nvec,
                         char **vec) {
   option_set(vec[0], vec[1]);
@@ -65,9 +65,9 @@ static struct option {
   int minargs, maxargs;
   void (*handler)(int nvec, char **vec);
 } options[] = {
-  { "columns", 1, INT_MAX, option_columns },
-  { "include", 1, 1, option_include },
-  { "label", 2, 2, option_label },
+  { "columns", 1, INT_MAX, option__columns },
+  { "include", 1, 1, option__include },
+  { "label", 2, 2, option__label },
 };
 
 static void option__split_error(const char *msg,
@@ -79,13 +79,11 @@ static void option__split_error(const char *msg,
 
 static void option__readfile(const char *name) {
   int n, i;
-  int fd;
   FILE *fp;
   char **vec, *buffer;
   struct read_options_state cs;
-  const char *path;
 
-  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);
@@ -155,24 +153,26 @@ void option_set(const char *name, const char *value) {
  */
 const char *option_label(const char *key) {
   const char *label;
+  char **lptr;
 
   option__init();
-  if(!(label = *(char **)hash_find(labels, key))) {
-    /* No label found */
-    if(!strncmp(key, "images.", 7)) {
-      static const char *url_static;
-      /* images.X defaults to <url.static>X.png */
-
-      if(!url_static)
-       url_static = option_label("url.static");
-      byte_xasprintf((char **)&label, "%s%s.png", url_static, key + 7);
-    } else if((label = strrchr(key, '.')))
-      /* X.Y defaults to Y */
-      ++label;
-    else
-      /* otherwise default to label name */
-      label = key;
-  }
+  lptr = hash_find(labels, key);
+  if(lptr)
+    return *lptr;
+  /* No label found */
+  if(!strncmp(key, "images.", 7)) {
+    static const char *url_static;
+    /* images.X defaults to <url.static>X.png */
+    
+    if(!url_static)
+      url_static = option_label("url.static");
+    byte_xasprintf((char **)&label, "%s%s.png", url_static, key + 7);
+  } else if((label = strrchr(key, '.')))
+    /* X.Y defaults to Y */
+    ++label;
+  else
+    /* otherwise default to label name */
+    label = key;
   return label;
 }