int main(){ // Función 2 int cantidadArchivos = 0; char file2[] = "input-strings.txt"; char **archivos = cargarData2(file2,&cantidadArchivos); //Llamar a descomprimir y guardar en otro archivo FILE *fp; fp = fopen("strings-descomprimidos.txt", "w"); if(fp == NULL){ printf("[ERROR] main: No se pudo abrir el archivo strings-descomprimidos.txt \n"); exit(0); } int i2; char *returnString; for (i2 = 0; i2 < cantidadArchivos; ++i2){ returnString = descomprimir(archivos[i2]); printf("[INFO] main: Guardando string\n"); fwrite(returnString, strlen(returnString) * sizeof(char), 1, fp); if(i2 != cantidadArchivos-1){ fwrite("\n", sizeof(char), 1, fp); } if(strcmp(returnString,"El archivo no existe") != 0){ free((void *) returnString); } } fclose(fp); // Funcion 1 int cantidad = 0; char file1[] = "string.txt"; char **strings = cargarData1(file1,&cantidad); pCML(strings, cantidad); free((void *)strings); free((void *)archivos); return 0; }
int main(int argc, char *argv[]) { FILE *fpin, *fpout; struct nodo *raiz; struct tablaCod *tabla; struct header h; u16 v; int verbose=0, benchmark=0; double tiempo; printf("hufc v. 0.2.2 Compress/Expand files using Huffman coding\n"); if (argc < 2) { printf("To see help, write: %s -h\n", argv[0]); exit(0); } // Mostrar la ayuda? if (ExistArg("-h", argc, argv)) { sintaxis(argv[0]); exit(0); } // Modo verbose? if (ExistArg("-v", argc, argv)) verbose=1; // Medir el tiempo de crc o de checksum? if (ExistArg("-b", argc, argv)) benchmark=1; if ((fpin=fopen(argv[1], "rb")) == NULL) { perror("fopen: input file"); exit(1); } // Leer crc o checksum? if (ExistArg("-r", argc, argv)) { if (!isHuf(fpin)) printf("%s: not in huf format!\n", argv[1]); else { switch (leerDetErr(fpin)) { case USE_CCITT: printf("%s: crc = 0x%04X\n", argv[1], readcrcsum(fpin)); break; case USE_CHECKSUM: printf("%s: checksum = 0x%04X\n", argv[1], readcrcsum(fpin)); break; default: printf("%s: error detection not used\n", argv[1]); } } fclose(fpin); exit(0); } // Testear el fichero? if (ExistArg("-t", argc, argv)) { if (!isHuf(fpin)) printf("%s: not in huf format!\n", argv[1]); else { switch (testfile(fpin, leerDetErr(fpin))) { case FILE_OK: printf("%s: seems to be ok\n", argv[1]); break; case FILE_CORRUPTED: printf("%s: file corrupted!\n", argv[1]); break; default: printf("%s: error detection not used\n", argv[1]); } } fclose(fpin); exit(0); } // Descomprimir if (ExistArg("-x", argc, argv)) { if (!isHuf(fpin)) { printf("%s: not in huf format!\n", argv[1]); fclose(fpin); exit(0); } // Testeamos el fichero h.deterr=leerDetErr(fpin); if (testfile(fpin, h.deterr) == FILE_CORRUPTED) { printf("%s: file corrupted!\n", argv[1]); fclose(fpin); exit(0); } raiz=leerCabecera(fpin, &h); fpout=fopen(h.filename, "wb"); if (fpout == NULL) { perror("fopen: output file"); exit(1); } // Le damos al fichero sus permisos originales chmod(h.filename, h.permisos); descomprimir(fpin, fpout, raiz, &h, verbose); } // Comprimir else { if (verbose) { printf("Scanning file (this may take a while)... "); fflush(stdout); } calcularFreq(fpin, &raiz); if (verbose) printf("Done\n"); raiz=crearArbolHuffman(raiz); tabla=crearTablaCod(raiz); if (ExistArg("-ccitt", argc, argv)) h.deterr=USE_CCITT; else if (ExistArg("-sum", argc, argv)) h.deterr=USE_CHECKSUM; else h.deterr=DONT_USE_ERR_DET; setHeaderPermisos(&h, argv[1]); setHeaderFileName(&h, argv[1]); fpout=fopen(getCompressedFileName(&h), "w+b"); if (fpout == NULL) { perror("fopen: output file"); exit(1); } escribirCabecera(fpout, &h, raiz); h.padding_bits=comprimir(fpin, fpout, tabla, verbose); escribirPadding(fpout, h.padding_bits); borrarTablaCod(tabla); fflush(fpout); switch (h.deterr) { case USE_CCITT: if (benchmark) tiempo=gettime(); v=calculacrc(fpout); if (verbose) printf(" crc = 0x%04X\n", v); if (benchmark) printf("crc time: %g s\n", gettime()-tiempo); writecrcsum(fpout, v); break; case USE_CHECKSUM: if (benchmark) tiempo=gettime(); v=calculasum(fpout, COMPRIMIR); if (verbose) printf(" checksum = 0x%04X\n", v); if (benchmark) printf("checksum time: %g s\n", gettime()-tiempo); writecrcsum(fpout, v); break; default: if (verbose) printf("\n"); } } borrarArbolHuffman(raiz); fclose(fpin); fclose(fpout); return 0; }