void GatherOutPut_find(FILE *fp) { char *line = NULL; line = (char *)malloc(sizeof(char) * FIND_LINELEN); if(line == NULL) T_ERR("cannot malloc space for line"); fdview = malloc(sizeof(struct Find_view)); fdview->findinfo = (struct fileinfo_find *)malloc(sizeof(struct fileinfo_find)*128); if(fdview->findinfo == NULL) T_ERR("cannot malloc space for fdview"); fdview->lineidx = 0; while(fgets(line,FIND_LINELEN,fp) != NULL) { if(line == NULL) continue; GenerateFileInfo_find(line); fdview->lineidx++; } if(fdview->lineidx == 0){ endwin(); printf("can not get any output from find\n"); quit(1); } Draw_Find_OutPut(); refresh(); free(line); }
static void Kreportf(CTX, int level, kline_t pline, const char *fmt, ...) { if(level == DEBUG_ && !verbose_sugar) return; va_list ap; va_start(ap , fmt); fflush(stdlog); if(pline != 0) { const char *file = SS_t(pline); fprintf(stdlog, " - (%s:%d) %s" , shortfilename(file), (kushort_t)pline, T_ERR(level)); } else { fprintf(stdlog, " - %s" , T_ERR(level)); } vfprintf(stdlog, fmt, ap); fprintf(stdlog, "\n"); va_end(ap); if(level == CRIT_) { kraise(0); } }
void GatherOutPut_ls(FILE *fp) { char *line = NULL; void *new_space; int y = 0, is_expand = 0; char type[32]; char size[32]; line = (char *)malloc(sizeof(char) * LS_LINELEN); if(line == NULL) T_ERR("cannot malloc space for line"); lsview = malloc(sizeof(struct LS_view)); lsview->fileinfo =(struct fileinfo *)malloc(sizeof(struct fileinfo) * 128); if(lsview->fileinfo == NULL) T_ERR("cannot malloc space for lsview"); lsview->fileno = 0; while(fgets(line,LS_LINELEN,fp) != NULL) { if(y == 0){ /*ignore the total line*/ y++; continue; } GenerateFileInfo(line); lsview->fileno++; if(is_expand == 0 && lsview->fileno > 128) { new_space = realloc(lsview->fileinfo, sizeof(struct fileinfo) * 128); if(new_space == NULL) T_ERR("cannot realloc more space for lsview"); lsview->fileinfo =(struct fileinfo *) new_space; is_expand = 1; } } /*when all the input is saved into*/ Draw_LS_OutPut(); refresh(); }
/** * this function is to show the ls * default order into ncurses * */ void RenderLs_dft(void) { FILE *pipe_ls; char *lines; pipe_ls = popen(LS_DEFAULT,"r"); if(pipe_ls == NULL) T_ERR("can't not open the pipe for ls"); GatherOutPut_ls(pipe_ls); pclose(pipe_ls); }
int main(int argc,char **argv) { FILE *fp; char ch; enum request request; request = REQ_VIEW_MAIN; fp = fopen("config","r+"); if(fp == NULL) T_ERR("cannot read the file config!\nplease checkout the file is exist\n"); argvs = argv; load_command(fp); fclose(fp); convert_command(); command_type = parser_option(argc, argv); if(command_type == -1) exit(1); g_current = 0; g_change = 0; #if CURSES_MOD == 1 Init_Screen(); mvwaddstr(stdscr,LINES/2,COLS/2,"Loading......"); #endif #if CURSES_MOD == 1 while(view_control(request)) { ch = wgetch(status_win); request = get_request(ch); } #endif #if CURSES_MOD == 1 getch(); #endif #if CURSES_MOD == 1 quit(0); #endif return 0; }
void RenderFind(void) { FILE *pipe_find; char cmd[BUFSIZ]; /** * we will create the commad according * the find_type * */ switch(find_type){ case FIND_DEFAULT: sprintf(cmd,fc[FIND_DEFAULT].command,argvs[2]); break; case FIND_WITH_DEPTH_MAX: sprintf(cmd,fc[FIND_WITH_DEPTH_MAX].command,level,argvs[3]); break; case FIND_WITH_DEPTH_MIN: sprintf(cmd,fc[FIND_WITH_DEPTH_MIN].command,level,argvs[3]); break; case FIND_WITH_TYPE: sprintf(cmd,fc[FIND_WITH_TYPE].command,argvs[2],argvs[3]); break; case FIND_WITH_PATH: sprintf(cmd,fc[FIND_WITH_PATH].command,argvs[2],argvs[3]); break; case FIND_FULL: sprintf(cmd,fc[FIND_FULL].command,argvs[2],argvs[3],argvs[4]); break; default: printf("cannot show the result in curses\n may your input error\n"); break; } pipe_find = popen(cmd,"r"); if(pipe_find == NULL) T_ERR("can not open the pipe for find"); GatherOutPut_find(pipe_find); pclose(pipe_find); }