/* File : driver.c Author : Richard A. O'Keefe Updated: %G% Purpose: Test driver for wbxml() decoder. */ #ifndef lint static char SCCSid[] = "%Z%%E% %M% %I%"; #endif/*lint*/ #include #include #include "wbxml.h" static char *error_message[] = { "no error", "unexpected end of file", "only version 2 is supported", "only ISO Latin 1 and UTF-8 are supported", "only WML and HTML are supported", "bad WBXML data", "OPAQUE and EXT_{0,1,2} are not implemented", "too much data for fixed size table", "too much data for heap allocation", }; void quit(char const *msg) { fflush(stdout); fprintf(stderr, "%s:at byte %ld: %s\n", "wbxml", ftell(stdin), msg); exit(EXIT_FAILURE); } int main(int argc, char **argv) { struct ROKXML_handlers const *h = 0; int i; FILE *src = stdin; while (argc > 1 && argv[1][0] == '-') { switch (argv[1][1]) { case 'h': case 'H': argc--, argv++; if (argv[0][2] == '\0') { argc--, argv++; h = get_handlers(argv[0]); } else { h = get_handlers(argv[0]+2); } continue; case 'k': case 'K': argc--, argv++; if (argv[0][2] == '\0') { argc--, argv++; new_counter(argv[0]); } else { new_counter(argv[0]+2); } continue; case '-': argc--, argv++; break; case '\0': break; default: fprintf(stderr, "Unknown option: %s\n", argv[1]); exit(EXIT_FAILURE); } break; } if (h == 0) h = get_handlers("e?"); h = install_counters(h); if (argc > 1) { src = fopen(argv[1], "rb"); if (src == 0) quit("can't open input"); } i = wbxml(src, h); if (i != 0) quit(error_message[i]); if (ferror(src)) quit("input had transmission error"); if (src != stdin) fclose(src); return EXIT_SUCCESS; }