diff --git a/c/tex_parser/tex_table.c b/c/tex_parser/tex_table.c index 392855b..578fcf6 100644 --- a/c/tex_parser/tex_table.c +++ b/c/tex_parser/tex_table.c @@ -89,16 +89,22 @@ int parse_table(const char *table_source, size_t len, struct table_s *table, str break; case IN_TAG: - if (islower(c) || isdigit(c) || (!tag && c == '\\')) { // test for char, digit and newline tag "\\" + if (isalpha(c) || isdigit(c) || (!tag && c == '\\')) { // test for char, digit and newline tag "\\" tag = zalloc_append8_str(tag, c); + } else if (isspace(c)) { + } else if (c == '{' || c == '[') { + where_stack[++tex_level] = IN_TAGPARM; + + } else if (c == '%') { + where_stack[++tex_level] = IN_COMMENT; + + } else if (!tag) { + error->code = TEX_PARSING_ERROR_UNDEF; + error->message = TEX_PARSING_ERROR_UNDEF_STR; + return error->code; } else { - if (!tag) { - error->code = TEX_PARSING_ERROR_UNDEF; - error->message = TEX_PARSING_ERROR_UNDEF_STR; - return error->code; - - } else if (!strcmp(tag, TEX_TAG_BEGIN)) { + if (!strcmp(tag, TEX_TAG_BEGIN)) { where_stack[tex_level] = IN_TAG_BEGIN; } else if (!strcmp(tag, TEX_TAG_CLINE)) { @@ -131,18 +137,24 @@ int parse_table(const char *table_source, size_t len, struct table_s *table, str } else if (!strcmp(tag, TEX_TAG_SLASH)) { where_stack[tex_level] = IN_TAG_SLASH; + } else { // unknown tag + } + printf("\\%s\n", tag); + tag = zfree_null(tag); } + break; case IN_TAGPARM: - if (c == '{') { // tag params + if (c == '{' || c == '[') { // tag params where_stack[++tex_level] = IN_TAGPARM; - } else if (c == '}') { // end tag params + } else if (c == '}' || c == ']') { // end tag params where_stack[tex_level--] = IN_UNDEF; } else if (c == '\\') { // new tag + tag = zfree_null(tag); where_stack[++tex_level] = IN_TAG; } else if (isprint(c)) { @@ -156,10 +168,11 @@ int parse_table(const char *table_source, size_t len, struct table_s *table, str break; case IN_TAG_BEGIN: - if (c == '{') { // tag params + if (c == '{' || c == '[') { // tag params where_stack[++tex_level] = IN_TAGPARM; } else if (c == '\\') { // new tag + tag = zfree_null(tag); where_stack[tex_level] = IN_TAG; if (FALSE) { // longtable diff --git a/c/tex_parser/tex_table.geany b/c/tex_parser/tex_table.geany index d288539..d9bcb84 100644 --- a/c/tex_parser/tex_table.geany +++ b/c/tex_parser/tex_table.geany @@ -18,7 +18,7 @@ long_line_column=72 [files] current_page=1 FILE_NAME_0=709;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table_test.c;0 -FILE_NAME_1=4204;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table.c;0 +FILE_NAME_1=4568;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table.c;0 FILE_NAME_2=119;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table.h;0 FILE_NAME_3=1762;C;0;16;1;1;1;/home/kolan/projects/include/zalloc_ext.h;0 FILE_NAME_4=634;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table_tags.h;0 diff --git a/c/tex_parser/tex_table_test.c b/c/tex_parser/tex_table_test.c index 6b72e79..ee75bf3 100644 --- a/c/tex_parser/tex_table_test.c +++ b/c/tex_parser/tex_table_test.c @@ -32,7 +32,10 @@ int main(int argc, char *argv[]) struct table_s table; memset(&table, 0, sizeof(struct table_s)); /* Коммент по-русски */ - parse_table(tex_buf, (size_t)stat_buf.st_size, &table, &error); + int result = parse_table(tex_buf, (size_t)stat_buf.st_size, &table, &error); + if (result) { + printf("Parsing error: %s\n", error.message); + } tex_buf = xfree_null(tex_buf);