dev/c/tex_parser/tex_parser_test.c

52 lines
1.2 KiB
C

#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#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_parser_test /path/to/example.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 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, &tex_struct, &error);
//~ setlocale(LC_ALL, "");
if (error)
puts(error->message);
xclear(&tex_buf);
return EXIT_SUCCESS;
}