Commit c15f950b authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Fixed some nasty bugs.

parent ebc6681c
/*
* $Id: conf-file.c,v 1.1 1994/01/12 01:28:41 ceder Exp $
* $Id: conf-file.c,v 1.2 1994/01/12 04:07:33 ceder Exp $
* Copyright (C) 1994 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -26,7 +26,7 @@
* Read configuration files.
*/
static char *rcsid = "$Id: conf-file.c,v 1.1 1994/01/12 01:28:41 ceder Exp $";
static char *rcsid = "$Id: conf-file.c,v 1.2 1994/01/12 04:07:33 ceder Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -56,9 +56,9 @@ init_init(const struct parameter *par)
{
int ix;
npar = 0;
for (; par[npar].name != NULL; par++)
npar++;
for (npar = 0; par[npar].name != NULL; npar++)
;
assert (assignment_count == NULL);
assignment_count = smalloc(npar * sizeof (*assignment_count));
......@@ -79,19 +79,25 @@ assign_defaults(const struct parameter *par,
{
if (assignment_count[ix] < par[ix].min_assignments)
{
log ("Parameter %s only assigned %d times (%d times needed)",
log ("Parameter %s only assigned %d times (%d times needed)\n",
assignment_count[ix], par[ix].min_assignments);
(*err)++;
}
else if (assignment_count[ix] == 0)
{
if ((*par[ix].assigner)(par[ix].default_val, &par[ix]) != OK)
{
log ("default assigner failed for %s\n", par[ix].name);
(*err)++;
}
}
}
}
/* Perform the assignments on one line. */
/* Perform the assignments on one line.
Returns EOF on end-of-file, 0 otherwise.
A log message is printed, and (*err) is incremented,
if errors are detected. */
static int
configure_line(FILE *fp,
const struct parameter *par,
......@@ -118,7 +124,7 @@ configure_line(FILE *fp,
case '#': /* Comment line */
return 0;
case '\0': /* Too long */
log ("line too long (max %d chars allowed): %s", MAXLINE-1, line);
log ("line too long (max %d chars allowed): %s\n", MAXLINE-1, line);
(*err)++;
return 0;
case '\n': /* Empty line */
......@@ -128,7 +134,7 @@ configure_line(FILE *fp,
val = strchr(line, ':');
if (val == NULL)
{
log("missing colon: %s", line);
log("missing colon: %s\n", line);
(*err)++;
return 0;
}
......@@ -138,11 +144,11 @@ configure_line(FILE *fp,
switch (*val)
{
case '\n':
log ("empty value: %s", line);
log ("empty value: %s\n", line);
(*err)++;
return 0;
case '\0':
log ("line too long (max %d chars allowed): %s", MAXLINE-1, line);
log ("line too long (max %d chars allowed): %s\n", MAXLINE-1, line);
(*err)++;
return 0;
}
......@@ -150,7 +156,7 @@ configure_line(FILE *fp,
end = strchr(val, '\n');
if (end == NULL)
{
log ("line too long (max %d chars allowed): %s", MAXLINE-1, line);
log ("line too long (max %d chars allowed): %s\n", MAXLINE-1, line);
(*err)++;
return 0;
}
......@@ -163,24 +169,28 @@ configure_line(FILE *fp,
if (!strcasecmp(start, par[ix].name))
{
found++;
if (assignment_count[ix] > par[ix].max_assignments)
if (assignment_count[ix] > par[ix].max_assignments
&& par[ix].max_assignments != -1)
{
(*err)++;
log ("variable already assigned %d times: %s",
log ("variable already assigned %d times: %s\n",
assignment_count[ix], line);
}
else
{
assignment_count[ix]++;
if ((*par[ix].assigner)(val, &par[ix]) != OK)
{
log ("assigner for %s failed\n", par[ix].name);
(*err)++;
}
}
}
}
if (found != 0)
if (found != 1)
{
log ("line matches %d times: %s", found, line);
log ("line matches %d times: %s\n", found, line);
(*err)++;
return 0;
}
......@@ -216,7 +226,8 @@ Success
assign_text_no(const char *val,
const struct parameter *par)
{
*(Text_no*)par->value = atol(val);
if (val != NULL)
*(Text_no*)par->value = atol(val);
return OK;
}
......@@ -224,7 +235,8 @@ Success
assign_conf_no(const char *val,
const struct parameter *par)
{
*(Conf_no*)par->value = atol(val);
if (val != NULL)
*(Conf_no*)par->value = atol(val);
return OK;
}
......@@ -232,7 +244,8 @@ Success
assign_int(const char *val,
const struct parameter *par)
{
*(int*)par->value = atol(val);
if (val != NULL)
*(int*)par->value = atol(val);
return OK;
}
......@@ -240,8 +253,13 @@ Success
assign_string(const char *val,
const struct parameter *par)
{
*(char**)par->value = smalloc(strlen(val) + 1);
strcpy(*(char**)par->value, val);
if (val == NULL)
*(char**)par->value = NULL;
else
{
*(char**)par->value = smalloc(strlen(val) + 1);
strcpy(*(char**)par->value, val);
}
return OK;
}
......@@ -249,16 +267,23 @@ Success
assign_bool(const char *val,
const struct parameter *par)
{
if (!strcasecmp(val, "true")
if (val == NULL
||!strcasecmp(val, "false")
|| !strcasecmp(val, "off")
|| !strcasecmp(val, "0"))
{
*(Bool*)par->value = FALSE;
}
else if (!strcasecmp(val, "true")
|| !strcasecmp(val, "on")
|| !strcasecmp(val, "1"))
{
*(Bool*)par->value = TRUE;
else if (!strcasecmp(val, "false")
|| !strcasecmp(val, "off")
|| !strcasecmp(val, "0"))
*(Bool*)par->value = FALSE;
}
else
{
return FAILURE;
}
return OK;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment