int main(int c, char **v) { FILE * file = fopen(v[1],"rb"); int fileLen = fseek(file,0,SEEK_END); fileLen = ftell(file); rewind(file); //printf("%s,%d\n",filename,fileLen); char * data = malloc(fileLen); if(data==NULL) { fclose(file); return -1; } fread(data,1,fileLen,file); fclose(file); int outlen=0; char * out = chm_parse(data,fileLen,v[2],&outlen); //char * out = chm_parse(data,fileLen,NULL,&outlen); if(out && outlen>0) { printf("%s",out); free(out); out = NULL; } return 0; }
static bool extract_fd(const char* path, const char* base_path) { fd_reader_ctx ctx; if (!fd_reader_init(&ctx, path)) { fprintf(stderr, "failed to open %s\n", path); return false; } chm_file f; bool ok = chm_parse(&f, fd_reader, &ctx); if (!ok) { fprintf(stderr, "chm_parse() failed\n"); fd_reader_close(&ctx); return false; } printf("%s:\n", path); ok = extract(&f, base_path); chm_close(&f); fd_reader_close(&ctx); return ok; }