First tex_parser() successful pass

This commit is contained in:
Kolan Sh 2011-06-20 17:24:43 +04:00
parent 41f6ac46e7
commit 41185418ed
6 changed files with 71 additions and 71 deletions

View File

@ -53,13 +53,15 @@ endif
%.o :
$(CC) -c $(CFLAGS) $(LDFLAGS) $(INCLUDE) -o $@ $<
tex_table_test_obj = tex_table_test.o tex_table.o zalloc.o xalloc.o xerror.o
tex_table_test_obj = tex_table_test.o tex_table.o zalloc_ext.o zalloc.o xalloc.o xerror.o
tex_table_test: $(tex_table_test_obj)
$(CC) $(CFLAGS) $(LDFLAGS) $(INCLUDE) -o $@ $(tex_table_test_obj)
tex_table_test.o: tex_table_test.c tex_table.o
tex_table.o: tex_table.c tex_table.h zalloc.o xalloc.o
tex_table.o: tex_table.c tex_table.h zalloc_ext.o zalloc.o xalloc.o
zalloc_ext.o: $(KOLAN_INCLUDE)/zalloc_ext.c $(KOLAN_INCLUDE)/zalloc_ext.h zalloc.o xerror.o
zalloc.o: $(KOLAN_INCLUDE)/zalloc.c $(KOLAN_INCLUDE)/zalloc.h xerror.o

View File

@ -8,94 +8,91 @@
#define MAX_TEX_STACK_LEVEL 128
char * const PARSING_ERROR = "Error parsing";
int parse_table(const char *table_source, size_t len, struct table_s *table, struct xerror_s *error)
{
if (!len)
len = strlen(table_source);
char *tag = NULL;
size_t i = 0;
if (!len)
len = strlen(table_source);
enum where_e
{
IN_GLOBAL = 0,
IN_COMMENT,
IN_TAG,
IN_TAG_CRLBRACEPAR,
IN_TAG_SQRBRACEPAR,
IN_TAG_SQUAREBRACE_COMMA,
IN_UNDEF = 0, // undefined place
IN_COMMENT, // any comment
IN_TAG, // any tag
IN_CRLBR, // parameter in curly bracket
IN_SQRBR, // parameter in square bracket
IN_FORMULA, // in $...$
IN_LONGTABLE, // in tag
} where_stack[MAX_TEX_STACK_LEVEL] = {IN_UNDEF};
size_t tex_level = 0;
IN_TAGCLOSE,
//~ IN_TAG,
IN_TAG_END,
IN_TAG_BEGIN_END,
IN_TAG_PARAM,
IN_TAG_BEGIN_PARAM
} where_stack[MAX_TEX_STACK_LEVEL] = {IN_GLOBAL};
int tex_level = 0;
//~ where_e where_stack[32] = ;
/* Ищем первое вхождение
* \begin{longtable}
*/
/* for (i = 0; i < len; i++) {
for (i = 0; i < len; i++) {
char c = table_source[i];
switch (where) {
case IN_GLOBAL:
switch (where_stack[tex_level]) {
case IN_UNDEF:
if (c == '\\') {
zfree(&tag);
where = IN_TAG;
zfree(tag); tag = NULL;
where_stack[tex_level] = IN_TAG;
} else if (c == '%') {
where_stack[++tex_level] = IN_COMMENT;
} else {
error->code = -1;
error->message = PARSING_ERROR;
return -1;
}
break;
case IN_COMMENT:
if (c == '\r' || c == '\n') {
where_stack[tex_level--] = IN_UNDEF;
}
break;
case IN_TAG:
if (!isalpha(c)) {
//~ size_t len = zmalloc_getlen(tag);
//~ zrealloc(&tag, len + 1);
//~ tag[len] = c;
if (islower(c) || isdigit(c)) {
zalloc_append8_str(tag, c);
} else {
if (!strcmp(tag, TEX_TAG_BEGIN))
where = IN_TAG_BEGIN_END;
else
where = IN_TAG_END;
}
if (!strcmp(tag, TEX_TAG_BEGIN)) {
break;
} else if (!strcmp(tag, TEX_TAG_CLINE)) {
case IN_TAG_PARAM:
//~ if ()
} else if (!strcmp(tag, TEX_TAG_END)) {
if (!isspace(c) || c == '{') {
} else if (!strcmp(tag, TEX_TAG_ENDFOOT)) {
} else if (!strcmp(tag, TEX_TAG_ENDHEAD)) {
} else if (isspace(c)) {
} else {
} else if (!strcmp(tag, TEX_TAG_HLINE)) {
} else if (!strcmp(tag, TEX_TAG_HSPACE)) {
} else if (!strcmp(tag, TEX_TAG_MULTICOLUMN)) {
} else if (!strcmp(tag, TEX_TAG_MULTIROW)) {
} else if (!strcmp(tag, TEX_TAG_TABULARNEWLINE)) {
} else if (!strcmp(tag, TEX_TAG_SLASH)) {
}
}
break;
case IN_TAG_BEGIN_PARAM:
if (isalpha(c)) {
} else if (isspace(c)) {
} else {
}
default:
error->code = -1;
error->message = PARSING_ERROR;
return -1;
break;
case IN_TAG_END:
break;
case IN_TAG_BEGIN_END:
break;
}
}*/
}
table->id = "Drossel1.Table1";

View File

@ -18,12 +18,10 @@ long_line_column=72
[files]
current_page=1
FILE_NAME_0=216;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table_test.c;0
FILE_NAME_1=415;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table.c;0
FILE_NAME_2=2117;LaTeX;0;45;1;1;1;/home/kolan/dev/c/tex_parser/tables4.tex;0
FILE_NAME_3=9842;LaTeX;0;45;1;1;1;/home/kolan/dev/c/tex_parser/tables5.tex;0
FILE_NAME_4=2352;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table.h;0
FILE_NAME_5=612;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table_tags.h;0
FILE_NAME_6=1740;Make;0;16;1;1;1;/home/kolan/dev/c/tex_parser/Makefile;0
FILE_NAME_1=480;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table.c;0
FILE_NAME_2=549;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table.h;0
FILE_NAME_3=612;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table_tags.h;0
FILE_NAME_4=1740;Make;0;16;1;1;1;/home/kolan/dev/c/tex_parser/Makefile;0
[build-menu]
NF_00_LB=_Сделать

View File

@ -42,8 +42,10 @@ struct footer_s {
};
struct table_s {
size_t document_offset; // offset in the LaTeX document
size_t document_size; // size in the LaTeX document
char *id; // "Drossel1.Table1"
char **coumnt_scheme; // "|>{\centering}m{0.1\paperwidth}"
char **column_scheme; // "|>{\centering}m{0.1\paperwidth}"
struct header_s header;
struct footer_s footer;
struct row_s *rows;

View File

@ -11,5 +11,6 @@ const char * const TEX_TAG_HSPACE = "hspace";
const char * const TEX_TAG_MULTICOLUMN = "multicolumn";
const char * const TEX_TAG_MULTIROW = "multirow";
const char * const TEX_TAG_TABULARNEWLINE = "tabularnewline";
const char * const TEX_TAG_SLASH = "\\";
#endif // TEX_TABLE_TAGS_H

View File

@ -32,7 +32,7 @@ int main(int argc, char *argv[])
/* Коммент по-русски */
parse_table(tex_buf, (size_t)stat_buf.st_size, &table, &error);
xfree(&tex_buf);
tex_buf = xfree_null(tex_buf);
return EXIT_SUCCESS;
}