diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-03-16 01:09:07 +0100 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-03-16 01:09:07 +0100 |
| commit | 2522effc2444a6cb4eb9f3b6168d344983d72170 (patch) | |
| tree | f6801aa6e8c7571581f264e64b1da2cd62dd61be /src/bench.c | |
| download | libstl-c-2522effc2444a6cb4eb9f3b6168d344983d72170.tar.gz libstl-c-2522effc2444a6cb4eb9f3b6168d344983d72170.zip | |
Initial version
Diffstat (limited to 'src/bench.c')
| -rw-r--r-- | src/bench.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/bench.c b/src/bench.c new file mode 100644 index 0000000..b406be3 --- /dev/null +++ b/src/bench.c @@ -0,0 +1,57 @@ +#include "stl.h" + +#include <err.h> +#include <stdio.h> +#include <stdlib.h> + +static char buf[BUFSIZ]; + +static char *stl_err[] = { + STL_STRERROR_INIT +}; + +int +main(int argc, const char **argv) +{ + struct stl_result res; + struct stl stl; + size_t count; + int n, rc; + + stl_init(&stl, STL_TYPE_DETECT); + + count = 0; + while (1) { + n = fread(buf, 1, BUFSIZ, stdin); + if (n <= 0) errx(1, "truncated input"); + + while (1) { + rc = stl_feed(&stl, &res, buf, n); + if (rc == STL_DONE) break; + if (rc == STL_INCOMPLETE) break; + if (rc != STL_OK) errx(1, "libstl: %s", stl_err[rc]); + + switch (res.type) { + case STL_RES_FILETYPE: + printf("filetype: %s\n", + res.filetype == STL_TYPE_ASCII + ? "ascii" : "binary"); + break; + case STL_RES_HEADER: + printf("header: %s\n", res.header.str); + break; + case STL_RES_SOLID_NAME: + printf("name: %s\n", res.solid_name.str); + break; + case STL_RES_TRIANGLE: + count += 1; + break; + } + } + + if (rc == STL_DONE) + break; + } + + printf("triangles: %lu\n", count); +} |
