00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <fcntl.h>
00004 #include <sys/types.h>
00005 #include <sys/stat.h>
00006 #include <unistd.h>
00007 #include <string.h>
00008 #include <errno.h>
00009 #include <math.h>
00010
00011 int main(int, char *[])
00012 {
00013 struct stat statbuff;
00014
00015 int ret;
00016
00017 ret = stat("map.bin", &statbuff);
00018 if(ret == -1) {
00019 printf("Can't stat file map.bin (%s)\n", strerror(errno));
00020 return 0;
00021 }
00022
00023 int sz = statbuff.st_size;
00024 uint *buff = (uint *)malloc(sz);
00025 float *fbuff = (float *)buff;
00026 char *cbuff = (char *)buff;
00027
00028 if(!buff) {
00029 printf("Can't allocate %d bytes\n",sz);
00030 return 0;
00031 }
00032
00033 int fd = open("map.bin", O_RDONLY);
00034 if(fd == -1) {
00035 printf("Can't open file map.bin (%s)\n", strerror(errno));
00036 return 0;
00037 }
00038
00039 ret = read(fd, buff, sz);
00040 if(sz != ret) {
00041 printf("Only read %d of %d bytes\n",ret,sz);
00042 return 0;
00043 }
00044
00045 close(fd);
00046
00047 printf("#define MAPDOTBINFILE_SZ %d\n", sz);
00048 printf("u_int mapdotbinfile[%d] = {\n", sz/4);
00049
00050 for(int i=0;i<sz/4;i++) {
00051 printf("0x%08x, ", buff[i]);
00052 if( ((i+1) % 10) == 0) printf("\n");
00053 }
00054
00055 printf("};\n");
00056
00057 free(buff);
00058 }