/* * This function is used to split ls output * into filename type and size. * */ void GenerateFileInfo(char *line) { char *buf = line; char *outptr = NULL; char *res[1]; char *name = NULL; int i = 0; //res = malloc(sizeof(char) * 128); /*first step is to get the finename*/ while((res[0] = strtok_r(buf," ",&outptr)) != NULL) { buf = NULL; if(i == 4){ strcpy(lsview->fileinfo[lsview->fileno].size,res[0]); lsview->fileinfo[lsview->fileno].size[strlen(res[0])]='K'; lsview->fileinfo[lsview->fileno].size[strlen(res[0])+1] = '\0'; } if(i == 8){ right_trim(res[0]); strcpy(lsview->fileinfo[lsview->fileno].name,res[0]); lsview->fileinfo[lsview->fileno].name[strlen(res[0])] = '\0'; } i++; } name = lsview->fileinfo[lsview->fileno].name; /*second get the filetype */ GatherFileType(name,lsview->fileinfo[lsview->fileno].type); }
void GenerateFileInfo_find(char *line) { //assert(line == NULL); char *buf; int linelen, pathlen; linelen = strlen(line); buf = strrchr(line,'/'); strcpy(fdview->findinfo[fdview->lineidx].name,buf+1); pathlen = linelen - strlen(buf); strncpy(fdview->findinfo[fdview->lineidx].path,line,pathlen); right_trim(line); GatherFileType(line,fdview->findinfo[fdview->lineidx].type); }