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

📄 complete.c

📁 spice中支持多层次元件模型仿真的可单独运行的插件源码
💻 C
📖 第 1 页 / 共 2 页
字号:
        wl->wl_next = cctowl(cc->cc_child, true);        if (wl->wl_next)            wl->wl_next->wl_prev = wl;    } else        wl = cctowl(cc->cc_child, true);    if (sib) {        if (wl) {            for (end = wl; end->wl_next; end = end->wl_next)                ;            end->wl_next = cctowl(cc->cc_sibling, true);            if (end->wl_next)                end->wl_next->wl_prev = wl;        } else            wl = cctowl(cc->cc_sibling, true);    }    return (wl);}/* We use this in com_device... */wordlist *cp_cctowl(stuff)    char *stuff;{    return (cctowl((struct ccom *) stuff, true));}/* Turn on and off the escape break character and cooked mode. */voidcp_ccon(on)    bool on;{#ifdef TIOCSTI#ifdef HAS_BSDTTY    static bool ison = false;    struct tchars tbuf;    struct sgttyb sbuf;    if (cp_nocc || !cp_interactive || (ison == on))        return;    ison = on;    /* Set the terminal up -- make escape the break character, and     * make sure we aren't in raw or cbreak mode.  Hope the (void) ioctl's     * won't fail.     */    (void) ioctl(fileno(cp_in), TIOCGETC, (char *) &tbuf);    if (on)        tbuf.t_brkc = ESCAPE;    else        tbuf.t_brkc = '\0';    (void) ioctl(fileno(cp_in), TIOCSETC, (char *) &tbuf);    (void) ioctl(fileno(cp_in), TIOCGETP, (char *) &sbuf);    sbuf.sg_flags &= ~(RAW|CBREAK);    (void) ioctl(fileno(cp_in), TIOCSETP, (char *) &sbuf);#else#  ifdef HAS_SYSVTTY#      define TERM_GET TCGETA#      define TERM_SET TCSETA    static struct termio sbuf;    static struct termio OS_Buf;#  else#    ifdef HAS_POSIXTTY#      define TERM_GET TCGETS#      define TERM_SET TCSETS    static struct termios sbuf;    static struct termios OS_Buf;#    endif#  endif#  ifdef TERM_GET    static bool ison = false;    if (cp_nocc || !cp_interactive || (ison == on))        return;    ison = on;    if (ison == true) {	(void) ioctl(fileno(cp_in), TERM_GET, (char *) &OS_Buf);	sbuf = OS_Buf;	sbuf.c_cc[VEOF] = 0;	sbuf.c_cc[VEOL] = ESCAPE;	sbuf.c_cc[VEOL2] = CNTRL_D;	(void) ioctl(fileno(cp_in), TERM_SET, (char *) &sbuf);    } else {	(void) ioctl(fileno(cp_in), TERM_SET, (char *) &OS_Buf);    }#  endif#endif#endif    return;}/* The following routines deal with the command and keyword databases. * Say whether a given word exists in the command database. */boolcp_comlook(word)    char *word;{    if (word && *word && clookup(word, &commands, false, false))        return (true);    else        return (false);}/* Add a command to the database, with the given keywords and filename flag. */voidcp_addcomm(word, bits0, bits1, bits2, bits3)    char *word;    long bits0, bits1, bits2, bits3;{    struct ccom *cc;    cc = clookup(word, &commands, false, true);    cc->cc_invalid = 0;    cc->cc_kwords[0] = bits0;    cc->cc_kwords[1] = bits1;    cc->cc_kwords[2] = bits2;    cc->cc_kwords[3] = bits3;    return;}/* Remove a command from the database. */voidcp_remcomm(word)    char *word;{    struct ccom *cc;        cc = clookup(word, &commands, false, false);    if (cc)        cdelete(cc);    return;}/* Add a keyword to the database. */voidcp_addkword(class, word)    int class;    char *word;{    struct ccom *cc;    if ((class < 1) || (class >= NCLASSES)) {        fprintf(cp_err, "cp_addkword: Internal Error: bad class %d\n",                class);        return;    }    word = copy(word);    cc = clookup(word, &keywords[class], false, true);    cc->cc_invalid = 0;    return;}/* Remove a keyword from the database. */voidcp_remkword(class, word)    char *word;{    struct ccom *cc;        if ((class < 1) || (class >= NCLASSES)) {        fprintf(cp_err, "cp_addkword: Internal Error: bad class %d\n",                class);        return;    }    cc = clookup(word, &keywords[class], false, false);    if (cc)        cdelete(cc);    return;}/* This routine is used when there are several keyword sets that are * to be switched between rapidly. The return value is the old tree at * that position, and the keyword class given is set to the argument. */char *cp_kwswitch(class, tree)    int class;    char *tree;{    char *old;    if ((class < 1) || (class >= NCLASSES)) {        fprintf(cp_err, "cp_addkword: Internal Error: bad class %d\n",                class);        return (NULL);    }    old = (char *) keywords[class];    keywords[class] = (struct ccom *) tree;    return (old);}/* Throw away all the stuff and prepare to rebuild it from scratch... *//* ARGSUSED */voidcp_ccrestart(kwords)    bool kwords;{    /* Ack. */    return;}static voidthrowaway(dbase)    struct ccom *dbase;{    if (dbase->cc_child)        throwaway(dbase->cc_child);    if (dbase->cc_sibling)        throwaway(dbase->cc_sibling);    tfree(dbase);    return;}/* Look up a word in the database. Because of the * way the tree is set up, this also works for looking up all words with * a given prefix (if the pref arg is true). If create is true, then the * node is created if it doesn't already exist. */static struct ccom *clookup(word, dd, pref, create)    register char *word;    struct ccom **dd;    bool pref;    bool create;{    register struct ccom *place = *dd, *tmpc;    int ind = 0, i;    char buf[BSIZE_SP];/* printf("----- adding %s -----\n", word); *//* prcc(); */    if (!place) {        /* This is the first time we were called. */        if (!create)            return (NULL);        else {            *dd = place = alloc(struct ccom);	    ZERO(place, struct ccom);            buf[0] = *word;            buf[1] = '\0';            place->cc_name = copy(buf);            if (word[1])                place->cc_invalid = 1;        }    }    while (word[ind]) {        /* Walk down the sibling list until we find a node that         * matches 'word' to 'ind' places.         */        while ((place->cc_name[ind] < word[ind]) && place->cc_sibling)            place = place->cc_sibling;        if (place->cc_name[ind] < word[ind]) {            /* This line doesn't go out that far... */            if (create) {                place->cc_sibling = alloc(struct ccom);		ZERO(place->cc_sibling, struct ccom);                place->cc_sibling->cc_ysibling = place;                place->cc_sibling->cc_parent = place->cc_parent;                place = place->cc_sibling;                place->cc_name = tmalloc(ind + 2);                for (i = 0; i < ind + 1; i++)                    place->cc_name[i] = word[i];                place->cc_name[ind + 1] = '\0';                place->cc_invalid = 1;            } else {                return (NULL);            }        } else if (place->cc_name[ind] > word[ind]) {            if (create) {                /* Put this one between place and its pred. */                tmpc = alloc(struct ccom);		ZERO(tmpc, struct ccom);                tmpc->cc_parent = place->cc_parent;                tmpc->cc_sibling = place;                tmpc->cc_ysibling = place->cc_ysibling;                place->cc_ysibling = tmpc;                place = tmpc;                if (tmpc->cc_ysibling)                    tmpc->cc_ysibling->cc_sibling = tmpc;                else if (tmpc->cc_parent)                    tmpc->cc_parent->cc_child = tmpc;                else                    *dd = place;                place->cc_name = tmalloc(ind + 2);                for (i = 0; i < ind + 1; i++)                    place->cc_name[i] = word[i];                place->cc_name[ind + 1] = '\0';                place->cc_invalid = 1;            } else {                return (NULL);            }        }        /* place now points to that node that matches the word for         * ind + 1 characters.         *//* printf("place %s, word %s, ind %d\n", place->cc_name, word, ind); */        if (word[ind + 1]) {    /* More to go... */            if (!place->cc_child) {                /* No children, maybe make one and go on. */                if (create) {                    tmpc = alloc(struct ccom);		    ZERO(tmpc, struct ccom);                    tmpc->cc_parent = place;                    place->cc_child = tmpc;                    place = tmpc;                    place->cc_name = tmalloc(ind + 3);                    for (i = 0; i < ind + 2; i++)                        place->cc_name[i] = word[i];                    place->cc_name[ind + 2] = '\0';                    if (word[ind + 2])                        place->cc_invalid = 1;                } else {                    return (NULL);                }            } else                place = place->cc_child;            ind++;        } else            break;    }    if (!pref && !create && place->cc_invalid) {        /* This is no good, we want a real word. */        return (NULL);    }    return (place);}/* Delete a node from the tree. Returns the new tree... */static voidcdelete(node)    struct ccom *node;{    node->cc_invalid = 1;    return;}

⌨️ 快捷键说明

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