您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ F_CLR函数代码示例

51自学网 2021-06-01 20:45:28
  C++
这篇教程C++ F_CLR函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中F_CLR函数的典型用法代码示例。如果您正苦于以下问题:C++ F_CLR函数的具体用法?C++ F_CLR怎么用?C++ F_CLR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了F_CLR函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: __rec_open

//.........这里部分代码省略.........		 * and check the errno values.		 */		errno = 0;		if (lseek(rfd, (off_t)0, SEEK_CUR) == -1 && errno == ESPIPE) {			switch (flags & O_ACCMODE) {			case O_RDONLY:				F_SET(t, R_RDONLY);				break;			default:				goto einval;			}slow:			if ((t->bt_rfp = fdopen(rfd, "r")) == NULL)				goto err;			F_SET(t, R_CLOSEFP);			t->bt_irec =			    F_ISSET(t, R_FIXLEN) ? __rec_fpipe : __rec_vpipe;		} else {			switch (flags & O_ACCMODE) {			case O_RDONLY:				F_SET(t, R_RDONLY);				break;			case O_RDWR:				break;			default:				goto einval;			}			if (fstat(rfd, &sb))				goto err;			/*			 * Kluge -- we'd like to test to see if the file is too			 * big to mmap.  Since, we don't know what size or type			 * off_t's or size_t's are, what the largest unsigned			 * integral type is, or what random insanity the local			 * C compiler will perpetrate, doing the comparison in			 * a portable way is flatly impossible.  Hope that mmap			 * fails if the file is too large.			 */			if (sb.st_size == 0)				F_SET(t, R_EOF);			else {#ifdef MMAP_NOT_AVAILABLE				/*				 * XXX				 * Mmap doesn't work correctly on many current				 * systems.  In particular, it can fail subtly,				 * with cache coherency problems.  Don't use it				 * for now.				 */				t->bt_msize = sb.st_size;				if ((t->bt_smap = mmap(NULL, t->bt_msize,				    PROT_READ, MAP_FILE | MAP_PRIVATE, rfd,				    (off_t)0)) == (caddr_t)-1)					goto slow;				t->bt_cmap = t->bt_smap;				t->bt_emap = t->bt_smap + sb.st_size;				t->bt_irec = F_ISSET(t, R_FIXLEN) ?				    __rec_fmap : __rec_vmap;				F_SET(t, R_MEMMAPPED);#else				goto slow;#endif			}		}	}	/* Use the recno routines. */	dbp->close = __rec_close;	dbp->del = __rec_delete;	dbp->fd = __rec_fd;	dbp->get = __rec_get;	dbp->put = __rec_put;	dbp->seq = __rec_seq;	dbp->sync = __rec_sync;	/* If the root page was created, reset the flags. */	if ((h = mpool_get(t->bt_mp, P_ROOT, 0)) == NULL)		goto err;	if ((h->flags & P_TYPE) == P_BLEAF) {		F_CLR(h, P_TYPE);		F_SET(h, P_RLEAF);		mpool_put(t->bt_mp, h, MPOOL_DIRTY);	} else		mpool_put(t->bt_mp, h, 0);	if (openinfo && openinfo->flags & R_SNAPSHOT &&	    !F_ISSET(t, R_EOF | R_INMEM) &&	    t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR)                goto err;	return (dbp);einval:	errno = EINVAL;err:	sverrno = errno;	if (dbp != NULL)		(void)__bt_close(dbp);	if (fname != NULL)		(void)close(rfd);	errno = sverrno;	return (NULL);}
开发者ID:AgamAgarwal,项目名称:minix,代码行数:101,


示例2: exwr

//.........这里部分代码省略.........		 */		F_SET(sp, SC_EX_WAIT_YES);		/*		 * !!!		 * Ignore the return cursor position, the cursor doesn't		 * move.		 */		if (ex_filter(sp, cmdp, &cmdp->addr1,		    &cmdp->addr2, &rm, cmdp->argv[1]->bp, FILTER_WRITE))			return (1);		/* Ex terminates with a bang, even if the command fails. */		if (!F_ISSET(sp, SC_VI) && !F_ISSET(sp, SC_EX_SILENT))			(void)ex_puts(sp, "!/n");		return (0);	}	/* Set the FS_ALL flag if we're writing the entire file. */	if (cmdp->addr1.lno <= 1 && !db_exist(sp, cmdp->addr2.lno + 1))		LF_SET(FS_ALL);	/* If "write >>" it's an append to a file. */	if (cmdp->argc != 0 && cmd != XIT && p[0] == '>' && p[1] == '>') {		LF_SET(FS_APPEND);		/* Skip ">>" and whitespace. */		for (p += 2; *p && cmdskip(*p); ++p);	}	/* If no other arguments, just write the file back. */	if (cmdp->argc == 0 || *p == '/0')		return (file_write(sp,		    &cmdp->addr1, &cmdp->addr2, NULL, flags));	/* Build an argv so we get an argument count and file expansion. */	if (argv_exp2(sp, cmdp, p, STRLEN(p)))		return (1);	/*	 *  0 args: impossible.	 *  1 args: impossible (I hope).	 *  2 args: read it.	 * >2 args: object, too many args.	 *	 * The 1 args case depends on the argv_sexp() function refusing	 * to return success without at least one non-blank character.	 */	switch (cmdp->argc) {	case 0:	case 1:		abort();		/* NOTREACHED */	case 2:		INT2CHAR(sp, cmdp->argv[1]->bp, cmdp->argv[1]->len+1,			 n, nlen);		name = v_strdup(sp, n, nlen - 1);		/*		 * !!!		 * Historically, the read and write commands renamed		 * "unnamed" files, or, if the file had a name, set		 * the alternate file name.		 */		if (F_ISSET(sp->frp, FR_TMPFILE) &&		    !F_ISSET(sp->frp, FR_EXNAMED)) {			if ((n = v_strdup(sp, name, nlen - 1)) != NULL) {				free(sp->frp->name);				sp->frp->name = n;			}			/*			 * The file has a real name, it's no longer a			 * temporary, clear the temporary file flags.			 *			 * !!!			 * If we're writing the whole file, FR_NAMECHANGE			 * will be cleared by the write routine -- this is			 * historic practice.			 */			F_CLR(sp->frp, FR_TMPEXIT | FR_TMPFILE);			F_SET(sp->frp, FR_NAMECHANGE | FR_EXNAMED);			/* Notify the screen. */			(void)sp->gp->scr_rename(sp, sp->frp->name, 1);		} else			set_alt_name(sp, name);		break;	default:		INT2CHAR(sp, p, STRLEN(p) + 1, n, nlen);		ex_emsg(sp, n, EXM_FILECOUNT);		return (1);	}	rc = file_write(sp, &cmdp->addr1, &cmdp->addr2, name, flags);	free(name);	return rc;}
开发者ID:alexandermerritt,项目名称:dragonfly,代码行数:101,


示例3: __bt_open

//.........这里部分代码省略.........		}		if ((t->bt_fd = _open(fname, flags, mode)) < 0)			goto err;	} else {		if ((flags & O_ACCMODE) != O_RDWR)			goto einval;		if ((t->bt_fd = tmp()) == -1)			goto err;		F_SET(t, B_INMEM);	}	if (_fcntl(t->bt_fd, F_SETFD, 1) == -1)		goto err;	if (_fstat(t->bt_fd, &sb))		goto err;	if (sb.st_size) {		if ((nr = _read(t->bt_fd, &m, sizeof(BTMETA))) < 0)			goto err;		if (nr != sizeof(BTMETA))			goto eftype;		/*		 * Read in the meta-data.  This can change the notion of what		 * the lorder, page size and flags are, and, when the page size		 * changes, the cachesize value can change too.  If the user		 * specified the wrong byte order for an existing database, we		 * don't bother to return an error, we just clear the NEEDSWAP		 * bit.		 */		if (m.magic == BTREEMAGIC)			F_CLR(t, B_NEEDSWAP);		else {			F_SET(t, B_NEEDSWAP);			M_32_SWAP(m.magic);			M_32_SWAP(m.version);			M_32_SWAP(m.psize);			M_32_SWAP(m.free);			M_32_SWAP(m.nrecs);			M_32_SWAP(m.flags);		}		if (m.magic != BTREEMAGIC || m.version != BTREEVERSION)			goto eftype;		if (m.psize < MINPSIZE || m.psize > MAX_PAGE_OFFSET + 1 ||		    m.psize & (sizeof(indx_t) - 1) )			goto eftype;		if (m.flags & ~SAVEMETA)			goto eftype;		b.psize = m.psize;		F_SET(t, m.flags);		t->bt_free = m.free;		t->bt_nrecs = m.nrecs;	} else {		/*		 * Set the page size to the best value for I/O to this file.		 * Don't overflow the page offset type.		 */		if (b.psize == 0) {			b.psize = sb.st_blksize;			if (b.psize < MINPSIZE)				b.psize = MINPSIZE;			if (b.psize > MAX_PAGE_OFFSET + 1)				b.psize = MAX_PAGE_OFFSET + 1;		}
开发者ID:alexandermerritt,项目名称:dragonfly,代码行数:67,


示例4: vs_output

