dev/cpp/tex_parser/tex_table_class_test.cpp

37 lines
829 B
C++

#include <stdio.h>
#include <cstdlib>
#include <sys/stat.h>
#include <errno.h>
//~ #include <iostream>
//~ #include <sys/types.h>
//~ #include <unistd.h>
#include "xmalloc.h"
#include "xerror.h"
using namespace std;
int main(int argc, char *argv[])
{
if (argc != 2)
xerrx(-1, "Usage: ./tex_table_class_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]);
tex_buf[stat_buf.st_size] = 0;
fclose(tex_file);
return EXIT_SUCCESS;
}