⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file.c

📁 minicom2.0源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	if(*new_dir == '/')	    strncpy(work_dir, new_dir, min_len);	else	    snprintf(work_dir, min_len, "%s/%s", homedir, new_dir);    }    new_filedir(dirdat, 1);}/* * Initialize the file directory. */static intinit_filedir(){    int x1, x2;    int retstat = -1;    dirflush = 0;    x1 = (COLS / 2) - 37;    x2 = (COLS / 2) + 37;    dsub = wopen(x1 - 1, LINES - 3, x2 + 1, LINES - 3, BNONE, 	stdattr, mfcolor, mbcolor, 0, 0, 1);    main_w = wopen(x1, 2, x2, LINES - 6, BSINGLE, stdattr, mfcolor,	mbcolor, 0, 0, 1);    if(ret_buf != NULL ||      (retstat = ((ret_buf = (char *)malloc(BUFSIZ)) == NULL)? -1 : 0) == 0) {	retstat = new_filedir((GETSDIR_ENTRY *) NULL, 0);	dirflush = 1;	wredraw(dsub, 1);    }    return(retstat);}static inttag_untag(pat, tag)char *pat;int tag;{    GETSDIR_ENTRY *my_d = dirdat;    int indxr, cntr;    for(indxr = nrents, cntr = 0; indxr; --indxr, ++my_d)	if(S_ISREG(my_d->mode) && wildmat(my_d->fname, pat)) {	    if(tag) {		my_d->cflags |= FL_TAG;		++cntr;	    }	    else if(my_d->cflags & FL_TAG) {		my_d->cflags &= ~FL_TAG;		++cntr;	    }	}    return(cntr);}/* * concatenate tagged files into a buffer */static char *concat_list(d)GETSDIR_ENTRY *d;{    GETSDIR_ENTRY *my_d;    int indxr, len;    my_d = d;    for(indxr = nrents, len = 0; indxr; --indxr, ++my_d)	if(my_d->cflags & FL_TAG)	    len += strlen(my_d->fname) + 1;    if(len) {	if(len > BUFSIZ) {	  if((ret_buf = (char *)realloc(ret_buf, len)) == NULL) {	      file_tell(_("Too many files tagged - buffer would overflow"));	      return(NULL);	  }	}	    	*ret_buf = (char) 0;	my_d = d;	for(indxr = nrents; indxr; --indxr, ++my_d)	    if(my_d->cflags & FL_TAG) {		/* this could be *much* more efficient */		strcat(ret_buf, my_d->fname);		strcat(ret_buf, " ");	    }	ret_buf[strlen(ret_buf) - 1] = (char) 0;	return(ret_buf);    }    return(NULL);}/* * Draw the file directory. * *      howmany - How many files can be selected *		      0 = none (for directory selection only, as in "rz") *		      1 = one  (for single-file up-/down-loads, as in "rx") *		     -1 = any number (for multiple files, as in "sz") * *    downloading - Is this for download selection? *		      0 = no *		      1 = yes - when single file selected, see if it exists */char *filedir(howmany, downloading)int howmany;int downloading;{    time_t click_time = (time_t) 0;    how_many = howmany;    down_loading = downloading;    init_filedir();again:    wlocate(main_w, 0, cur + FILE_MWTR - top);    if(first) {	wredraw(main_w, 1);	first = 0;    }    while(!quit) {	d = getno(cur, dirdat);	/*	if(S_ISDIR(d->mode))	    prone(main_w, top, top, d, longest, 0);		*/	switch(c = wxgetch()) {	    case K_UP:	    case 'k':		/*		if(S_ISDIR(d->mode))		    prone(main_w, top, top, d, longest, 1);			*/		cur -= (cur > 0);		break;	    case K_DN:	    case 'j':		/*		if(S_ISDIR(d->mode))		    prone(main_w, top, top, d, longest, 1);			*/		cur += (cur < nrents - 1);		break;	    case K_LT:	    case 'h':		subm--;		if(subm < 0)		    subm = SUBM_OKAY;		break;	    case K_RT:	    case 'l':		subm = (subm + 1) % 6;		break;	    case K_PGUP:	    case '\002': /* Control-B */		pgud = 1;		quit = 1;		break;		    case K_PGDN:	    case '\006': /* Control-F */		pgud = 2;		quit = 1;		break;		    case 'f':    /* Find. */		subm = 1;		quit = 1;		break;	    case ' ':    /* Tag if not directory */		if(S_ISDIR(d->mode)) {		    time_t this_time = time((time_t *) NULL);		    if(this_time - click_time < 2) {			GETSDIR_ENTRY *d2 = getno(cur, dirdat);			goto_filedir(d2->fname, 0);			click_time = (time_t) 0;		    }		    else			click_time = this_time;		}		else {		    if(how_many) {			if((d->cflags ^= FL_TAG) & FL_TAG) {			    if(tag_cnt && how_many == 1) {				d->cflags &= ~FL_TAG;				file_tell(_("Can select only one!"));				break;			    }			    ++tag_cnt;			}			else			    --tag_cnt;			wlocate(main_w, 0, cur + FILE_MWTR - top);			prone(main_w, top, top, d, longest, d->cflags & FL_TAG);				wputc(main_w, '\n');			cur += (cur < nrents - 1);		    }		}		break;	    case 'G':	    case 'g':		subm = 0;		goto real_programmers_use_gotos;		break;	    case 'P':	    case 'p':		subm = 1;		goto real_programmers_use_gotos;		break;	    case 'S':	    case 's':		subm = 2;		goto real_programmers_use_gotos;		break;	    case 'T':	    case 't':		subm = 3;		goto real_programmers_use_gotos;		break;	    case 'U':	    case 'u':		subm = 4;		goto real_programmers_use_gotos;		break;	    case 'O':	    case 'o':		subm = SUBM_OKAY;real_programmers_use_gotos:		c = '\n';		quit = 1;		break;	    case '\033':	    case '\r':	    case '\n':		quit = 1;		break;	    default:		break;	}	if(c != ' ')	    click_time = (time_t) 0;	if(cur < top) {	    top--;	    prdir(main_w, top, top, dirdat, longest);		}	if(cur - top > main_w->ys - (2 + FILE_MWTR)) {	    top++;	    prdir(main_w, top, top, dirdat, longest);	}	/*	if(cur != ocur)	    wlocate(main_w, 0, cur + FILE_MWTR - top);	 */	ocur = cur;	dhili(subm);	/* this really needs to go in dhili !!!*/	wlocate(main_w, 0, cur + FILE_MWTR - top);    }    quit = 0;    /* ESC means quit */    if(c == '\033') {	wclose(main_w, 1);	wclose(dsub, 1);	free(dirdat);	return(NULL);    }    /* Page up or down ? */    if(pgud == 1) { /* Page up */	ocur = top;	top -= main_w->ys - (1 + FILE_MWTR);	if(top < 0)	    top = 0;	cur = top;	pgud = 0;	if(ocur != top)	    prdir(main_w, top, cur, dirdat, longest);	ocur = cur;	goto again;    }    if(pgud == 2) { /* Page down */	ocur = top;	if(top < nrents - main_w->ys + (1 + FILE_MWTR)) {	    top += main_w->ys - (1 + FILE_MWTR);	    if(top > nrents - main_w->ys + (1 + FILE_MWTR)) {		top = nrents - main_w->ys + (1 + FILE_MWTR);	    }	    cur = top;	} else	    cur = nrents - 1;	pgud = 0;	if(ocur != top)	    prdir(main_w, top, cur, dirdat, longest);	ocur = cur;	goto again;    }    if(c =='\r' || c == '\n') {	switch(subm) {	    case 0:		/* Goto directory */		{		    char buf[128];		    char *s;		    strncpy(buf, down_loading? P_DOWNDIR : P_UPDIR,			sizeof(buf) -1);		    s = input(_("Goto directory:"), buf);/*		    if(s == CNULL || *s == (char) 0) */		    if(s == CNULL)			break;		    goto_filedir(buf, 1);		}		break;	    case 1:		/* Previous directory */		goto_filedir(prev_dir, 1);		break;	    case 2:		/* File (wildcard) spec */		{		    char *s = input(_("Filename pattern:"), wc_mem);		    if(s == CNULL || *s == (char) 0)			break;		    strcpy(wc_str, wc_mem);		    new_filedir(dirdat, 1);		    wc_str[0] = (char) 0;		}		break;	    case 3:		/* Tag */		if(how_many == 1)		    file_tell(_("Can select only one!"));		else if(how_many == -1) {		    char tag_buf[128];		    char *s;		    strncpy(tag_buf, wc_mem, 128);		    		    s = input(_("Tag pattern:"), tag_buf);		    if(s != CNULL && *s != (char) 0) {			int newly_tagged;			if((newly_tagged = tag_untag(tag_buf, 1)) == 0) {			    file_tell(_("No file(s) tagged"));			    goto tag_end;			}			tag_cnt += newly_tagged;			prdir(main_w, top, top, dirdat, longest);  		    }		}tag_end:		break;	    case 4:		/* Untag */		{		    char tag_buf[128];		    char *s;		    int untagged;		    strncpy(tag_buf, wc_mem, 128);		    		    s = input(_("Untag pattern:"), tag_buf);		    if(s == CNULL || *s == (char) 0)			goto untag_end;		    if((untagged = tag_untag(tag_buf, 0)) == 0) {			file_tell(_("No file(s) untagged"));			goto untag_end;		    }		    tag_cnt -= untagged;		    prdir(main_w, top, top, dirdat, longest);  		}untag_end:		break;	    case 5:		{		  /* Done */		  char *ret_ptr = NULL;	/* failsafe: assume failure */		  if(how_many != 0 && !tag_cnt) {		    while(1) {		      s = input(_("No file selected - enter filename:"),				ret_buf);		      if(s != CNULL && *s != (char) 0) {			int f_exist = access(ret_buf, F_OK);			if(down_loading) {			  if(f_exist != -1) {			    /* ask 'em if they're *sure* */			    char buf[BUFSIZ];			    snprintf(buf, sizeof(buf), 				    _("File: \"%s\" exists!. Over-write?"),				    ret_buf);			    if(ask(buf, d_yesno) == 0) {			      ret_ptr = ret_buf;			      break;			    }			  }			  else {			    ret_ptr = ret_buf;			    break;			  }			}			else {			  if(f_exist == -1)			    file_tell(_("no such file!"));			  else {			    ret_ptr = ret_buf;			    break;			  }			}		      }		      else {				/* maybe want to ask: "abort?", here */			goto again;		      }		    }		  }		  else {		    /* put 'em in a buffer for return */		    if(how_many == 0) {		      /* current working directory */		      ret_ptr = work_dir;		    }		    else {		      ret_ptr = concat_list(dirdat);		    }		  }		  wclose(main_w, 1);		  wclose(dsub, 1);		  free(dirdat);		  return(ret_ptr);		}		break;	    default:		/* should "beep", I guess (? shouldn't get here) */		file_tell("BEEP!");		break;	} /* switch */    }    goto again;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -