示例#1
0
/*
 * readRegistry
 * Read a file into the registry.
 */
int
readRegistry(int f, int n)
{
    meUByte filebuf [meBUF_SIZE_MAX];
    meUByte rootbuf [32];
    meUByte modebuf [10];
    int mode = 0;

    /* Get the input from the command line */
    if ((meGetString((meUByte *)"Read registry root",0, 0, rootbuf, 32) == meABORT) ||
        (((n & 4) == 0) &&
         (meGetString((meUByte *)"Registry file",MLFILECASE, 0, filebuf, meBUF_SIZE_MAX) == meABORT)) ||
        (meGetString((meUByte *)"File Mode", 0, 0, modebuf, 10) == meABORT))
        return meABORT;
    
    /* Get the mode out */
    if (regDecodeMode (&mode, modebuf) == meABORT)
        return meABORT;

    mode &= ~meREGMODE_FROOT ;
    if((n & 4) == 0)
        mode |= meREGMODE_FROOT ;
    
    /* Read the file */
    if(regRead(rootbuf, filebuf, mode) == NULL)
        return meFALSE;
    return meTRUE;
}
示例#2
0
文件: macro.c 项目: collects/me
/* macroHelpDefine:
 * Set up a macro help definition
 */
int
macroHelpDefine(int f, int n)
{
    meUByte name[meBUF_SIZE_MAX] ;
    meUByte sect[20] ;
    
    if((lpStoreBp=helpBufferFind()) == NULL)
        return meABORT ;
    if(meGetString((meUByte *)"Enter name", MLCOMMAND, 0, name+4, meBUF_SIZE_MAX-4) <= 0)
        return false ;
    sect[0] = '\0' ;
    if(meGetString((meUByte *)"Enter section", 0, 0, sect, 20) == meABORT)
        return false ;
    /* and set the macro store pointers to it */
    lpStore = meLineGetNext(lpStoreBp->baseLine) ;
    name[0] = '!' ;
    name[1] = (f) ? '0'+n:' ' ;
    if(sect[0] == '\0')
    {
        name[2] = ' ' ; 
        name[3] = ' ' ; 
    }
    else
    {
        name[2] = sect[0] ; 
        name[3] = (sect[1] == '\0') ? ' ':sect[1] ;
    }
    addLine(lpStore,name) ;
    lpStoreBp->lineCount++ ;
    mcStore = 2 ;
    return true ;
}
示例#3
0
/*
 * findRegistry
 * Find a key in the registry by indexing
 */
int
findRegistry (int f, int n)
{
    meUByte rootbuf [meBUF_SIZE_MAX];
    meUByte valbuf [12];
    int index;
    meRegNode *rnp ;

    /* Get the arguments */
    if((meGetString((meUByte *)"Registry Path", 0, 0, rootbuf, meBUF_SIZE_MAX) == meABORT) ||
       (meGetString((meUByte *)"Index", 0, 0, valbuf, 12) == meABORT))
        return meABORT;
    index = meAtoi (valbuf);

    /* Assigns the new value */
    if((rnp = regFind (&root, rootbuf)) == NULL)
        return mlwrite(MWCLEXEC|MWABORT,(meUByte *)"[Cannot find node %s]",rootbuf);
    /* Find the node that is indexed */
    f = index ;
    rnp = rnp->child;
    while((--index >= 0) && rnp)
        rnp = rnp->next;
    if(rnp == NULL)
    {
        resultStr [0] ='\0';
        return mlwrite (MWCLEXEC|MWABORT,(meUByte *)"Cannot find node at index %d", f);
    }
    meStrncpy(resultStr, rnp->name, meBUF_SIZE_MAX-1);
    resultStr[meBUF_SIZE_MAX-1] = '\0';
    return meTRUE;
}
示例#4
0
文件: macro.c 项目: collects/me
/* macroFileDefine:
 * Set up a macro buffer and flag to store all
 * executed command lines there			*/
int
macroFileDefine(int f, int n)
{
    register meMacro *mac ;	/* pointer to macro */
    meUByte fname[meBUF_SIZE_MAX] ;
    int ii=0 ;
    
    if(meGetString((meUByte *)"Enter file", MLCOMMAND, 0, fname, meBUF_SIZE_MAX) <= 0)
        return false ;
    while((mac=createMacro(NULL)) != NULL)
    {
        if(n == 0)
            mac->hlp->flag |= meMACRO_HIDE ;
        mac->hlp->flag |= meMACRO_FILE ;
        mac->fname = meStrdup(fname) ;
        ii++ ;
    }
    if(ii == 0)
    {
        if((mac=createMacro(fname)) == NULL)
            return false ;
        if(n == 0)
            mac->hlp->flag |= meMACRO_HIDE ;
        mac->hlp->flag |= meMACRO_FILE ;
    }
    return true ;
}
示例#5
0
文件: frame.c 项目: collects/me
/*
 * frameChangeDepth  - Change the depth of the screen.
 * Resize the screen, re-writing the screen
 */
int
frameChangeDepth(int f, int n)
{
    /* if no argument is given then prompt for the new depth */
    if (f == false)
    {
        meUByte buff[meSBUF_SIZE_MAX] ;

        if (meGetString((meUByte *)"New depth", 0, 0, buff, meSBUF_SIZE_MAX) <= 0)
            return false ;
        n = meAtoi(buff) ;
    }
    else
        /* n is a delta, add this to the current width to get the new width */
        n = frameCur->depth + 1 + n ;
    if ((n < 4) || (n > 400))           /* Argument in range ?? */
        return mlwrite(MWABORT,(meUByte *)"[Screen depth %d out of range]", n);
    if (n == (frameCur->depth+1))
        return true;                    /* Already the right size */

    if(meFrameChangeDepth(frameCur,n) <= 0)
        return false ;

#ifdef _WINDOW
    meFrameSetWindowSize(frameCur) ;    /* Change the size of the window */
#endif
    return true ;
}
示例#6
0
文件: macro.c 项目: collects/me
int	
helpItem(int f, int n)
{
    meUByte buf[meBUF_SIZE_MAX] ;
    
    if(meGetString((meUByte *)"Help on item", 0, 0, buf, meBUF_SIZE_MAX-10) <= 0)
        return false ;
    return findHelpItem(buf,0) ;
}
示例#7
0
文件: macro.c 项目: collects/me
int
executeString(int f, int n)
{
    meUByte sbuf[meBUF_SIZE_MAX] ;
    
    if(meGetString((meUByte *)"Enter string", MLFFZERO, 0, sbuf, meBUF_SIZE_MAX) <= 0)
        return 0 ;
    return stringExec(f,n,sbuf) ;
}
示例#8
0
文件: macro.c 项目: collects/me
int	
helpVariable(int f, int n)
{
    meUByte buf[meBUF_SIZE_MAX] ;

    if(meGetString((meUByte *)"Help on variable", MLVARBL, 0, buf, meBUF_SIZE_MAX-10) <= 0)
        return false ;
    meStrcat(buf,"(5)") ;
    return findHelpItem(buf,0) ;
}
示例#9
0
/*
 * saveRegistry
 * Save the registry to a file.
 * 
 * Note the return value for this is:
 * meABORT - there was a major failure (i.e. couldn't open the file)
 * meFALSE - user quit
 * meTRUE  - succeded
 * this is used by the exit function which ignore the major failures
 */
