diff options
author | Jordan K. Hubbard <jkh@FreeBSD.org> | 1998-11-22 13:20:09 +0000 |
---|---|---|
committer | Jordan K. Hubbard <jkh@FreeBSD.org> | 1998-11-22 13:20:09 +0000 |
commit | efbcb4ae039e1213887469353d3212378271b4f2 (patch) | |
tree | a667f0a693133ce4c0288e85a35a7e5b97ee2f6e /lib/libutil/property.c | |
parent | 570f565d11edb6d53e0d93d1c2d14b6c6d2c0a0a (diff) | |
download | src-efbcb4ae039e1213887469353d3212378271b4f2.tar.gz src-efbcb4ae039e1213887469353d3212378271b4f2.zip |
Better document the file format, add in support for nested {}'s in multi-line
property values.
Notes
Notes:
svn path=/head/; revision=41291
Diffstat (limited to 'lib/libutil/property.c')
-rw-r--r-- | lib/libutil/property.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/libutil/property.c b/lib/libutil/property.c index 211450c80464..23714a0c3daf 100644 --- a/lib/libutil/property.c +++ b/lib/libutil/property.c @@ -35,6 +35,7 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <err.h> #include <sys/types.h> #include <libutil.h> @@ -62,7 +63,7 @@ properties_read(int fd) char buf[BUFSIZ * 4]; int bp, n, v, max; enum { LOOK, COMMENT, NAME, VALUE, MVALUE, COMMIT, FILL, STOP } state; - int ch = 0; + int ch = 0, blevel = 0; n = v = bp = max = 0; head = ptr = NULL; @@ -135,8 +136,10 @@ properties_read(int fd) case VALUE: if (v == 0 && isspace(ch)) continue; - else if (ch == '{') + else if (ch == '{') { state = MVALUE; + ++blevel; + } else if (ch == '\n' || !ch) { hold_v[v] = '\0'; v = n = 0; @@ -156,16 +159,20 @@ properties_read(int fd) case MVALUE: /* multiline value */ if (v >= MAX_VALUE) { + warn("properties_read: value exceeds max length"); state = COMMENT; n = v = 0; } - else if (ch == '}') { + else if (ch == '}' && !--blevel) { hold_v[v] = '\0'; v = n = 0; state = COMMIT; } - else + else { hold_v[v++] = ch; + if (ch == '{') + ++blevel; + } break; case COMMIT: |