aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2006-02-02 13:59:42 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2006-02-02 13:59:42 +0000
commitcdd76d659b22b25aa4b3e043d4fc3f7615875aee (patch)
tree19382d8f1b78362fed68c1594d2c8d2ed25bc425
parent8f00973b1f4aef1ebd997107645b1e18079b98e7 (diff)
downloadtagr-cdd76d659b22b25aa4b3e043d4fc3f7615875aee.tar.gz
tagr-cdd76d659b22b25aa4b3e043d4fc3f7615875aee.tar.bz2
Use logmsg() instead of fprintf. Synchronize with plaintext_logs branch.
git-svn-id: file:///svnroot/tagr/trunk@82 7c378d0d-a4e4-4a64-9229-dfce8bfd23d4
-rw-r--r--readconfig.c141
1 files changed, 122 insertions, 19 deletions
diff --git a/readconfig.c b/readconfig.c
index e1bc6bb..3edbca6 100644
--- a/readconfig.c
+++ b/readconfig.c
@@ -73,15 +73,15 @@ router_handler (void *data, int argc, char **argv)
long max = strtoul (argv[4], &p, 10);
if (*p)
{
- fprintf (stderr, "%s:%lu: bad maximum speed value\n",
- configfile, (unsigned long) line);
+ logmsg (L_ERR, "%s:%lu: bad maximum speed value\n",
+ configfile, (unsigned long) line);
return;
}
sd = calloc (1, sizeof (*sd));
if (!sd)
{
- fprintf (stderr, "cannot allocate %lu bytes\n",
- (unsigned long) sizeof (*sd));
+ logmsg (L_CRIT, "cannot allocate %lu bytes\n",
+ (unsigned long) sizeof (*sd));
abort ();
}
assign_string (&sd->id, argv[1]);
@@ -93,12 +93,107 @@ router_handler (void *data, int argc, char **argv)
sd_count++;
}
+static void
+bool_handler (void *data, int argc, char **argv)
+{
+ int *pval = data;
+ if (strcmp (argv[1], "yes") == 0
+ || strcmp (argv[1], "t") == 0
+ || strcmp (argv[1], "true") == 0)
+ *pval = 1;
+ else if (strcmp (argv[1], "no") == 0
+ || strcmp (argv[1], "nil") == 0
+ || strcmp (argv[1], "false") == 0)
+ *pval = 0;
+ else
+ logmsg (L_ERR, "%s:%lu: expected boolean value but found `%s'\n",
+ configfile, (unsigned long) line, argv[1]);
+}
+
+static void
+color_handler (void *data, int argc, char **argv)
+{
+ int *pcol = data;
+ char *p;
+ unsigned long n;
+
+ n = strtoul (argv[1], &p, 0);
+ if (*p)
+ {
+ int i;
+ for (i = 0; i < 2; i++)
+ {
+ if (!*p)
+ {
+ logmsg (L_ERR, "%s:%lu: expected , but found newline",
+ configfile, (unsigned long) line);
+ return;
+ }
+
+ if (*p != ',')
+ {
+ logmsg (L_ERR, "%s:%lu: expected , but found `%c'\n",
+ configfile, (unsigned long) line, *p);
+ return;
+ }
+ if (n > 0xff)
+ logmsg (L_ERR, "%s:%lu: bad color component value: %lu",
+ configfile, (unsigned long) line, n);
+ *pcol++ = n & 0xff;
+ n = strtoul (p+1, &p, 0);
+ }
+ *pcol++ = n & 0xff;
+ }
+ else
+ {
+ pcol[2] = n & 0xff;
+ n >>= 8;
+ pcol[1] = n & 0xff;
+ n >>= 8;
+ pcol[0] = n & 0xff;
+ n >>= 8;
+ if (n > 0)
+ logmsg (L_ERR, "%s:%lu: bad color value, truncated",
+ configfile, (unsigned long) line);
+ }
+}
+
+static void
+suffix_handler (void *data, int argc, char **argv)
+{
+ int i;
+
+ number_suffix_count = argc;
+ number_suffix = xcalloc (argc, sizeof (number_suffix[0]));
+ number_suffix[0] = "";
+ for (i = 1; i < argc; i++)
+ number_suffix[i] = strdup (argv[i]);
+}
+
static struct command_table command_table[] = {
{"basedir", 2, string_handler, &basedir},
{"user", 2, string_handler, &user},
{"template", 2, string_handler, &html_template},
{"port", 2, port_handler, NULL},
{"router", 5, router_handler, NULL},
+ /* I18N */
+ { "number-suffixes", 0, suffix_handler, NULL },
+ /* Graphic presentation: */
+ { "transparent", 1, bool_handler, &transparent_option },
+ { "percent", 1, bool_handler, &percent_option },
+ { "zero-unknown", 1, bool_handler, &zero_unknown_option },
+ { "fill-incoming", 1, bool_handler, &fill_incoming_option },
+ /* Colors */
+ { "color-background", 1, color_handler, color_background },
+ { "color-light", 1, color_handler, color_light },
+ { "color-dark", 1, color_handler, color_dark },
+ { "color-major", 1, color_handler, color_major },
+ { "color-in", 1, color_handler, color_in },
+ { "color-out", 1, color_handler, color_out },
+ { "color-grid", 1, color_handler, color_grid },
+ { "color-in-max", 1, color_handler, color_in_max },
+ { "color-out-max", 1, color_handler, color_out_max },
+ { "color-percent", 1, color_handler, color_percent },
{NULL,}
};
@@ -118,14 +213,22 @@ handle_command (int argc, char **argv)
{
struct command_table *p = find_command (argv[0]);
if (!p)
- fprintf (stderr, "%s:%lu: unknown statement\n",
- configfile, (unsigned long) line);
+ logmsg (L_ERR, "%s:%lu: unknown statement\n",
+ configfile, (unsigned long) line);
+ else if (p->nargs == 0)
+ {
+ if (argc < 2)
+ logmsg (L_ERR, "%s:%lu: too few arguments to `%s'\n",
+ configfile, (unsigned long) line, argv[0]);
+ else
+ p->handler (p->data, argc, argv);
+ }
else if (p->nargs > argc)
- fprintf (stderr, "%s:%lu: too few arguments to `%s'\n",
- configfile, (unsigned long) line, argv[0]);
+ logmsg (L_ERR, "%s:%lu: too few arguments to `%s'\n",
+ configfile, (unsigned long) line, argv[0]);
else if (p->nargs < argc)
- fprintf (stderr, "%s:%lu: too many arguments to `%s'\n",
- configfile, (unsigned long) line, argv[0]);
+ logmsg (L_ERR, "%s:%lu: too many arguments to `%s'\n",
+ configfile, (unsigned long) line, argv[0]);
else
p->handler (p->data, argc, argv);
}
@@ -142,8 +245,8 @@ readconfig ()
fp = fopen (configfile, "r");
if (!fp)
{
- fprintf (stderr, "cannot open file %s: %s\n",
- configfile, strerror (errno));
+ logmsg (L_CRIT, "cannot open file %s: %s\n",
+ configfile, strerror (errno));
return -1;
}
@@ -157,8 +260,8 @@ readconfig ()
line++;
if (argcv_get (buf, "", "#", &argc, &argv))
- fprintf (stderr, "%s:%lu: cannot parse line\n",
- configfile, (unsigned long) line);
+ logmsg (L_WARNING, "%s:%lu: cannot parse line\n",
+ configfile, (unsigned long) line);
else if (argc > 0)
handle_command (argc, argv);
argcv_free (argc, argv);
@@ -169,22 +272,22 @@ readconfig ()
errcnt = 0;
if (!basedir)
{
- fprintf (stderr, "%s: `basedir' not defined\n", configfile);
+ logmsg (L_ERR, "%s: `basedir' not defined\n", configfile);
errcnt++;
}
if (!html_template)
{
- fprintf (stderr, "%s: `template' not defined\n", configfile);
+ logmsg (L_ERR, "%s: `template' not defined\n", configfile);
errcnt++;
}
if (port <= 0)
- fprintf (stderr, "%s: `port' not defined. Using 5671\n", configfile);
+ logmsg (L_ERR, "%s: `port' not defined. Using 5671\n", configfile);
if (sd_count == 0)
{
- fprintf (stderr, "%s: no routers are declared. Nothing to do\n",
- configfile);
+ logmsg (L_ERR, "%s: no routers are declared. Nothing to do\n",
+ configfile);
errcnt++;
}

Return to:

Send suggestions and report system problems to the System administrator.