t_shape *is_valid_shape(char *s) { t_shape *tmp; tmp = NULL; if ((tmp = is_i(s)) != NULL) return (tmp); if ((tmp = is_o(s)) != NULL) return (tmp); if ((tmp = is_t(s)) != NULL) return (tmp); if ((tmp = is_l(s)) != NULL) return (tmp); if ((tmp = is_j(s)) != NULL) return (tmp); if ((tmp = is_z(s)) != NULL) return (tmp); if ((tmp = is_s(s)) != NULL) return (tmp); return (NULL); }
int print_output(char **output, int i, char **argv, int argc) { //stat files struct stat buf; int exists; int x; for(x = 0; x < i; x++) { exists = stat(output[x], &buf); if (exists < 0) { fprintf(stderr, "%s not found\n", output[x]); } else { ////////////get the argument int arge = find_arg_element(argv, argc); char* ls_arg; ls_arg = (char*)malloc(MAX_BUFFER_SIZE); if(arge != -1) ls_arg = strdup(argv[arge]); else ls_arg = ""; /////////////filter arguments // l option char *l_opt; l_opt = (char*)malloc(MAX_BUFFER_SIZE); if(str_index(ls_arg, "l") != -1) { //convert stat's date time_t rawtime = buf.st_mtime; char *date = ctime(&rawtime); //get rid of end newline date[strlen(date) - 1] = '\0'; int read, write, execute; read = buf.st_mode & S_IEXEC; read = (int)read; //read = sqrt(read) - 1; sprintf(l_opt, "%4d %d %d %4d %5d %s", buf.st_mode, buf.st_nlink, buf.st_uid, buf.st_gid, buf.st_size, date); } else {l_opt = "";} // t option char *t_opt; t_opt = (char*)malloc(MAX_BUFFER_SIZE); if(str_index(ls_arg, "t") != -1) { //convert stat's date time_t rawtime = buf.st_mtime; char *date = ctime(&rawtime); //get rid of end newline date[strlen(date) - 1] = '\0'; sprintf(t_opt, "%s", date); } else {t_opt = "";} // f option char *f_opt; f_opt = (char*)malloc(MAX_BUFFER_SIZE); if(str_index(ls_arg, "f") != -1) { //open file and see what its first bits look like FILE *fp; fp = fopen(output[x], "r"); char line [MAX_BUFFER_SIZE]; if(fp != NULL) { if(fgets(line, sizeof(line), fp ) != NULL) { //fputs ( line, stdout ); //print_ts_str(line); if(is_o(output[x]) == 1) f_opt = " - Relocatable .o file"; else if(is_elf(line) == 1) f_opt = " - ELF File"; else if(is_dos(fp) == 1) f_opt = " - ASCII File"; else if(is_ascii(fp) == 1) f_opt = " - ASCII File"; else f_opt = " - file unknow"; } else f_opt = " - directory"; } fclose(fp); } else {f_opt = "";} //print formatted text printf("%s %s %10s %s\n", t_opt, l_opt, output[x], f_opt); } } return(0); }