#include "stl.h" #include #include #include 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); }