dev/c/tex_parser/tex_table_test.c
Kolan Sh 0f3ecd8e70 no c++ just c
--HG--
rename : c/tex_parser/tex_table_class.cpp => c/tex_parser/tex_table.c
rename : c/tex_parser/tex_table_class.geany => c/tex_parser/tex_table.geany
rename : c/tex_parser/tex_table_class.hpp => c/tex_parser/tex_table.h
rename : c/tex_parser/tex_table_class_tags.hpp => c/tex_parser/tex_table_tags.h
rename : c/tex_parser/tex_table_class_test.cpp => c/tex_parser/tex_table_test.c
2011-06-10 14:31:10 +04:00

38 lines
901 B
C

#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include "tex_table.h"
#include "zmalloc.h"
#include "xmalloc.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(errno, "Error reading %s", argv[1]);
fclose(tex_file);
tex_buf[stat_buf.st_size] = 0;
struct xerror_s error;
struct table_s table;
parse_table(tex_buf, (size_t)stat_buf.st_size, &table, &error);
xfree(&tex_buf);
return EXIT_SUCCESS;
}