From 1490268ea6ae75e5e9b78861c56dc9b04db903f3 Mon Sep 17 00:00:00 2001 From: Louis Burda Date: Mon, 10 May 2021 17:18:28 +0200 Subject: extended query function to load file info, added poc test --- service/src/stlfile.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'service/src/stlfile.c') diff --git a/service/src/stlfile.c b/service/src/stlfile.c index 4f6d0e1..95d3a07 100644 --- a/service/src/stlfile.c +++ b/service/src/stlfile.c @@ -254,12 +254,14 @@ parse_file(struct parseinfo *info, char *buf, size_t len) const char *tmp; char *bp; + if (len < 7) return FAIL; + if (info->valid) free_info(info); for (bp = buf; strchr(wsset, *bp); bp++); /* check bin vs ascii with first keyword */ - status = !strncmp("solid ", bp, 6) + status = !strncmp("solid", bp, 5) && strchr(wsset, bp[5]) ? parse_file_ascii(info, buf, len) : parse_file_bin(info, buf, len); if (status == FAIL) return FAIL; @@ -312,8 +314,8 @@ load_info(struct parseinfo *info, FILE *f) nread += fread(&info->loopcount, sizeof(int), 1, f); for (i = 0; i < 3; i++) { - nread += fwrite(&info->bbmin[i], sizeof(float), 1, f); - nread += fwrite(&info->bbmax[i], sizeof(float), 1, f); + nread += fread(&info->bbmin[i], sizeof(float), 1, f); + nread += fread(&info->bbmax[i], sizeof(float), 1, f); } nread += fread(info->header, 80, 1, f); @@ -323,6 +325,8 @@ load_info(struct parseinfo *info, FILE *f) freadstr(f, &info->modelname); freadstr(f, &info->hash); + info->valid = 1; + return OK; } @@ -333,10 +337,12 @@ print_info(struct parseinfo *info) #define FILTERCHAR(c) ((c) >= 32 ? (c) : ' ') - printf("Name: %s\n", info->modelname); + printf(" === Model info === \n"); + + printf(" Name: %s\n", info->modelname); if (info->type == TYPE_BIN) { - printf("Header:\n"); + printf(" Header:\n "); for (i = 0; i < 80; i += k) { for (k = 0; k < MIN(80 - i, 20); k++) printf(" %02x", (uint8_t) info->header[i+k]); @@ -347,12 +353,14 @@ print_info(struct parseinfo *info) } } - printf("Hash: %s\n", info->hash); - printf("Triangles: %i\n", info->loopcount); - printf("Bounding Box: %.2f x %.2f x %.2f\n", + printf(" Hash: %s\n", info->hash); + printf(" Triangles: %i\n", info->loopcount); + printf(" Bounding Box: %.2f x %.2f x %.2f\n", info->bbmax[0] - info->bbmin[0], info->bbmax[1] - info->bbmin[1], info->bbmax[2] - info->bbmin[2]); + + printf(" ================== \n"); } void -- cgit v1.2.3-71-gd317