до encodingdefault дошло

This commit is contained in:
Kolan Sh 2011-06-27 15:09:19 +04:00
parent b175af9da4
commit be3dbe915f
1 changed files with 106 additions and 66 deletions

View File

@ -7,9 +7,11 @@
#include "zalloc.h" #include "zalloc.h"
#include "c_const.h" #include "c_const.h"
/* unnecessary includes */ /* only for debug */
#define __TEX_TABLE_DEBUG 0
#include <stdio.h> #include <stdio.h>
int parse_table(const char *table_source, size_t len, struct table_s *table, struct xerror_s *error) int parse_table(const char *table_source, size_t len, struct table_s *table, struct xerror_s *error)
{ {
if (!len) 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)"; error->message = "empty tag (IN_TAG)";
return error->code; return error->code;
} else if (!strcmp(tag, TEX_TAG_BEGIN)) { } else {
where_stack[tex_level] = IN_TAG_BEGIN; if (!strcmp(tag, TEX_TAG_BEGIN)) {
printf("\\%s\n", tag); where_stack[tex_level] = IN_TAG_BEGIN;
tag = zfree_null(tag); #ifdef __TEX_TABLE_DEBUG
printf("\\%s\n", tag);
#endif
tag = zfree_null(tag);
} else if (!strcmp(tag, TEX_TAG_CLINE)) { } else if (!strcmp(tag, TEX_TAG_CLINE)) {
where_stack[tex_level] = IN_TAG_CLINE; where_stack[tex_level] = IN_TAG_CLINE;
printf("\\%s\n", tag); #ifdef __TEX_TABLE_DEBUG
tag = zfree_null(tag); printf("\\%s\n", tag);
#endif
tag = zfree_null(tag);
} else if (!strcmp(tag, TEX_TAG_END)) { } else if (!strcmp(tag, TEX_TAG_END)) {
where_stack[tex_level] = IN_TAG_END; where_stack[tex_level] = IN_TAG_END;
printf("\\%s\n", tag); #ifdef __TEX_TABLE_DEBUG
tag = zfree_null(tag); printf("\\%s\n", tag);
#endif
tag = zfree_null(tag);
} else if (!strcmp(tag, TEX_TAG_ENDFOOT)) { } else if (!strcmp(tag, TEX_TAG_ENDFOOT)) {
where_stack[tex_level] = IN_TAG_ENDFOOT; where_stack[tex_level] = IN_TAG_ENDFOOT;
printf("\\%s\n", tag); #ifdef __TEX_TABLE_DEBUG
tag = zfree_null(tag); printf("\\%s\n", tag);
#endif
tag = zfree_null(tag);
} else if (!strcmp(tag, TEX_TAG_ENDHEAD)) { } else if (!strcmp(tag, TEX_TAG_ENDHEAD)) {
where_stack[tex_level] = IN_TAG_ENDHEAD; where_stack[tex_level] = IN_TAG_ENDHEAD;
printf("\\%s\n", tag); #ifdef __TEX_TABLE_DEBUG
tag = zfree_null(tag); printf("\\%s\n", tag);
#endif
tag = zfree_null(tag);
} else if (!strcmp(tag, TEX_TAG_HLINE)) { } else if (!strcmp(tag, TEX_TAG_HLINE)) {
where_stack[tex_level] = IN_TAG_HLINE; where_stack[tex_level] = IN_TAG_HLINE;
printf("\\%s\n", tag); #ifdef __TEX_TABLE_DEBUG
tag = zfree_null(tag); printf("\\%s\n", tag);
#endif
tag = zfree_null(tag);
} else if (!strcmp(tag, TEX_TAG_HSPACE)) { } else if (!strcmp(tag, TEX_TAG_HSPACE)) {
where_stack[tex_level] = IN_TAG_HSPACE; where_stack[tex_level] = IN_TAG_HSPACE;
printf("\\%s\n", tag); #ifdef __TEX_TABLE_DEBUG
tag = zfree_null(tag); printf("\\%s\n", tag);
#endif
tag = zfree_null(tag);
} else if (!strcmp(tag, TEX_TAG_MULTICOLUMN)) { } else if (!strcmp(tag, TEX_TAG_MULTICOLUMN)) {
where_stack[tex_level] = IN_TAG_MULTICOLUMN; where_stack[tex_level] = IN_TAG_MULTICOLUMN;
printf("\\%s\n", tag); #ifdef __TEX_TABLE_DEBUG
tag = zfree_null(tag); printf("\\%s\n", tag);
#endif
tag = zfree_null(tag);
} else if (!strcmp(tag, TEX_TAG_MULTIROW)) { } else if (!strcmp(tag, TEX_TAG_MULTIROW)) {
where_stack[tex_level] = IN_TAG_MULTIROW; where_stack[tex_level] = IN_TAG_MULTIROW;
printf("\\%s\n", tag); #ifdef __TEX_TABLE_DEBUG
tag = zfree_null(tag); printf("\\%s\n", tag);
#endif
tag = zfree_null(tag);
} else if (!strcmp(tag, TEX_TAG_TABULARNEWLINE)) { } else if (!strcmp(tag, TEX_TAG_TABULARNEWLINE)) {
where_stack[tex_level] = IN_TAG_TABULARNEWLINE; where_stack[tex_level] = IN_TAG_TABULARNEWLINE;
printf("\\%s\n", tag); #ifdef __TEX_TABLE_DEBUG
tag = zfree_null(tag); printf("\\%s\n", tag);
#endif
tag = zfree_null(tag);
} else if (!strcmp(tag, TEX_TAG_SLASH)) { } else if (!strcmp(tag, TEX_TAG_SLASH)) {
where_stack[tex_level] = IN_TAG_SLASH; where_stack[tex_level] = IN_TAG_SLASH;
printf("\\%s\n", tag); #ifdef __TEX_TABLE_DEBUG
tag = zfree_null(tag); printf("\\%s\n", tag);
#endif
tag = zfree_null(tag);
} else if (c == '%') { } else if (c == '%') {
printf("\\%s\n", tag); #ifdef __TEX_TABLE_DEBUG
tag = zfree_null(tag); printf("\\%s\n", tag);
where_stack[tex_level] = IN_TAG_UNKNOWN; #endif
where_stack[++tex_level] = IN_COMMENT; tag = zfree_null(tag);
where_stack[tex_level] = IN_TAG_UNKNOWN;
where_stack[++tex_level] = IN_COMMENT;
} else if (c == '{' || c == '[') { } else if (c == '{' || c == '[') {
printf("\\%s\n", tag); #ifdef __TEX_TABLE_DEBUG
tag = zfree_null(tag); printf("\\%s\n", tag);
where_stack[tex_level] = IN_TAG_UNKNOWN; #endif
where_stack[++tex_level] = IN_TAGPARM; tag = zfree_null(tag);
where_stack[tex_level] = IN_TAG_UNKNOWN;
where_stack[++tex_level] = IN_TAGPARM;
} else if (isspace(c)) { // \tag { for example } else if (isspace(c)) { // \tag { for example
printf("\\%s\n", tag); #ifdef __TEX_TABLE_DEBUG
tag = zfree_null(tag); printf("\\%s\n", tag);
where_stack[tex_level] = IN_TAG_UNKNOWN; #endif
where_stack[++tex_level] = IN_SPACE; tag = zfree_null(tag);
where_stack[tex_level] = IN_TAG_UNKNOWN;
where_stack[++tex_level] = IN_SPACE;
} else { // unknown tag } else { // unknown tag
printf("\\%s\n", tag); #ifdef __TEX_TABLE_DEBUG
tag = zfree_null(tag); printf("\\%s\n", tag);
where_stack[tex_level] = IN_TAG_UNKNOWN; #endif
tag = zfree_null(tag);
where_stack[tex_level] = IN_TAG_UNKNOWN;
}
if (c == '\\')
i--;
} }
break; break;
@ -215,8 +252,8 @@ int parse_table(const char *table_source, size_t len, struct table_s *table, str
tag = zfree_null(tag); tag = zfree_null(tag);
where_stack[tex_level] = IN_TAG; where_stack[tex_level] = IN_TAG;
if (FALSE) { // longtable } else if (c == '%') {
} where_stack[++tex_level] = IN_COMMENT;
} else if (isspace(c)) { } else if (isspace(c)) {
where_stack[++tex_level] = IN_SPACE; 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 if (FALSE) { // longtable
} }
} else if (c == '%') {
where_stack[++tex_level] = IN_COMMENT;
} else if (isspace(c)) { } else if (isspace(c)) {
where_stack[++tex_level] = IN_SPACE; where_stack[++tex_level] = IN_SPACE;