dev/c/tex_parser/tex_parser_test.c

49 lines
1.2 KiB
C
Raw Normal View History

#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
2011-06-20 20:07:17 +04:00
#include <string.h>
//~ #include <locale.h>
#include "tex_parser.h"
#include "zalloc.h"
#include "xalloc.h"
#include "xerror.h"
int main(int argc, char *argv[])
{
if (argc != 2)
xerrx(-1, "Usage: ./tex_table_test /path/to/table.tex", NULL);
FILE *tex_file = fopen(argv[1], "rb");
if (!tex_file)
xerr(errno, "Cannot open %s", argv[1]);
struct stat stat_buf;
if (fstat(fileno(tex_file), &stat_buf) == -1)
xerr(errno, "Cannot stat %s", argv[1]);
char *tex_buf = (char *)xmalloc((size_t)stat_buf.st_size + 1);
if (fread(tex_buf, 1, (size_t)stat_buf.st_size, tex_file) != (size_t)stat_buf.st_size)
xerrx(-1, "Error reading %s", argv[1]);
fclose(tex_file);
tex_buf[stat_buf.st_size] = 0;
struct xerror_s error;
struct table_s table;
2011-06-20 20:07:17 +04:00
memset(&table, 0, sizeof(struct table_s));
2011-06-27 14:43:41 +04:00
memset(&error, 0, sizeof(struct xerror_s));
//~ setlocale(LC_ALL, "ru_RU.KOI8-R");
/* Коммент по-русски */
2011-06-23 19:44:22 +04:00
int result = parse_table(tex_buf, (size_t)stat_buf.st_size, &table, &error);
if (result) {
2011-06-27 14:43:41 +04:00
printf("Parsing error at %d, symb=%c: %s\n", error.code + 1, tex_buf[error.code], error.message);
2011-06-23 19:44:22 +04:00
}
2011-06-20 17:24:43 +04:00
tex_buf = xfree_null(tex_buf);
return EXIT_SUCCESS;
}