static sds parse_section(sds str, char *tag, char type) { puts("parse_section"); sds buff = sdsempty(); switch (type) { case '#': buff = tag_section(str, tag); break; case '^': buff = tag_inverted(str, tag); break; } // tag = sdscpylen(tag,buff,sdslen(buff)); puts("free buff"); //sdsfree(buff); // return tag; printf("section str: '%s'\n", str); printf("section tag: '%s'\n", tag); printf("section type: '%c'\n", type); return str; }
void parse(FILE *stream) { char buffer[MAX_WORD_LEN]; int c = 0, index = 0; while (EOF != (c = tolower(getc(stream)))) { switch (c) { case '<': /* Tags */ /* End the current word */ if (index) { buffer[index] = '\0'; clean_word(buffer); word(buffer); index = 0; } /* Get the next character and decide what to do next */ c = getc(stream); /* Case doesn't matter here */ switch (c) { case '/': /* End tags */ tag_section(buffer, stream); end_tag(buffer); break; default: /* Start tags */ c = ungetc(c, stream); if (EOF != c) { tag_section(buffer, stream); start_tag(buffer); } break; } break; case '&': /* Entity references */ entity_ref(stream); /*if (39 == entity_ref(stream)) ungetc(39, stream);*/ break; default: /* Plain text */ if (index == MAX_WORD_LEN) { fprintf(stderr, "Maximum word length exceeded!\n"); exit(EXIT_FAILURE); } if (isalnum(c) || c == 39) { if (c != 39 || index) { /* no ' allowed at the start */ buffer[index++] = c; } } else if (index) { buffer[index] = '\0'; clean_word(buffer); word(buffer); index = 0; } break; } } if (!feof(stream)) { /* Stop due to an error! */ perror("Parsing failure"); exit(EXIT_FAILURE); } }