obj/lib/regex-test: obj/lib/regex-test.o obj/lib/libsh.a
obj/lib/hash-test: obj/lib/hash-test.o obj/lib/libsh.a
obj/lib/str-test: obj/lib/str-test.o obj/lib/libsh.a
+
+include lib/perl/Makefile
+include lib/shell/Makefile
--- /dev/null
+# Support routines for shell scripts
+
+DIRS+=lib/shell
+PROGS+=obj/lib/shell/config obj/lib/shell/logger
+
+obj/lib/shell/config: obj/lib/shell/config.o obj/lib/libsh.a
+obj/lib/shell/logger: obj/lib/shell/logger.o obj/lib/libsh.a
--- /dev/null
+/*
+ * Sherlock Library -- Shell Interface to Configuration Files
+ *
+ * (c) 2002 Martin Mares <mj@ucw.cz>
+ *
+ * Once we were using this beautiful Shell version, but it turned out
+ * that it doesn't work with nested config files:
+ *
+ * eval `sed <cf/sherlock '/^#/d;/^ *$/d;s/ \+$//;
+ * h;s@[^ ]*@@;x;s@[ ].*@@;y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/;G;s/\n//;
+ * /^\[SECTION\]/,/^\[/ {; /^[A-Z]/ { s/^\([^ ]\+\)[ ]*\(.*\)$/SH_\1="\2"/; p; }; };
+ * d;'`
+ */
+
+#include "lib/lib.h"
+#include "lib/conf.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+static void
+help(void)
+{
+ die("Usage: config [-C<configfile>] [-S<section>.<option>=<value>] <section> <item>[=<default>] <item2> ... [*]");
+}
+
+int main(int argc, char **argv)
+{
+ int i = 1;
+ int start;
+ struct cfitem *items, *c;
+ byte **vars;
+
+ log_init("config");
+ while (i < argc && argv[i][0] == '-')
+ i++;
+ if (i + 1 >= argc)
+ help();
+ start = i;
+ c = items = alloca(sizeof(struct cfitem) * (argc-i+1));
+ vars = alloca(sizeof(byte *) * argc);
+ c->name = argv[i];
+ c->type = CT_SECTION;
+ c->var = NULL;
+ c++;
+ while (++i < argc)
+ {
+ if (!strcmp(argv[i], "*"))
+ items->type = CT_INCOMPLETE_SECTION;
+ else
+ {
+ byte *e = strchr(argv[i], '=');
+ if (e)
+ *e++ = 0;
+ else
+ e = "";
+ c->name = argv[i];
+ c->type = CT_STRING;
+ c->var = &vars[i];
+ *(byte **)c->var = e;
+ c++;
+ }
+ }
+ c->type = CT_STOP;
+ cf_register(items);
+ if (cf_getopt(start, argv, CF_SHORT_OPTS, CF_NO_LONG_OPTS, NULL) != -1)
+ help();
+
+ c = items+1;
+ while (c->type)
+ {
+ printf("CF_%s=\"%s\"\n", c->name, *(byte **)c->var);
+ c++;
+ }
+
+ return 0;
+}
--- /dev/null
+/*
+ * Sherlock Utilities -- A Simple Logger for use in shell scripts
+ *
+ * (c) 2001 Martin Mares <mj@ucw.cz>
+ */
+
+#include "lib/lib.h"
+
+#include <stdio.h>
+#include <string.h>
+
+int
+main(int argc, char **argv)
+{
+ byte buf[1024], *c;
+
+ log_init("logger");
+ if (argc < 3 || argc > 4 || strlen(argv[2]) != 1)
+ die("Usage: logger [<logname>:]<progname> <level> [<text>]");
+ if (c = strchr(argv[1], ':'))
+ {
+ *c++ = 0;
+ log_init(c);
+ log_file(argv[1]);
+ }
+ else
+ log_init(argv[1]);
+ if (argc > 3)
+ log(argv[2][0], argv[3]);
+ else
+ while (fgets(buf, sizeof(buf), stdin))
+ {
+ c = strchr(buf, '\n');
+ if (c)
+ *c = 0;
+ log(argv[2][0], buf);
+ }
+ return 0;
+}