示例#1
0
文件: macro.c 项目: collects/me
/*
 * Begin a keyboard macro.
 * Error if not at the top level in keyboard processing. Set up variables and
 * return.
 */
int
startKbdMacro(int f, int n)
{
    if (kbdmode != meSTOP)
    {
        mlwrite(0,(meUByte *)"Macro already active");
        return false ;
    }
    mlwrite(0,(meUByte *)"[Start macro]");
    kbdptr = &lkbdptr[0];
    kbdlen = 0 ;
    kbdmode = meRECORD;
    frameAddModeToWindows(WFMODE) ;  /* and update ALL mode lines */
    return true ;
}
示例#2
0
文件: macro.c 项目: collects/me
/*
 * End keyboard macro. Check for the same limit conditions as the above
 * routine. Set up the variables and return to the caller.
 */
int
endKbdMacro(int f, int n)
{
    if (kbdmode == mePLAY)
        return true ;
    if (kbdmode == meRECORD)
    {
        frameAddModeToWindows(WFMODE) ;  /* and update ALL mode lines */
        mlwrite(0,(meUByte *)"[End macro]");
        kbdmode = meSTOP;

        lkbdlen = kbdlen ;
        return true ;
    }
    return mlwrite(MWABORT,(meUByte *)"Macro not active");
}
示例#3
0
int
meUndo(int f, int n)
{
    if(n < -1)
    {
#ifndef NDEBUG
        if(n == -4)
        {
            meUndoNode *nn ;
            FILE *undoFp=NULL ;
            if(undoFp == NULL)
                undoFp = fopen("undo.log","w+") ;
            fprintf(undoFp,"[Undo stack for %s]\n",frameCur->bufferCur->name) ;
            nn=frameCur->bufferCur->undoHead ;
            while(nn != NULL)
            {
                if(meUndoIsLineSort(nn))
                {
                    fprintf(undoFp,"Undo 0x%02x %p %ld %ld:",nn->type,nn->next,
                            nn->udata.lineSort[0],nn->count) ;
                    for(n=0 ; n<nn->count ; n++)
                        fprintf(undoFp," %ld",nn->udata.lineSort[n+1]) ;
                    fprintf(undoFp,"\n") ;
                }
#if MEOPT_NARROW
                else if(meUndoIsNarrow(nn))
                {
                    meUndoNarrow *nun = (meUndoNarrow *) nn ;
                    fprintf(undoFp,"Undo 0x%02x %p Nrrw %x %ld %ld %d [%s]\n",nun->type,nun->next,
                            nun->name,nun->count,nun->udata.dotp,nun->markupCmd,nun->str) ;
                }
#endif
                else
                {
                    fprintf(undoFp,"Undo 0x%02x %p %ld (%ld,%d) [%s]\n",nn->type,nn->next,nn->count,
                            nn->udata.dotp,nn->doto,nn->str) ;
                    if(meUndoIsReplace(nn))
                    {
                        for(n=0 ; n<nn->doto ; n++)
                            fprintf(undoFp,"(%d,%d) ",nn->udata.pos[n][0],nn->udata.pos[n][1]) ;
                        fprintf(undoFp,"\n") ;
                    }
                }
                nn = nn->next ;
            }
            fprintf(undoFp,"---------------\n") ;
            fflush(undoFp) ;
        }
        else
#endif
            undoContFlag++ ;
    }
    else if(!meModeTest(frameCur->bufferCur->mode,MDUNDO))
        return ctrlg(meFALSE,1) ;
    else if(n < 0)
        meUndoRemove(frameCur->bufferCur) ;
    else
    {
        static meUndoNode *cun ;
        static meInt  ccount ;
        static meUShort cdoto ;

        if((lastflag != meCFUNDO) && ((cun = frameCur->bufferCur->undoHead) != NULL))
        {
            cdoto = cun->doto ;
            ccount = cun->count ;
        }
        for(;;)
        {
            meInt count, cont ;
            if((cun == NULL) || ((n <= 0) && !meModeTest(frameCur->bufferCur->mode,MDEDIT)))
                break ;
            if(bufferSetEdit() <= 0)               /* Check we can change the buffer */
                return meABORT ;
            cont=0 ;
            if(cun->type & meUNDO_SPECIAL)
            {
                if(meUndoIsSetEdit(cun))
                {
                    if(!(cun->type & meUNDO_UNSET_EDIT))
                    {
                        autowriteremove(frameCur->bufferCur) ;
                        meModeClear(frameCur->bufferCur->mode,MDEDIT) ;
                        frameAddModeToWindows(WFMODE) ;  /* update ALL mode lines */
                    }
                }
                else if(meUndoIsLineSort(cun))
                {
                    meLine *ln, *eln, **list ;
                    meInt *lineSort, *undoInfo, dddd ;
                    lineSort = cun->udata.lineSort ;
                    windowGotoLine(meTRUE,(*lineSort++) + 1) ;
                    if((list = meMalloc(cun->count * sizeof(meLine *))) == NULL)
                        return meABORT ;
                    undoInfo = meUndoAddLineSort(cun->count) ;
                    eln = frameCur->windowCur->dotLine ;
                    ln = meLineGetPrev(eln) ;
                    for(count=0 ; count<cun->count ; eln=meLineGetNext(eln),count++)
                    {
                        list[*lineSort++] = eln ;
                        eln->prev = (meLine *) count ;
                    }
                    for(count=0 ; count<cun->count ; ln=meLineGetNext(ln),count++)
                    {
                        if(undoInfo != NULL)
                        {
                            dddd = (meInt) list[count]->prev ;
                            *undoInfo++ = dddd ;
                        }
                        ln->next = list[count] ;
                        list[count]->prev = ln ;
                    }
                    ln->next = eln ;
                    eln->prev = ln ;
                    frameCur->windowCur->dotLine = list[0] ;
                    meFree(list) ;
                }
#if MEOPT_NARROW
                else if(meUndoIsNarrow(cun))
                {
                    meUndoNarrow *nun = (meUndoNarrow *) cun ;
                    meInt name ;
                    name = nun->name ;
                    windowGotoLine(meTRUE,nun->udata.dotp+1) ;
                    if(nun->type & meUNDO_NARROW_ADD)
                    {
                        meNarrow *nrrw ;
                        nrrw = frameCur->bufferCur->narrow ;
                        while(nrrw->name != name)
                            nrrw = nrrw->next ;
                        frameCur->bufferCur->dotLine = frameCur->windowCur->dotLine ;
                        frameCur->bufferCur->dotLineNo = frameCur->windowCur->dotLineNo ;
                        frameCur->bufferCur->dotOffset = 0 ;
                        meBufferRemoveNarrow(frameCur->bufferCur,nrrw,
                                             (nun->markupCmd > 0) ? nun->str:NULL,1) ;
                    }
                    else
                    {
                        meLine *slp ;
                        slp = frameCur->windowCur->dotLine ;
                        windowGotoLine(meTRUE,ccount+1) ;
                        meBufferCreateNarrow(frameCur->bufferCur,slp,frameCur->windowCur->dotLine,
                                             nun->udata.dotp,ccount,name,nun->scheme,
                                             (nun->markupFlag) ? nun->str:NULL,nun->markupCmd,1) ;
                    }
                }
#endif
                if(cun->type & meUNDO_CONTINUE)
                    cont=1 ;
                goto meUndoNext ;
            }
            if(cun->type & meUNDO_REPLACE)
            {
                windowGotoLine(meTRUE,cun->udata.pos[cdoto-1][0]+1) ;
                count = cun->udata.pos[cdoto-1][1] ;
                if(count < 0)
                {
                    cont = 1 ;
                    count = -1 - count ;
                }
                frameCur->windowCur->dotOffset = (meUShort) count ;
            }
            else
            {
                if(cun->type & meUNDO_CONTINUE)
                    cont = 1 ;
                windowGotoLine(meTRUE,cun->udata.dotp+1) ;
                frameCur->windowCur->dotOffset = cdoto ;
            }
            if(cun->type & meUNDO_SINGLE)
            {
                ccount-- ;
                count = 1 ;
            }
            else
                count = ccount ;
            if(cun->type & meUNDO_INSERT)
            {
                meWindowBackwardChar(frameCur->windowCur,count) ;
                if((count == 1))
                    meUndoAddDelChar() ;
                else
                    meUndoAddDelChars(count) ;
                mldelete(count,NULL) ;
            }
            if(cun->type & meUNDO_DELETE)
            {
                /* When dealing with long lines this loop becomes infinitly
                 * long because of the number of times that the line is
                 * re-allocated - pre-allocate the line length first. In order
                 * to reduce the processing overhead then we find the longest
                 * strings and then add them back in in one go, this ensures
                 * that we only ever re-allocate the line once. 
                 * Jon - 99/12/12.
                 */
                meUByte *ss, cc ;
                ss = cun->str ;
                /* Deal with a single character undo */
                if(cun->type & meUNDO_SINGLE)
                {
                    ss += ccount ;
                    if((cc = *ss++) == meCHAR_NL)
                        lineInsertNewline(meBUFINSFLAG_UNDOCALL);
                    else if (cc != '\0')
                        lineInsertChar(1, cc);
                    meUndoAddInsChar() ;
                }
                else
                {
                    /* Deal with a multiple character undo. */
                    count = bufferInsertText(ss,meBUFINSFLAG_UNDOCALL) ;
                    if(count > 0)
                        meUndoAddInsChars(count) ;
                }
            }
            if((cun->type & meUNDO_SINGLE) && (ccount > 0))
            {
                if(cun->type & meUNDO_FORWARD)
                    cdoto++ ;
                else if(cun->type & meUNDO_INSERT)
                    cdoto-- ;
            }
            else if(cun->type & meUNDO_REPLACE)
            {
                cdoto-- ;
                if(!cdoto)
                    goto meUndoNext ;
            }
            else
            {
meUndoNext:
                if((cun = cun->next) != NULL)
                {
                    cdoto = cun->doto ;
                    ccount = cun->count ;
                }
            }
            if(!cont && (--n == 0))
                break ;
        }
        thisflag = meCFUNDO ;
    }
    return meTRUE ;
}