/* * vs_output -- *	Output the text to the screen. */static voidvs_output(SCR *sp, mtype_t mtype, const char *line, int llen){	unsigned char *kp;	GS *gp;	VI_PRIVATE *vip;	size_t chlen, notused;	int ch, len, rlen, tlen;	const char *p, *t;	char *cbp, *ecbp, cbuf[128];	gp = sp->gp;	vip = VIP(sp);	for (p = line, rlen = llen; llen > 0;) {		/* Get the next physical line. */		if ((p = memchr(line, '/n', llen)) == NULL)			len = llen;		else			len = p - line;		/*		 * The max is sp->cols characters, and we may have already		 * written part of the line.		 */		if (len + vip->lcontinue > sp->cols)			len = sp->cols - vip->lcontinue;		/*		 * If the first line output, do nothing.  If the second line		 * output, draw the divider line.  If drew a full screen, we		 * remove the divider line.  If it's a continuation line, move		 * to the continuation point, else, move the screen up.		 */		if (vip->lcontinue == 0) {			if (!IS_ONELINE(sp)) {				if (vip->totalcount == 1) {					(void)gp->scr_move(sp,					    LASTLINE(sp) - 1, 0);					(void)gp->scr_clrtoeol(sp);					(void)vs_divider(sp);					F_SET(vip, VIP_DIVIDER);					++vip->totalcount;					++vip->linecount;				}				if (vip->totalcount == sp->t_maxrows &&				    F_ISSET(vip, VIP_DIVIDER)) {					--vip->totalcount;					--vip->linecount;					F_CLR(vip, VIP_DIVIDER);				}			}			if (vip->totalcount != 0)				vs_scroll(sp, NULL, SCROLL_W_QUIT);			(void)gp->scr_move(sp, LASTLINE(sp), 0);			++vip->totalcount;			++vip->linecount;			if (INTERRUPTED(sp))				break;		} else			(void)gp->scr_move(sp, LASTLINE(sp), vip->lcontinue);		/* Error messages are in inverse video. */		if (mtype == M_ERR)			(void)gp->scr_attr(sp, SA_INVERSE, 1);		/* Display the line, doing character translation. */#define	FLUSH {								/	*cbp = '/0';							/	(void)gp->scr_addstr(sp, cbuf, cbp - cbuf);			/	cbp = cbuf;							/}		ecbp = (cbp = cbuf) + sizeof(cbuf) - 1;		for (t = line, tlen = len; tlen--; ++t) {			ch = *t;			/*			 * Replace tabs with spaces, there are places in			 * ex that do column calculations without looking			 * at <tabs> -- and all routines that care about			 * <tabs> do their own expansions.  This catches			 * <tabs> in things like tag search strings.			 */			if (ch == '/t')				ch = ' ';			chlen = KEY_LEN(sp, ch);			if (cbp + chlen >= ecbp)				FLUSH;			for (kp = KEY_NAME(sp, ch); chlen--;)				*cbp++ = *kp++;		}		if (cbp > cbuf)			FLUSH;		if (mtype == M_ERR)			(void)gp->scr_attr(sp, SA_INVERSE, 0);//.........这里部分代码省略.........
开发者ID:VargMon,项目名称:netbsd-cvs-mirror,代码行数:101,


示例5: vs_resolve

/* * vs_resolve -- *	Deal with message output. * * PUBLIC: int vs_resolve __P((SCR *, SCR *, int)); */intvs_resolve(SCR *sp, SCR *csp, int forcewait){	EVENT ev;	GS *gp;	WIN *wp;	MSGS *mp;	VI_PRIVATE *vip;	size_t oldy, oldx;	int redraw;	/*	 * Vs_resolve is called from the main vi loop and the refresh function	 * to periodically ensure that the user has seen any messages that have	 * been displayed and that any status lines are correct.  The sp screen	 * is the screen we're checking, usually the current screen.  When it's	 * not, csp is the current screen, used for final cursor positioning.	 */	gp = sp->gp;	wp = sp->wp;	vip = VIP(sp);	if (csp == NULL)		csp = sp;	/* Save the cursor position. */	(void)gp->scr_cursor(csp, &oldy, &oldx);	/* Ring the bell if it's scheduled. */	if (F_ISSET(gp, G_BELLSCHED)) {		F_CLR(gp, G_BELLSCHED);		(void)gp->scr_bell(sp);	}	/* Display new file status line. */	if (F_ISSET(sp, SC_STATUS)) {		F_CLR(sp, SC_STATUS);		msgq_status(sp, sp->lno, MSTAT_TRUNCATE);	}	/* Report on line modifications. */	mod_rpt(sp);	/*	 * Flush any saved messages.  If the screen isn't ready, refresh	 * it.  (A side-effect of screen refresh is that we can display	 * messages.)  Once this is done, don't trust the cursor.  That	 * extra refresh screwed the pooch.	 */	if (gp->msgq.lh_first != NULL) {		if (!F_ISSET(sp, SC_SCR_VI) && vs_refresh(sp, 1))			return (1);		while ((mp = gp->msgq.lh_first) != NULL) {			wp->scr_msg(sp, mp->mtype, mp->buf, mp->len);			LIST_REMOVE(mp, q);			free(mp->buf);			free(mp);		}		F_SET(vip, VIP_CUR_INVALID);	}	switch (vip->totalcount) {	case 0:		redraw = 0;		break;	case 1:		/*		 * If we're switching screens, we have to wait for messages,		 * regardless.  If we don't wait, skip updating the modeline.		 */		if (forcewait)			vs_scroll(sp, NULL, SCROLL_W);		else			F_SET(vip, VIP_S_MODELINE);		redraw = 0;		break;	default:		/*		 * If >1 message line in use, prompt the user to continue and		 * repaint overwritten lines.		 */		vs_scroll(sp, NULL, SCROLL_W);		ev.e_event = E_REPAINT;		ev.e_flno = vip->totalcount >=		    sp->rows ? 1 : sp->rows - vip->totalcount;		ev.e_tlno = sp->rows;		redraw = 1;		break;	}	/* Reset the count of overwriting lines. */	vip->linecount = vip->lcontinue = vip->totalcount = 0;//.........这里部分代码省略.........
开发者ID:VargMon,项目名称:netbsd-cvs-mirror,代码行数:101,


示例6: cl_vi_init

/* * cl_vi_init -- *	Initialize the curses vi screen. */static intcl_vi_init(SCR *sp){	CL_PRIVATE *clp;	char *o_cols, *o_lines, *o_term;	const char *ttype;	clp = CLP(sp);	/* If already initialized, just set the terminal modes. */	if (F_ISSET(clp, CL_SCR_VI_INIT))		goto fast;	/* Curses vi always reads from (and writes to) a terminal. */	if (!F_ISSET(clp, CL_STDIN_TTY) || !isatty(STDOUT_FILENO)) {		msgq(sp, M_ERR,		    "016|Vi's standard input and output must be a terminal");		return (1);	}	/* We'll need a terminal type. */	if (opts_empty(sp, O_TERM, 0))		return (1);	ttype = O_STR(sp, O_TERM);	/*	 * XXX	 * Changing the row/column and terminal values is done by putting them	 * into the environment, which is then read by curses.  What this loses	 * in ugliness, it makes up for in stupidity.  We can't simply put the	 * values into the environment ourselves, because in the presence of a	 * kernel mechanism for returning the window size, entering values into	 * the environment will screw up future screen resizing events, e.g. if	 * the user enters a :shell command and then resizes their window.  So,	 * if they weren't already in the environment, we make sure to delete	 * them immediately after setting them.	 *	 * XXX	 * Putting the TERM variable into the environment is necessary, even	 * though we're using newterm() here.  We may be using initscr() as	 * the underlying function.	 */	o_term = getenv("TERM");	cl_putenv(sp, "TERM", ttype, 0);	o_lines = getenv("LINES");	cl_putenv(sp, "LINES", NULL, (u_long)O_VAL(sp, O_LINES));	o_cols = getenv("COLUMNS");	cl_putenv(sp, "COLUMNS", NULL, (u_long)O_VAL(sp, O_COLUMNS));	/* Delete cur_term if exists. */	if (F_ISSET(clp, CL_SETUPTERM)) {		if (del_curterm(cur_term))			return (1);		F_CLR(clp, CL_SETUPTERM);	}	/*	 * XXX	 * The SunOS initscr() can't be called twice.  Don't even think about	 * using it.  It fails in subtle ways (e.g. select(2) on fileno(stdin)	 * stops working).  (The SVID notes that applications should only call	 * initscr() once.)	 *	 * XXX	 * The HP/UX newterm doesn't support the NULL first argument, so we	 * have to specify the terminal type.	 */	errno = 0;	if ((clp->screen = newterm(__UNCONST(ttype), stdout, stdin)) == NULL) {		if (errno)			msgq(sp, M_SYSERR, "%s", ttype);		else			msgq(sp, M_ERR, "%s: unknown terminal type", ttype);		return (1);	}	if (o_term == NULL)		cl_unsetenv(sp, "TERM");	if (o_lines == NULL)		cl_unsetenv(sp, "LINES");	if (o_cols == NULL)		cl_unsetenv(sp, "COLUMNS");	/*	 * XXX	 * Someone got let out alone without adult supervision -- the SunOS	 * newterm resets the signal handlers.  There's a race, but it's not	 * worth closing.	 */	(void)sig_init(sp->gp, sp);	/*	 * We use raw mode.  What we want is 8-bit clean, however, signals	 * and flow control should continue to work.  Admittedly, it sounds	 * like cbreak, but it isn't.  Using cbreak() can get you additional	 * things like IEXTEN, which turns on flags like DISCARD and LNEXT.//.........这里部分代码省略.........
开发者ID:jaredmcneill,项目名称:netbsd-src,代码行数:101,


示例7: cl_screen

/* * cl_screen -- *	Switch screen types. * * PUBLIC: int cl_screen __P((SCR *, u_int32_t)); */intcl_screen(SCR *sp, u_int32_t flags){	CL_PRIVATE *clp;	WINDOW *win;	GS *gp;	int ret, error;	sigset_t oset;	gp = sp->gp;	clp = CLP(sp);	win = CLSP(sp) ? CLSP(sp) : stdscr;	ret = 0;	/*	 * During initialization of the screen, block signals to make sure that	 * curses/terminfo routines are not interrupted.	 */	error = sigprocmask(SIG_BLOCK, &__sigblockset, &oset);	/* See if the current information is incorrect. */	if (F_ISSET(gp, G_SRESTART)) {		if (CLSP(sp)) {		    delwin(CLSP(sp));		    sp->cl_private = NULL;		}		if (cl_quit(gp)) {			ret = 1;			goto end;		}		F_CLR(gp, G_SRESTART);	}		/* See if we're already in the right mode. */	if ((LF_ISSET(SC_EX) && F_ISSET(sp, SC_SCR_EX)) ||	    (LF_ISSET(SC_VI) && F_ISSET(sp, SC_SCR_VI)))		goto end;	/*	 * Fake leaving ex mode.	 *	 * We don't actually exit ex or vi mode unless forced (e.g. by a window	 * size change).  This is because many curses implementations can't be	 * called twice in a single program.  Plus, it's faster.  If the editor	 * "leaves" vi to enter ex, when it exits ex we'll just fall back into	 * vi.	 */	if (F_ISSET(sp, SC_SCR_EX))		F_CLR(sp, SC_SCR_EX);	/*	 * Fake leaving vi mode.	 *	 * Clear out the rest of the screen if we're in the middle of a split	 * screen.  Move to the last line in the current screen -- this makes	 * terminal scrolling happen naturally.  Note: *don't* move past the	 * end of the screen, as there are ex commands (e.g., :read ! cat file)	 * that don't want to.  Don't clear the info line, its contents may be	 * valid, e.g. :file|append.	 */	if (F_ISSET(sp, SC_SCR_VI)) {		F_CLR(sp, SC_SCR_VI);		if (TAILQ_NEXT(sp, q) != NULL) {			(void)wmove(win, RLNO(sp, sp->rows), 0);			wclrtobot(win);		}		(void)wmove(win, RLNO(sp, sp->rows) - 1, 0);		wrefresh(win);	}	/* Enter the requested mode. */	if (LF_ISSET(SC_EX)) {		if (cl_ex_init(sp)) {			ret = 1;			goto end;		}		F_SET(clp, CL_IN_EX | CL_SCR_EX_INIT);		/*		 * If doing an ex screen for ex mode, move to the last line		 * on the screen.		 */		if (F_ISSET(sp, SC_EX) && clp->cup != NULL)			tputs(tgoto(clp->cup,			    0, O_VAL(sp, O_LINES) - 1), 1, cl_putchar);	} else {		if (cl_vi_init(sp)) {			ret = 1;			goto end;		}		F_CLR(clp, CL_IN_EX);		F_SET(clp, CL_SCR_VI_INIT);//.........这里部分代码省略.........
开发者ID:jaredmcneill,项目名称:netbsd-src,代码行数:101,


示例8: v_cmd

//.........这里部分代码省略.........	/* Pick up optional buffer. */	if (key == '"') {		cpart = ISPARTIAL;		if (F_ISSET(vp, VC_BUFFER)) {			msgq(sp, M_ERR, "234|Only one buffer may be specified");			return (GC_ERR);		}		if (ismotion != NULL) {			v_emsg(sp, NULL, VIM_COMBUF);			return (GC_ERR);		}		KEY(vp->buffer, 0);		F_SET(vp, VC_BUFFER);		KEY(key, EC_MAPCOMMAND);	}	/* Check for an OOB command key. */	cpart = ISPARTIAL;	if (key > MAXVIKEY) {		v_emsg(sp, KEY_NAME(sp, key), VIM_NOCOM);		return (GC_ERR);	}	kp = &vikeys[vp->key = key];	/*	 * !!!	 * Historically, D accepted and then ignored a count.  Match it.	 */	if (vp->key == 'D' && F_ISSET(vp, VC_C1SET)) {		*comcountp = 0;		vp->count = 0;		F_CLR(vp, VC_C1SET);	}	/* Check for command aliases. */	if (kp->func == NULL && (kp = v_alias(sp, vp, kp)) == NULL)		return (GC_ERR);	/* The tildeop option makes the ~ command take a motion. */	if (key == '~' && O_ISSET(sp, O_TILDEOP))		kp = &tmotion;	vp->kp = kp;	/*	 * Find the command.  The only legal command with no underlying	 * function is dot.  It's historic practice that <escape> doesn't	 * just erase the preceding number, it beeps the terminal as well.	 * It's a common problem, so just beep the terminal unless verbose	 * was set.	 */	if (kp->func == NULL) {		if (key != '.') {			v_emsg(sp, KEY_NAME(sp, key),			    ev.e_value == K_ESCAPE ? VIM_NOCOM_B : VIM_NOCOM);			return (GC_ERR);		}		/* If called for a motion command, stop now. */		if (dp == NULL)			goto usage;		/*		 * !!!
开发者ID:Alkzndr,项目名称:freebsd,代码行数:67,


示例9: vi

/* * vi -- * 	Main vi command loop. * * PUBLIC: int vi __P((SCR **)); */intvi(SCR **spp){	GS *gp;	MARK abs;	SCR *next, *sp;	VICMD cmd = { 0 }, *vp;	VI_PRIVATE *vip;	int comcount, mapped, rval;	/* Get the first screen. */	sp = *spp;	gp = sp->gp;	/* Point to the command structure. */	vp = &cmd;	/* Reset strange attraction. */	F_SET(vp, VM_RCM_SET);	/* Initialize the vi screen. */	if (v_init(sp))		return (1);	/* Set the focus. */	(void)sp->gp->scr_rename(sp, sp->frp->name, 1);	for (vip = VIP(sp), rval = 0;;) {		/* Resolve messages. */		if (!MAPPED_KEYS_WAITING(sp) && vs_resolve(sp, NULL, 0))			goto ret;		/*		 * If not skipping a refresh, return to command mode and		 * refresh the screen.		 */		if (F_ISSET(vip, VIP_S_REFRESH))			F_CLR(vip, VIP_S_REFRESH);		else {			sp->showmode = SM_COMMAND;			if (vs_refresh(sp, 0))				goto ret;		}		/* Set the new favorite position. */		if (F_ISSET(vp, VM_RCM_SET | VM_RCM_SETFNB | VM_RCM_SETNNB)) {			F_CLR(vip, VIP_RCM_LAST);			(void)vs_column(sp, &sp->rcm);		}		/*		 * If not currently in a map, log the cursor position,		 * and set a flag so that this command can become the		 * DOT command.		 */		if (MAPPED_KEYS_WAITING(sp))			mapped = 1;		else {			if (log_cursor(sp))				goto err;			mapped = 0;		}		/*		 * There may be an ex command waiting, and we returned here		 * only because we exited a screen or file.  In this case,		 * we simply go back into the ex parser.		 */		if (EXCMD_RUNNING(gp)) {			vp->kp = &vikeys[':'];			goto ex_continue;		}		/* Refresh the command structure. */		memset(vp, 0, sizeof(VICMD));		/*		 * We get a command, which may or may not have an associated		 * motion.  If it does, we get it too, calling its underlying		 * function to get the resulting mark.  We then call the		 * command setting the cursor to the resulting mark.		 *		 * !!!		 * Vi historically flushed mapped characters on error, but		 * entering extra <escape> characters at the beginning of		 * a map wasn't considered an error -- in fact, users would		 * put leading <escape> characters in maps to clean up vi		 * state before the map was interpreted.  Beauty!		 */		switch (v_cmd(sp, DOT, vp, NULL, &comcount, &mapped)) {		case GC_ERR:			goto err;		case GC_ERR_NOFLUSH:			goto gc_err_noflush;//.........这里部分代码省略.........
开发者ID:Alkzndr,项目名称:freebsd,代码行数:101,


示例10: rcv_sync

/* * rcv_sync -- *	Sync the file, optionally: *		flagging the backup file to be preserved *		snapshotting the backup file and send email to the user *		sending email to the user if the file was modified *		ending the file session * * PUBLIC: int rcv_sync __P((SCR *, u_int)); */intrcv_sync(SCR *sp, u_int flags){	EXF *ep;	int fd, rval;	char buf[1024];	const char *dp;	/* Make sure that there's something to recover/sync. */	ep = sp->ep;	if (ep == NULL || !F_ISSET(ep, F_RCV_ON))		return (0);	/* Sync the file if it's been modified. */	if (F_ISSET(ep, F_MODIFIED)) {		/*		 * If we are using a db1 version of the database,		 * we want to sync the underlying btree not the		 * recno tree which is transient anyway.		 */#ifndef R_RECNOSYNC#define	R_RECNOSYNC 0#endif		if (ep->db->sync(ep->db, R_RECNOSYNC)) {			F_CLR(ep, F_RCV_ON | F_RCV_NORM);			msgq_str(sp, M_SYSERR,			    ep->rcv_path, "060|File backup failed: %s");			return (1);		}		/* REQUEST: don't remove backing file on exit. */		if (LF_ISSET(RCV_PRESERVE))			F_SET(ep, F_RCV_NORM);		/* REQUEST: send email. */		if (LF_ISSET(RCV_EMAIL))			rcv_email(sp, ep->rcv_mpath);	}	/*	 * !!!	 * Each time the user exec's :preserve, we have to snapshot all of	 * the recovery information, i.e. it's like the user re-edited the	 * file.  We copy the DB(3) backing file, and then create a new mail	 * recovery file, it's simpler than exiting and reopening all of the	 * underlying files.	 *	 * REQUEST: snapshot the file.	 */	rval = 0;	if (LF_ISSET(RCV_SNAPSHOT)) {		if (opts_empty(sp, O_RECDIR, 0))			goto err;		dp = O_STR(sp, O_RECDIR);		(void)snprintf(buf, sizeof(buf), "%s/vi.XXXXXX", dp);		if ((fd = rcv_mktemp(sp, buf, dp, S_IRUSR | S_IWUSR)) == -1)			goto err;		sp->gp->scr_busy(sp,		    "061|Copying file for recovery...", BUSY_ON);		if (rcv_copy(sp, fd, ep->rcv_path) ||		    close(fd) || rcv_mailfile(sp, 1, buf)) {			(void)unlink(buf);			(void)close(fd);			rval = 1;		}		sp->gp->scr_busy(sp, NULL, BUSY_OFF);	}	if (0) {err:		rval = 1;	}	/* REQUEST: end the file session. */	if (LF_ISSET(RCV_ENDSESSION) && file_end(sp, NULL, 1))		rval = 1;	return (rval);}
开发者ID:Stichting-MINIX-Research-Foundation,项目名称:minix,代码行数:87,


示例11: __rec_page_dirty_update

/* * __rec_page_dirty_update -- *	Update a dirty page's reference on eviction. */static int__rec_page_dirty_update(    WT_SESSION_IMPL *session, WT_REF *parent_ref, WT_PAGE *page){	WT_ADDR *addr;	WT_PAGE_MODIFY *mod;	mod = page->modify;	switch (F_ISSET(mod, WT_PM_REC_MASK)) {	case WT_PM_REC_EMPTY:				/* Page is empty */		if (parent_ref->addr != NULL &&		    __wt_off_page(page->parent, parent_ref->addr)) {			__wt_free(session, ((WT_ADDR *)parent_ref->addr)->addr);			__wt_free(session, parent_ref->addr);		}		/*		 * Update the parent to reference an empty page.		 *		 * Set the transaction ID to WT_TXN_NONE because the fact that		 * reconciliation left the page "empty" means there's no older		 * transaction in the system that might need to see an earlier		 * version of the page.  It isn't necessary (WT_TXN_NONE is 0),		 * but it's the right thing to do.		 *		 * Publish: a barrier to ensure the structure fields are set		 * before the state change makes the page available to readers.		 */		parent_ref->page = NULL;		parent_ref->addr = NULL;		parent_ref->txnid = WT_TXN_NONE;		WT_PUBLISH(parent_ref->state, WT_REF_DELETED);		break;	case WT_PM_REC_REPLACE: 			/* 1-for-1 page swap */		if (parent_ref->addr != NULL &&		    __wt_off_page(page->parent, parent_ref->addr)) {			__wt_free(session, ((WT_ADDR *)parent_ref->addr)->addr);			__wt_free(session, parent_ref->addr);		}		/*		 * Update the parent to reference the replacement page.		 *		 * Publish: a barrier to ensure the structure fields are set		 * before the state change makes the page available to readers.		 */		WT_RET(__wt_calloc(session, 1, sizeof(WT_ADDR), &addr));		*addr = mod->u.replace;		mod->u.replace.addr = NULL;		mod->u.replace.size = 0;		parent_ref->page = NULL;		parent_ref->addr = addr;		WT_PUBLISH(parent_ref->state, WT_REF_DISK);		break;	case WT_PM_REC_SPLIT:				/* Page split */		/*		 * Update the parent to reference new internal page(s).		 *		 * Publish: a barrier to ensure the structure fields are set		 * before the state change makes the page available to readers.		 */		parent_ref->page = mod->u.split;		WT_PUBLISH(parent_ref->state, WT_REF_MEM);		/* Clear the page else discarding the page will free it. */		mod->u.split = NULL;		F_CLR(mod, WT_PM_REC_SPLIT);		break;	WT_ILLEGAL_VALUE(session);	}	return (0);}
开发者ID:RolfAndreassen,项目名称:wiredtiger,代码行数:78,


示例12: __wt_meta_track_off

/* * __wt_meta_track_off -- *	Turn off metadata operation tracking, unrolling on error. */int__wt_meta_track_off(WT_SESSION_IMPL *session, bool need_sync, bool unroll){	WT_DECL_RET;	WT_META_TRACK *trk, *trk_orig;	WT_SESSION_IMPL *ckpt_session;	int saved_ret;	bool did_drop;	saved_ret = 0;	WT_ASSERT(session,	    WT_META_TRACKING(session) && session->meta_track_nest > 0);	trk_orig = session->meta_track;	trk = session->meta_track_next;	/* If it was a nested transaction, there is nothing to do. */	if (--session->meta_track_nest != 0)		return (0);	/* Turn off tracking for unroll. */	session->meta_track_next = session->meta_track_sub = NULL;	/*	 * If there were no operations logged, skip unnecessary metadata	 * checkpoints.  For example, this happens if attempting to create a	 * data source that already exists (or drop one that doesn't).	 */	if (trk == trk_orig)		goto err;	/* Unrolling doesn't require syncing the metadata. */	if (unroll)		goto err;	if (F_ISSET(session, WT_SESSION_SCHEMA_TXN)) {		F_CLR(session, WT_SESSION_SCHEMA_TXN);#ifdef WT_ENABLE_SCHEMA_TXN		WT_ERR(__wt_txn_commit(session, NULL));		__wt_errx(session, "TRACK: Commit internal schema txn");#endif	}	/*	 * If we don't have the metadata cursor (e.g, we're in the process of	 * creating the metadata), we can't sync it.	 */	if (!need_sync || session->meta_cursor == NULL ||	    F_ISSET(S2C(session), WT_CONN_IN_MEMORY))		goto err;	/* If we're logging, make sure the metadata update was flushed. */	if (FLD_ISSET(S2C(session)->log_flags, WT_CONN_LOG_ENABLED))		WT_WITH_DHANDLE(session,		    WT_SESSION_META_DHANDLE(session),		    ret = __wt_txn_checkpoint_log(		    session, false, WT_TXN_LOG_CKPT_SYNC, NULL));	else {		WT_ASSERT(session, F_ISSET(session, WT_SESSION_LOCKED_SCHEMA));		ckpt_session = S2C(session)->meta_ckpt_session;		/*		 * If this operation is part of a running transaction, that		 * should be included in the checkpoint.		 */		ckpt_session->txn.id = session->txn.id;		WT_ASSERT(session,		    !F_ISSET(session, WT_SESSION_LOCKED_METADATA));		WT_WITH_DHANDLE(ckpt_session, WT_SESSION_META_DHANDLE(session),		    WT_WITH_METADATA_LOCK(ckpt_session,			ret = __wt_checkpoint(ckpt_session, NULL)));		ckpt_session->txn.id = WT_TXN_NONE;		if (ret == 0)			WT_WITH_DHANDLE(session,			    WT_SESSION_META_DHANDLE(session),			    ret = __wt_checkpoint_sync(session, NULL));	}err:	/*	 * Undo any tracked operations on failure.	 * Apply any tracked operations post-commit.	 */	did_drop = false;	if (unroll || ret != 0) {		saved_ret = ret;		ret = 0;		while (--trk >= trk_orig) {			did_drop = did_drop || trk->op == WT_ST_DROP_COMMIT;			WT_TRET(__meta_track_unroll(session, trk));		}	} else		for (; trk_orig < trk; trk_orig++) {			did_drop = did_drop ||			    trk_orig->op == WT_ST_DROP_COMMIT;			WT_TRET(__meta_track_apply(session, trk_orig));		}//.........这里部分代码省略.........
开发者ID:mongodb,项目名称:mongo,代码行数:101,


示例13: __bt_seqadv

/* * __bt_seqadvance -- *	Advance the sequential scan. * * Parameters: *	t:	tree *	flags:	R_NEXT, R_PREV * * Side effects: *	Pins the page the new key/data record is on. * * Returns: *	RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key. */static int__bt_seqadv(BTREE *t, EPG *ep, int flags){	CURSOR *c;	PAGE *h;	indx_t idx;	pgno_t pg;	int exact;	/*	 * There are a couple of states that we can be in.  The cursor has	 * been initialized by the time we get here, but that's all we know.	 */	c = &t->bt_cursor;	/*	 * The cursor was deleted where there weren't any duplicate records,	 * so the key was saved.  Find out where that key would go in the	 * current tree.  It doesn't matter if the returned key is an exact	 * match or not -- if it's an exact match, the record was added after	 * the delete so we can just return it.  If not, as long as there's	 * a record there, return it.	 */	if (F_ISSET(c, CURS_ACQUIRE))		return (__bt_first(t, &c->key, ep, &exact));	/* Get the page referenced by the cursor. */	if ((h = mpool_get(t->bt_mp, c->pg.pgno, 0)) == NULL)		return (RET_ERROR);	/*	 * Find the next/previous record in the tree and point the cursor at	 * it.  The cursor may not be moved until a new key has been found.	 */	switch (flags) {	case R_NEXT:			/* Next record. */		/*		 * The cursor was deleted in duplicate records, and moved		 * forward to a record that has yet to be returned.  Clear		 * that flag, and return the record.		 */		if (F_ISSET(c, CURS_AFTER))			goto usecurrent;		idx = c->pg.index;		if (++idx == NEXTINDEX(h)) {			pg = h->nextpg;			mpool_put(t->bt_mp, h, 0);			if (pg == P_INVALID)				return (RET_SPECIAL);			if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)				return (RET_ERROR);			idx = 0;		}		break;	case R_PREV:			/* Previous record. */		/*		 * The cursor was deleted in duplicate records, and moved		 * backward to a record that has yet to be returned.  Clear		 * that flag, and return the record.		 */		if (F_ISSET(c, CURS_BEFORE)) {usecurrent:		F_CLR(c, CURS_AFTER | CURS_BEFORE);			ep->page = h;			ep->index = c->pg.index;			return (RET_SUCCESS);		}		idx = c->pg.index;		if (idx == 0) {			pg = h->prevpg;			mpool_put(t->bt_mp, h, 0);			if (pg == P_INVALID)				return (RET_SPECIAL);			if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL)				return (RET_ERROR);			idx = NEXTINDEX(h) - 1;		} else			--idx;		break;	}	ep->page = h;	ep->index = idx;	return (RET_SUCCESS);}
开发者ID:BlueFireworks,项目名称:rtems-libbsd,代码行数:98,


示例14: v_exaddr

//.........这里部分代码省略.........		return (1);		/*	 * Remember where any remaining command information is, and clean	 * up the fake ex command.	 */	cmd = cmdp->cp;	len = cmdp->clen;	gp->excmd.clen = 0;	if (err)		goto err2;	/* Copy out the new cursor position and make sure it's okay. */	switch (cmdp->addrcnt) {	case 1:		vp->m_stop = cmdp->addr1;		break;	case 2:		vp->m_stop = cmdp->addr2;		break;	}	if (!db_exist(sp, vp->m_stop.lno)) {		ex_badaddr(sp, &fake,		    vp->m_stop.lno == 0 ? A_ZERO : A_EOF, NUM_OK);		goto err2;	}	/*	 * !!!	 * Historic practice is that a trailing 'z' was ignored if it was a	 * motion command.  Should probably be an error, but not worth the	 * effort.	 */	if (ISMOTION(vp))		return (v_correct(sp, vp, F_ISSET(cmdp, E_DELTA)));			/*	 * !!!	 * Historically, if it wasn't a motion command, a delta in the search	 * pattern turns it into a first nonblank movement.	 */	nb = F_ISSET(cmdp, E_DELTA);	/* Check for the 'z' command. */	if (len != 0) {		if (*cmd != 'z')			goto err1;		/* No blanks, just like the z command. */		for (t = cmd + 1, tlen = len - 1; tlen > 0; ++t, --tlen)			if (!isdigit(*t))				break;		if (tlen &&		    (*t == '-' || *t == '.' || *t == '+' || *t == '^')) {			++t;			--tlen;			type = 1;		} else			type = 0;		if (tlen)			goto err1;		/* The z command will do the nonblank for us. */		nb = 0;		/* Default to z+. */		if (!type &&		    v_event_push(sp, NULL, L("+"), 1, CH_NOMAP | CH_QUOTED))			return (1);		/* Push the user's command. */		if (v_event_push(sp, NULL, cmd, len, CH_NOMAP | CH_QUOTED))			return (1);		/* Push line number so get correct z display. */		tlen = snprintf(buf,		    sizeof(buf), "%lu", (u_long)vp->m_stop.lno);		CHAR2INT(sp, buf, tlen, w, wlen);		if (v_event_push(sp, NULL, w, wlen, CH_NOMAP | CH_QUOTED))			return (1);		 		/* Don't refresh until after 'z' happens. */		F_SET(VIP(sp), VIP_S_REFRESH);	}	/* Non-motion commands move to the end of the range. */	vp->m_final = vp->m_stop;	if (nb) {		F_CLR(vp, VM_RCM_MASK);		F_SET(vp, VM_RCM_SETFNB);	}	return (0);err1:	msgq(sp, M_ERR,	    "188|Characters after search string, line offset and/or z command");err2:	vp->m_final.lno = s_lno;	vp->m_final.cno = s_cno;	return (1);}
开发者ID:Alkzndr,项目名称:freebsd,代码行数:101,


示例15: __wt_btcur_prev

/* * __wt_btcur_prev -- *	Move to the previous record in the tree. */int__wt_btcur_prev(WT_CURSOR_BTREE *cbt){	WT_DECL_RET;	WT_SESSION_IMPL *session;	int newpage;	session = (WT_SESSION_IMPL *)cbt->iface.session;	WT_BSTAT_INCR(session, cursor_read_prev);	__cursor_func_init(cbt, 0);	/*	 * If we aren't already iterating in the right direction, there's	 * some setup to do.	 */	if (!F_ISSET(cbt, WT_CBT_ITERATE_PREV))		__wt_btcur_iterate_setup(cbt, 0);	/*	 * Walk any page we're holding until the underlying call returns not-	 * found.  Then, move to the previous page, until we reach the start	 * of the file.	 */	for (newpage = 0;; newpage = 1) {		if (F_ISSET(cbt, WT_CBT_ITERATE_APPEND)) {			switch (cbt->page->type) {			case WT_PAGE_COL_FIX:				ret = __cursor_fix_append_prev(cbt, newpage);				break;			case WT_PAGE_COL_VAR:				ret = __cursor_var_append_prev(cbt, newpage);				break;			WT_ILLEGAL_VALUE_ERR(session);			}			if (ret == 0)				break;			F_CLR(cbt, WT_CBT_ITERATE_APPEND);			if (ret != WT_NOTFOUND)				break;			newpage = 1;		}		if (cbt->page != NULL) {			switch (cbt->page->type) {			case WT_PAGE_COL_FIX:				ret = __cursor_fix_prev(cbt, newpage);				break;			case WT_PAGE_COL_VAR:				ret = __cursor_var_prev(cbt, newpage);				break;			case WT_PAGE_ROW_LEAF:				ret = __cursor_row_prev(cbt, newpage);				break;			WT_ILLEGAL_VALUE_ERR(session);			}			if (ret != WT_NOTFOUND)				break;		}		do {			WT_ERR(__wt_tree_np(session, &cbt->page, 0, 0));			WT_ERR_TEST(cbt->page == NULL, WT_NOTFOUND);		} while (		    cbt->page->type == WT_PAGE_COL_INT ||		    cbt->page->type == WT_PAGE_ROW_INT);		/*		 * The last page in a column-store has appended entries.		 * We handle it separately from the usual cursor code:		 * it's only that one page and it's in a simple format.		 */		if (cbt->page->type != WT_PAGE_ROW_LEAF &&		    (cbt->ins_head = WT_COL_APPEND(cbt->page)) != NULL)			F_SET(cbt, WT_CBT_ITERATE_APPEND);	}err:	__cursor_func_resolve(cbt, ret);	return (ret);}
开发者ID:qixin,项目名称:wiredtiger,代码行数:83,


示例16: v_motion

/* * v_motion -- * * Get resulting motion mark. */static intv_motion(	SCR *sp,	VICMD *dm,	VICMD *vp,	int *mappedp){	VICMD motion;	size_t len;	u_long cnt;	u_int flags;	int tilde_reset, notused;	/*	 * If '.' command, use the dot motion, else get the motion command.	 * Clear any line motion flags, the subsequent motion isn't always	 * the same, i.e. "/aaa" may or may not be a line motion.	 */	if (F_ISSET(vp, VC_ISDOT)) {		motion = *dm;		F_SET(&motion, VC_ISDOT);		F_CLR(&motion, VM_COMMASK);	} else {		memset(&motion, 0, sizeof(VICMD));		if (v_cmd(sp, NULL, &motion, vp, &notused, mappedp) != GC_OK)			return (1);	}	/*	 * A count may be provided both to the command and to the motion, in	 * which case the count is multiplicative.  For example, "3y4y" is the	 * same as "12yy".  This count is provided to the motion command and	 * not to the regular function.	 */	cnt = motion.count = F_ISSET(&motion, VC_C1SET) ? motion.count : 1;	if (F_ISSET(vp, VC_C1SET)) {		motion.count *= vp->count;		F_SET(&motion, VC_C1SET);		/*		 * Set flags to restore the original values of the command		 * structure so dot commands can change the count values,		 * e.g. "2dw" "3." deletes a total of five words.		 */		F_CLR(vp, VC_C1SET);		F_SET(vp, VC_C1RESET);	}	/*	 * Some commands can be repeated to indicate the current line.  In	 * this case, or if the command is a "line command", set the flags	 * appropriately.  If not a doubled command, run the function to get	 * the resulting mark. 	 */	if (vp->key == motion.key) {		F_SET(vp, VM_LDOUBLE | VM_LMODE);		/* Set the origin of the command. */		vp->m_start.lno = sp->lno;		vp->m_start.cno = 0;		/*		 * Set the end of the command.		 *		 * If the current line is missing, i.e. the file is empty,		 * historic vi permitted a "cc" or "!!" command to insert		 * text.		 */		vp->m_stop.lno = sp->lno + motion.count - 1;		if (db_get(sp, vp->m_stop.lno, 0, NULL, &len)) {			if (vp->m_stop.lno != 1 ||			   (vp->key != 'c' && vp->key != '!')) {				v_emsg(sp, NULL, VIM_EMPTY);				return (1);			}			vp->m_stop.cno = 0;		} else			vp->m_stop.cno = len ? len - 1 : 0;	} else {		/*		 * Motion commands change the underlying movement (*snarl*).		 * For example, "l" is illegal at the end of a line, but "dl"		 * is not.  Set flags so the function knows the situation.		 */		motion.rkp = vp->kp;		/*		 * XXX		 * Use yank instead of creating a new motion command, it's a		 * lot easier for now.		 */		if (vp->kp == &tmotion) {			tilde_reset = 1;			vp->kp = &vikeys['y'];		} else//.........这里部分代码省略.........
开发者ID:Alkzndr,项目名称:freebsd,代码行数:101,


示例17: msgq_status

/* * msgq_status -- *	Report on the file's status. * * PUBLIC: void msgq_status(SCR *, recno_t, u_int); */voidmsgq_status(SCR *sp, recno_t lno, u_int flags){	recno_t last;	size_t blen, len;	int cnt, needsep;	const char *t;	char **ap, *bp, *np, *p, *s, *ep;	CHAR_T *wp;	size_t wlen;	/* Get sufficient memory. */	len = strlen(sp->frp->name);	GET_SPACE_GOTOC(sp, bp, blen, len * MAX_CHARACTER_COLUMNS + 128);	p = bp;	ep = bp + blen;	/* Convert the filename. */	CHAR2INT(sp, sp->frp->name, len + 1, wp, wlen);	/* Copy in the filename. */	for (; *wp != '/0'; ++wp) {		len = KEY_LEN(sp, *wp);		memcpy(p, KEY_NAME(sp, *wp), len);		p += len;	}	np = p;	*p++ = ':';	*p++ = ' ';	/* Copy in the argument count. */	if (F_ISSET(sp, SC_STATUS_CNT) && sp->argv != NULL) {		for (cnt = 0, ap = sp->argv; *ap != NULL; ++ap, ++cnt);		if (cnt > 1) {			(void)snprintf(p, ep - p,			    msg_cat(sp, "317|%d files to edit", NULL), cnt);			p += strlen(p);			*p++ = ':';			*p++ = ' ';		}		F_CLR(sp, SC_STATUS_CNT);	}	/*	 * See nvi/exf.c:file_init() for a description of how and when the	 * read-only bit is set.	 *	 * !!!	 * The historic display for "name changed" was "[Not edited]".	 */	needsep = 0;	if (F_ISSET(sp->frp, FR_NEWFILE)) {		F_CLR(sp->frp, FR_NEWFILE);		t = msg_cat(sp, "021|new file", &len);		memcpy(p, t, len);		p += len;		needsep = 1;	} else {		if (F_ISSET(sp->frp, FR_NAMECHANGE)) {			t = msg_cat(sp, "022|name changed", &len);			memcpy(p, t, len);			p += len;			needsep = 1;		}		if (needsep) {			*p++ = ',';			*p++ = ' ';		}		if (F_ISSET(sp->ep, F_MODIFIED))			t = msg_cat(sp, "023|modified", &len);		else			t = msg_cat(sp, "024|unmodified", &len);		memcpy(p, t, len);		p += len;		needsep = 1;	}	if (F_ISSET(sp->frp, FR_UNLOCKED)) {		if (needsep) {			*p++ = ',';			*p++ = ' ';		}		t = msg_cat(sp, "025|UNLOCKED", &len);		memcpy(p, t, len);		p += len;		needsep = 1;	}	if (O_ISSET(sp, O_READONLY)) {		if (needsep) {			*p++ = ',';			*p++ = ' ';		}		t = msg_cat(sp, "026|readonly", &len);		memcpy(p, t, len);		p += len;//.........这里部分代码省略.........
开发者ID:lichray,项目名称:nvi2,代码行数:101,


示例18: v_init

/* * v_init -- *	Initialize the vi screen. */static intv_init(SCR *sp){	GS *gp;	VI_PRIVATE *vip;	gp = sp->gp;	vip = VIP(sp);	/* Switch into vi. */	if (gp->scr_screen(sp, SC_VI))		return (1);	(void)gp->scr_attr(sp, SA_ALTERNATE, 1);	F_CLR(sp, SC_EX | SC_SCR_EX);	F_SET(sp, SC_VI);	/*	 * Initialize screen values.	 *	 * Small windows: see vs_refresh(), section 6a.	 *	 * Setup:	 *	t_minrows is the minimum rows to display	 *	t_maxrows is the maximum rows to display (rows - 1)	 *	t_rows is the rows currently being displayed	 */	sp->rows = vip->srows = O_VAL(sp, O_LINES);	sp->cols = O_VAL(sp, O_COLUMNS);	sp->t_rows = sp->t_minrows = O_VAL(sp, O_WINDOW);	if (sp->rows != 1) {		if (sp->t_rows > sp->rows - 1) {			sp->t_minrows = sp->t_rows = sp->rows - 1;			msgq(sp, M_INFO,			    "214|Windows option value is too large, max is %u",			    (u_int)sp->t_rows);		}		sp->t_maxrows = sp->rows - 1;	} else		sp->t_maxrows = 1;	sp->roff = sp->coff = 0;	/* Create a screen map. */	CALLOC_RET(sp, HMAP, SMAP *, SIZE_HMAP(sp), sizeof(SMAP));	TMAP = HMAP + (sp->t_rows - 1);	HMAP->lno = sp->lno;	HMAP->coff = 0;	HMAP->soff = 1;	/*	 * Fill the screen map from scratch -- try and center the line.  That	 * way if we're starting with a file we've seen before, we'll put the	 * line in the middle, otherwise, it won't work and we'll end up with	 * the line at the top.	 */	F_SET(sp, SC_SCR_REFORMAT | SC_SCR_CENTER);	/* Invalidate the cursor. */	F_SET(vip, VIP_CUR_INVALID);	/* Paint the screen image from scratch. */	F_SET(vip, VIP_N_EX_PAINT);	return (0);}
开发者ID:Alkzndr,项目名称:freebsd,代码行数:69,


示例19: cl_ex_init

/* * cl_ex_init -- *	Initialize the ex screen. */static intcl_ex_init(SCR *sp){	CL_PRIVATE *clp;	int error;	const char *ttype;	clp = CLP(sp);	/* If already initialized, just set the terminal modes. */	if (F_ISSET(clp, CL_SCR_EX_INIT))		goto fast;	/* If not reading from a file, we're done. */	if (!F_ISSET(clp, CL_STDIN_TTY))		return (0);	if (F_ISSET(clp, CL_CHANGE_TERM)) {		if (F_ISSET(clp, CL_SETUPTERM) && del_curterm(cur_term))			return (1);		F_CLR(clp, CL_SETUPTERM | CL_CHANGE_TERM);	}	if (!F_ISSET(clp, CL_SETUPTERM)) {		/* We'll need a terminal type. */		if (opts_empty(sp, O_TERM, 0))			return (1);		ttype = O_STR(sp, O_TERM);		(void)setupterm(ttype, STDOUT_FILENO, &error);		if (error == 0 || error == -1)			return (1);	}	/* Get the ex termcap/terminfo strings. */	(void)cl_getcap(sp, "cup", &clp->cup);	(void)cl_getcap(sp, "smso", &clp->smso);	(void)cl_getcap(sp, "rmso", &clp->rmso);	(void)cl_getcap(sp, "el", &clp->el);	(void)cl_getcap(sp, "cuu1", &clp->cuu1);	/* Enter_standout_mode and exit_standout_mode are paired. */	if (clp->smso == NULL || clp->rmso == NULL) {		if (clp->smso != NULL) {			free(clp->smso);			clp->smso = NULL;		}		if (clp->rmso != NULL) {			free(clp->rmso);			clp->rmso = NULL;		}	}	/*	 * Turn on canonical mode, with normal input and output processing.	 * Start with the original terminal settings as the user probably	 * had them (including any local extensions) set correctly for the	 * current terminal.	 *	 * !!!	 * We can't get everything that we need portably; for example, ONLCR,	 * mapping <newline> to <carriage-return> on output isn't required	 * by POSIX 1003.1b-1993.  If this turns out to be a problem, then	 * we'll either have to play some games on the mapping, or we'll have	 * to make all ex printf's output /r/n instead of /n.	 */	clp->ex_enter = clp->orig;	clp->ex_enter.c_lflag  |= ECHO | ECHOE | ECHOK | ICANON | IEXTEN | ISIG;#ifdef ECHOCTL	clp->ex_enter.c_lflag |= ECHOCTL;#endif#ifdef ECHOKE	clp->ex_enter.c_lflag |= ECHOKE;#endif	clp->ex_enter.c_iflag |= ICRNL;	clp->ex_enter.c_oflag |= OPOST;#ifdef ONLCR	clp->ex_enter.c_oflag |= ONLCR;#endiffast:	if (tcsetattr(STDIN_FILENO, TCSADRAIN | TCSASOFT, &clp->ex_enter)) {		if (errno == EINTR)			goto fast;		msgq(sp, M_SYSERR, "tcsetattr");		return (1);	}	return (0);}
开发者ID:jaredmcneill,项目名称:netbsd-src,代码行数:91,


示例20: vs_msg

/* * vs_msg -- *	Display ex output or error messages for the screen. * * This routine is the default editor interface for all ex output, and all ex * and vi error/informational messages.  It implements the standard strategy * of stealing lines from the bottom of the vi text screen.  Screens using an * alternate method of displaying messages, e.g. dialog boxes, should set their * scr_msg function to the correct function before calling the editor. * * PUBLIC: void vs_msg __P((SCR *, mtype_t, char *, size_t)); */voidvs_msg(SCR *sp, mtype_t mtype, char *line, size_t len){	GS *gp;	VI_PRIVATE *vip;	size_t maxcols, oldx, oldy, padding;	const char *e, *s, *t;	gp = sp->gp;	vip = VIP(sp);	/*	 * Ring the bell if it's scheduled.	 *	 * XXX	 * Shouldn't we save this, too?	 */	if (F_ISSET(sp, SC_TINPUT_INFO) || F_ISSET(gp, G_BELLSCHED)) {		if (F_ISSET(sp, SC_SCR_VI)) {			F_CLR(gp, G_BELLSCHED);			(void)gp->scr_bell(sp);		} else			F_SET(gp, G_BELLSCHED);	}	/*	 * If vi is using the error line for text input, there's no screen	 * real-estate for the error message.  Nothing to do without some	 * information as to how important the error message is.	 */	if (F_ISSET(sp, SC_TINPUT_INFO))		return;	/*	 * Ex or ex controlled screen output.	 *	 * If output happens during startup, e.g., a .exrc file, we may be	 * in ex mode but haven't initialized the screen.  Initialize here,	 * and in this case, stay in ex mode.	 *	 * If the SC_SCR_EXWROTE bit is set, then we're switching back and	 * forth between ex and vi, but the screen is trashed and we have	 * to respect that.  Switch to ex mode long enough to put out the	 * message.	 *	 * If the SC_EX_WAIT_NO bit is set, turn it off -- we're writing to	 * the screen, so previous opinions are ignored.	 */	if (F_ISSET(sp, SC_EX | SC_SCR_EXWROTE)) {		if (!F_ISSET(sp, SC_SCR_EX)) {			if (F_ISSET(sp, SC_SCR_EXWROTE)) {				if (sp->gp->scr_screen(sp, SC_EX))					return;			} else				if (ex_init(sp))					return;		}		if (mtype == M_ERR)			(void)gp->scr_attr(sp, SA_INVERSE, 1);		(void)printf("%.*s", (int)len, line);		if (mtype == M_ERR)			(void)gp->scr_attr(sp, SA_INVERSE, 0);		(void)fflush(stdout);		F_CLR(sp, SC_EX_WAIT_NO);		if (!F_ISSET(sp, SC_SCR_EX))			(void)sp->gp->scr_screen(sp, SC_VI);		return;	}	/* If the vi screen isn't ready, save the message. */	if (!F_ISSET(sp, SC_SCR_VI)) {		(void)vs_msgsave(sp, mtype, line, len);		return;	}	/* Save the cursor position. */	(void)gp->scr_cursor(sp, &oldy, &oldx);	/* If it's an ex output message, just write it out. */	if (mtype == M_NONE) {		vs_output(sp, mtype, line, len);		goto ret;	}	/*//.........这里部分代码省略.........
开发者ID:VargMon,项目名称:netbsd-cvs-mirror,代码行数:101,


示例21: ex_read

//.........这里部分代码省略.........	case R_ARG:		name = sp->frp->name;		break;	case R_EXPANDARG:		if (argv_exp2(sp, cmdp, arg, arglen))			return (1);		/*		 *  0 args: impossible.		 *  1 args: impossible (I hope).		 *  2 args: read it.		 * >2 args: object, too many args.		 *		 * The 1 args case depends on the argv_sexp() function refusing		 * to return success without at least one non-blank character.		 */		switch (cmdp->argc) {		case 0:		case 1:			abort();			/* NOTREACHED */		case 2:			INT2CHAR(sp, cmdp->argv[1]->bp, cmdp->argv[1]->len + 1, 				 name, nlen);			/*			 * !!!			 * Historically, the read and write commands renamed			 * "unnamed" files, or, if the file had a name, set			 * the alternate file name.			 */			if (F_ISSET(sp->frp, FR_TMPFILE) &&			    !F_ISSET(sp->frp, FR_EXNAMED)) {				if ((p = strdup(name)) != NULL) {					free(sp->frp->name);					sp->frp->name = p;				}				/*				 * The file has a real name, it's no longer a				 * temporary, clear the temporary file flags.				 */				F_CLR(sp->frp, FR_TMPEXIT | FR_TMPFILE);				F_SET(sp->frp, FR_NAMECHANGE | FR_EXNAMED);				/* Notify the screen. */				(void)sp->gp->scr_rename(sp, sp->frp->name, 1);				name = sp->frp->name;			} else {				set_alt_name(sp, name);				name = sp->alt_name;			}			break;		default:			ex_wemsg(sp, cmdp->argv[0]->bp, EXM_FILECOUNT);			return (1);				}		break;	}	/*	 * !!!	 * Historically, vi did not permit reads from non-regular files, nor	 * did it distinguish between "read !" and "read!", so there was no	 * way to "force" it.  We permit reading from named pipes too, since	 * they didn't exist when the original implementation of vi was done	 * and they seem a reasonable addition.	 */	if ((fp = fopen(name, "r")) == NULL || fstat(fileno(fp), &sb)) {		msgq_str(sp, M_SYSERR, name, "%s");		return (1);	}	if (!S_ISFIFO(sb.st_mode) && !S_ISREG(sb.st_mode)) {		(void)fclose(fp);		msgq(sp, M_ERR,		    "145|Only regular files and named pipes may be read");		return (1);	}	/* Try and get a lock. */	if (file_lock(sp, NULL, NULL, fileno(fp), 0) == LOCK_UNAVAIL)		msgq(sp, M_ERR, "146|%s: read lock was unavailable", name);	rval = ex_readfp(sp, name, fp, &cmdp->addr1, &nlines, 0);	/*	 * In vi, set the cursor to the first line read in, if anything read	 * in, otherwise, the address.  (Historic vi set it to the line after	 * the address regardless, but since that line may not exist we don't	 * bother.)	 *	 * In ex, set the cursor to the last line read in, if anything read in,	 * otherwise, the address.	 */	if (F_ISSET(sp, SC_VI)) {		sp->lno = cmdp->addr1.lno;		if (nlines)			++sp->lno;	} else		sp->lno = cmdp->addr1.lno + nlines;	return (rval);}
开发者ID:ajinkya93,项目名称:netbsd-src,代码行数:101,


示例22: vs_ex_resolve

/* * vs_ex_resolve -- *	Deal with ex message output. * * This routine is called when exiting a colon command to resolve any ex * output that may have occurred. * * PUBLIC: int vs_ex_resolve __P((SCR *, int *)); */intvs_ex_resolve(SCR *sp, int *continuep){	EVENT ev;	GS *gp;	VI_PRIVATE *vip;	sw_t wtype;	gp = sp->gp;	vip = VIP(sp);	*continuep = 0;	/* If we ran any ex command, we can't trust the cursor position. */	F_SET(vip, VIP_CUR_INVALID);	/* Terminate any partially written message. */	if (vip->lcontinue != 0) {		vs_output(sp, vip->mtype, ".", 1);		vip->lcontinue = 0;		vip->mtype = M_NONE;	}	/*	 * If we switched out of the vi screen into ex, switch back while we	 * figure out what to do with the screen and potentially get another	 * command to execute.	 *	 * If we didn't switch into ex, we're not required to wait, and less	 * than 2 lines of output, we can continue without waiting for the	 * wait.	 *	 * Note, all other code paths require waiting, so we leave the report	 * of modified lines until later, so that we won't wait for no other	 * reason than a threshold number of lines were modified.  This means	 * we display cumulative line modification reports for groups of ex	 * commands.  That seems right to me (well, at least not wrong).	 */	if (F_ISSET(sp, SC_SCR_EXWROTE)) {		if (sp->gp->scr_screen(sp, SC_VI))			return (1);	} else		if (!F_ISSET(sp, SC_EX_WAIT_YES) && vip->totalcount < 2) {			F_CLR(sp, SC_EX_WAIT_NO);			return (0);		}	/* Clear the required wait flag, it's no longer needed. */	F_CLR(sp, SC_EX_WAIT_YES);	/*	 * Wait, unless explicitly told not to wait or the user interrupted	 * the command.  If the user is leaving the screen, for any reason,	 * they can't continue with further ex commands.	 */	if (!F_ISSET(sp, SC_EX_WAIT_NO) && !INTERRUPTED(sp)) {		wtype = F_ISSET(sp, SC_EXIT | SC_EXIT_FORCE |		    SC_FSWITCH | SC_SSWITCH) ? SCROLL_W : SCROLL_W_EX;		if (F_ISSET(sp, SC_SCR_EXWROTE))			vs_wait(sp, continuep, wtype);		else			vs_scroll(sp, continuep, wtype);		if (*continuep)			return (0);	}	/* If ex wrote on the screen, refresh the screen image. */	if (F_ISSET(sp, SC_SCR_EXWROTE))		F_SET(vip, VIP_N_EX_PAINT);	/*	 * If we're not the bottom of the split screen stack, the screen	 * image itself is wrong, so redraw everything.	 */	if (sp->q.cqe_next != (void *)&sp->wp->scrq)		F_SET(sp, SC_SCR_REDRAW);	/* If ex changed the underlying file, the map itself is wrong. */	if (F_ISSET(vip, VIP_N_EX_REDRAW))		F_SET(sp, SC_SCR_REFORMAT);	/* Ex may have switched out of the alternate screen, return. */	(void)gp->scr_attr(sp, SA_ALTERNATE, 1);	/*	 * Whew.  We're finally back home, after what feels like years.	 * Kiss the ground.	 */	F_CLR(sp, SC_SCR_EXWROTE | SC_EX_WAIT_NO);	/*//.........这里部分代码省略.........
开发者ID:VargMon,项目名称:netbsd-cvs-mirror,代码行数:101,


示例23: __wt_las_sweep

//.........这里部分代码省略.........	__wt_las_cursor(session, &cursor, &session_flags);	/*	 * If we're not starting a new sweep, position the cursor using the key	 * from the last call (we don't care if we're before or after the key,	 * just roughly in the same spot is fine).	 */	if (key->size != 0) {		__wt_cursor_set_raw_key(cursor, key);		ret = cursor->search_near(cursor, &notused);		/*		 * Don't search for the same key twice; if we don't set a new		 * key below, it's because we've reached the end of the table		 * and we want the next pass to start at the beginning of the		 * table. Searching for the same key could leave us stuck at		 * the end of the table, repeatedly checking the same rows.		 */		key->size = 0;		if (ret != 0)			goto srch_notfound;	}	/*	 * The sweep server wakes up every 10 seconds (by default), it's a slow	 * moving thread. Try to review the entire lookaside table once every 5	 * minutes, or every 30 calls.	 *	 * The reason is because the lookaside table exists because we're seeing	 * cache/eviction pressure (it allows us to trade performance and disk	 * space for cache space), and it's likely lookaside blocks are being	 * evicted, and reading them back in doesn't help things. A trickier,	 * but possibly better, alternative might be to review all lookaside	 * blocks in the cache in order to get rid of them, and slowly review	 * lookaside blocks that have already been evicted.	 */	cnt = (uint64_t)WT_MAX(100, conn->las_record_cnt / 30);	/* Discard pages we read as soon as we're done with them. */	F_SET(session, WT_SESSION_NO_CACHE);	/* Walk the file. */	for (; cnt > 0 && (ret = cursor->next(cursor)) == 0; --cnt) {		/*		 * If the loop terminates after completing a work unit, we will		 * continue the table sweep next time. Get a local copy of the		 * sweep key, we're going to reset the cursor; do so before		 * calling cursor.remove, cursor.remove can discard our hazard		 * pointer and the page could be evicted from underneath us.		 */		if (cnt == 1) {			WT_ERR(__wt_cursor_get_raw_key(cursor, key));			if (!WT_DATA_IN_ITEM(key))				WT_ERR(__wt_buf_set(				    session, key, key->data, key->size));		}		WT_ERR(cursor->get_key(cursor,		    &las_id, las_addr, &las_counter, &las_txnid, las_key));		/*		 * If the on-page record transaction ID associated with the		 * record is globally visible, the record can be discarded.		 *		 * Cursor opened overwrite=true: won't return WT_NOTFOUND should		 * another thread remove the record before we do, and the cursor		 * remains positioned in that case.		 */		if (__wt_txn_visible_all(session, las_txnid)) {			WT_ERR(cursor->remove(cursor));			++remove_cnt;		}	}srch_notfound:	WT_ERR_NOTFOUND_OK(ret);	if (0) {err:		__wt_buf_free(session, key);	}	WT_TRET(__wt_las_cursor_close(session, &cursor, session_flags));	/*	 * If there were races to remove records, we can over-count.  All	 * arithmetic is signed, so underflow isn't fatal, but check anyway so	 * we don't skew low over time.	 */	if (remove_cnt > S2C(session)->las_record_cnt)		S2C(session)->las_record_cnt = 0;	else if (remove_cnt > 0)		(void)__wt_atomic_subi64(&conn->las_record_cnt, remove_cnt);	F_CLR(session, WT_SESSION_NO_CACHE);	__wt_scr_free(session, &las_addr);	__wt_scr_free(session, &las_key);	return (ret);}
开发者ID:hgGeorg,项目名称:mongo,代码行数:101,


示例24: ex_move

/* * ex_move -- :[line [,line]] mo[ve] line *	Move selected lines. * * PUBLIC: int ex_move(SCR *, EXCMD *); */intex_move(SCR *sp, EXCMD *cmdp){	LMARK *lmp;	MARK fm1, fm2;	recno_t cnt, diff, fl, tl, mfl, mtl;	size_t blen, len;	int mark_reset;	char *bp, *p;	NEEDFILE(sp, cmdp);	/*	 * It's not possible to move things into the area that's being	 * moved.	 */	fm1 = cmdp->addr1;	fm2 = cmdp->addr2;	if (cmdp->lineno >= fm1.lno && cmdp->lineno <= fm2.lno) {		msgq(sp, M_ERR, "Destination line is inside move range");		return (1);	}	/*	 * Log the positions of any marks in the to-be-deleted lines.  This	 * has to work with the logging code.  What happens is that we log	 * the old mark positions, make the changes, then log the new mark	 * positions.  Then the marks end up in the right positions no matter	 * which way the log is traversed.	 *	 * XXX	 * Reset the MARK_USERSET flag so that the log can undo the mark.	 * This isn't very clean, and should probably be fixed.	 */	fl = fm1.lno;	tl = cmdp->lineno;	/* Log the old positions of the marks. */	mark_reset = 0;	LIST_FOREACH(lmp, &sp->ep->marks, q)		if (lmp->name != ABSMARK1 &&		    lmp->lno >= fl && lmp->lno <= tl) {			mark_reset = 1;			F_CLR(lmp, MARK_USERSET);			(void)log_mark(sp, lmp);		}	/* Get memory for the copy. */	GET_SPACE_RET(sp, bp, blen, 256);	/* Move the lines. */	diff = (fm2.lno - fm1.lno) + 1;	if (tl > fl) {				/* Destination > source. */		mfl = tl - diff;		mtl = tl;		for (cnt = diff; cnt--;) {			if (db_get(sp, fl, DBG_FATAL, &p, &len))				return (1);			BINC_RET(sp, bp, blen, len);			memcpy(bp, p, len);			if (db_append(sp, 1, tl, bp, len))				return (1);			if (mark_reset)				LIST_FOREACH(lmp, &sp->ep->marks, q)					if (lmp->name != ABSMARK1 &&					    lmp->lno == fl)						lmp->lno = tl + 1;			if (db_delete(sp, fl))				return (1);		}	} else {				/* Destination < source. */
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:77,


示例25: file_init

/* * file_init -- *	Start editing a file, based on the FREF structure.  If successsful, *	let go of any previous file.  Don't release the previous file until *	absolutely sure we have the new one. * * PUBLIC: int file_init __P((SCR *, FREF *, char *, int)); */intfile_init(SCR *sp, FREF *frp, char *rcv_name, int flags){    EXF *ep;    struct stat sb;    size_t psize;    int fd, exists, open_err, readonly, stolen;    char *oname, tname[MAXPATHLEN];    stolen = open_err = readonly = 0;    /*     * If the file is a recovery file, let the recovery code handle it.     * Clear the FR_RECOVER flag first -- the recovery code does set up,     * and then calls us!  If the recovery call fails, it's probably     * because the named file doesn't exist.  So, move boldly forward,     * presuming that there's an error message the user will get to see.     */    if (F_ISSET(frp, FR_RECOVER)) {        F_CLR(frp, FR_RECOVER);        return (rcv_read(sp, frp));    }    /*     * Required FRP initialization; the only flag we keep is the     * cursor information.     */    F_CLR(frp, ~FR_CURSORSET);    /*     * Scan the user's path to find the file that we're going to     * try and open.     */    if (file_spath(sp, frp, &sb, &exists))        return (1);    /*     * Check whether we already have this file opened in some     * other screen.     */    if (exists) {        EXF *exfp;        for (exfp = sp->gp->exfq.cqh_first;                exfp != (EXF *)&sp->gp->exfq; exfp = exfp->q.cqe_next) {            if (exfp->mdev == sb.st_dev &&                    exfp->minode == sb.st_ino &&                    (exfp != sp->ep || exfp->refcnt > 1)) {                ep = exfp;                goto postinit;            }        }    }    /*     * Required EXF initialization:     *	Flush the line caches.     *	Default recover mail file fd to -1.     *	Set initial EXF flag bits.     */    CALLOC_RET(sp, ep, EXF *, 1, sizeof(EXF));    CIRCLEQ_INIT(&ep->scrq);    sp->c_lno = ep->c_nlines = OOBLNO;    ep->rcv_fd = ep->fcntl_fd = -1;    F_SET(ep, F_FIRSTMODIFY);    /*     * If no name or backing file, for whatever reason, create a backing     * temporary file, saving the temp file name so we can later unlink     * it.  If the user never named this file, copy the temporary file name     * to the real name (we display that until the user renames it).     */    oname = frp->name;    if (LF_ISSET(FS_OPENERR) || oname == NULL || !exists) {        if (opts_empty(sp, O_TMP_DIRECTORY, 0))            goto err;        (void)snprintf(tname, sizeof(tname),                       "%s/vi.XXXXXX", O_STR(sp, O_TMP_DIRECTORY));        if ((fd = mkstemp(tname)) == -1) {            msgq(sp, M_SYSERR,                 "237|Unable to create temporary file");            goto err;        }        (void)close(fd);        if (frp->name == NULL)            F_SET(frp, FR_TMPFILE);        if ((frp->tname = strdup(tname)) == NULL ||                (frp->name == NULL &&                 (frp->name = strdup(tname)) == NULL)) {            if (frp->tname != NULL) {                free(frp->tname);            }//.........这里部分代码省略.........
开发者ID:fishman,项目名称:nvi,代码行数:101,


示例26: cl_suspend

//.........这里部分代码省略.........		if (F_ISSET(clp, CL_STDIN_TTY)) {			(void)tcgetattr(STDIN_FILENO, &t);			(void)tcsetattr(STDIN_FILENO,			    TCSASOFT | TCSADRAIN, &clp->orig);		}		/* Stop the process group. */		(void)kill(0, SIGTSTP);		/* Time passes ... */		/* Restore terminal settings. */		if (F_ISSET(clp, CL_STDIN_TTY))			(void)tcsetattr(STDIN_FILENO, TCSASOFT | TCSADRAIN, &t);		return (0);	}	/*	 * Move to the lower left-hand corner of the screen.	 *	 * XXX	 * Not sure this is necessary in System V implementations, but it	 * shouldn't hurt.	 */	getyx(win, y, x);	(void)wmove(win, LINES - 1, 0);	(void)wrefresh(win);	/*	 * Temporarily end the screen.  System V introduced a semantic where	 * endwin() could be restarted.  We use it because restarting curses	 * from scratch often fails in System V.  4BSD curses didn't support	 * restarting after endwin(), so we have to do what clean up we can	 * without calling it.	 */	/* Save the terminal settings. */	(void)tcgetattr(STDIN_FILENO, &t);	/* Restore the cursor keys to normal mode. */	(void)keypad(stdscr, FALSE);	/* Restore the window name. */	(void)cl_rename(sp, NULL, 0);#ifdef HAVE_BSD_CURSES	(void)cl_attr(sp, SA_ALTERNATE, 0);#else	(void)endwin();#endif	/*	 * XXX	 * Restore the original terminal settings.  This is bad -- the	 * reset can cause character loss from the tty queue.  However,	 * we can't call endwin() in BSD curses implementations, and too	 * many System V curses implementations don't get it right.	 */	(void)tcsetattr(STDIN_FILENO, TCSADRAIN | TCSASOFT, &clp->orig);	/* Stop the process group. */	(void)kill(0, SIGTSTP);	/* Time passes ... */	/*	 * If we received a killer signal, we're done.  Leave everything	 * unchanged.  In addition, the terminal has already been reset	 * correctly, so leave it alone.	 */	if (clp->killersig) {		F_CLR(clp, CL_SCR_EX_INIT | CL_SCR_VI_INIT);		return (0);	}	/* Restore terminal settings. */	wrefresh(win);			    /* Needed on SunOs/Solaris ? */	if (F_ISSET(clp, CL_STDIN_TTY))		(void)tcsetattr(STDIN_FILENO, TCSASOFT | TCSADRAIN, &t);#ifdef HAVE_BSD_CURSES	(void)cl_attr(sp, SA_ALTERNATE, 1);#endif	/* Set the window name. */	(void)cl_rename(sp, sp->frp->name, 1);	/* Put the cursor keys into application mode. */	(void)keypad(stdscr, TRUE);	/* Refresh and repaint the screen. */	(void)wmove(win, y, x);	(void)cl_refresh(sp, 1);	/* If the screen changed size, set the SIGWINCH bit. */	if (cl_ssize(sp, 1, NULL, NULL, &changed))		return (1);	if (changed)		F_SET(CLP(sp), CL_SIGWINCH);	return (0);}
开发者ID:Hooman3,项目名称:minix,代码行数:101,


示例27: file_write

//.........这里部分代码省略.........            return (1);        to.cno = 0;        tm = &to;    }    rval = ex_writefp(sp, name, fp, fm, tm, &nlno, &nch, 0);    /*     * Save the new last modification time -- even if the write fails     * we re-init the time.  That way the user can clean up the disk     * and rewrite without having to force it.     */    if (noname) {        if (stat(name, &sb))            time(&ep->mtime);        else {            F_SET(ep, F_DEVSET);            ep->mdev = sb.st_dev;            ep->minode = sb.st_ino;            ep->mtime = sb.st_mtime;        }    }    /*     * If the write failed, complain loudly.  ex_writefp() has already     * complained about the actual error, reinforce it if data was lost.     */    if (rval) {        if (!LF_ISSET(FS_APPEND))            msgq_str(sp, M_ERR, name,                     "254|%s: WARNING: FILE TRUNCATED");        return (1);    }    /*     * Once we've actually written the file, it doesn't matter that the     * file name was changed -- if it was, we've already whacked it.     */    F_CLR(frp, FR_NAMECHANGE);    /*     * If wrote the entire file, and it wasn't by appending it to a file,     * clear the modified bit.  If the file was written to the original     * file name and the file is a temporary, set the "no exit" bit.  This     * permits the user to write the file and use it in the context of the     * filesystem, but still keeps them from discarding their changes by     * exiting.     */    if (LF_ISSET(FS_ALL) && !LF_ISSET(FS_APPEND)) {        F_CLR(ep, F_MODIFIED);        if (F_ISSET(frp, FR_TMPFILE)) {            if (noname)                F_SET(frp, FR_TMPEXIT);            else                F_CLR(frp, FR_TMPEXIT);        }    }    p = msg_print(sp, name, &nf);    switch (mtype) {    case NEWFILE:        msgstr = msg_cat(sp,                         "256|%s: new file: %lu lines, %lu characters", NULL);        len = snprintf(buf, sizeof(buf), msgstr, p, nlno, nch);        break;    case OLDFILE:        msgstr = msg_cat(sp, LF_ISSET(FS_APPEND) ?                         "315|%s: appended: %lu lines, %lu characters" :                         "257|%s: %lu lines, %lu characters", NULL);        len = snprintf(buf, sizeof(buf), msgstr, p, nlno, nch);        break;    default:        abort();    }    /*     * There's a nasty problem with long path names.  Cscope and tags files     * can result in long paths and vi will request a continuation key from     * the user.  Unfortunately, the user has typed ahead, and chaos will     * result.  If we assume that the characters in the filenames only take     * a single screen column each, we can trim the filename.     */    s = buf;    if (len >= sp->cols) {        for (s = buf, t = buf + strlen(p); s < t &&                (*s != '/' || len >= sp->cols - 3); ++s, --len);        if (s == t)            s = buf;        else {            *--s = '.';		/* Leading ellipses. */            *--s = '.';            *--s = '.';        }    }    msgq(sp, M_INFO, s);    if (nf)        FREE_SPACE(sp, p, 0);    return (0);}
开发者ID:fishman,项目名称:nvi,代码行数:101,


示例28: re_compile

/* * re_compile -- *	Compile the RE. * * PUBLIC: int re_compile(SCR *, * PUBLIC:     char *, size_t, char **, size_t *, regex_t *, u_int); */intre_compile(SCR *sp, char *ptrn, size_t plen, char **ptrnp, size_t *lenp,    regex_t *rep, u_int flags){	size_t len;	int reflags, replaced, rval;	char *p;	/* Set RE flags. */	reflags = 0;	if (!LF_ISSET(RE_C_TAG)) {		if (O_ISSET(sp, O_EXTENDED))			reflags |= REG_EXTENDED;		if (O_ISSET(sp, O_IGNORECASE))			reflags |= REG_ICASE;		if (O_ISSET(sp, O_ICLOWER)) {			for (p = ptrn, len = plen; len > 0; ++p, --len)				if (isupper(*p))					break;			if (len == 0)				reflags |= REG_ICASE;		}	}	/* If we're replacing a saved value, clear the old one. */	if (LF_ISSET(RE_C_SEARCH) && F_ISSET(sp, SC_RE_SEARCH)) {		regfree(&sp->re_c);		F_CLR(sp, SC_RE_SEARCH);	}	if (LF_ISSET(RE_C_SUBST) && F_ISSET(sp, SC_RE_SUBST)) {		regfree(&sp->subre_c);		F_CLR(sp, SC_RE_SUBST);	}	/*	 * If we're saving the string, it's a pattern we haven't seen before,	 * so convert the vi-style RE's to POSIX 1003.2 RE's.  Save a copy for	 * later recompilation.   Free any previously saved value.	 */	if (ptrnp != NULL) {		if (LF_ISSET(RE_C_TAG)) {			if (re_tag_conv(sp, &ptrn, &plen, &replaced))				return (1);		} else			if (re_conv(sp, &ptrn, &plen, &replaced))				return (1);		/* Discard previous pattern. */		if (*ptrnp != NULL) {			free(*ptrnp);			*ptrnp = NULL;		}		if (lenp != NULL)			*lenp = plen;		/*		 * Copy the string into allocated memory.		 *		 * XXX		 * Regcomp isn't 8-bit clean, so the pattern is nul-terminated		 * for now.  There's just no other solution.  		 */		MALLOC(sp, *ptrnp, plen + 1);		if (*ptrnp != NULL) {			memcpy(*ptrnp, ptrn, plen);			(*ptrnp)[plen] = '/0';		}		/* Free up conversion-routine-allocated memory. */		if (replaced)			FREE_SPACE(sp, ptrn, 0);		if (*ptrnp == NULL)			return (1);		ptrn = *ptrnp;	}	/*	 * XXX	 * Regcomp isn't 8-bit clean, so we just lost if the pattern	 * contained a nul.  Bummer!	 */	if ((rval = regcomp(rep, ptrn, /* plen, */ reflags)) != 0) {		if (!LF_ISSET(RE_C_SILENT))			re_error(sp, rval, rep); 		return (1);	}	if (LF_ISSET(RE_C_SEARCH))		F_SET(sp, SC_RE_SEARCH);	if (LF_ISSET(RE_C_SUBST))		F_SET(sp, SC_RE_SUBST);//.........这里部分代码省略.........
开发者ID:mosconi,项目名称:openbsd,代码行数:101,


示例29: __txn_rollback_to_stable_lookaside_fixup

/* * __txn_rollback_to_stable_lookaside_fixup -- *	Remove any updates that need to be rolled back from the lookaside file. */static int__txn_rollback_to_stable_lookaside_fixup(WT_SESSION_IMPL *session){	WT_CONNECTION_IMPL *conn;	WT_CURSOR *cursor;	WT_DECL_RET;	WT_DECL_TIMESTAMP(rollback_timestamp)	WT_ITEM las_addr, las_key, las_timestamp;	WT_TXN_GLOBAL *txn_global;	uint64_t las_counter, las_txnid, remove_cnt;	uint32_t las_id, session_flags;	conn = S2C(session);	cursor = NULL;	remove_cnt = 0;	session_flags = 0;		/* [-Werror=maybe-uninitialized] */	WT_CLEAR(las_timestamp);	/*	 * Copy the stable timestamp, otherwise we'd need to lock it each time	 * it's accessed. Even though the stable timestamp isn't supposed to be	 * updated while rolling back, accessing it without a lock would	 * violate protocol.	 */	txn_global = &S2C(session)->txn_global;	__wt_readlock(session, &txn_global->rwlock);	__wt_timestamp_set(&rollback_timestamp, &txn_global->stable_timestamp);	__wt_readunlock(session, &txn_global->rwlock);	__wt_las_cursor(session, &cursor, &session_flags);	/* Discard pages we read as soon as we're done with them. */	F_SET(session, WT_SESSION_NO_CACHE);	/* Walk the file. */	for (; (ret = cursor->next(cursor)) == 0; ) {		WT_ERR(cursor->get_key(cursor, &las_id, &las_addr, &las_counter,		    &las_txnid, &las_timestamp, &las_key));		/* Check the file ID so we can skip durable tables */		if (__bit_test(conn->stable_rollback_bitstring, las_id))			continue;		/*		 * Entries with no timestamp will have a timestamp of zero,		 * which will fail the following check and cause them to never		 * be removed.		 */		if (__wt_timestamp_cmp(		    &rollback_timestamp, las_timestamp.data) < 0) {			WT_ERR(cursor->remove(cursor));			++remove_cnt;		}	}	WT_ERR_NOTFOUND_OK(ret);err:	WT_TRET(__wt_las_cursor_close(session, &cursor, session_flags));	/*	 * If there were races to remove records, we can over-count. Underflow	 * isn't fatal, but check anyway so we don't skew low over time.	 */	if (remove_cnt > conn->las_record_cnt)		conn->las_record_cnt = 0;	else if (remove_cnt > 0)		(void)__wt_atomic_sub64(&conn->las_record_cnt, remove_cnt);	F_CLR(session, WT_SESSION_NO_CACHE);	return (ret);}
开发者ID:mpobrien,项目名称:mongo,代码行数:73,



注:本文中的F_CLR函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ F_ENTER函数代码示例
C++ FZ_ASSERT函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。