void TreeKey::assureKeyPath(const char *keyBuffer) { if (!keyBuffer) { keyBuffer = unsnappedKeyText; //assert we have something to do before setting root if (!*keyBuffer) return; } char *keybuf = 0; stdstr(&keybuf, keyBuffer); root(); // TODO: change to NOT use strtok. strtok is dangerous. SWBuf tok = strtok(keybuf, "/"); tok.trim(); while (tok.size()) { bool foundkey = false; if (hasChildren()) { firstChild(); if (tok == getLocalName()) { foundkey = true; } else { while (nextSibling()) { if (getLocalName()) { if (tok == getLocalName()) { foundkey = true; break; } } } } if (!foundkey) { append(); setLocalName(tok); save(); } } else { appendChild(); setLocalName(tok); save(); } #ifdef DEBUG // std::cout << getLocalName() << " : " << tok << std::endl; #endif tok = strtok(0, "/"); tok.trim(); } delete [] keybuf; }
DirDef::DirDef(const char *path) : Definition(path,1,1,path), visited(FALSE) { bool fullPathNames = Config_getBool(FULL_PATH_NAMES); // get display name (stipping the paths mentioned in STRIP_FROM_PATH) // get short name (last part of path) m_shortName = path; m_diskName = path; if (m_shortName.at(m_shortName.length()-1)=='/') { // strip trailing / m_shortName = m_shortName.left(m_shortName.length()-1); } int pi=m_shortName.findRev('/'); if (pi!=-1) { // remove everything till the last / m_shortName = m_shortName.mid(pi+1); } setLocalName(m_shortName); m_dispName = fullPathNames ? stripFromPath(path) : m_shortName; if (m_dispName.length()>0 && m_dispName.at(m_dispName.length()-1)=='/') { // strip trailing / m_dispName = m_dispName.left(m_dispName.length()-1); } m_fileList = new FileList; m_usedDirs = new QDict<UsedDir>(257); m_usedDirs->setAutoDelete(TRUE); m_dirCount = g_dirCount++; m_level=-1; m_parent=0; }