summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1998-11-22 13:20:09 +0000
committerjkh <jkh@FreeBSD.org>1998-11-22 13:20:09 +0000
commita60281fac393cb2fbe3af0cee55fc8a5c3ee55f7 (patch)
tree9bd1b2ce75786834ec7f19514c3760e42c5a94ef /lib
parent85b18b5acfa02f4661df276c473a64c429a75368 (diff)
downloadFreeBSD-src-a60281fac393cb2fbe3af0cee55fc8a5c3ee55f7.zip
FreeBSD-src-a60281fac393cb2fbe3af0cee55fc8a5c3ee55f7.tar.gz
Better document the file format, add in support for nested {}'s in multi-line
property values.
Diffstat (limited to 'lib')
-rw-r--r--lib/libutil/property.321
-rw-r--r--lib/libutil/property.c15
2 files changed, 28 insertions, 8 deletions
diff --git a/lib/libutil/property.3 b/lib/libutil/property.3
index bcd3556..eebdde6 100644
--- a/lib/libutil/property.3
+++ b/lib/libutil/property.3
@@ -23,7 +23,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $Id: property.3,v 1.2 1998/10/09 07:33:58 jkh Exp $
+.\" $Id: property.3,v 1.3 1998/10/14 11:04:36 jkh Exp $
.\" "
.Dd October 7, 1998
.Os
@@ -65,9 +65,7 @@ pairs from the file descriptor passed in
.Fa fd
and returns the head of a new property list, assuming that the
file's contents have been parsed properly, or NULL in case
-of error. The property list pointer should be passed to
-.Fn properties_free
-when no longer needed.
+of error.
.Pp
.Fn property_find
Returns the associated value string for the property named
@@ -78,7 +76,22 @@ if found, otherwise NULL.
is used to free the structure returned by
.Fn properties_read
when it is no longer needed.
+.Pp
+.Sh FILE FORMAT
+Each property in the file is assumed to have the format of
+.Fa name = value
+where
+.Fa name
+is an alphanumeric string (and any punctuation not including the `=' character)
+and
+.Fa value
+is an arbitary string of text terminated by a newline character. If newlines
+are desired, the entire value should be enclosed in { } (curly-bracket)
+characters. Any line beginning with a # or ; character is assumed to
+be a comment and will be ignored.
.Sh SEE ALSO
.Xr auth_getval 3
.Sh BUGS
Simplistic.
+.Sh AUTHOR
+Jordan Hubbard
diff --git a/lib/libutil/property.c b/lib/libutil/property.c
index 211450c..23714a0 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:
OpenPOWER on IntegriCloud