TRUE error control
This commit is contained in:
parent
3bf2247c74
commit
848b51ee9c
@ -13,7 +13,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
int tex_parse(const char *source, size_t len, struct zerror_s *error)
|
void tex_parse(const char *source, size_t len, struct zerror_s **error)
|
||||||
{
|
{
|
||||||
memset(error, 0, sizeof(*error));
|
memset(error, 0, sizeof(*error));
|
||||||
|
|
||||||
@ -50,9 +50,10 @@ int tex_parse(const char *source, size_t len, struct zerror_s *error)
|
|||||||
|
|
||||||
/* stack checking */
|
/* stack checking */
|
||||||
if (tex_level + 1 == MAX_TEX_STACK_LEVEL) {
|
if (tex_level + 1 == MAX_TEX_STACK_LEVEL) {
|
||||||
error->code = (int)i;
|
z_set_error(error, TEX_PARSER_DOMAIN, TEX_PARSER_ERROR_STACK,
|
||||||
error->message = "stack overflow";
|
"tex_parse(): stack overflow, symbol %c(0x%2.2x) at position %d",
|
||||||
return error->code;
|
source[i], (u_int8_t)source[i], i);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read one character from input stream */
|
/* read one character from input stream */
|
||||||
@ -78,9 +79,10 @@ int tex_parse(const char *source, size_t len, struct zerror_s *error)
|
|||||||
} else if (isgraph(c) || c < 0) {
|
} else if (isgraph(c) || c < 0) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
error->code = (int)i;
|
z_set_error(error, TEX_PARSER_DOMAIN, TEX_PARSER_ERROR_UNEXPECTED_SYMBOL,
|
||||||
error->message = "unexpected symbol (IN_UDEF)";
|
"tex_parse(): IN_UNDEF unexpected symbol %c(0x%2.2x) at position %d",
|
||||||
return error->code;
|
source[i], (u_int8_t)source[i], i);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -99,9 +101,10 @@ int tex_parse(const char *source, size_t len, struct zerror_s *error)
|
|||||||
where_stack[tex_level--] = IN_UNDEF;
|
where_stack[tex_level--] = IN_UNDEF;
|
||||||
|
|
||||||
} else if (!tag) {
|
} else if (!tag) {
|
||||||
error->code = (int)i;
|
z_set_error(error, TEX_PARSER_DOMAIN, TEX_PARSER_ERROR_UNEXPECTED_SYMBOL,
|
||||||
error->message = "empty tag (IN_TAG)";
|
"tex_parse(): IN_TAG empty tag, symbol %c(0x%2.2x) at position %d",
|
||||||
return error->code;
|
source[i], (u_int8_t)source[i], i);
|
||||||
|
return;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!strcmp(tag, TEX_TAG_BEGIN))
|
if (!strcmp(tag, TEX_TAG_BEGIN))
|
||||||
@ -173,9 +176,10 @@ int tex_parse(const char *source, size_t len, struct zerror_s *error)
|
|||||||
} else if (isgraph(c) || c < 0) {
|
} else if (isgraph(c) || c < 0) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
error->code = (int)i;
|
z_set_error(error, TEX_PARSER_DOMAIN, TEX_PARSER_ERROR_UNEXPECTED_SYMBOL,
|
||||||
error->message = "unexpected symbol (IN_TAGPARM)";
|
"tex_parse(): IN_TAGPARM unexpected symbol %c(0x%2.2x) at position %d",
|
||||||
return error->code;
|
source[i], (u_int8_t)source[i], i);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -237,9 +241,11 @@ int tex_parse(const char *source, size_t len, struct zerror_s *error)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
error->code = (int)i;
|
z_set_error(error, TEX_PARSER_DOMAIN, TEX_PARSER_ERROR_UNKNOWN,
|
||||||
error->message = "unknown error (IN_TAG_))";
|
"tex_parse(): IN_(%d) error in code(uncontrolled nested switch case),"
|
||||||
return error->code;
|
" symbol %c(0x%2.2x) at position %d",
|
||||||
|
where_stack[tex_level], source[i], (u_int8_t)source[i], i);
|
||||||
|
return;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,9 +269,10 @@ int tex_parse(const char *source, size_t len, struct zerror_s *error)
|
|||||||
else if (isgraph(c) || c < 0) {
|
else if (isgraph(c) || c < 0) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
error->code = (int)i;
|
z_set_error(error, TEX_PARSER_DOMAIN, TEX_PARSER_ERROR_UNEXPECTED_SYMBOL,
|
||||||
error->message = "unexpected symbol (IN_TAG_)";
|
"tex_parse(): IN_%d unexpected symbol %c(0x%2.2x) at position %d",
|
||||||
return error->code;
|
where_stack[tex_level], source[i], (u_int8_t)source[i], i);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -274,12 +281,11 @@ int tex_parse(const char *source, size_t len, struct zerror_s *error)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
error->code = (int)i;
|
z_set_error(error, TEX_PARSER_DOMAIN, TEX_PARSER_ERROR_PLACE_UNKNOWN,
|
||||||
error->message = "unknown error";
|
"tex_parse(): IN_%d unknown place, symbol %c(0x%2.2x) at position %d",
|
||||||
return error->code;
|
where_stack[tex_level], source[i], (u_int8_t)source[i], i);
|
||||||
|
return;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -3,26 +3,28 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "zerror.h"
|
|
||||||
#include "tex_parser_table.h"
|
#include "tex_parser_table.h"
|
||||||
#include "tex_parser_graphics.h"
|
#include "tex_parser_graphics.h"
|
||||||
|
|
||||||
|
#include "zerror.h"
|
||||||
|
|
||||||
//~
|
#define TEX_PARSER_DOMAIN 0
|
||||||
//~ struct node_s {
|
|
||||||
//~ enum {
|
enum {
|
||||||
//~ TEXOBJ_UNDEF = 0,
|
TEX_PARSER_NOERROR = 0,
|
||||||
//~ TEXOBJ_TABLE,
|
TEX_PARSER_ERROR_UNKNOWN,
|
||||||
//~ TEXOBJ_IMAGE,
|
TEX_PARSER_ERROR_STACK,
|
||||||
//~ } type;
|
TEX_PARSER_ERROR_PLACE_UNKNOWN,
|
||||||
//~ };
|
TEX_PARSER_ERROR_UNEXPECTED_SYMBOL,
|
||||||
//~
|
};
|
||||||
//~ struct tex_tree_s {
|
|
||||||
//~
|
struct tex_struct_s {
|
||||||
//~ };
|
void *tables;
|
||||||
|
void *graphics;
|
||||||
|
};
|
||||||
|
|
||||||
/* LaTeX parser
|
/* LaTeX parser
|
||||||
*/
|
*/
|
||||||
int tex_parse(const char *source, size_t len, struct zerror_s *error);
|
void tex_parse(const char *source, size_t len, struct zerror_s **error);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,19 +29,17 @@ int main(int argc, char *argv[])
|
|||||||
fclose(tex_file);
|
fclose(tex_file);
|
||||||
tex_buf[stat_buf.st_size] = 0;
|
tex_buf[stat_buf.st_size] = 0;
|
||||||
|
|
||||||
struct zerror_s error;
|
struct zerror_s *error;
|
||||||
memset(&error, 0, sizeof(struct zerror_s));
|
|
||||||
|
|
||||||
//~ setlocale(LC_ALL, "ru_RU.KOI8-R");
|
//~ setlocale(LC_ALL, "ru_RU.KOI8-R");
|
||||||
|
|
||||||
/* Коммент по-русски */
|
/* Коммент по-русски */
|
||||||
int result = tex_parse(tex_buf, (size_t)stat_buf.st_size, &error);
|
tex_parse(tex_buf, (size_t)stat_buf.st_size, &error);
|
||||||
|
|
||||||
//~ setlocale(LC_ALL, "");
|
//~ setlocale(LC_ALL, "");
|
||||||
|
|
||||||
if (result) {
|
if (error)
|
||||||
printf("Parsing error at %d, symb=%c: %s\n", error.code + 1, tex_buf[error.code], error.message);
|
puts(error->message);
|
||||||
}
|
|
||||||
|
|
||||||
xclear(&tex_buf);
|
xclear(&tex_buf);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user