First tex_parser() successful pass
This commit is contained in:
parent
41f6ac46e7
commit
41185418ed
|
@ -53,13 +53,15 @@ endif
|
||||||
%.o :
|
%.o :
|
||||||
$(CC) -c $(CFLAGS) $(LDFLAGS) $(INCLUDE) -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)
|
tex_table_test: $(tex_table_test_obj)
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) $(INCLUDE) -o $@ $(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_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
|
zalloc.o: $(KOLAN_INCLUDE)/zalloc.c $(KOLAN_INCLUDE)/zalloc.h xerror.o
|
||||||
|
|
||||||
|
|
|
@ -8,94 +8,91 @@
|
||||||
|
|
||||||
#define MAX_TEX_STACK_LEVEL 128
|
#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)
|
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;
|
char *tag = NULL;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
|
if (!len)
|
||||||
|
len = strlen(table_source);
|
||||||
|
|
||||||
enum where_e
|
enum where_e
|
||||||
{
|
{
|
||||||
IN_GLOBAL = 0,
|
IN_UNDEF = 0, // undefined place
|
||||||
IN_COMMENT,
|
IN_COMMENT, // any comment
|
||||||
IN_TAG,
|
IN_TAG, // any tag
|
||||||
IN_TAG_CRLBRACEPAR,
|
IN_CRLBR, // parameter in curly bracket
|
||||||
IN_TAG_SQRBRACEPAR,
|
IN_SQRBR, // parameter in square bracket
|
||||||
IN_TAG_SQUAREBRACE_COMMA,
|
IN_FORMULA, // in $...$
|
||||||
|
IN_LONGTABLE, // in tag
|
||||||
|
} where_stack[MAX_TEX_STACK_LEVEL] = {IN_UNDEF};
|
||||||
|
|
||||||
|
size_t tex_level = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
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++) {
|
|
||||||
char c = table_source[i];
|
char c = table_source[i];
|
||||||
|
|
||||||
switch (where) {
|
switch (where_stack[tex_level]) {
|
||||||
case IN_GLOBAL:
|
case IN_UNDEF:
|
||||||
if (c == '\\') {
|
if (c == '\\') {
|
||||||
zfree(&tag);
|
zfree(tag); tag = NULL;
|
||||||
where = IN_TAG;
|
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;
|
break;
|
||||||
|
|
||||||
case IN_TAG:
|
case IN_TAG:
|
||||||
if (!isalpha(c)) {
|
if (islower(c) || isdigit(c)) {
|
||||||
//~ size_t len = zmalloc_getlen(tag);
|
zalloc_append8_str(tag, c);
|
||||||
//~ zrealloc(&tag, len + 1);
|
|
||||||
//~ tag[len] = c;
|
|
||||||
} else {
|
} else {
|
||||||
if (!strcmp(tag, TEX_TAG_BEGIN))
|
if (!strcmp(tag, TEX_TAG_BEGIN)) {
|
||||||
where = IN_TAG_BEGIN_END;
|
|
||||||
else
|
|
||||||
where = IN_TAG_END;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
} else if (!strcmp(tag, TEX_TAG_CLINE)) {
|
||||||
|
|
||||||
case IN_TAG_PARAM:
|
} else if (!strcmp(tag, TEX_TAG_END)) {
|
||||||
//~ if ()
|
|
||||||
|
|
||||||
if (!isspace(c) || c == '{') {
|
} else if (!strcmp(tag, TEX_TAG_ENDFOOT)) {
|
||||||
|
|
||||||
|
} else if (!strcmp(tag, TEX_TAG_ENDHEAD)) {
|
||||||
|
|
||||||
} else if (isspace(c)) {
|
} else if (!strcmp(tag, TEX_TAG_HLINE)) {
|
||||||
} else {
|
|
||||||
|
} 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;
|
break;
|
||||||
|
|
||||||
case IN_TAG_BEGIN_PARAM:
|
default:
|
||||||
if (isalpha(c)) {
|
error->code = -1;
|
||||||
} else if (isspace(c)) {
|
error->message = PARSING_ERROR;
|
||||||
} else {
|
return -1;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IN_TAG_END:
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IN_TAG_BEGIN_END:
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
table->id = "Drossel1.Table1";
|
table->id = "Drossel1.Table1";
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,10 @@ long_line_column=72
|
||||||
[files]
|
[files]
|
||||||
current_page=1
|
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_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_1=480;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_2=549;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table.h;0
|
||||||
FILE_NAME_3=9842;LaTeX;0;45;1;1;1;/home/kolan/dev/c/tex_parser/tables5.tex;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=2352;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table.h;0
|
FILE_NAME_4=1740;Make;0;16;1;1;1;/home/kolan/dev/c/tex_parser/Makefile;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
|
|
||||||
|
|
||||||
[build-menu]
|
[build-menu]
|
||||||
NF_00_LB=_Сделать
|
NF_00_LB=_Сделать
|
||||||
|
|
|
@ -42,8 +42,10 @@ struct footer_s {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct table_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 *id; // "Drossel1.Table1"
|
||||||
char **coumnt_scheme; // "|>{\centering}m{0.1\paperwidth}"
|
char **column_scheme; // "|>{\centering}m{0.1\paperwidth}"
|
||||||
struct header_s header;
|
struct header_s header;
|
||||||
struct footer_s footer;
|
struct footer_s footer;
|
||||||
struct row_s *rows;
|
struct row_s *rows;
|
||||||
|
|
|
@ -11,5 +11,6 @@ const char * const TEX_TAG_HSPACE = "hspace";
|
||||||
const char * const TEX_TAG_MULTICOLUMN = "multicolumn";
|
const char * const TEX_TAG_MULTICOLUMN = "multicolumn";
|
||||||
const char * const TEX_TAG_MULTIROW = "multirow";
|
const char * const TEX_TAG_MULTIROW = "multirow";
|
||||||
const char * const TEX_TAG_TABULARNEWLINE = "tabularnewline";
|
const char * const TEX_TAG_TABULARNEWLINE = "tabularnewline";
|
||||||
|
const char * const TEX_TAG_SLASH = "\\";
|
||||||
|
|
||||||
#endif // TEX_TABLE_TAGS_H
|
#endif // TEX_TABLE_TAGS_H
|
||||||
|
|
|
@ -32,7 +32,7 @@ int main(int argc, char *argv[])
|
||||||
/* Коммент по-русски */
|
/* Коммент по-русски */
|
||||||
parse_table(tex_buf, (size_t)stat_buf.st_size, &table, &error);
|
parse_table(tex_buf, (size_t)stat_buf.st_size, &table, &error);
|
||||||
|
|
||||||
xfree(&tex_buf);
|
tex_buf = xfree_null(tex_buf);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue