예제 #1
0
파일: macro.c 프로젝트: collects/me
int
nameKbdMacro(int f, int n)
{
    meUByte buf[meBUF_SIZE_MAX] ;
    int ss ;
    
    if (kbdmode != meSTOP)
        return mlwrite(MWABORT,(meUByte *)"Macro already active!");
    if(lkbdlen <= 0)
        return mlwrite(MWABORT,(meUByte *)"No macro defined!") ;
    if((ss=macroDefine(false, true)) > 0)
    {
        meStrcpy(buf,"execute-string \"") ;
        n = expandexp(lkbdlen,lkbdptr,meBUF_SIZE_MAX-2,16,buf,-1,NULL,meEXPAND_BACKSLASH|meEXPAND_FFZERO|meEXPAND_PRINTABLE) ;
        meStrcpy(buf+n,"\"") ;
        addLine(lpStore,buf) ;
    }
    mcStore = 0 ;
    lpStore = NULL ;
    return ss ;
}
예제 #2
0
/*
 * regSave
 * Save the registry back to file
 */
int
regSave(meRegNode *rnp, meUByte *fname, int mode)
{
    meRegNode *rr ;
    meInt ss=meTRUE, level=0, lineCount, charCount ;
    meUInt flags ;

    if(mode & meREGMODE_FROOT)
    {
        /* Find the filename */
        if ((fname == NULL) || (fname[0] == '\0'))
        {
            fname = NULL;
            if(rnp->mode & meREGMODE_FROOT)
                fname = rnp->value;        /* Use the default file name */
            if(fname == NULL)
                return mlwrite(MWABORT|MWPAUSE,(meUByte *)"Registry: No file name specified on save");
        }
        flags = meRWFLAG_WRITE ;
        if(mode & meREGMODE_BACKUP)
            flags |= meRWFLAG_BACKUP ;
        if(mode & meREGMODE_CRYPT)
        {
            meUByte s1[meBUF_SIZE_MAX], *s2 ;
            int len ;
            meCrypt(NULL,0);
            meStrcpy(s1,getFileBaseName(fname)) ;
            len = meStrlen(s1) + 1 ;
            meCrypt(s1,len) ;
            if((s2=meUserName) == NULL)
                s2 = (meUByte *) "" ;
            meStrcpy(s1+len,s2) ;
            meCrypt(s1,len+meStrlen(s1+len)+1) ;
            flags |= meRWFLAG_CRYPT ;
        }
        /* Open the file */
        if(ffWriteFileOpen(fname,flags,NULL) <= 0)
            return meABORT ;
        
        /* Add a recognition string to the header */
        if(!(mode & meREGMODE_CRYPT))
            ss = ffWriteFileWrite(12,(meUByte *) ";-!- erf -!-",1) ;
    }
    else
    {
        mode &= ~meREGMODE_CRYPT ;
        lineCount = 0 ;
        charCount = 0 ;
    }
    
    /* Recurse the children of the node and write to file */
    rr = rnp->child ;
    while((ss > 0) && (rr != NULL))
    {
        meUByte buff[4096] ;
        int  len ;
        /* Print the node */
        if((len = level) != 0)
            memset(buff,' ',len) ;
        buff[len++] = '"' ;
        len = expandexp(-1,rr->name,4096-11,len,buff,-1,NULL,meEXPAND_BACKSLASH|meEXPAND_FFZERO|meEXPAND_PRINTABLE) ;
        buff[len++] = '"' ;
        if (rr->mode & (meREGMODE_HIDDEN|meREGMODE_INTERNAL))
        {
            buff[len++] = ' ' ;
            buff[len++] = '0' + (rr->mode & (meREGMODE_HIDDEN|meREGMODE_INTERNAL)) ;
        }
        if (rr->value != NULL)
        {
            buff[len++] = ' ' ;
            buff[len++] = '=' ;
            buff[len++] = ' ' ;
            buff[len++] = '"' ;
            len = expandexp(-1,rr->value,4096-4,len,buff,-1,NULL,meEXPAND_BACKSLASH|meEXPAND_FFZERO|meEXPAND_PRINTABLE) ;
            buff[len++] = '"' ;
        }
        /* write open '{' if it has children */
        if (rr->child != NULL)
        {
            buff[len++] = ' ' ;
            buff[len++] = '{' ;
        }
        if((mode & meREGMODE_FROOT) == 0)
        {
            buff[len] = '\0' ;
            if((ss = addLine(frameCur->windowCur->dotLine,buff)) <= 0)
                break ;
            lineCount += ss ;
            charCount += len + 1 ;
        }
        else if((ss = ffWriteFileWrite(len,buff,1)) <= 0)
            break ;
        /* Descend child */
        if (rr->child != NULL)
        {
            rr = rr->child;
            level++;
            continue;
        }
        /* Ascend the tree */
        for (;;)
        {
            /* Move to sibling */
            if (rr->next != NULL)
            {
                rr = rr->next;
                break;
            }
            
            if (rr->parent != NULL)
            {
                if (--level < 0)
                {
                    rr = NULL;
                    break;
                }
                rr = rr->parent;
                /* as we are assending the tree, at least the first 'level'
                 * number of chars in buffer must be ' 's so just splat in the '}'
                 */
                len = level ;
                buff[len++] = '}' ;
                if((mode & meREGMODE_FROOT) == 0)
                {
                    buff[len] = '\0' ;
                    if((ss = addLine(frameCur->windowCur->dotLine,buff)) <= 0)
                        break ;
                    lineCount += ss ;
                    charCount += len + 1 ;
                }
                else if((ss = ffWriteFileWrite(len,buff,1)) <= 0)
                    break ;
            }
        }
    }
    
    if(mode & meREGMODE_FROOT)
    {
        if(ffWriteFileClose(fname,meRWFLAG_WRITE,NULL) <= 0)
            return meABORT ;
        rnp->mode &= ~meREGMODE_CHANGE;
    }
    else
    {
        meWindow *wp ;
        level = frameCur->windowCur->dotLineNo ;
        frameCur->bufferCur->lineCount += lineCount ;
        meFrameLoopBegin() ;
        for(wp=loopFrame->windowList; wp!=NULL; wp=wp->next)
        {
            if (wp->buffer == frameCur->bufferCur)
            {
                if(wp->dotLineNo >= level)
                    wp->dotLineNo += lineCount ;
                if(wp->markLineNo >= level)
                    wp->markLineNo += lineCount ;
                wp->updateFlags |= WFMAIN|WFMOVEL ;
            }
        }
        meFrameLoopEnd() ;
        frameCur->windowCur->dotOffset = 0 ;
#if MEOPT_UNDO
        meUndoAddInsChars(charCount) ;
#endif
        if(ss <= 0)
            return mlwrite(MWABORT|MWPAUSE,(meUByte *)"[Failed to write registry %s]",fname) ;
    }
    return meTRUE ;
}
예제 #3
0
/*
 * listRegistry
 * List the contents of the registry.
 */
int
listRegistry (int f, int n)
{
    meBuffer *bp;                         /* Buffer pointer */
    meWindow *wp;                         /* Window associated with buffer */
    meRegNode *rnp, *cnp, *nnp ;          /* Draw the nodes */
    meUByte vstrbuf [meBUF_SIZE_MAX];     /* Vertical string buffer */
    meUByte *bn, buf[meBUF_SIZE_MAX*2];   /* Working line buffer */
    int level = 0;                        /* Depth in the registry */
    int len;                              /* Length of the string */

    rnp = &root;
    if((n & 0x02) != 0)
    {
        if(meGetString((meUByte *)"Registry Path",0, 0, buf, meBUF_SIZE_MAX) == meABORT)
            return meABORT;

        /* Find the node */
        if((rnp = regFind(rnp,buf)) == NULL)
            return mlwrite(MWCLEXEC|MWABORT,(meUByte *)"[Cannot find node %s]",buf);
    }
    
    if((n & 0x01) == 0)
    {
        /* prompt for and get the new buffer name */
        if((len = getBufferName((meUByte *) "Buffer", 0, 0, buf)) <= 0)
            return len ;
        bn = buf ;
    }
    else
        bn = BregistryN ;
    
    /* Find the buffer and vapour the old one */
    if((wp = meWindowPopup(bn,BFND_CREAT|BFND_CLEAR|WPOP_USESTR,NULL)) == NULL)
        return meFALSE;
    bp = wp->buffer ;                   /* Point to the buffer */

    /* Recurse the children of the node and write to file */
    do
    {
        /* get the current node's first drawn child */
        cnp = rnp->child ;
        while((cnp != NULL) && (cnp->mode & meREGMODE_INVISIBLE))
            cnp = cnp->next ;

        /* get the current node's next drawn sibling */
        nnp = rnp->next ;
        while((nnp != NULL) && (nnp->mode & meREGMODE_INVISIBLE))
            nnp = nnp->next ;

        /* Add continuation bars if we are at a child level */
        if((len = level) != 0)
            meStrncpy (buf, vstrbuf, len);
        
        /* Add connection bars for siblings */
        if(level && (nnp != NULL))
            buf [len++] = boxChars[BCNES] ;
        else
            buf [len++] = boxChars[BCNE];
        
        /* Add continuation barss for children */
        if (rnp->mode & meREGMODE_INTERNAL)
            buf[len++] = '!';
        else if (cnp == NULL)
            buf[len++] = boxChars[BCEW];
        else if (rnp->mode & meREGMODE_HIDDEN)
            buf[len++] = '+';
        else
            buf[len++] = '-';
        buf[len++] = ' ';
        
        /* Add the name of the node */
        buf[len++] = '"';
        len = expandexp(-1,rnp->name,(meBUF_SIZE_MAX*2)-7,len,buf,-1,NULL,meEXPAND_BACKSLASH|meEXPAND_FFZERO) ;
        buf[len++] = '"';
        
        /* Add the value */
        if ((rnp->value != NULL) && !(rnp->mode & meREGMODE_INTERNAL))
        {
            buf[len++] = ' ';
            buf[len++] = '=';
            buf[len++] = ' ';
            buf[len++] = '"';
            len = expandexp(-1,rnp->value,(meBUF_SIZE_MAX*2)-2,len,buf,-1,NULL,meEXPAND_BACKSLASH|meEXPAND_FFZERO) ;
            buf[len++] = '"';
        }
        /* Add the string to the print buffer */
        buf[len] = '\0';
        addLineToEob(bp,buf);
        /* Descend child */
        if((cnp != NULL) && !(rnp->mode & (meREGMODE_HIDDEN|meREGMODE_INTERNAL)))
        {
            vstrbuf[level] = (level && (nnp != NULL)) ? boxChars[BCNS] : ' ' ;
            level++;
            rnp = cnp ;
            continue ;
        }
        
        /* Ascend the tree */
        while((nnp == NULL) && (--level >= 0) && ((rnp = rnp->parent) != NULL))
        {
            /* Move to next drawn sibling */
            nnp = rnp->next ;
            while((nnp != NULL) && (nnp->mode & meREGMODE_INVISIBLE))
                nnp = nnp->next ;
        }
        rnp = nnp ;
    } while((level > 0) && (rnp != NULL)) ;

    /* Set up the buffer for display */
    bp->dotLine = meLineGetNext(bp->baseLine);
    bp->dotOffset = 0 ;
    bp->dotLineNo = 0 ;
    meModeSet(bp->mode,MDVIEW) ;
    meModeClear(bp->mode,MDAUTOSV) ;
    meModeClear(bp->mode,MDUNDO) ;
    resetBufferWindows(bp) ;
    return meTRUE;
}