From be3dbe915fc58e77794b90f2b4fb0d071b476e5f Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Mon, 27 Jun 2011 15:09:19 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=20encodingdefault=20=D0=B4=D0=BE?= =?UTF-8?q?=D1=88=D0=BB=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- c/tex_parser/tex_table.c | 172 ++++++++++++++++++++++++--------------- 1 file changed, 106 insertions(+), 66 deletions(-) diff --git a/c/tex_parser/tex_table.c b/c/tex_parser/tex_table.c index 7cfd490..2116de4 100644 --- a/c/tex_parser/tex_table.c +++ b/c/tex_parser/tex_table.c @@ -7,9 +7,11 @@ #include "zalloc.h" #include "c_const.h" -/* unnecessary includes */ +/* only for debug */ +#define __TEX_TABLE_DEBUG 0 #include + int parse_table(const char *table_source, size_t len, struct table_s *table, struct xerror_s *error) { if (!len) @@ -91,83 +93,118 @@ int parse_table(const char *table_source, size_t len, struct table_s *table, str error->message = "empty tag (IN_TAG)"; return error->code; - } else if (!strcmp(tag, TEX_TAG_BEGIN)) { - where_stack[tex_level] = IN_TAG_BEGIN; - printf("\\%s\n", tag); - tag = zfree_null(tag); + } else { + if (!strcmp(tag, TEX_TAG_BEGIN)) { + where_stack[tex_level] = IN_TAG_BEGIN; + #ifdef __TEX_TABLE_DEBUG + printf("\\%s\n", tag); + #endif + tag = zfree_null(tag); - } else if (!strcmp(tag, TEX_TAG_CLINE)) { - where_stack[tex_level] = IN_TAG_CLINE; - printf("\\%s\n", tag); - tag = zfree_null(tag); + } else if (!strcmp(tag, TEX_TAG_CLINE)) { + where_stack[tex_level] = IN_TAG_CLINE; + #ifdef __TEX_TABLE_DEBUG + printf("\\%s\n", tag); + #endif + tag = zfree_null(tag); - } else if (!strcmp(tag, TEX_TAG_END)) { - where_stack[tex_level] = IN_TAG_END; - printf("\\%s\n", tag); - tag = zfree_null(tag); + } else if (!strcmp(tag, TEX_TAG_END)) { + where_stack[tex_level] = IN_TAG_END; + #ifdef __TEX_TABLE_DEBUG + printf("\\%s\n", tag); + #endif + tag = zfree_null(tag); - } else if (!strcmp(tag, TEX_TAG_ENDFOOT)) { - where_stack[tex_level] = IN_TAG_ENDFOOT; - printf("\\%s\n", tag); - tag = zfree_null(tag); + } else if (!strcmp(tag, TEX_TAG_ENDFOOT)) { + where_stack[tex_level] = IN_TAG_ENDFOOT; + #ifdef __TEX_TABLE_DEBUG + printf("\\%s\n", tag); + #endif + tag = zfree_null(tag); - } else if (!strcmp(tag, TEX_TAG_ENDHEAD)) { - where_stack[tex_level] = IN_TAG_ENDHEAD; - printf("\\%s\n", tag); - tag = zfree_null(tag); + } else if (!strcmp(tag, TEX_TAG_ENDHEAD)) { + where_stack[tex_level] = IN_TAG_ENDHEAD; + #ifdef __TEX_TABLE_DEBUG + printf("\\%s\n", tag); + #endif + tag = zfree_null(tag); - } else if (!strcmp(tag, TEX_TAG_HLINE)) { - where_stack[tex_level] = IN_TAG_HLINE; - printf("\\%s\n", tag); - tag = zfree_null(tag); + } else if (!strcmp(tag, TEX_TAG_HLINE)) { + where_stack[tex_level] = IN_TAG_HLINE; + #ifdef __TEX_TABLE_DEBUG + printf("\\%s\n", tag); + #endif + tag = zfree_null(tag); - } else if (!strcmp(tag, TEX_TAG_HSPACE)) { - where_stack[tex_level] = IN_TAG_HSPACE; - printf("\\%s\n", tag); - tag = zfree_null(tag); + } else if (!strcmp(tag, TEX_TAG_HSPACE)) { + where_stack[tex_level] = IN_TAG_HSPACE; + #ifdef __TEX_TABLE_DEBUG + printf("\\%s\n", tag); + #endif + tag = zfree_null(tag); - } else if (!strcmp(tag, TEX_TAG_MULTICOLUMN)) { - where_stack[tex_level] = IN_TAG_MULTICOLUMN; - printf("\\%s\n", tag); - tag = zfree_null(tag); + } else if (!strcmp(tag, TEX_TAG_MULTICOLUMN)) { + where_stack[tex_level] = IN_TAG_MULTICOLUMN; + #ifdef __TEX_TABLE_DEBUG + printf("\\%s\n", tag); + #endif + tag = zfree_null(tag); - } else if (!strcmp(tag, TEX_TAG_MULTIROW)) { - where_stack[tex_level] = IN_TAG_MULTIROW; - printf("\\%s\n", tag); - tag = zfree_null(tag); + } else if (!strcmp(tag, TEX_TAG_MULTIROW)) { + where_stack[tex_level] = IN_TAG_MULTIROW; + #ifdef __TEX_TABLE_DEBUG + printf("\\%s\n", tag); + #endif + tag = zfree_null(tag); - } else if (!strcmp(tag, TEX_TAG_TABULARNEWLINE)) { - where_stack[tex_level] = IN_TAG_TABULARNEWLINE; - printf("\\%s\n", tag); - tag = zfree_null(tag); + } else if (!strcmp(tag, TEX_TAG_TABULARNEWLINE)) { + where_stack[tex_level] = IN_TAG_TABULARNEWLINE; + #ifdef __TEX_TABLE_DEBUG + printf("\\%s\n", tag); + #endif + tag = zfree_null(tag); - } else if (!strcmp(tag, TEX_TAG_SLASH)) { - where_stack[tex_level] = IN_TAG_SLASH; - printf("\\%s\n", tag); - tag = zfree_null(tag); + } else if (!strcmp(tag, TEX_TAG_SLASH)) { + where_stack[tex_level] = IN_TAG_SLASH; + #ifdef __TEX_TABLE_DEBUG + printf("\\%s\n", tag); + #endif + tag = zfree_null(tag); - } else if (c == '%') { - printf("\\%s\n", tag); - tag = zfree_null(tag); - where_stack[tex_level] = IN_TAG_UNKNOWN; - where_stack[++tex_level] = IN_COMMENT; + } else if (c == '%') { + #ifdef __TEX_TABLE_DEBUG + printf("\\%s\n", tag); + #endif + tag = zfree_null(tag); + where_stack[tex_level] = IN_TAG_UNKNOWN; + where_stack[++tex_level] = IN_COMMENT; - } else if (c == '{' || c == '[') { - printf("\\%s\n", tag); - tag = zfree_null(tag); - where_stack[tex_level] = IN_TAG_UNKNOWN; - where_stack[++tex_level] = IN_TAGPARM; + } else if (c == '{' || c == '[') { + #ifdef __TEX_TABLE_DEBUG + printf("\\%s\n", tag); + #endif + tag = zfree_null(tag); + where_stack[tex_level] = IN_TAG_UNKNOWN; + where_stack[++tex_level] = IN_TAGPARM; - } else if (isspace(c)) { // \tag { for example - printf("\\%s\n", tag); - tag = zfree_null(tag); - where_stack[tex_level] = IN_TAG_UNKNOWN; - where_stack[++tex_level] = IN_SPACE; + } else if (isspace(c)) { // \tag { for example + #ifdef __TEX_TABLE_DEBUG + printf("\\%s\n", tag); + #endif + tag = zfree_null(tag); + where_stack[tex_level] = IN_TAG_UNKNOWN; + where_stack[++tex_level] = IN_SPACE; - } else { // unknown tag - printf("\\%s\n", tag); - tag = zfree_null(tag); - where_stack[tex_level] = IN_TAG_UNKNOWN; + } else { // unknown tag + #ifdef __TEX_TABLE_DEBUG + printf("\\%s\n", tag); + #endif + tag = zfree_null(tag); + where_stack[tex_level] = IN_TAG_UNKNOWN; + } + + if (c == '\\') + i--; } break; @@ -215,8 +252,8 @@ int parse_table(const char *table_source, size_t len, struct table_s *table, str tag = zfree_null(tag); where_stack[tex_level] = IN_TAG; - if (FALSE) { // longtable - } + } else if (c == '%') { + where_stack[++tex_level] = IN_COMMENT; } else if (isspace(c)) { where_stack[++tex_level] = IN_SPACE; @@ -241,6 +278,9 @@ int parse_table(const char *table_source, size_t len, struct table_s *table, str if (FALSE) { // longtable } + } else if (c == '%') { + where_stack[++tex_level] = IN_COMMENT; + } else if (isspace(c)) { where_stack[++tex_level] = IN_SPACE;