/* * rnodeLink * Link a new node to the parent. * Perform an insertion sort. */ static void rnodeLink (meRegNode *pnp, meRegNode *np) { meRegNode *tnp; np->parent = pnp; /* Link the new node as a child immediately if possible */ if (((tnp = pnp->child) == NULL) || (meStrcmp (np->name, tnp->name) < 0)) { pnp->child = np; np->next = tnp; } else { /* Iterate down the list and add the node */ for (;;) { /* Link to the next */ if (((pnp = tnp->next) == NULL) || (meStrcmp (np->name, pnp->name) < 0)) { np->next = pnp; tnp->next = np; break; } else tnp = pnp; } } }
void meUndoAddReplace(meUByte *dstr, meInt count) { if(meModeTest(frameCur->bufferCur->mode,MDUNDO)) { meUndoCoord *co ; meUndoNode *nn ; int doto, contFlag ; contFlag = (frameCur->bufferCur->undoContFlag == undoContFlag) ; nn = frameCur->bufferCur->undoHead ; if((nn == NULL) || !meUndoIsReplace(nn) || (nn->count != count) || (nn->doto == 0xffff) || meStrcmp(nn->str,dstr)) { meUByte *dd ; if((nn = meUndoCreateNode(sizeof(meUndoNode)+meStrlen(dstr))) == NULL) return ; nn->type |= meUNDO_DELETE|meUNDO_INSERT|meUNDO_REPLACE ; nn->udata.pos = NULL ; nn->doto = 0 ; nn->count = count ; dd = nn->str ; while((*dd++ = *dstr++)) ; } /* replace is the same as last time */ if(!(nn->doto & 0x0f) && ((nn->udata.pos = meRealloc(nn->udata.pos,sizeof(meUndoCoord)* (nn->doto+16))) == NULL)) return ; co = nn->udata.pos ; doto = frameCur->windowCur->dotOffset ; if(contFlag) /* sub 1 of so 0 becomes less than 0 */ doto = -1 - doto ; co[nn->doto][0] = frameCur->windowCur->dotLineNo ; co[nn->doto++][1] = doto ; frameCur->bufferCur->undoContFlag = undoContFlag ; } }
static int findHelpItem(meUByte *item, int silent) { meWindow *wp ; meBuffer *bp, *hbp ; meLine *lp, *elp ; int sectLen, itemLen, ii ; meUByte *ss, cc, sect[5] ; itemLen = meStrlen(item) ; if((item[itemLen-1] == ')') && ((item[(ii=itemLen-3)] == '(') || (item[(ii=itemLen-4)] == '(') )) { sectLen = itemLen-ii-2 ; meStrcpy(sect,item+ii) ; itemLen = ii ; item[itemLen] = '\0' ; } else { sectLen = 0 ; sect[0] = '\0' ; sect[1] = '\0' ; } if((hbp=helpBufferFind()) == NULL) return meABORT ; elp = hbp->baseLine ; try_again: lp = meLineGetNext(elp) ; while(lp != elp) { if((lp->text[0] == '!') && (!sectLen || ((sect[1] == lp->text[2]) && (((sectLen == 1) && (lp->text[3] == ' ')) || (sect[2] == lp->text[3]))))) { if((cc=lp->text[1]) == ' ') { ii = meLineGetLength(lp) - 4 ; if(ii != itemLen) ii = -1 ; } else { ii = cc - '0' ; if(ii > itemLen) ii = -1 ; } if((ii > 0) && !meStrncmp(item,lp->text+4,ii)) break ; } lp = meLineGetNext(lp) ; } if(lp == elp) { meMacro *mac ; if(!meModeTest(hbp->mode,MDLOCK)) { if(helpBufferLoad(hbp) == meABORT) return meABORT ; goto try_again ; } if((getMacroTypeS(item) == TKCMD) && ((ii = decode_fncname(item,1)) >= CK_MAX) && ((mac = getMacro(ii)) != NULL) && (mac->hlp->flag & meMACRO_FILE)) { meModeClear(hbp->mode,MDVIEW) ; if(mac->fname != NULL) execFile(mac->fname,0,1) ; else execFile(mac->name,0,1) ; helpBufferReset(hbp) ; if(!(mac->hlp->flag & meMACRO_FILE)) goto try_again ; } if(!silent) mlwrite(MWABORT,(meUByte *)"[Can't find help on %s%s]",item,sect); return meABORT ; } if((wp = meWindowPopup(BhelpN,BFND_CREAT|BFND_CLEAR|WPOP_USESTR,NULL)) == NULL) return false ; if((sectLen == 0) && (lp->text[2] != ' ')) { ss = sect ; *ss++ = '(' ; *ss++ = lp->text[2] ; if(lp->text[3] != ' ') *ss++ = lp->text[3] ; *ss++ = ')' ; *ss = '\0' ; } bp = wp->buffer ; /* Add the header */ { meUByte buff[meBUF_SIZE_MAX] ; sprintf((char *)buff,"\033cD%s%s\033cA",lp->text+4,sect) ; addLineToEob(bp,buff) ; addLineToEob(bp,(meUByte *)"\n\033lsMicroEmacs\033lm[Home]\033le \033lsCommand G\033lm[Commands]\033le \033lsVariable \033lm[Variables]\033le \033lsMacro Lan\033lm[Macro-Dev]\033le \033lsGlobal G\033lm[Glossary]\033le") ; memset(buff,boxChars[BCEW],78) ; buff[78] = '\n' ; buff[79] = '\0' ; addLineToEob(bp,buff) ; } while(((lp=meLineGetNext(lp)) != elp) && (lp->text[0] == '!')) ; while((lp != elp) && ((cc=lp->text[0]) != '!')) { if(cc == '|') { if(meStrcmp(item,lp->text+1)) lp = meLineGetNext(lp) ; } else if(cc == '$') { if(lp->text[1] == 'a') { if(sect[1] == '5') { meUByte line[meBUF_SIZE_MAX], *ss ; if((ss = getval(item)) != NULL) { addLineToEob(bp,(meUByte *)"\n\n\033cEVALUE\033cA\n") ; meStrcpy(line," \"") ; meStrncpy(line+5,ss,meBUF_SIZE_MAX-13) ; line[meBUF_SIZE_MAX-2] = '\0' ; meStrcat(line,"\"") ; addLineToEob(bp,line) ; } } if(sect[1] == '2') { if((ii = decode_fncname(item,1)) >= 0) { meBind *ktp ; meUByte line[meBUF_SIZE_MAX], *ss ; addLineToEob(bp,(meUByte *)"\n\n\033cEBINDINGS\033cA\n") ; meStrcpy(line," ") ; ss = line+4 ; for(ktp = &keytab[0] ; ktp->code != ME_INVALID_KEY ; ktp++) { if(ktp->index == ii) { *ss++ = '"' ; meGetStringFromKey(ktp->code,ss); ss += meStrlen(ss) ; *ss++ = '"' ; *ss++ = ' ' ; } } if(ss == line+4) meStrcpy(ss,"none") ; else *ss = '\0' ; addLineToEob(bp,line) ; } } } } else addLineToEob(bp,lp->text) ; lp = meLineGetNext(lp) ; } /* Add the footer */ { meUByte buff[meBUF_SIZE_MAX] ; buff[0] = '\n' ; memset(buff+1,boxChars[BCEW],78) ; sprintf((char *)buff+79,"\n\033lsCopyright\033lm%s\033le",meCopyright) ; addLineToEob(bp,buff) ; } bp->dotLine = meLineGetNext(bp->baseLine); bp->dotOffset = 0 ; bp->dotLineNo = 0 ; meModeClear(bp->mode,MDEDIT) ; /* don't flag this as a change */ meModeSet(bp->mode,MDVIEW) ; /* put this buffer view mode */ resetBufferWindows(bp) ; /* Update the window */ mlerase(MWCLEXEC); /* clear the mode line */ return true ; }
static meMacro * createMacro(meUByte *name) { meUByte buff[meBUF_SIZE_MAX] ; register meMacro *mac ; register meLine *hlp ; register int idx ; /* If the macro name has not been give then try and get one */ if((name == NULL) && (meGetString((meUByte *)"Macro name",MLCOMMAND|MLEXECNOUSER, 0, buff, meBUF_SIZE_MAX) > 0) && (buff[0] != '\0')) name = buff ; if((name == NULL) || ((hlp = meLineMalloc(0,0)) == NULL)) return NULL ; /* if it already exists */ if((idx = decode_fncname(name,1)) >= 0) { /* if function return error, else clear the buffer */ if(idx < CK_MAX) { mlwrite(MWABORT|MWPAUSE,(meUByte *)"Error! can't re-define a base function") ; meFree(hlp) ; return NULL ; } mac = getMacro(idx) ; if(!(mac->hlp->flag & meMACRO_EXEC)) { #if MEOPT_EXTENDED if(mac->hlp->flag & meMACRO_FILE) { if(meNullFree(mac->fname)) mac->fname = NULL ; } #endif meLineLoopFree(mac->hlp,1) ; } } else { meCommand **cmd ; if((cmdTableSize & 0x1f) == 0) { /* run out of room in the command table, malloc more */ meCommand **nt ; if((nt = (meCommand **) meMalloc((cmdTableSize+0x20)*sizeof(meCommand *))) == NULL) return NULL ; memcpy(nt,cmdTable,cmdTableSize*sizeof(meCommand *)) ; if(cmdTable != __cmdTable) free(cmdTable) ; cmdTable = nt ; } if(((mac = (meMacro *) meMalloc(sizeof(meMacro))) == NULL) || ((mac->name = meStrdup(name)) == NULL)) { meFree(hlp) ; return NULL ; } mac->id = cmdTableSize ; #if MEOPT_EXTENDED mac->varList.head = NULL ; mac->varList.count = 0 ; mac->fname = NULL ; mac->callback = -1 ; #endif cmdTable[cmdTableSize++] = (meCommand *) mac ; /* insert macro into the alphabetic list */ cmd = &(cmdHead) ; while((*cmd != NULL) && (meStrcmp((*cmd)->name,name) < 0)) cmd = &((*cmd)->anext) ; mac->anext = *cmd ; *cmd = (meCommand *) mac ; #if MEOPT_CMDHASH /* insert macro into the hash table */ { meUInt key ; mac->hnext = NULL ; key = cmdHashFunc(name) ; cmd = &(cmdHash[key]) ; while(*cmd != NULL) cmd = &((*cmd)->hnext) ; *cmd = (meCommand *) mac ; } #endif } mac->hlp = hlp ; hlp->next = hlp ; hlp->prev = hlp ; return mac ; }
/* * setRegistry * Assign a new value to the registry */ int setRegistry (int f, int n) { meUByte buf1[meBUF_SIZE_MAX], *name ; meUByte buf2[meBUF_SIZE_MAX] ; meRegNode *rnp, *pnp, *nnp ; /* Get the arguments */ if(meGetString((meUByte *)"Registry Path", 0, 0, buf1, meBUF_SIZE_MAX) == meABORT) return meABORT; if(n & 0x02) { if(((rnp = regFind(&root,buf1)) == NULL) || (rnp == &root)) return mlwrite(MWCLEXEC|MWABORT,(meUByte *)"[Cannot find node %s]",buf1); /* setting the name of the node, not the value */ if(meGetString((meUByte *)"name", 0, 0, buf2, meBUF_SIZE_MAX) == meABORT) return meABORT; if(((name=meStrrchr(buf2,'/')) != NULL) && (name[1] == '\0')) { *name = '\0' ; name = meStrrchr(buf2,'/') ; } if(name != NULL) { *name++ = '\0' ; if((pnp = regFind(&root,buf2)) == NULL) return mlwrite(MWCLEXEC|MWABORT,(meUByte *)"[Cannot find node %s]",buf2) ; nnp = pnp ; do { if(nnp == rnp) return mlwrite(MWCLEXEC|MWABORT,(meUByte *)"[Cannot move node to itself or one of its children]") ; } while((nnp=nnp->parent) != NULL) ; } else { name = buf2 ; pnp = rnp->parent ; } if((pnp != rnp->parent) || meStrcmp(name,rnp->name)) { if((name[0] == '\0') || (regFind(pnp,name) != NULL)) return mlwrite(MWCLEXEC|MWABORT,(meUByte *)"[Cannot set registry node]"); if((nnp = rnodeNew(name)) == NULL) return meABORT; rnodeUnlink(rnp) ; nnp->value = rnp->value ; nnp->child = rnp->child ; nnp->mode = rnp->mode ; meFree(rnp) ; rnodeLink(pnp,nnp) ; rnp = nnp->child ; while(rnp != NULL) { rnp->parent = nnp ; rnp = rnp->next ; } } } else { if(meGetString((meUByte *)"Value", 0, 0, buf2, meBUF_SIZE_MAX) == meABORT) return meABORT; /* Assigns the new value */ if(regSet(&root,buf1,buf2) == NULL) return mlwrite(MWCLEXEC|MWABORT,(meUByte *)"[Cannot set registry node]"); } return meTRUE; }