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

📄 edstruct.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 5 页
字号:
 * any room. Always grow the buffer in chunks, on the assumption that if you * put something in the kill buffer you are going to put more stuff there too * later. Return TRUE if all is well, and FALSE on errors. */globle int kinsert(c)int c;{#if  IBM_MSC || IBM_TBC || IBM_ICB	char far *nbufp;#else        register char   *nbufp;#endif        register int    i;        if (kused == ksize) {                if ((nbufp= (char *) genalloc((unsigned) ksize+KBLOCK)) == NULL)                        return (FALSE);                for (i=0; i<ksize; ++i)                        nbufp[i] = kbufp[i];                if (kbufp != NULL)                        genfree((VOID *) kbufp, (unsigned) ksize);                kbufp  = nbufp;                ksize += KBLOCK;        }        kbufp[kused++] = (char) c;        return (TRUE);}/* * This function gets characters from the kill buffer. If the character index * "n" is off the end, it returns "-1". This lets the caller just scan along * until it gets a "-1" back. */globle int kremove(n)int n;{        if (n >= kused)                return (-1);        else                return (kbufp[n] & 0xFF);}/* ========================================================================== *                        WINDOW MANAGEMENT FUNCTIONS * ========================================================================== *//* * Again, some of these functions are internal, and some are * attached to keys that the user actually types. *//* * Reposition dot in the current window to line "n". If the argument is * positive, it is that line. If it is negative it is that line from the * bottom. If it is 0 the window is centered (this is what the standard * redisplay code does). With no argument it defaults to 1. Bound to M-!. * Because of the default, it works like in Gosling. */#if IBM_TBC#pragma argsused#endifgloble int reposition(f, n)int f,n;    {    curwp->w_force = (char) n;    curwp->w_flag |= WFFORCE;    return (TRUE);    }/* * Refresh the screen. With no argument, it just does the refresh. With an * argument it recenters "." in the current window. Bound to "C-L". */#if IBM_TBC#pragma argsused#endifgloble int EditorRefresh(f, n)int f,n;    {    if (f == FALSE)        sgarbf = TRUE;    else        {        curwp->w_force = 0;             /* Center dot. */        curwp->w_flag |= WFFORCE;        }    return (TRUE);    }/* * The command make the next window (next => down the screen) the current * window. There are no real errors, although the command does nothing if * there is only 1 window on the screen. Bound to "C-X C-N". */#if IBM_TBC#pragma argsused#endifgloble int nextwind(f, n)int f,n;    {    register WINDOW *wp;    if ((wp = curwp->w_wndp) == NULL)        wp = wheadp;    curwp = wp;    curbp = wp->w_bufp;    return (TRUE);    }/* * This command makes the previous window (previous => up the screen) the * current window. There arn't any errors, although the command does not do a * lot if there is 1 window. */#if IBM_TBC#pragma argsused#endifgloble int prevwind(f, n)int f,n;    {    register WINDOW *wp1;    register WINDOW *wp2;    wp1 = wheadp;    wp2 = curwp;    if (wp1 == wp2)        wp2 = NULL;    while (wp1->w_wndp != wp2)        wp1 = wp1->w_wndp;    curwp = wp1;    curbp = wp1->w_bufp;    return (TRUE);    }/* * This command moves the current window down by "arg" lines. Recompute the * top line in the window. The move up and move down code is almost completely * the same; most of the work has to do with reframing the window, and picking * a new dot. We share the code by having "move down" just be an interface to * "move up". Magic. Bound to "C-X C-N". */globle int mvdnwind(f, n)int f,n;    {    return (mvupwind(f, -n));    }/* * Move the current window up by "arg" lines. Recompute the new top line of * the window. Look to see if "." is still on the screen. If it is, you win. * If it isn't, then move "." to center it in the new framing of the window * (this command does not really move "."; it moves the frame). Bound to * "C-X C-P". */#if IBM_TBC#pragma argsused#endifgloble int mvupwind(f, n)int f,n;    {    register LINE *lp;    register int i;    lp = curwp->w_linep;    if (n < 0)        {        while (n++ && lp!=curbp->b_linep)            lp = lforw(lp);        }    else        {        while (n-- && lback(lp)!=curbp->b_linep)            lp = lback(lp);        }    curwp->w_linep = lp;    curwp->w_flag |= WFHARD;            /* Mode line is OK. */    for (i = 0; i < curwp->w_ntrows; ++i)        {        if (lp == curwp->w_dotp)            return (TRUE);        if (lp == curbp->b_linep)            break;        lp = lforw(lp);        }    lp = curwp->w_linep;    i  = curwp->w_ntrows/2;    while (i-- && lp != curbp->b_linep)        lp = lforw(lp);    curwp->w_dotp  = lp;    curwp->w_doto  = 0;    return (TRUE);    }/* * This command makes the current window the only window on the screen. Bound * to "C-X 1". Try to set the framing so that "." does not have to move on the * display. Some care has to be taken to keep the values of dot and mark in * the buffer structures right if the distruction of a window makes a buffer * become undisplayed. */#if IBM_TBC#pragma argsused#endifgloble int onlywind(f, n)int f,n;{        register WINDOW *wp;        register LINE   *lp;        register int    i;        while (wheadp != curwp) {                wp = wheadp;                wheadp = wp->w_wndp;                if (--wp->w_bufp->b_nwnd == 0) {                        wp->w_bufp->b_dotp  = wp->w_dotp;                        wp->w_bufp->b_doto  = wp->w_doto;                        wp->w_bufp->b_markp = wp->w_markp;                        wp->w_bufp->b_marko = wp->w_marko;                }                genfree((VOID *) wp, (unsigned) sizeof(WINDOW));        }        while (curwp->w_wndp != NULL) {                wp = curwp->w_wndp;                curwp->w_wndp = wp->w_wndp;                if (--wp->w_bufp->b_nwnd == 0) {                        wp->w_bufp->b_dotp  = wp->w_dotp;                        wp->w_bufp->b_doto  = wp->w_doto;                        wp->w_bufp->b_markp = wp->w_markp;                        wp->w_bufp->b_marko = wp->w_marko;                }                genfree((VOID *) wp, (unsigned) sizeof(WINDOW));        }        lp = curwp->w_linep;        i  = curwp->w_toprow;        while (i!=0 && lback(lp)!=curbp->b_linep) {                --i;                lp = lback(lp);        }        curwp->w_toprow = 0;        curwp->w_ntrows = (char) (term.t_nrow-1);        curwp->w_linep  = lp;        curwp->w_flag  |= WFMODE|WFHARD;        return (TRUE);}/* * Split the current window. A window smaller than 3 lines cannot be split. * The only other error that is possible is a "malloc" failure allocating the * structure for the new window. Bound to "C-X 2". */#if IBM_TBC#pragma argsused#endifgloble int splitwind(f, n)int f,n;{        register WINDOW *wp;        register LINE   *lp;        register int    ntru;        register int    ntrl;        register int    ntrd;        register WINDOW *wp1;        register WINDOW *wp2;        if (curwp->w_ntrows < 3) {                mlwrite("Cannot split a %d line window", curwp->w_ntrows);                return (FALSE);        }        if ((wp = (WINDOW *) genalloc((unsigned) sizeof(WINDOW))) == NULL) {                mlwrite("Cannot allocate WINDOW block");                return (FALSE);        }        ++curbp->b_nwnd;                        /* Displayed twice.     */        wp->w_bufp  = curbp;        wp->w_dotp  = curwp->w_dotp;        wp->w_doto  = curwp->w_doto;        wp->w_markp = curwp->w_markp;        wp->w_marko = curwp->w_marko;        wp->w_flag  = 0;        wp->w_force = 0;        ntru = (curwp->w_ntrows-1) / 2;         /* Upper size           */        ntrl = (curwp->w_ntrows-1) - ntru;      /* Lower size           */        lp = curwp->w_linep;        ntrd = 0;        while (lp != curwp->w_dotp) {                ++ntrd;                lp = lforw(lp);        }        lp = curwp->w_linep;        if (ntrd <= ntru) {                     /* Old is upper window. */                if (ntrd == ntru)               /* Hit mode line.       */                        lp = lforw(lp);                curwp->w_ntrows = (char) ntru;                wp->w_wndp = curwp->w_wndp;                curwp->w_wndp = wp;                wp->w_toprow = curwp->w_toprow+ntru+1;                wp->w_ntrows = (char) ntrl;        } else {                                /* Old is lower window  */                wp1 = NULL;                wp2 = wheadp;                while (wp2 != curwp) {                        wp1 = wp2;                        wp2 = wp2->w_wndp;                }                if (wp1 == NULL)                        wheadp = wp;                else                        wp1->w_wndp = wp;                wp->w_wndp   = curwp;                wp->w_toprow = curwp->w_toprow;                wp->w_ntrows = (char) ntru;                ++ntru;                         /* Mode line.           */                curwp->w_toprow += (char) ntru;                curwp->w_ntrows  = (char) ntrl;                while (ntru--)                        lp = lforw(lp);        }        curwp->w_linep = lp;                    /* Adjust the top lines */        wp->w_linep = lp;                       /* if necessary.        */        curwp->w_flag |= WFMODE|WFHARD;        wp->w_flag |= WFMODE|WFHARD;        return (TRUE);}/* * Enlarge the current window. Find the window that loses space. Make sure it * is big enough. If so, hack the window descriptions, and ask redisplay to do * all the hard work. You don't just set "force reframe" because dot would * move. Bound to "C-X Z". */globle int enlargewind(f, n)int f,n;{        register WINDOW *adjwp;        register LINE   *lp;        register int    i;        if (n < 0)                return (shrinkwind(f, -n));        if (wheadp->w_wndp == NULL) {                mlwrite("Only one window");                return (FALSE);        }        if ((adjwp=curwp->w_wndp) == NULL) {                adjwp = wheadp;                while (adjwp->w_wndp != curwp)                        adjwp = adjwp->w_wndp;        }        if (adjwp->w_ntrows <= (char) n) {                mlwrite("Impossible change");                return (FALSE);        }        if (curwp->w_wndp == adjwp) {           /* Shrink below.        */                lp = adjwp->w_linep;                for (i=0; i<n && lp!=adjwp->w_bufp->b_linep; ++i)                        lp = lforw(lp);                adjwp->w_linep  = lp;                adjwp->w_toprow += (char) n;        } else {                                /* Shrink above.        */                lp = curwp->w_linep;                for (i=0; i<n && lback(lp)!=curbp->b_linep; ++i)                        lp = lback(lp);                curwp->w_linep  = lp;                curwp->w_toprow -= (char) n;        }        curwp->w_ntrows += (char) n;        adjwp->w_ntrows -= (char) n;        curwp->w_flag |= WFMODE|WFHARD;        adjwp->w_flag |= WFMODE|WFHARD;        return (TRUE);}/* * Shrink the current window. Find the window that gains space. Hack at the * window descriptions. Ask the redisplay to do all the hard work. Bound to * "C-X C-Z". */globle int shrinkwind(f, n)int f,n;{        register WINDOW *adjwp;        register LINE   *lp;        register int    i;        if (n < 0)                return (enlargewind(f, -n));        if (wheadp->w_wndp == NULL) {                mlwrite("Only one window");                return (FALSE);        }        if ((adjwp=curwp->w_wndp) == NULL) {                adjwp = wheadp;                while (adjwp->w_wndp != curwp)                        adjwp = adjwp->w_wndp;        }        if (curwp->w_ntrows <= (char) n) {                mlwrite("Impossible change");                return (FALSE);        }        if (curwp->w_wndp == adjwp) {           /* Grow below.          */                lp = adjwp->w_linep;                for (i=0; i<n && lback(lp)!=adjwp->w_bufp->b_linep; ++i)                        lp = lback(lp);                adjwp->w_linep  = lp;                adjwp->w_toprow -= (char) n;        } else {                                /* Grow above.          */                lp = curwp->w_linep;                for (i=0; i<n && lp!=curbp->b_linep; ++i)

⌨️ 快捷键说明

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