/* * 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; }
/** Parses the input string to a vector of pairs * * Parses the input string in the form a,b,c{n},d{m},e,f * to a vector of pairs with base number (a,b,c,d,e,f) and multipliers * (1,1,n,m,e,f) * * \param[in] s as const std::string in the form a,b{n} * \return std::vector<pair> with uint32_t (base, multiplier) */ void parseString( const std::string s ) { boost::regex regFind( "[0-9]+(\\{[0-9]+\\})*", boost::regex_constants::perl ); boost::sregex_token_iterator iter( s.begin( ), s.end( ), regFind, 0 ); boost::sregex_token_iterator end; parsedInput.clear(); parsedInput.reserve( std::distance( iter, end ) ); for(; iter != end; ++iter ) { std::string pM = *iter; // find multiplier n and base b of b{n} boost::regex regMultipl( "(.*\\{)|(\\})", boost::regex_constants::perl ); std::string multipl = boost::regex_replace( pM, regMultipl, "" ); boost::regex regBase( "\\{.*\\}", boost::regex_constants::perl ); std::string base = boost::regex_replace( pM, regBase, "" ); // no Multiplier {n} given if( multipl == *iter ) multipl = "1"; const std::pair<uint32_t, uint32_t> g( boost::lexical_cast<uint32_t > ( base ), boost::lexical_cast<uint32_t > ( multipl ) ); parsedInput.push_back( g ); } }
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); }
/* * 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) ; }
/* * 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; }
/* * 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; }
/* * 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; }