diff options
author | phil <phil@FreeBSD.org> | 2016-03-17 00:46:36 +0000 |
---|---|---|
committer | phil <phil@FreeBSD.org> | 2016-03-17 00:46:36 +0000 |
commit | 0efb2620b96d9cbb76b33a390facfc24ff231ba3 (patch) | |
tree | afa76ef09b8528cae96477148b1c0437ceb1f2d4 /0.4.5/tests/core/test_04.c | |
parent | 3ce11bd9fc4d042a890334b8e0c5adcb094b9d17 (diff) | |
download | FreeBSD-src-0efb2620b96d9cbb76b33a390facfc24ff231ba3.zip FreeBSD-src-0efb2620b96d9cbb76b33a390facfc24ff231ba3.tar.gz |
Tag libxo 0.4.5
Approved by: sjg
Diffstat (limited to '0.4.5/tests/core/test_04.c')
-rw-r--r-- | 0.4.5/tests/core/test_04.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/0.4.5/tests/core/test_04.c b/0.4.5/tests/core/test_04.c new file mode 100644 index 0000000..5e25302 --- /dev/null +++ b/0.4.5/tests/core/test_04.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2014, Juniper Networks, Inc. + * All rights reserved. + * This SOFTWARE is licensed under the LICENSE provided in the + * ../Copyright file. By downloading, installing, copying, or otherwise + * using the SOFTWARE, you agree to be bound by the terms of that + * LICENSE. + * Phil Shafer, July 2014 + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "xo.h" + +xo_info_t info[] = { + { "employee", "object", "Employee data" }, + { "first-name", "string", "First name of employee" }, + { "last-name", "string", "Last name of employee" }, + { "department", "number", "Department number" }, +}; +int info_count = (sizeof(info) / sizeof(info[0])); + +int +main (int argc, char **argv) +{ + struct employee { + const char *e_first; + const char *e_last; + unsigned e_dept; + } employees[] = { + { "Terry", "Jones", 660 }, + { "Leslie", "Patterson", 341 }, + { "Ashley", "Smith", 1440 }, + { NULL, NULL } + }, *ep = employees; + + argc = xo_parse_args(argc, argv); + if (argc < 0) + return 1; + + xo_set_info(NULL, info, info_count); + + xo_open_container("employees"); + xo_open_list("employee"); + + xo_emit("{T:Last Name/%-12s}{T:First Name/%-14s}{T:Department/%s}\n"); + for ( ; ep->e_first; ep++) { + xo_open_instance("employee"); + xo_emit("{:first-name/%-12s/%s}{:last-name/%-14s/%s}" + "{:department/%8u/%u}\n", + ep->e_first, ep->e_last, ep->e_dept); + xo_close_instance("employee"); + } + + xo_close_list("employee"); + xo_close_container("employees"); + + xo_finish(); + + return 0; +} |