Все теги добавлены в варианты
This commit is contained in:
parent
186fc07303
commit
e48a755e0c
|
@ -5,25 +5,24 @@
|
||||||
#include "tex_table_tags.h"
|
#include "tex_table_tags.h"
|
||||||
#include "zalloc_ext.h"
|
#include "zalloc_ext.h"
|
||||||
#include "zalloc.h"
|
#include "zalloc.h"
|
||||||
|
#include "c_const.h"
|
||||||
|
|
||||||
/* unnecessary includes */
|
/* unnecessary includes */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define MAX_TEX_STACK_LEVEL 128
|
|
||||||
|
|
||||||
enum tex_parse_err {
|
enum tex_parse_err {
|
||||||
PARSE_ERROR_UNDEF = 0,
|
TEX_PARSING_NOERROR = 0,
|
||||||
PARSE_ERROR,
|
TEX_PARSING_ERROR_UNDEF,
|
||||||
PARSE_ERROR_STACKOVERFLOW
|
TEX_PARSING_ERROR_STACKOVERFLOW
|
||||||
};
|
};
|
||||||
|
|
||||||
char * const TEX_PARSING_ERROR = "Error parsing";
|
char * const TEX_PARSING_ERROR_UNDEF_STR = "unknown parsing error";
|
||||||
char * const TEX_PARSING_ERROR_STACKOVERFLOW = "Error parsing";
|
char * const TEX_PARSING_ERROR_STACKOVERFLOW_STR = "parser stack overflow";
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
char *tag = NULL,
|
char *tag = NULL;/*,
|
||||||
*brpar = NULL;
|
*brpar = NULL;*/
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
if (!len)
|
if (!len)
|
||||||
|
@ -34,12 +33,20 @@ int parse_table(const char *table_source, size_t len, struct table_s *table, str
|
||||||
IN_UNDEF = 0, // undefined place
|
IN_UNDEF = 0, // undefined place
|
||||||
IN_COMMENT, // any comment
|
IN_COMMENT, // any comment
|
||||||
IN_TAG, // any tag
|
IN_TAG, // any tag
|
||||||
IN_CRLBR, // parameter in curly bracket
|
|
||||||
IN_SQRBR, // parameter in square bracket
|
|
||||||
IN_TAG_BEGIN, // in \begin tag
|
|
||||||
IN_TAGPARM, // in \tag{} curly braces
|
IN_TAGPARM, // in \tag{} curly braces
|
||||||
IN_LONGTABLE, // in longtable
|
IN_TAG_BEGIN,
|
||||||
|
IN_TAG_CLINE,
|
||||||
|
IN_TAG_END,
|
||||||
|
IN_TAG_ENDFOOT,
|
||||||
|
IN_TAG_ENDHEAD,
|
||||||
|
IN_TAG_HLINE,
|
||||||
|
IN_TAG_HSPACE,
|
||||||
|
IN_TAG_MULTICOLUMN,
|
||||||
|
IN_TAG_MULTIROW,
|
||||||
|
IN_TAG_TABULARNEWLINE,
|
||||||
|
IN_TAG_SLASH,
|
||||||
IN_FORMULA, // in $...$
|
IN_FORMULA, // in $...$
|
||||||
|
IN_LONGTABLE, // in longtable
|
||||||
|
|
||||||
} where_stack[MAX_TEX_STACK_LEVEL] = {IN_UNDEF};
|
} where_stack[MAX_TEX_STACK_LEVEL] = {IN_UNDEF};
|
||||||
|
|
||||||
|
@ -49,9 +56,9 @@ int parse_table(const char *table_source, size_t len, struct table_s *table, str
|
||||||
|
|
||||||
/* stack checking */
|
/* stack checking */
|
||||||
if (tex_level + 1 == MAX_TEX_STACK_LEVEL) {
|
if (tex_level + 1 == MAX_TEX_STACK_LEVEL) {
|
||||||
error->code = -1;
|
error->code = TEX_PARSING_ERROR_STACKOVERFLOW;
|
||||||
error->message = TEX_PARSING_ERROR_STACKOVERFLOW;
|
error->message = TEX_PARSING_ERROR_STACKOVERFLOW_STR;
|
||||||
return -1;
|
return error->code;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read one character from input stream */
|
/* read one character from input stream */
|
||||||
|
@ -62,15 +69,15 @@ int parse_table(const char *table_source, size_t len, struct table_s *table, str
|
||||||
case IN_UNDEF:
|
case IN_UNDEF:
|
||||||
if (c == '\\') {
|
if (c == '\\') {
|
||||||
tag = zfree_null(tag);
|
tag = zfree_null(tag);
|
||||||
where_stack[tex_level] = IN_TAG;
|
where_stack[++tex_level] = IN_TAG;
|
||||||
|
|
||||||
} else if (c == '%') {
|
} else if (c == '%') {
|
||||||
where_stack[++tex_level] = IN_COMMENT;
|
where_stack[++tex_level] = IN_COMMENT;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
error->code = -1;
|
error->code = TEX_PARSING_ERROR_UNDEF;
|
||||||
error->message = TEX_PARSING_ERROR;
|
error->message = TEX_PARSING_ERROR_UNDEF_STR;
|
||||||
return -1;
|
return error->code;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -82,75 +89,143 @@ int parse_table(const char *table_source, size_t len, struct table_s *table, str
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IN_TAG:
|
case IN_TAG:
|
||||||
if (islower(c) || isdigit(c) || (!tag && c == '\\')) {
|
if (islower(c) || isdigit(c) || (!tag && c == '\\')) { // test for char, digit and newline tag "\\"
|
||||||
tag = zalloc_append8_str(tag, c);
|
tag = zalloc_append8_str(tag, c);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!tag) {
|
if (!tag) {
|
||||||
error->code = -1;
|
error->code = TEX_PARSING_ERROR_UNDEF;
|
||||||
error->message = TEX_PARSING_ERROR;
|
error->message = TEX_PARSING_ERROR_UNDEF_STR;
|
||||||
return -1;
|
return error->code;
|
||||||
|
|
||||||
} else if (!strcmp(tag, TEX_TAG_BEGIN)) {
|
} else if (!strcmp(tag, TEX_TAG_BEGIN)) {
|
||||||
where_stack[tex_level++] = IN_TAG_BEGIN;
|
where_stack[tex_level] = IN_TAG_BEGIN;
|
||||||
|
|
||||||
} else if (!strcmp(tag, TEX_TAG_CLINE)) {
|
} else if (!strcmp(tag, TEX_TAG_CLINE)) {
|
||||||
|
where_stack[tex_level] = IN_TAG_CLINE;
|
||||||
|
|
||||||
} else if (!strcmp(tag, TEX_TAG_END)) {
|
} else if (!strcmp(tag, TEX_TAG_END)) {
|
||||||
|
where_stack[tex_level] = IN_TAG_END;
|
||||||
|
|
||||||
} else if (!strcmp(tag, TEX_TAG_ENDFOOT)) {
|
} else if (!strcmp(tag, TEX_TAG_ENDFOOT)) {
|
||||||
|
where_stack[tex_level] = IN_TAG_ENDFOOT;
|
||||||
|
|
||||||
} else if (!strcmp(tag, TEX_TAG_ENDHEAD)) {
|
} else if (!strcmp(tag, TEX_TAG_ENDHEAD)) {
|
||||||
|
where_stack[tex_level] = IN_TAG_ENDHEAD;
|
||||||
|
|
||||||
} else if (!strcmp(tag, TEX_TAG_HLINE)) {
|
} else if (!strcmp(tag, TEX_TAG_HLINE)) {
|
||||||
|
where_stack[tex_level] = IN_TAG_HLINE;
|
||||||
|
|
||||||
} else if (!strcmp(tag, TEX_TAG_HSPACE)) {
|
} else if (!strcmp(tag, TEX_TAG_HSPACE)) {
|
||||||
|
where_stack[tex_level] = IN_TAG_HSPACE;
|
||||||
|
|
||||||
} else if (!strcmp(tag, TEX_TAG_MULTICOLUMN)) {
|
} else if (!strcmp(tag, TEX_TAG_MULTICOLUMN)) {
|
||||||
|
where_stack[tex_level] = IN_TAG_MULTICOLUMN;
|
||||||
|
|
||||||
} else if (!strcmp(tag, TEX_TAG_MULTIROW)) {
|
} else if (!strcmp(tag, TEX_TAG_MULTIROW)) {
|
||||||
|
where_stack[tex_level] = IN_TAG_MULTIROW;
|
||||||
|
|
||||||
} else if (!strcmp(tag, TEX_TAG_TABULARNEWLINE)) {
|
} else if (!strcmp(tag, TEX_TAG_TABULARNEWLINE)) {
|
||||||
|
where_stack[tex_level] = IN_TAG_TABULARNEWLINE;
|
||||||
|
|
||||||
} else if (!strcmp(tag, TEX_TAG_SLASH)) {
|
} else if (!strcmp(tag, TEX_TAG_SLASH)) {
|
||||||
|
where_stack[tex_level] = IN_TAG_SLASH;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IN_TAG_BEGIN:
|
case IN_TAGPARM:
|
||||||
if (c == '{') {
|
if (c == '{') { // tag params
|
||||||
where_stack[++tex_level] = IN_TAGPARM;
|
where_stack[++tex_level] = IN_TAGPARM;
|
||||||
|
|
||||||
} else if (isspace(c)) {
|
} else if (c == '}') { // end tag params
|
||||||
|
where_stack[tex_level--] = IN_UNDEF;
|
||||||
|
|
||||||
|
} else if (c == '\\') { // new tag
|
||||||
|
where_stack[++tex_level] = IN_TAG;
|
||||||
|
|
||||||
|
} else if (isprint(c)) {
|
||||||
|
//~ brpar = zalloc_append8_str(brpar, c); // ???????
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
error->code = -1;
|
error->code = TEX_PARSING_ERROR_UNDEF;
|
||||||
error->message = TEX_PARSING_ERROR;
|
error->message = TEX_PARSING_ERROR_UNDEF_STR;
|
||||||
return -1;
|
return error->code;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IN_TAGPARM:
|
case IN_TAG_BEGIN:
|
||||||
if (c == '}') {
|
if (c == '{') { // tag params
|
||||||
where_stack[tex_level--] = IN_UNDEF;
|
where_stack[++tex_level] = IN_TAGPARM;
|
||||||
|
|
||||||
} else if (isgraph(c)) {
|
} else if (c == '\\') { // new tag
|
||||||
brpar = zalloc_append8_str(brpar, c);
|
where_stack[tex_level] = IN_TAG;
|
||||||
|
|
||||||
|
if (FALSE) { // longtable
|
||||||
|
}
|
||||||
|
|
||||||
} else if (isspace(c)) {
|
} else if (isspace(c)) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
error->code = -1;
|
error->code = TEX_PARSING_ERROR_UNDEF;
|
||||||
error->message = TEX_PARSING_ERROR;
|
error->message = TEX_PARSING_ERROR_UNDEF_STR;
|
||||||
return -1;
|
return error->code;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case IN_TAG_CLINE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IN_TAG_END:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IN_TAG_ENDFOOT:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IN_TAG_ENDHEAD:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IN_TAG_HLINE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IN_TAG_HSPACE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IN_TAG_MULTICOLUMN:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IN_TAG_MULTIROW:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IN_TAG_TABULARNEWLINE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IN_TAG_SLASH:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IN_FORMULA:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IN_LONGTABLE:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
error->code = -1;
|
error->code = TEX_PARSING_ERROR_UNDEF;
|
||||||
error->message = TEX_PARSING_ERROR;
|
error->message = TEX_PARSING_ERROR_UNDEF_STR;
|
||||||
return -1;
|
return error->code;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,13 @@ long_line_column=72
|
||||||
[files]
|
[files]
|
||||||
current_page=1
|
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_0=709;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table_test.c;0
|
||||||
FILE_NAME_1=523;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table.c;0
|
FILE_NAME_1=4204;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table.c;0
|
||||||
FILE_NAME_2=1762;C;0;16;1;1;1;/home/kolan/projects/include/zalloc_ext.h;0
|
FILE_NAME_2=119;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table.h;0
|
||||||
FILE_NAME_3=2350;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
|
FILE_NAME_4=634;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table_tags.h;0
|
||||||
FILE_NAME_5=1488;Make;0;16;1;1;1;/home/kolan/dev/c/tex_parser/Makefile;0
|
FILE_NAME_5=1859;Make;0;16;1;1;1;/home/kolan/dev/c/tex_parser/Makefile;0
|
||||||
|
FILE_NAME_6=0;LaTeX;0;53;1;1;1;/home/kolan/dev/c/tex_parser/tables5.tex;0
|
||||||
|
FILE_NAME_7=0;Пустой;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tables4.aux;0
|
||||||
|
|
||||||
[build-menu]
|
[build-menu]
|
||||||
NF_00_LB=_Сделать
|
NF_00_LB=_Сделать
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
#include "xerror.h"
|
#include "xerror.h"
|
||||||
|
|
||||||
|
#define MAX_TEX_STACK_LEVEL 128
|
||||||
|
|
||||||
/* Ячейка.
|
/* Ячейка.
|
||||||
* Если встречается ячейка с \multicolumn{n}, то
|
* Если встречается ячейка с \multicolumn{n}, то
|
||||||
* следующие n-1 ячеек в таблице пустые и при компиляции
|
* следующие n-1 ячеек в таблице пустые и при компиляции
|
||||||
|
|
Loading…
Reference in New Issue