int main(int argc, char **argv) { int f, x; char fileName[1024]; char *realName; struct stat statBuf; int serr; int rate; int err=0; int compType=1; //default compression type - heatshrink int compLvl=-1; for (x=1; x<argc; x++) { if (strcmp(argv[x], "-c")==0 && argc>=x-2) { compType=atoi(argv[x=1]); x++; } else if (strcmp(argv[x], "-l")==0 && argc>=x-2) { compLvl=atoi(argv[x=1]); if (compLvl<1 || compLvl>9) err=1; x++; } else { err=1; } } if (err) { fprintf(stderr, "%s - Program to create espfs images\n", argv[0]); fprintf(stderr, "Usage: \nfind | %s [-c compressor] [-l compression_level] > out.espfs\n", argv[0]); fprintf(stderr, "Compressors:\n0 - None\n1 - Heatshrink(defautl\n"); fprintf(stderr, "Compression level: 1 is worst but low RAM usage, higher is better compression \nbut uses more ram on decompression. -1 = compressors default.\n"); exit(0); } while(fgets(fileName, sizeof(fileName), stdin)) { //Kill off '\n' at the end fileName[strlen(fileName)-1]=0; //Only include files serr=stat(fileName, &statBuf); if ((serr==0) && S_ISREG(statBuf.st_mode)) { //Strip off './' or '/' madness. realName=fileName; if (fileName[0]=='.') realName++; if (realName[0]=='/') realName++; f=open(fileName, O_RDONLY); if (f>0) { rate=handleFile(f, realName, compType, compLvl); fprintf(stderr, "%s (%d%%)\n", realName, rate); close(f); } else { perror(fileName); } } else { if (serr!=0) { perror(fileName); } } } finishArchive(); return 0; }
int main(int argc, char **argv) { int f, x; char fileName[1024]; char *realName; struct stat statBuf; int serr; int rate; int err=0; int compType; //default compression type - heatshrink int compLvl=-1; #ifdef __MINGW32__ /* Switch to binary mode */ _setmode(_fileno(stdout),_O_BINARY); #endif #ifdef ESPFS_HEATSHRINK compType = COMPRESS_HEATSHRINK; #else compType = COMPRESS_NONE; #endif for (x=1; x<argc; x++) { if (strcmp(argv[x], "-c")==0 && argc>=x-2) { compType=atoi(argv[x+1]); x++; } else if (strcmp(argv[x], "-l")==0 && argc>=x-2) { compLvl=atoi(argv[x+1]); if (compLvl<1 || compLvl>9) err=1; x++; #ifdef ESPFS_GZIP } else if (strcmp(argv[x], "-g")==0 && argc>=x-2) { if (!parseGzipExtensions(argv[x+1])) err=1; x++; #endif } else { err=1; } } #ifdef ESPFS_GZIP if (gzipExtensions == NULL) { parseGzipExtensions(strdup("html,css,js")); } #endif if (err) { fprintf(stderr, "%s - Program to create espfs images\n", argv[0]); fprintf(stderr, "Usage: \nfind | %s [-c compressor] [-l compression_level] ", argv[0]); #ifdef ESPFS_GZIP fprintf(stderr, "[-g gzipped_extensions] "); #endif fprintf(stderr, "> out.espfs\n"); fprintf(stderr, "Compressors:\n"); #ifdef ESPFS_HEATSHRINK fprintf(stderr, "0 - None\n1 - Heatshrink(default)\n"); #else fprintf(stderr, "0 - None(default)\n"); #endif fprintf(stderr, "\nCompression level: 1 is worst but low RAM usage, higher is better compression \nbut uses more ram on decompression. -1 = compressors default.\n"); #ifdef ESPFS_GZIP fprintf(stderr, "\nGzipped extensions: list of comma separated, case sensitive file extensions \nthat will be gzipped. Defaults to 'html,css,js'\n"); #endif exit(0); } while(fgets(fileName, sizeof(fileName), stdin)) { //Kill off '\n' at the end fileName[strlen(fileName)-1]=0; //Only include files serr=stat(fileName, &statBuf); if ((serr==0) && S_ISREG(statBuf.st_mode)) { //Strip off './' or '/' madness. realName=fileName; if (fileName[0]=='.') realName++; if (realName[0]=='/') realName++; f=open(fileName, O_RDONLY); if (f>0) { char *compName = "unknown"; rate=handleFile(f, realName, compType, compLvl, &compName); fprintf(stderr, "%s (%d%%, %s)\n", realName, rate, compName); close(f); } else { perror(fileName); } } else { if (serr!=0) { perror(fileName); } } } finishArchive(); return 0; }