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