char *check_single_match_multi(char **folder, char *to_find, int i, int nbr) { char *matchs; DIR *dir; struct dirent *dirent; matchs = NULL; while (folder[i]) { if ((dir = opendir(folder[i++])) != NULL) { while ((dirent = readdir(dir)) != NULL) { if (beggin_match(dirent->d_name, to_find)) { if (!match(matchs, dirent->d_name)) nbr++; if ((matchs = my_strdup(dirent->d_name)) == NULL) return (my_errors("Strdup : error\n", NULL)); } } if (closedir(dir) != 0) my_errors("Closedir : error\n", NULL); } } return (((nbr == 1) ? matchs : check_special_single_match_multi(folder, to_find, 0, 0))); }
char *check_special_single_match_multi(char **folder, char *to_find, int i, int nbr) { DIR *dir; char *match; struct dirent *dirent; nbr = 0; i = 0; while (folder[i]) { if ((dir = opendir(folder[i++])) == NULL) return (NULL); while ((dirent = readdir(dir)) != NULL) { if (hidden_match(dirent->d_name, to_find)) { if ((match = my_strdup(dirent->d_name)) == NULL) return (my_errors("Strdup : error\n", NULL)); nbr++; } } if (closedir(dir) != 0) my_errors("Closedir : error\n", NULL); } return ((nbr == 1) ? match : NULL); }
char *my_clear(char *term) { char *str; char *term_buffer; term_buffer = NULL; if (tgetent(term_buffer, term) != 1) return (my_errors("\nTgetent : error. Could not clear\n", NULL)); if ((str = tgetstr("cl", NULL)) == NULL) return (my_errors("\nTgetstr : error. Could not clear\n", NULL)); tputs(str, 1, &my_putchar_int); return (NULL); }
char *check_other_match_multi(char **folder, char *to_find) { int i; int j; int key; char *match; char **matchs; if ((matchs = (get_multi_match_multi(folder, to_find, 1, 0))) == NULL) return (NULL); if ((match = malloc((biggest_in_tab(matchs) + 5) * sizeof(char))) == NULL) return (my_errors("Malloc : error\n", NULL)); i = 0; key = 0; while (!key) { j = 0; while (matchs[j] && matchs[j][i] == matchs[0][i]) j++; key = (matchs[j]) ? 1 : 0; match[i] = (matchs[j]) ? '\0' : matchs[0][i]; i = (matchs[j]) ? i : i + 1; } return ((i <= my_strlen(to_find)) ? NULL : match); }
void my_next(t_tools tool, t_list **list, int buff) { struct winsize argp; struct termios tmp; tmp.c_iflag = 0; if (ioctl (0, TIOCGWINSZ, &argp) == -1) { my_restore(tool, tmp); my_errors("Ioctl : error\n", NULL); } my_left(tool, list, buff, argp); my_right(tool, list, buff, argp); }
int main(int ac, char **av) { t_bsq_params params; int y; int x; int fd; my_errors(ac, av[1]); fd = open(av[1], O_RDONLY); if (fd == -1) { my_putstr_errors("Error: File not found.\n"); exit(84); } y = get_fnb(fd); x = first_line(fd); close(fd); fd = open(av[1], O_RDONLY); get_fnb(fd); my_bsq(params, x, y, fd, av[1]); return (0); }
/** * Na ausência do ficheiro de destino, gera o seu nome como: * :: Na realização da compressão * ficheiro_origem.DEFAULT_EXT_NAME (.z) * :: Na realização da descompressão * ficheiro_origem.SEM DEFAULT_EXT_NAME (sem .z) * * No Caso da extensão não ser conhecida não realiza a operação. * */ unsigned int newOutputFile(struct cmdLnArgs *myargs, char *outputfile){ int sizeOfExt=0; int equal=0; sizeOfExt=(myargs->action == compress_action)?strlen(myargs->source)+strlen(DEFAULT_EXT_NAME):strlen(myargs->source)-strlen(DEFAULT_EXT_NAME); outputfile=(char *)malloc(sizeof(char)*(sizeOfExt)); if (outputfile == NULL){ my_errors(Z_MEM_ERROR); return false; } if (myargs->action == compress_action){ myargs->destination=strcpy(outputfile,myargs->source); myargs->destination=strcat(outputfile,DEFAULT_EXT_NAME); }else{ equal=strcmp(&(myargs->source[sizeOfExt]),DEFAULT_EXT_NAME); if(equal){ my_cmdErrors(CMD_INVALID_EXT); return false; } myargs->destination=strncpy(outputfile,myargs->source,sizeOfExt); } return true; }
int main(int argc, char **argv) { int ret=0; myArgs myargs; myFilter myfilter; header fhp; char * outputfile=0; FILE *sourceFile; FILE *destinationFile; if(argc == 1){ progUsage(argv[0]); return UNSUCCESS; } init_Args(&myargs); ret=parseArgs(&myargs,argc,argv); if (ret == false) { progUsage(argv[0]); return UNSUCCESS; } if (myargs.destination == NULL){ ret=newOutputFile(&myargs,outputfile); if (ret == false){ return UNSUCCESS; } myargs.destParsed=true; } /** * Recolher dados para a operacao de filtragem **/ myfilter.sourceName=myargs.source; myfilter.type=myargs.filter; if (myargs.action == compress_action){ myfilter.nbrChars=processFileHeader(myfilter.sourceName,&fhp); myfilter.bpp=(fhp.magicValue>3 ? 3:1); myfilter.lineSize=fhp.imageWidth*myfilter.bpp; myfilter.firstLine=true; } /** * Processamento do ficheiro **/ sourceFile=fopen(myargs.source,"rb"); destinationFile=fopen(myargs.destination,"wr"); SET_BINARY_MODE(sourceFile); SET_BINARY_MODE(destinationFile); printf("Processing file: %s into %s ...", myargs.source,myargs.destination); if (myargs.action == compress_action){ ret = my_compress(sourceFile,destinationFile, myargs.compressLevel, myfilter); }else{ ret = my_decompress(sourceFile, destinationFile, myfilter); } if (ret != Z_OK){ printf("--- ::: ERROR. File not processed!\n"); my_errors(ret); if(myargs.destParsed){ cleanNewFileName(outputfile); } return UNSUCCESS; } printf(" ::: DONE File successufly processed!\n"); if(myargs.destParsed){ cleanNewFileName(outputfile); } return ret; }