Все теги добавлены в варианты
This commit is contained in:
parent
186fc07303
commit
e48a755e0c
|
@ -5,25 +5,24 @@
|
|||
#include "tex_table_tags.h"
|
||||
#include "zalloc_ext.h"
|
||||
#include "zalloc.h"
|
||||
#include "c_const.h"
|
||||
|
||||
/* unnecessary includes */
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX_TEX_STACK_LEVEL 128
|
||||
|
||||
enum tex_parse_err {
|
||||
PARSE_ERROR_UNDEF = 0,
|
||||
PARSE_ERROR,
|
||||
PARSE_ERROR_STACKOVERFLOW
|
||||
TEX_PARSING_NOERROR = 0,
|
||||
TEX_PARSING_ERROR_UNDEF,
|
||||
TEX_PARSING_ERROR_STACKOVERFLOW
|
||||
};
|
||||
|
||||
char * const TEX_PARSING_ERROR = "Error parsing";
|
||||
char * const TEX_PARSING_ERROR_STACKOVERFLOW = "Error parsing";
|
||||
char * const TEX_PARSING_ERROR_UNDEF_STR = "unknown parsing error";
|
||||
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)
|
||||
{
|
||||
char *tag = NULL,
|
||||
*brpar = NULL;
|
||||
char *tag = NULL;/*,
|
||||
*brpar = NULL;*/
|
||||
size_t i = 0;
|
||||
|
||||
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_COMMENT, // any comment
|
||||
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_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_LONGTABLE, // in longtable
|
||||
|
||||
} 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 */
|
||||
if (tex_level + 1 == MAX_TEX_STACK_LEVEL) {
|
||||
error->code = -1;
|
||||
error->message = TEX_PARSING_ERROR_STACKOVERFLOW;
|
||||
return -1;
|
||||
error->code = TEX_PARSING_ERROR_STACKOVERFLOW;
|
||||
error->message = TEX_PARSING_ERROR_STACKOVERFLOW_STR;
|
||||
return error->code;
|
||||
}
|
||||
|
||||
/* 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:
|
||||
if (c == '\\') {
|
||||
tag = zfree_null(tag);
|
||||
where_stack[tex_level] = IN_TAG;
|
||||
where_stack[++tex_level] = IN_TAG;
|
||||
|
||||
} else if (c == '%') {
|
||||
where_stack[++tex_level] = IN_COMMENT;
|
||||
|
||||
} else {
|
||||
error->code = -1;
|
||||
error->message = TEX_PARSING_ERROR;
|
||||
return -1;
|
||||
error->code = TEX_PARSING_ERROR_UNDEF;
|
||||
error->message = TEX_PARSING_ERROR_UNDEF_STR;
|
||||
return error->code;
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -82,75 +89,143 @@ int parse_table(const char *table_source, size_t len, struct table_s *table, str
|
|||
break;
|
||||
|
||||
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);
|
||||
|
||||
} else {
|
||||
if (!tag) {
|
||||
error->code = -1;
|
||||
error->message = TEX_PARSING_ERROR;
|
||||
return -1;
|
||||
error->code = TEX_PARSING_ERROR_UNDEF;
|
||||
error->message = TEX_PARSING_ERROR_UNDEF_STR;
|
||||
return error->code;
|
||||
|
||||
} 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)) {
|
||||
where_stack[tex_level] = IN_TAG_CLINE;
|
||||
|
||||
} else if (!strcmp(tag, TEX_TAG_END)) {
|
||||
where_stack[tex_level] = IN_TAG_END;
|
||||
|
||||
} else if (!strcmp(tag, TEX_TAG_ENDFOOT)) {
|
||||
where_stack[tex_level] = IN_TAG_ENDFOOT;
|
||||
|
||||
} else if (!strcmp(tag, TEX_TAG_ENDHEAD)) {
|
||||
where_stack[tex_level] = IN_TAG_ENDHEAD;
|
||||
|
||||
} else if (!strcmp(tag, TEX_TAG_HLINE)) {
|
||||
where_stack[tex_level] = IN_TAG_HLINE;
|
||||
|
||||
} else if (!strcmp(tag, TEX_TAG_HSPACE)) {
|
||||
where_stack[tex_level] = IN_TAG_HSPACE;
|
||||
|
||||
} else if (!strcmp(tag, TEX_TAG_MULTICOLUMN)) {
|
||||
where_stack[tex_level] = IN_TAG_MULTICOLUMN;
|
||||
|
||||
} else if (!strcmp(tag, TEX_TAG_MULTIROW)) {
|
||||
where_stack[tex_level] = IN_TAG_MULTIROW;
|
||||
|
||||
} else if (!strcmp(tag, TEX_TAG_TABULARNEWLINE)) {
|
||||
where_stack[tex_level] = IN_TAG_TABULARNEWLINE;
|
||||
|
||||
} else if (!strcmp(tag, TEX_TAG_SLASH)) {
|
||||
where_stack[tex_level] = IN_TAG_SLASH;
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case IN_TAG_BEGIN:
|
||||
if (c == '{') {
|
||||
case IN_TAGPARM:
|
||||
if (c == '{') { // tag params
|
||||
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 {
|
||||
error->code = -1;
|
||||
error->message = TEX_PARSING_ERROR;
|
||||
return -1;
|
||||
error->code = TEX_PARSING_ERROR_UNDEF;
|
||||
error->message = TEX_PARSING_ERROR_UNDEF_STR;
|
||||
return error->code;
|
||||
}
|
||||
break;
|
||||
|
||||
case IN_TAGPARM:
|
||||
if (c == '}') {
|
||||
where_stack[tex_level--] = IN_UNDEF;
|
||||
case IN_TAG_BEGIN:
|
||||
if (c == '{') { // tag params
|
||||
where_stack[++tex_level] = IN_TAGPARM;
|
||||
|
||||
} else if (isgraph(c)) {
|
||||
brpar = zalloc_append8_str(brpar, c);
|
||||
} else if (c == '\\') { // new tag
|
||||
where_stack[tex_level] = IN_TAG;
|
||||
|
||||
if (FALSE) { // longtable
|
||||
}
|
||||
|
||||
} else if (isspace(c)) {
|
||||
|
||||
} else {
|
||||
error->code = -1;
|
||||
error->message = TEX_PARSING_ERROR;
|
||||
return -1;
|
||||
error->code = TEX_PARSING_ERROR_UNDEF;
|
||||
error->message = TEX_PARSING_ERROR_UNDEF_STR;
|
||||
return error->code;
|
||||
}
|
||||
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:
|
||||
error->code = -1;
|
||||
error->message = TEX_PARSING_ERROR;
|
||||
return -1;
|
||||
error->code = TEX_PARSING_ERROR_UNDEF;
|
||||
error->message = TEX_PARSING_ERROR_UNDEF_STR;
|
||||
return error->code;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,13 @@ long_line_column=72
|
|||
[files]
|
||||
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_1=523;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_3=2350;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table.h;0
|
||||
FILE_NAME_1=4204;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table.c;0
|
||||
FILE_NAME_2=119;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_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]
|
||||
NF_00_LB=_Сделать
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include "xerror.h"
|
||||
|
||||
#define MAX_TEX_STACK_LEVEL 128
|
||||
|
||||
/* Ячейка.
|
||||
* Если встречается ячейка с \multicolumn{n}, то
|
||||
* следующие n-1 ячеек в таблице пустые и при компиляции
|
||||
|
|
Loading…
Reference in New Issue