int main (int argc, char **argv) { char line[5000]; size_t length; rfc822parse_t msg; msg = rfc822parse_open (msg_cb, NULL); if (!msg) abort (); while (fgets (line, sizeof (line), stdin)) { length = strlen (line); if (length && line[length - 1] == '\n') line[--length] = 0; if (length && line[length - 1] == '\r') line[--length] = 0; if (rfc822parse_insert (msg, line, length)) abort (); } dump_structure (msg, NULL, 0); rfc822parse_close (msg); return 0; }
/* Internal debug function to print the structure of the message. */ static void dump_structure (rfc822parse_t msg, part_t part, int indent) { if (!part) { printf ("*** Structure of this message:\n"); part = msg->parts; } for (; part; part = part->right) { rfc822parse_field_t ctx; part_t save_part; /* ugly hack - we should have a function to get part inforation. */ const char *s; save_part = msg->current_part; msg->current_part = part; ctx = rfc822parse_parse_field (msg, "Content-Type", -1); msg->current_part = save_part; if (ctx) { const char *s1, *s2; s1 = rfc822parse_query_media_type (ctx, &s2); if (s1) printf ("*** %*s %s/%s", indent*2, "", s1, s2); else printf ("*** %*s [not found]", indent*2, ""); s = rfc822parse_query_parameter (ctx, "boundary", 0); if (s) printf (" (boundary=\"%s\")", s); rfc822parse_release_field (ctx); } else printf ("*** %*s text/plain [assumed]", indent*2, ""); putchar('\n'); if (part->down) dump_structure (msg, part->down, indent + 1); } }
int main(int argc, char * * argv) { struct codebook * * cb = malloc(argc * sizeof(struct codebook *)); int i; if ( argc < 2 ) { fprintf(stderr, usage, argv[0]); fprintf(stderr, format); exit(1); } for ( i = 0; i < argc - 2; i++ ) { FILE * in = fopen(argv[i + 2], "r"); if ( in == NULL ) { perror(argv[i + 2]); exit(1); } cb[i] = load(in, argv[i + 2]); fclose(in); } printf(header); for ( i = 0; i < argc - 2; i++ ) { printf(" /* %s */\n", argv[i + 2]); dump_array(cb[i], i); } printf("\nconst struct lsp_codebook %s[] = {\n", argv[1]); for ( i = 0; i < argc - 2; i++ ) { printf(" /* %s */\n", argv[i + 2]); dump_structure(cb[i], i); printf(",\n"); } printf(" { 0, 0, 0, 0 }\n"); printf("};\n"); return 0; }