int
saveRegistry (int f, int n)
{
    meUByte filebuf [meBUF_SIZE_MAX];
    meUByte rootbuf [128];
    meRegNode *rnp;
    meInt mode ;
    
    if(n & 0x2)
    {
        rnp = root.child ;
        while (rnp != NULL)
        {
            if((f=regTestSave(rnp,n)) <= 0)
                return f ;
            rnp = rnp->next ;
        }
        return meTRUE ;
    }
    
    /* Get the input from the command line */
    if(meGetString((meUByte *)"Save registry root",0, 0, rootbuf, 128) == meABORT)
        return meFALSE;
    
    /* Find the root */
    if((rnp = regFind (&root, rootbuf)) == NULL)
        return mlwrite(MWCLEXEC|MWABORT,(meUByte *)"[Cannot find node %s]",rootbuf);
    
    mode = rnp->mode & ~meREGMODE_FROOT ;
    if((n & 4) == 0)
    {
        if(rnp->mode & meREGMODE_FROOT)
            meStrcpy(filebuf,rnp->value) ;
        else
            filebuf[0] = '\0' ;
    
        /* Get the filename */
        if(meGetString((meUByte *)"Registry file",MLFILECASE|MLFILECASE, 0, filebuf, meBUF_SIZE_MAX) <= 0)
            return meFALSE ;
        mode |= meREGMODE_FROOT ;
    }
    return regSave(rnp,filebuf,mode) ;
}
示例#10
0
int
deleteRegistry (int f, int n)
{
    meUByte rootbuf [meBUF_SIZE_MAX];
    meRegNode *rnp;

    if (meGetString((meUByte *)"Registry Path", 0, 0, rootbuf, meBUF_SIZE_MAX) == meABORT)
        return meABORT;
    if ((rnp = regFind (&root, rootbuf)) == NULL)
        return mlwrite(MWCLEXEC|MWABORT,(meUByte *)"[Cannot find node %s]",rootbuf);
    return regDelete (rnp);
}
示例#11
0
文件: macro.c 项目: collects/me
int	
helpCommand(int f, int n)
{
    meUByte *ss, buf[meBUF_SIZE_MAX] ;
              
    if(meGetString((meUByte *)"Help on command", MLCOMMAND, 0, buf, meBUF_SIZE_MAX-10) <= 0)
        return false ;
    ss = buf + meStrlen(buf) ;
    meStrcpy(ss,"(2)") ;
    if(findHelpItem(buf,1) > 0)
        return true ;
    meStrcpy(ss,"(3)") ;
    return findHelpItem(buf,0) ;
}
示例#12
0
文件: macro.c 项目: collects/me
meMacro *
userGetMacro(meUByte *buf, int len)
{
    register int idx ;
    
    if(meGetString((meUByte *)"Enter macro name ", MLCOMMAND,2,buf,len) > 0)
    {        
        if((idx = decode_fncname(buf,0)) < 0)
            mlwrite(MWABORT,(meUByte *)"%s not defined",buf) ;
        else if(idx < CK_MAX)
            mlwrite(MWABORT,(meUByte *)"%s is a command",buf) ;
        else
            return getMacro(idx) ;
    }
    return NULL ;
}
示例#13
0
文件: macro.c 项目: collects/me
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 ;
}
示例#14
0
/*
 * markRegistry
 * Mark a node in the registry.
 */
int
markRegistry (int f, int n)
{
    meUByte rootbuf [meBUF_SIZE_MAX];
    meUByte modebuf [10];
    int mode;
    meRegNode *rnp;

    /* Get the input from the command line */
    if ((meGetString((meUByte *)"Registry node",0, 0, rootbuf, meBUF_SIZE_MAX) == meABORT) ||
        (meGetString((meUByte *)"Mark modes", 0, 0, modebuf, 10) == meABORT))
        return meABORT;

    /* Find the node */
    if ((rnp = regFind (&root, rootbuf)) == NULL)
        return mlwrite(MWCLEXEC|MWABORT,(meUByte *)"[Cannot find node %s]",rootbuf);


    /* Find the integer offset if there is one. */
    if (f)
    {
        meRegNode *tnp, *nnp;

        tnp = rnp;
        f = n ;
        while((--n >= 0) && (tnp != NULL))
        {
            if(!(tnp->mode & (meREGMODE_HIDDEN|meREGMODE_INTERNAL)) &&
               ((nnp = tnp->child) != NULL))
                tnp = nnp ;
            else
                nnp = tnp->next ;
            
            while((tnp != NULL) && ((nnp == NULL) || (nnp->mode & meREGMODE_INVISIBLE)))
            {
                if(nnp == NULL)
                {
                    /* Make sure we are not back at the root */
                    if((tnp = tnp->parent) == rnp)
                        tnp = NULL;
                    else
                        nnp = tnp->next ;
                }
                else
                    nnp = nnp->next ;
            }
            tnp = nnp ;
        }

        /* tnp is the current node. Change the node */
        if ((rnp = tnp) == NULL)
            return mlwrite (MWCLEXEC|MWABORT,(meUByte *)"[Cannot locate node %d]", f);
    }

    /* Get the mode out */
    mode = rnp->mode;
    if (regDecodeMode (&mode, modebuf) == meABORT)
        return meABORT;
    rnp->mode = mode & meREGMODE_STORE_MASK ;

    /* If this is a query then return the path of the current node in
     * $result. */
    if (mode & meREGMODE_QUERY)
        findRegistryName (rnp, resultStr);
    else if (mode & meREGMODE_GETMODE)
    {
        meUByte *ss=resultStr ;
        int ii ;
        for(ii=0 ; ii<8 ; ii++)
            if(rnp->mode & (1<<ii))
                *ss++ = meRegModeList[ii] ;
        *ss = '\0' ;
    }

    return meTRUE;
}
示例#15
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;
}
示例#16
0
/*
 * 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;
}