66 for (key = buf; *key &&
ISSPACE(*key); key++)
69 return (
"no key found; expected format: key = value");
71 for (key_end = key; *key_end; key_end++) {
72 if (*key_end ==
'\\') {
75 }
else if (
ISSPACE(*key_end) || *key_end ==
'=') {
78 }
else if (*key_end ==
'"') {
79 in_quotes = !in_quotes;
83 return (
"unbalanced '\"\'");
89 return (
"missing '=' after attribute name");
108 static int compare(
int test_number,
const char *what,
109 const char *expect,
const char *real)
111 if ((expect == 0 && real == 0)
112 || (expect != 0 && real != 0 && strcmp(expect, real) == 0)) {
115 msg_warn(
"test %d: %s mis-match: expect='%s', real='%s'",
116 test_number, what, expect ? expect :
"(null)",
117 real ? real :
"(null)");
126 const char *expect_result;
127 const char *expect_key;
128 const char *expect_value;
130 static const struct test_info test_info[] = {
132 {
"xx = yy", 0,
"xx",
"yy"},
133 {
"xx=yy", 0,
"xx",
"yy"},
134 {
"xx =", 0,
"xx",
""},
135 {
"xx=", 0,
"xx",
""},
136 {
"xx",
"missing '=' after attribute name", 0, 0},
138 {
"\"xx \" = yy", 0,
"\"xx \"",
"yy"},
139 {
"\"xx \"= yy", 0,
"\"xx \"",
"yy"},
140 {
"\"xx \" =", 0,
"\"xx \"",
""},
141 {
"\"xx \"=", 0,
"\"xx \"",
""},
142 {
"\"xx \"",
"missing '=' after attribute name", 0, 0},
143 {
"\"xx ",
"unbalanced '\"'", 0, 0},
145 {
"\"\\\"xx \" = yy", 0,
"\"\\\"xx \"",
"yy"},
150 const struct test_info *tp;
152 for (tp = test_info; tp->input != 0; tp++) {
157 int test_number = (
int) (tp - test_info);
160 errs += compare(test_number,
"result", tp->expect_result, result);
161 errs += compare(test_number,
"key", tp->expect_key, key);
162 errs += compare(test_number,
"value", tp->expect_value, value);
char * mystrdup(const char *str)
int main(int argc, char **argv)
const char * split_qnameval(char *buf, char **pkey, char **pvalue)
void msg_warn(const char *fmt,...)
char * trimblanks(char *, ssize_t)