9 /* #include <split_nameval.h>
11 /* const char *split_nameval(buf, name, value)
16 /* split_nameval() takes a logical line from readlline() and expects
17 /* text of the form "name = value" or "name =". The buffer
18 /* argument is broken up into name and value substrings.
22 /* Result from readlline() or equivalent. The buffer is modified.
24 /* Upon successful completion, this is set to the name
27 /* Upon successful completion, this is set to the value
31 /* dict(3) mid-level dictionary routines
34 /* Fatal errors: out of memory.
36 /* The result is a null pointer in case of success, a string
37 /* describing the error otherwise: missing '=' after attribute
38 /* name; missing attribute name.
42 /* The Secure Mailer license must be distributed with this software.
45 /* IBM T.J. Watson Research
47 /* Yorktown Heights, NY 10598, USA
50 /* System libraries. */
56 /* Utility library. */
59 #include <stringops.h>
61 /* split_nameval - split text into name and value */
63 const char *split_nameval(char *buf
, char **name
, char **value
)
65 char *np
; /* name substring */
66 char *vp
; /* value substring */
71 * Ugly macros to make complex expressions less unreadable.
73 #define SKIP(start, var, cond) \
74 for (var = start; *var && (cond); var++);
78 for (p = (s) + strlen(s); p > (s) && ISSPACE(p[-1]); p--); \
82 SKIP(buf
, np
, ISSPACE(*np
)); /* find name begin */
84 return ("missing attribute name");
85 SKIP(np
, ep
, !ISSPACE(*ep
) && *ep
!= '='); /* find name end */
86 SKIP(ep
, cp
, ISSPACE(*cp
)); /* skip blanks before '=' */
87 if (*cp
!= '=') /* need '=' */
88 return ("missing '=' after attribute name");
89 *ep
= 0; /* terminate name */
90 cp
++; /* skip over '=' */
91 SKIP(cp
, vp
, ISSPACE(*vp
)); /* skip leading blanks */
92 TRIM(vp
); /* trim trailing blanks */