summaryrefslogtreecommitdiff
path: root/libc/string/config.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-10-07 23:37:03 +0000
committerEric Andersen <andersen@codepoet.org>2000-10-07 23:37:03 +0000
commitfbb4007ac88656122f9319dea4563a3a4fd40e82 (patch)
treeca4265ac43d139b3fd02ba32bfe6d5e12cadb65c /libc/string/config.c
parentb8f03a94957c913fa0d8588c41b0332b49310ff0 (diff)
Update and simplification.
Diffstat (limited to 'libc/string/config.c')
-rw-r--r--libc/string/config.c126
1 files changed, 61 insertions, 65 deletions
diff --git a/libc/string/config.c b/libc/string/config.c
index 58716b922..dad9a723e 100644
--- a/libc/string/config.c
+++ b/libc/string/config.c
@@ -17,76 +17,72 @@
static char *args[16];
static char cfgbuf[128];
-static char *
-ws(char **buf)
+static char *ws(char **buf)
{
- char *b = *buf;
- char *p;
-
- /* eat ws */
- while (*b &&
- (*b == ' ' ||
- *b == '\n' ||
- *b == '\t')) b++;
- p = b;
-
- /* find the end */
- while (*p &&
- !(*p == ' ' ||
- *p == '\n' ||
- *p == '\t')) p++;
- *p = 0;
- *buf = p+1;
- return b;
+ char *b = *buf;
+ char *p;
+
+ /* eat ws */
+ while (*b && (*b == ' ' || *b == '\n' || *b == '\t'))
+ b++;
+ p = b;
+
+ /* find the end */
+ while (*p && !(*p == ' ' || *p == '\n' || *p == '\t'))
+ p++;
+ *p = 0;
+ *buf = p + 1;
+ return b;
}
-char **
-cfgread(FILE *fp)
+char **cfgread(FILE * fp)
{
- char *ebuf;
- char *p;
- int i;
-
- if (!fp) {
- errno = EIO;
- return (void *)0;
- }
-
- while (fgets(cfgbuf, sizeof(cfgbuf), fp)) {
-
- /* ship comment lines */
- if (cfgbuf[0] == '#') continue;
-
- ebuf = cfgbuf + strlen(cfgbuf);
-
- p = cfgbuf;
- for (i = 0; i < 16 && p < ebuf; i++) {
- args[i] = ws(&p);
- }
- args[i] = (void *)0;
-
- /* return if we found something */
- if (strlen(args[0])) return args;
- }
- return (void *)0;
+ char *ebuf;
+ char *p;
+ int i;
+
+ if (!fp) {
+ errno = EIO;
+ return (void *) 0;
+ }
+
+ while (fgets(cfgbuf, sizeof(cfgbuf), fp)) {
+
+ /* ship comment lines */
+ if (cfgbuf[0] == '#')
+ continue;
+
+ ebuf = cfgbuf + strlen(cfgbuf);
+
+ p = cfgbuf;
+ for (i = 0; i < 16 && p < ebuf; i++) {
+ args[i] = ws(&p);
+ }
+ args[i] = (void *) 0;
+
+ /* return if we found something */
+ if (strlen(args[0]))
+ return args;
+ }
+ return (void *) 0;
}
-char **
-cfgfind(FILE *fp, char *var)
+char **cfgfind(FILE * fp, char *var)
{
- char **ret;
- char search[80];
-
- if (!fp || !var) {
- errno = EIO;
- return (void *)0;
- }
-
- strncpy(search, var, sizeof(search));
-
- fseek(fp, 0, SEEK_SET);
- while ((ret = cfgread(fp))) {
- if (!strcmp(ret[0], search)) return ret;
- }
- return (void *)0;
+ char **ret;
+ char search[80];
+
+ if (!fp || !var) {
+ errno = EIO;
+ return (void *) 0;
+ }
+
+ strncpy(search, var, sizeof(search));
+
+ fseek(fp, 0, SEEK_SET);
+ while ((ret = cfgread(fp))) {
+ if (!strcmp(ret[0], search))
+ return ret;
+ }
+ return (void *) 0;
}