печатает параметры
This commit is contained in:
parent
5640210c7b
commit
8241b39819
|
@ -11,14 +11,12 @@
|
|||
#include "zerror.h"
|
||||
|
||||
/* only for debug */
|
||||
#define __TEX_PARSER_DEBUG 0
|
||||
#define __TEX_PARSER_DEBUG
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
void tex_parse(const char *source, size_t len, struct zerror_s **error)
|
||||
void tex_parse(const char *source, size_t len, struct tex_struct_s **tex_struct, struct zerror_s **error)
|
||||
{
|
||||
memset(error, 0, sizeof(*error));
|
||||
|
||||
if (!len)
|
||||
len = strlen(source);
|
||||
|
||||
|
@ -164,19 +162,21 @@ void tex_parse(const char *source, size_t len, struct zerror_s **error)
|
|||
where_stack[++tex_level] = IN_TAGPARM;
|
||||
|
||||
} else if (c == '}' || c == ']') { // end tag params
|
||||
#ifdef __TEX_PARSER_DEBUG
|
||||
if (param)
|
||||
printf("IN_TAGPARM: {%s}\n", param);
|
||||
#endif
|
||||
where_stack[tex_level--] = IN_UNDEF;
|
||||
|
||||
} else if (c == '\\') { // new tag
|
||||
zclear(&tag);
|
||||
where_stack[++tex_level] = IN_TAG;
|
||||
|
||||
} else if (isspace(c)) {
|
||||
where_stack[++tex_level] = IN_SPACE;
|
||||
|
||||
} else if (c == '%') {
|
||||
where_stack[++tex_level] = IN_COMMENT;
|
||||
|
||||
} else if (isgraph(c) || c < 0) {
|
||||
} else if (isgraph(c) || isspace(c) || c < 0) {
|
||||
param = zalloc_append8_str(param, c);
|
||||
|
||||
} else {
|
||||
z_set_error(error, TEX_PARSER_DOMAIN, TEX_PARSER_ERROR_UNEXPECTED_SYMBOL,
|
||||
|
@ -184,8 +184,6 @@ void tex_parse(const char *source, size_t len, struct zerror_s **error)
|
|||
source[i], (u_int8_t)source[i], i);
|
||||
return;
|
||||
}
|
||||
|
||||
zalloc_append8_str(param, c);
|
||||
break;
|
||||
|
||||
case IN_TAG_UNKNOWN:
|
||||
|
@ -259,6 +257,10 @@ void tex_parse(const char *source, size_t len, struct zerror_s **error)
|
|||
where_stack[++tex_level] = IN_TAGPARM;
|
||||
|
||||
} else if (c == '}' || c == ']') {
|
||||
#ifdef __TEX_PARSER_DEBUG
|
||||
if (param)
|
||||
printf("IN_TAGPARM: {%s}\n", param);
|
||||
#endif
|
||||
where_stack[tex_level--] = IN_UNDEF;
|
||||
i--;
|
||||
|
||||
|
@ -266,10 +268,10 @@ void tex_parse(const char *source, size_t len, struct zerror_s **error)
|
|||
zclear(&tag);
|
||||
where_stack[tex_level] = IN_TAG;
|
||||
|
||||
} else if (isspace(c))
|
||||
} else if (isspace(c)) {
|
||||
where_stack[++tex_level] = IN_SPACE;
|
||||
|
||||
else if (c == '%')
|
||||
} else if (c == '%')
|
||||
where_stack[++tex_level] = IN_COMMENT;
|
||||
|
||||
else if (isgraph(c) || c < 0) {
|
||||
|
|
|
@ -10,7 +10,18 @@
|
|||
|
||||
#define TEX_PARSER_DOMAIN 0
|
||||
|
||||
enum {
|
||||
/**
|
||||
* enum tex_parser_error - the LaTeX parser error code
|
||||
*
|
||||
* @TEX_PARSER_NOERROR: Default state indicates no error.
|
||||
* @TEX_PARSER_ERROR_UNKNOWN:
|
||||
* @TEX_PARSER_ERROR_STACK:
|
||||
* @TEX_PARSER_ERROR_PLACE_UNKNOWN:
|
||||
* @TEX_PARSER_ERROR_UNEXPECTED_SYMBOL:
|
||||
*
|
||||
* Need some description here...
|
||||
*/
|
||||
enum tex_parser_error {
|
||||
TEX_PARSER_NOERROR = 0,
|
||||
TEX_PARSER_ERROR_UNKNOWN,
|
||||
TEX_PARSER_ERROR_STACK,
|
||||
|
@ -18,13 +29,62 @@ enum {
|
|||
TEX_PARSER_ERROR_UNEXPECTED_SYMBOL,
|
||||
};
|
||||
|
||||
struct tex_struct_s {
|
||||
void *tables;
|
||||
void *graphics;
|
||||
/**
|
||||
* enum tex_element_type - Type of LaTeX element
|
||||
*
|
||||
* TEX_ELEM_TEXT: Text containing non-arable code
|
||||
* TEX_ELEM_TABLE: LaTeX table or longtable
|
||||
* TEX_ELEM_GRAPHICS: LaTeX graphics (images, plots)
|
||||
*
|
||||
* Need some description here...
|
||||
*/
|
||||
enum tex_elem_type {
|
||||
TEX_ELEM_TEXT,
|
||||
TEX_ELEM_TABLE,
|
||||
TEX_ELEM_GRAPHICS
|
||||
};
|
||||
|
||||
/* LaTeX parser
|
||||
/**
|
||||
* struct tex_elem_s - Element of LaTeX code
|
||||
*
|
||||
* @type: LaTeX element type
|
||||
* @data: Element data structure
|
||||
*
|
||||
* Need some description here...
|
||||
*/
|
||||
void tex_parse(const char *source, size_t len, struct zerror_s **error);
|
||||
struct tex_elem_s {
|
||||
enum tex_elem_type type;
|
||||
|
||||
union {
|
||||
char *text;
|
||||
void *table;
|
||||
void *graphics;
|
||||
} data;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct tex_struct_s - LaTeX code structure
|
||||
*
|
||||
* @elems: List of LaTeX elements
|
||||
*
|
||||
* Need some description here...
|
||||
*/
|
||||
struct tex_struct_s {
|
||||
struct tex_elem_s *elems;
|
||||
};
|
||||
|
||||
/**
|
||||
* tex_parse() - Parse the LaTeX code
|
||||
*
|
||||
* @source: LaTeX code string
|
||||
* @len: Length of LaTeX string
|
||||
* @tex_struct: A return location for a #tex_struct_s
|
||||
* @error: A return location for a #zerror_s
|
||||
*
|
||||
* Parses LaTeX text string @source of length len to *@tex_struct.
|
||||
* If some error occurs, parser returns immediatly with error info in *@error.
|
||||
* @tex_struct or @error can't be %NULL,
|
||||
*/
|
||||
void tex_parse(const char *source, size_t len, struct tex_struct_s **tex_struct, struct zerror_s **error);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,12 +29,16 @@ int main(int argc, char *argv[])
|
|||
fclose(tex_file);
|
||||
tex_buf[stat_buf.st_size] = 0;
|
||||
|
||||
|
||||
struct tex_struct_s *tex_struct;
|
||||
struct zerror_s *error;
|
||||
memset(&tex_struct, 0, sizeof(tex_struct));
|
||||
memset(&error, 0, sizeof(error));
|
||||
|
||||
//~ setlocale(LC_ALL, "ru_RU.KOI8-R");
|
||||
|
||||
/* Коммент по-русски */
|
||||
tex_parse(tex_buf, (size_t)stat_buf.st_size, &error);
|
||||
tex_parse(tex_buf, (size_t)stat_buf.st_size, &tex_struct, &error);
|
||||
|
||||
//~ setlocale(LC_ALL, "");
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@ long_line_behaviour=1
|
|||
long_line_column=72
|
||||
|
||||
[files]
|
||||
current_page=1
|
||||
FILE_NAME_0=159;C;0;16;1;1;1;/home/kolan/dev/c/zalloc/zalloc_test.c;0
|
||||
FILE_NAME_1=1115;C;0;16;1;1;1;/home/kolan/projects/include/zalloc.c;0
|
||||
current_page=0
|
||||
FILE_NAME_0=830;C;0;16;1;1;1;/home/kolan/dev/c/zalloc/zalloc_test.c;0
|
||||
FILE_NAME_1=1591;C;0;16;1;1;1;/home/kolan/projects/include/zalloc.c;0
|
||||
FILE_NAME_2=1060;C;0;16;1;1;1;/home/kolan/projects/include/zalloc.h;0
|
||||
FILE_NAME_3=0;Make;0;16;1;1;1;/home/kolan/dev/c/zalloc/Makefile;0
|
||||
|
||||
|
|
Loading…
Reference in New Issue