2011-06-07 19:08:15 +04:00
|
|
|
#include <sys/stat.h>
|
2011-06-10 14:31:10 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
2011-06-07 19:08:15 +04:00
|
|
|
|
2011-06-10 14:31:10 +04:00
|
|
|
#include "tex_table.h"
|
|
|
|
#include "zmalloc.h"
|
2011-06-07 19:08:15 +04:00
|
|
|
#include "xmalloc.h"
|
2011-06-08 11:29:05 +04:00
|
|
|
#include "xerror.h"
|
2011-06-07 19:08:15 +04:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2011-06-08 13:24:34 +04:00
|
|
|
if (argc != 2)
|
2011-06-10 14:31:10 +04:00
|
|
|
xerrx(-1, "Usage: ./tex_table_test /path/to/table.tex", NULL);
|
2011-06-07 19:08:15 +04:00
|
|
|
|
|
|
|
FILE *tex_file = fopen(argv[1], "rb");
|
|
|
|
if (!tex_file)
|
2011-06-08 13:24:34 +04:00
|
|
|
xerr(errno, "Cannot open %s", argv[1]);
|
2011-06-07 19:08:15 +04:00
|
|
|
|
|
|
|
struct stat stat_buf;
|
2011-06-08 13:24:34 +04:00
|
|
|
if (fstat(fileno(tex_file), &stat_buf) == -1)
|
|
|
|
xerr(errno, "Cannot stat %s", argv[1]);
|
2011-06-07 19:08:15 +04:00
|
|
|
|
|
|
|
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)
|
2011-06-08 13:24:34 +04:00
|
|
|
xerrx(errno, "Error reading %s", argv[1]);
|
2011-06-10 14:31:10 +04:00
|
|
|
fclose(tex_file);
|
2011-06-07 19:08:15 +04:00
|
|
|
tex_buf[stat_buf.st_size] = 0;
|
|
|
|
|
2011-06-08 15:13:26 +04:00
|
|
|
struct xerror_s error;
|
2011-06-10 14:31:10 +04:00
|
|
|
struct table_s table;
|
|
|
|
parse_table(tex_buf, (size_t)stat_buf.st_size, &table, &error);
|
2011-06-08 15:13:26 +04:00
|
|
|
|
2011-06-10 14:31:10 +04:00
|
|
|
xfree(&tex_buf);
|
2011-06-07 19:08:15 +04:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|