logindefs: fix coding style
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
43b53f57c1
commit
3f9c237dcb
|
@ -19,20 +19,20 @@
|
||||||
* products derived from this software without their specific prior
|
* products derived from this software without their specific prior
|
||||||
* written permission.
|
* written permission.
|
||||||
*/
|
*/
|
||||||
#include <errno.h>
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <limits.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <sys/syslog.h>
|
#include <sys/syslog.h>
|
||||||
|
|
||||||
#include "c.h"
|
#include "c.h"
|
||||||
#include "nls.h"
|
|
||||||
#include "xalloc.h"
|
|
||||||
#include "pathnames.h"
|
|
||||||
#include "logindefs.h"
|
#include "logindefs.h"
|
||||||
|
#include "nls.h"
|
||||||
|
#include "pathnames.h"
|
||||||
|
#include "xalloc.h"
|
||||||
|
|
||||||
struct item {
|
struct item {
|
||||||
char *name; /* name of the option. */
|
char *name; /* name of the option. */
|
||||||
|
@ -76,7 +76,6 @@ static void store(const char *name, const char *value, const char *path)
|
||||||
list = new;
|
list = new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void load_defaults(const char *filename)
|
static void load_defaults(const char *filename)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
@ -91,7 +90,7 @@ static void load_defaults(const char *filename)
|
||||||
char *p, *name, *data = NULL;
|
char *p, *name, *data = NULL;
|
||||||
|
|
||||||
if (*buf == '#' || *buf == '\n')
|
if (*buf == '#' || *buf == '\n')
|
||||||
continue; /* only comment or empty line */
|
continue; /* only comment or empty line */
|
||||||
|
|
||||||
p = strchr(buf, '#');
|
p = strchr(buf, '#');
|
||||||
if (p)
|
if (p)
|
||||||
|
@ -103,16 +102,16 @@ static void load_defaults(const char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!*buf)
|
if (!*buf)
|
||||||
continue; /* empty line */
|
continue; /* empty line */
|
||||||
|
|
||||||
/* ignore space at begin of the line */
|
/* ignore space at begin of the line */
|
||||||
name = buf;
|
name = buf;
|
||||||
while (*name && isspace((unsigned) *name))
|
while (*name && isspace((unsigned)*name))
|
||||||
name++;
|
name++;
|
||||||
|
|
||||||
/* go to the end of the name */
|
/* go to the end of the name */
|
||||||
data = name;
|
data = name;
|
||||||
while (*data && !(isspace((unsigned) *data) || *data == '='))
|
while (*data && !(isspace((unsigned)*data) || *data == '='))
|
||||||
data++;
|
data++;
|
||||||
if (data > name && *data)
|
if (data > name && *data)
|
||||||
*data++ = '\0';
|
*data++ = '\0';
|
||||||
|
@ -121,14 +120,16 @@ static void load_defaults(const char *filename)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* go to the begin of the value */
|
/* go to the begin of the value */
|
||||||
while (*data && (isspace((unsigned) *data) || *data == '=' || *data == '"'))
|
while (*data
|
||||||
data++;
|
&& (isspace((unsigned)*data) || *data == '='
|
||||||
|
|| *data == '"'))
|
||||||
|
data++;
|
||||||
|
|
||||||
/* remove space at the end of the value */
|
/* remove space at the end of the value */
|
||||||
p = data + strlen(data);
|
p = data + strlen(data);
|
||||||
if (p > data)
|
if (p > data)
|
||||||
p--;
|
p--;
|
||||||
while (p > data && (isspace((unsigned) *p) || *p == '"'))
|
while (p > data && (isspace((unsigned)*p) || *p == '"'))
|
||||||
*p-- = '\0';
|
*p-- = '\0';
|
||||||
|
|
||||||
store(name, data, filename);
|
store(name, data, filename);
|
||||||
|
@ -170,7 +171,7 @@ static const char *search_config(const char *name)
|
||||||
|
|
||||||
int getlogindefs_bool(const char *name, int dflt)
|
int getlogindefs_bool(const char *name, int dflt)
|
||||||
{
|
{
|
||||||
struct item *ptr= search(name);
|
struct item *ptr = search(name);
|
||||||
return ptr && ptr->value ? (strcasecmp(ptr->value, "yes") == 0) : dflt;
|
return ptr && ptr->value ? (strcasecmp(ptr->value, "yes") == 0) : dflt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +190,7 @@ long getlogindefs_num(const char *name, long dflt)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
syslog(LOG_NOTICE, _("%s: %s contains invalid numerical value: %s"),
|
syslog(LOG_NOTICE, _("%s: %s contains invalid numerical value: %s"),
|
||||||
search_config(name), name, ptr->value);
|
search_config(name), name, ptr->value);
|
||||||
return dflt;
|
return dflt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +211,6 @@ const char *getlogindefs_str(const char *name, const char *dflt)
|
||||||
return ptr->value;
|
return ptr->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef TEST_PROGRAM
|
#ifdef TEST_PROGRAM
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -218,15 +218,16 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
if (argc <= 1)
|
if (argc <= 1)
|
||||||
errx(EXIT_FAILURE, "usage: %s <filename> "
|
errx(EXIT_FAILURE, "usage: %s <filename> "
|
||||||
"[<str|num|bool> <valname>]", argv[0]);
|
"[<str|num|bool> <valname>]", argv[0]);
|
||||||
|
|
||||||
load_defaults(argv[1]);
|
load_defaults(argv[1]);
|
||||||
|
|
||||||
if (argc != 4) { /* list all */
|
if (argc != 4) { /* list all */
|
||||||
struct item *ptr;
|
struct item *ptr;
|
||||||
|
|
||||||
for (ptr = list; ptr; ptr = ptr->next)
|
for (ptr = list; ptr; ptr = ptr->next)
|
||||||
printf("%s: $%s: '%s'\n", ptr->path, ptr->name, ptr->value);
|
printf("%s: $%s: '%s'\n", ptr->path, ptr->name,
|
||||||
|
ptr->value);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -239,7 +240,8 @@ int main(int argc, char *argv[])
|
||||||
else if (strcmp(type, "num") == 0)
|
else if (strcmp(type, "num") == 0)
|
||||||
printf("$%s: '%ld'\n", name, getlogindefs_num(name, 0));
|
printf("$%s: '%ld'\n", name, getlogindefs_num(name, 0));
|
||||||
else if (strcmp(type, "bool") == 0)
|
else if (strcmp(type, "bool") == 0)
|
||||||
printf("$%s: '%s'\n", name, getlogindefs_bool(name, 0) ? "Y" : "N");
|
printf("$%s: '%s'\n", name,
|
||||||
|
getlogindefs_bool(name, 0) ? "Y" : "N");
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue