00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <sys/stat.h>
00013 #include <unistd.h>
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <MTNFile.h>
00017
00018 main(int argc, char** argv)
00019 {
00020 if (argc != 2) {
00021 fprintf(stderr, "Usage: mtnfile file.mtn\n");
00022 exit(1);
00023 }
00024
00025 struct stat st;
00026 if (stat(argv[1], &st) != 0) {
00027 perror("stat");
00028 exit(1);
00029 }
00030
00031 MTNFile* mtnfile = (MTNFile*)malloc(st.st_size);
00032 if (mtnfile == 0) {
00033 fprintf(stderr, "malloc() failed.\n");
00034 exit(1);
00035 }
00036
00037 FILE* fp = fopen(argv[1], "rb");
00038 if (fp == 0) {
00039 fprintf(stderr, "can't open %s\n", argv[1]);
00040 exit(1);
00041 }
00042
00043 if (fread((void*)mtnfile, 1, st.st_size, fp) != st.st_size) {
00044 fprintf(stderr, "fread() failed.\n");
00045 fclose(fp);
00046 exit(1);
00047 }
00048
00049 fclose(fp);
00050
00051 mtnfile->Print();
00052 }