void RebuildListsBasedOnGroups(vector<ExtraIconGroup *> &groups) { unsigned int i; for (i = 0; i < extraIconsByHandle.size(); ++i) extraIconsByHandle[i] = registeredExtraIcons[i]; for (i = 0; i < extraIconsBySlot.size(); ++i) { ExtraIcon *extra = extraIconsBySlot[i]; if (extra->getType() != EXTRAICON_TYPE_GROUP) continue; delete extra; } extraIconsBySlot.clear(); for (i = 0; i < groups.size(); ++i) { ExtraIconGroup *group = groups[i]; for (unsigned int j = 0; j < group->items.size(); ++j) extraIconsByHandle[group->items[j]->getID() - 1] = group; extraIconsBySlot.push_back(group); } for (i = 0; i < extraIconsByHandle.size(); ++i) { ExtraIcon *extra = extraIconsByHandle[i]; if (extra->getType() != EXTRAICON_TYPE_GROUP) extraIconsBySlot.push_back(extra); } std::sort(extraIconsBySlot.begin(), extraIconsBySlot.end(), compareFunc()); }
/* find an element inside the list `list'. */ t_list * CustomfindElement(t_list *list, void *data , int (*compareFunc)(void *a, void *b)) { t_list *current_elem; /* preconditions */ if (compareFunc == NULL) return findElement(list, data); if (list == NULL) return NULL; /* intialize the value of `current_elem' */ current_elem = list; while (current_elem != NULL) { void *other_Data; other_Data = LDATA(current_elem); if (compareFunc(other_Data, data)) break; current_elem = LNEXT(current_elem); } /* postconditions */ return current_elem; }
void CRepositoryBrowser::FillListCtrlForShadowTree(CShadowFilesTree* pTree) { for (TShadowFilesTreeMap::iterator itShadowTree = pTree->m_ShadowTree.begin(); itShadowTree != pTree->m_ShadowTree.end(); ++itShadowTree) { int icon = m_nIconFolder; if (!(*itShadowTree).second.m_bFolder) icon = SYS_IMAGE_LIST().GetFileIconIndex((*itShadowTree).second.m_sName); int indexItem = m_RepoList.InsertItem(m_RepoList.GetItemCount(), (*itShadowTree).second.m_sName, icon); m_RepoList.SetItemData(indexItem, (DWORD_PTR)&(*itShadowTree).second); if (!(*itShadowTree).second.m_bFolder) { CString temp; temp = CPathUtils::GetFileExtFromPath((*itShadowTree).second.m_sName); m_RepoList.SetItemText(indexItem, eCol_Extension, temp); StrFormatByteSize((*itShadowTree).second.m_iSize, temp.GetBuffer(20), 20); temp.ReleaseBuffer(); m_RepoList.SetItemText(indexItem, eCol_FileSize, temp); } } CRepoListCompareFunc compareFunc(&m_RepoList, m_currSortCol, m_currSortDesc); m_RepoList.SortItemsEx(&CRepoListCompareFunc::StaticCompare, (DWORD_PTR)&compareFunc); SetSortArrowA(&m_RepoList, m_currSortCol, !m_currSortDesc); }
/* add sorted */ t_list * addSorted(t_list *list, void * data , int (*compareFunc)(void *a, void *b)) { t_list *current_element; void *current_data; int counter; /* preconditions */ if (list == NULL) return addFirst(list, data); counter = 0; current_element = list; while(current_element != NULL) { /* get the current interval informations */ current_data = LDATA(current_element); assert(current_data != NULL); if (compareFunc(current_data, data) >= 0) { list = addElement(list, data, counter); return list; } /* retrieve the next element */ current_element = LNEXT(current_element); /* update the value of counter */ counter++; } return addElement(list, data, -1); }
static int dlNodeCmp(const void *elem1, const void *elem2) /* Compare two dlSorters indirectly, by calling compareFunc. */ { struct dlSorter *a = (struct dlSorter *)elem1; struct dlSorter *b = (struct dlSorter *)elem2; return compareFunc(&a->node->val, &b->node->val); }
void QmitkDataStorageTableModel::sort( int column, Qt::SortOrder order /*= Qt::AscendingOrder */ ) { bool sortDescending = (order == Qt::DescendingOrder) ? true: false; // do not sort twice !!! (dont know why, but qt calls this func twice. STUPID!) /* if(sortDescending != m_SortDescending) {*/ //m_SortDescending = sortDescending; DataNodeCompareFunction::CompareCriteria _CompareCriteria = DataNodeCompareFunction::CompareByName; DataNodeCompareFunction::CompareOperator _CompareOperator = sortDescending ? DataNodeCompareFunction::Greater: DataNodeCompareFunction::Less; if(column == 1) _CompareCriteria = DataNodeCompareFunction::CompareByClassName; else if(column == 2) _CompareCriteria = DataNodeCompareFunction::CompareByVisibility; DataNodeCompareFunction compareFunc(_CompareCriteria, _CompareOperator); std::sort(m_NodeSet.begin(), m_NodeSet.end(), compareFunc); QAbstractTableModel::beginResetModel(); QAbstractTableModel::endResetModel(); //} }
EXPORT_C void CExampleCookieManager::GetCookiesL(RHTTPTransaction aTransaction, RArray<CCookie*>& aCookieList, TBool& aCookie2Reqd) { // For comparing cookies to insert them in the correct order to the returned array TLinearOrder<CCookie*> compareFunc(CompareCookiePaths); // Ensure the array is empty __ASSERT_DEBUG(aCookieList.Count()==0, HTTPCookiePanic::Panic(HTTPCookiePanic::EGetCookiesArrayNotEmpty)); const TInt numCookies = iCookies.Count(); for (TInt ii=0; ii<numCookies; ++ii) { CCookie* cookie = iCookies[ii]; const TUriC8& uri = aTransaction.Request().URI(); if(CheckDomainMatch(*cookie, uri) && CheckPathMatch(*cookie, uri) && CheckPortMatch(*cookie, uri) && CheckSecureMatch(*cookie, uri)) { User::LeaveIfError(aCookieList.InsertInOrderAllowRepeats(cookie, compareFunc)); if(!cookie->FromCookie2()) aCookie2Reqd = ETrue; } } }
int getChildIndex(List* list,void* childData, compareFunc* compareFunc){ Iterator* iterator = getIterator(list); TreeNode *ptNode; int result; while(iterator->hasNext(iterator)){ ptNode = iterator->next(iterator); result = compareFunc(ptNode->data, childData); if(result) return iterator->currentPosition; } return -1; };
vector<int> Naive::run(bool (*compareFunc)(char, char)) { vector<int> resultados; for (unsigned int i = 0; i < haystack.length(); i++) { for (unsigned int j = 0; j < needle.length(); j++) { if (!compareFunc(haystack[i + j], needle[j])) { break; } else if (j == needle.length() - 1) { resultados.push_back(i); } } } return resultados; }
void CBrowseRefsDlg::FillListCtrlForShadowTree(CShadowTree* pTree, CString refNamePrefix, bool isFirstLevel) { if(pTree->IsLeaf()) { CString filter; m_ctrlFilter.GetWindowText(filter); filter.MakeLower(); bool positive = filter[0] != '!'; if (!positive) filter = filter.Mid(1); CString ref = refNamePrefix + pTree->m_csRefName; if (!(pTree->m_csRefName.IsEmpty() || pTree->m_csRefName == "refs" && pTree->m_pParent == NULL) && IsMatchFilter(pTree, ref, filter, positive)) { int indexItem = m_ListRefLeafs.InsertItem(m_ListRefLeafs.GetItemCount(), L""); m_ListRefLeafs.SetItemData(indexItem,(DWORD_PTR)pTree); m_ListRefLeafs.SetItemText(indexItem,eCol_Name, ref); m_ListRefLeafs.SetItemText(indexItem, eCol_Upstream, pTree->m_csUpstream); m_ListRefLeafs.SetItemText(indexItem, eCol_Date, pTree->m_csDate != 0 ? CLoglistUtils::FormatDateAndTime(pTree->m_csDate, m_DateFormat, true, m_bRelativeTimes) : _T("")); m_ListRefLeafs.SetItemText(indexItem,eCol_Msg, pTree->m_csSubject); m_ListRefLeafs.SetItemText(indexItem,eCol_LastAuthor, pTree->m_csAuthor); m_ListRefLeafs.SetItemText(indexItem,eCol_Hash, pTree->m_csRefHash); int pos = 0; m_ListRefLeafs.SetItemText(indexItem,eCol_Description, pTree->m_csDescription.Tokenize(_T("\n"), pos)); } } else { CString csThisName; if (!isFirstLevel && !m_bIncludeNestedRefs) return; else if (!isFirstLevel) csThisName=refNamePrefix+pTree->m_csRefName+L"/"; else m_pListCtrlRoot = pTree; for(CShadowTree::TShadowTreeMap::iterator itSubTree=pTree->m_ShadowTree.begin(); itSubTree!=pTree->m_ShadowTree.end(); ++itSubTree) { FillListCtrlForShadowTree(&itSubTree->second,csThisName,false); } } if (isFirstLevel) { CRefLeafListCompareFunc compareFunc(&m_ListRefLeafs, m_currSortCol, m_currSortDesc); m_ListRefLeafs.SortItemsEx(&CRefLeafListCompareFunc::StaticCompare, (DWORD_PTR)&compareFunc); SetSortArrow(&m_ListRefLeafs,m_currSortCol,!m_currSortDesc); } }
static const hashtItem * _findItem (hTab * htab, int key, void *item, int (*compareFunc) (void *, void *)) { hashtItem *htip; for (htip = htab->table[key]; htip; htip = htip->next) { /* if a compare function is given use it */ if (compareFunc && compareFunc (item, htip->item)) break; else if (item == htip->item) break; } return htip; }
/*-----------------------------------------------------------------*/ void hTabDeleteItem (hTab ** htab, int key, const void *item, DELETE_ACTION action, int (*compareFunc) (const void *, const void *)) { hashtItem *htip, **htipp; if (!(*htab)) return; /* first check if anything exists in the slot */ if (!(*htab)->table[key]) return; /* if delete chain */ if (action == DELETE_CHAIN) (*htab)->table[key] = NULL; else { /* delete specific item */ /* if a compare function is given then use the compare */ /* function to find the item, else just compare the items */ htipp = &((*htab)->table[key]); htip = (*htab)->table[key]; for (; htip; htip = htip->next) { if (compareFunc ? compareFunc (item, htip->item) : (item == htip->item)) { *htipp = htip->next; break; } htipp = &(htip->next); } } (*htab)->nItems--; if (!(*htab)->nItems) { *htab = NULL; } }
TreeNode* compareNodes(List* list, compareFunc* compareFunc, void* parentData){ Iterator *iterator = getIterator(list); TreeNode* treeNode,result; List *listOfChildren = create(); if(0 == iterator->hasNext(iterator)){ return NULL; }; insertChildern(treeNode,listOfChildren); while(iterator->hasNext(iterator)){ treeNode = (TreeNode*)iterator->next(iterator); if(compareFunc(treeNode->data,parentData)){ return treeNode; }; }; return compareNodes(listOfChildren,compareFunc,parentData); };
void sort(bool (*compareFunc)(T elem1, T elem2)) { for(int i=0; i<aSize; i++) { T minEl=arElem[i]; long posMin=i; for(int j=i+1; j<aSize; j++) { if(compareFunc(arElem[j],minEl)) { posMin=j; minEl=arElem[j]; } } if(i<posMin) { T tmp=arElem[i]; arElem[i]=minEl; arElem[posMin]=tmp; } } }
static DIR_ENTRY_T *direntry_addsorted(DIR_ENTRY_LIST_T **ppListArg, const DIR_ENTRY_T *pEntry, COMPARE_DIR_ENTRY compareFunc) { DIR_ENTRY_T *pEntryInserted = NULL; DIR_ENTRY_T *pEntryTmpNext = NULL; DIR_ENTRY_T *pEntryTmpPrev = NULL; //fprintf(stdout, "adding '%s'\n", pEntry->d_name); if(ppListArg && *ppListArg) { pEntryTmpNext = (*ppListArg)->pHead; while(pEntryTmpNext) { //fprintf(stdout, "comparing '%s' '%s' disp:'%s' '%s', tm:%u %u\n", pEntry->d_name, pEntryTmpNext->d_name, pEntry->displayname, pEntryTmpNext->displayname, pEntry->tm, pEntryTmpNext->tm); if(compareFunc && compareFunc(pEntry, pEntryTmpNext) <= 0) { //fprintf(stdout, "rc: break\n"); break; } //fprintf(stdout, "rc: %d\n", rc); pEntryTmpPrev = pEntryTmpNext; pEntryTmpNext = pEntryTmpNext->pnext; } } //fprintf(stdout, "no more... TmpNext: %s prev: %s\n", pEntryTmpNext ? pEntryTmpNext->d_name : "null", pEntryTmpPrev ? pEntryTmpPrev->d_name : "null"); if((pEntryInserted = direntry_add(ppListArg, pEntry))) { if(pEntryTmpNext) { pEntryTmpNext->pprev = pEntryInserted; pEntryInserted->pnext = pEntryTmpNext; } if(pEntryTmpPrev) { pEntryTmpPrev->pnext = pEntryInserted; pEntryInserted->pprev = pEntryTmpPrev; } if(pEntryTmpPrev == NULL) { (*ppListArg)->pHead = pEntryInserted; } } return pEntryInserted; }
void CBrowseRefsDlg::OnLvnColumnclickListRefLeafs(NMHDR *pNMHDR, LRESULT *pResult) { LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR); *pResult = 0; if(m_currSortCol == pNMLV->iSubItem) m_currSortDesc = !m_currSortDesc; else { m_currSortCol = pNMLV->iSubItem; m_currSortDesc = false; } CRefLeafListCompareFunc compareFunc(&m_ListRefLeafs, m_currSortCol, m_currSortDesc); m_ListRefLeafs.SortItemsEx(&CRefLeafListCompareFunc::StaticCompare, (DWORD_PTR)&compareFunc); SetSortArrow(&m_ListRefLeafs,m_currSortCol,!m_currSortDesc); }
void CRepositoryBrowser::OnLvnColumnclickRepoList(NMHDR *pNMHDR, LRESULT *pResult) { LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR); if (pResult) *pResult = 0; if (m_currSortCol == pNMLV->iSubItem) m_currSortDesc = !m_currSortDesc; else { m_currSortCol = pNMLV->iSubItem; m_currSortDesc = false; } CRepoListCompareFunc compareFunc(&m_RepoList, m_currSortCol, m_currSortDesc); m_RepoList.SortItemsEx(&CRepoListCompareFunc::StaticCompare, (DWORD_PTR)&compareFunc); SetSortArrowA(&m_RepoList, m_currSortCol, !m_currSortDesc); }
void CRepositoryBrowser::FillListCtrlForShadowTree(CShadowFilesTree* pTree) { for (TShadowFilesTreeMap::iterator itShadowTree = pTree->m_ShadowTree.begin(); itShadowTree != pTree->m_ShadowTree.end(); ++itShadowTree) { int icon = m_nIconFolder; if (!(*itShadowTree).second.m_bFolder && !(*itShadowTree).second.m_bSubmodule) { icon = SYS_IMAGE_LIST().GetFileIconIndex((*itShadowTree).second.m_sName); } int indexItem = m_RepoList.InsertItem(m_RepoList.GetItemCount(), (*itShadowTree).second.m_sName, icon); if ((*itShadowTree).second.m_bSubmodule) { m_RepoList.SetItemState(indexItem, INDEXTOOVERLAYMASK(OVERLAY_EXTERNAL), LVIS_OVERLAYMASK); } if ((*itShadowTree).second.m_bExecutable) m_RepoList.SetItemState(indexItem, INDEXTOOVERLAYMASK(OVERLAY_EXECUTABLE), LVIS_OVERLAYMASK); if ((*itShadowTree).second.m_bSymlink) m_RepoList.SetItemState(indexItem, INDEXTOOVERLAYMASK(OVERLAY_SYMLINK), LVIS_OVERLAYMASK); m_RepoList.SetItemData(indexItem, (DWORD_PTR)&(*itShadowTree).second); if (!(*itShadowTree).second.m_bFolder && !(*itShadowTree).second.m_bSubmodule) { CString temp; temp = CPathUtils::GetFileExtFromPath((*itShadowTree).second.m_sName); m_RepoList.SetItemText(indexItem, eCol_Extension, temp); StrFormatByteSize64((*itShadowTree).second.m_iSize, temp.GetBuffer(20), 20); temp.ReleaseBuffer(); m_RepoList.SetItemText(indexItem, eCol_FileSize, temp); } } CRepoListCompareFunc compareFunc(&m_RepoList, m_currSortCol, m_currSortDesc); m_RepoList.SortItemsEx(&CRepoListCompareFunc::StaticCompare, (DWORD_PTR)&compareFunc); SetSortArrowA(&m_RepoList, m_currSortCol, !m_currSortDesc); UpdateInfoLabel(); }
CELL * findAllList(CELL * pattern, CELL * list, CELL * exprCell) { CELL * result = nilCell; CELL * cell = NULL; CELL * exprRes; CELL * match; CELL * funcCell; int errNo; UINT * resultIdxSave; funcCell = evaluateExpression(exprCell->next); resultIdxSave = resultStackIdx; if(funcCell == nilCell && !isList(pattern->type)) return(errorProcExt(ERR_LIST_EXPECTED, pattern)); while(list != nilCell) { if(funcCell == nilCell) { /* match only takes lists*/ if(!isList(list->type)) goto CONTINUE_NEXT; match = patternMatchL((CELL *)pattern->contents, (CELL *)list->contents, TRUE); if(match == NULL || match == nilCell) goto CONTINUE_NEXT; deleteList(match); } else { cleanupResults(resultIdxSave); if(compareFunc(pattern, list, funcCell) != 0) goto CONTINUE_NEXT; } /* take out sysSymbol in future, should only be used in regex */ deleteList((CELL*)sysSymbol[0]->contents); sysSymbol[0]->contents = (UINT)copyCell(list); itSymbol->contents = (UINT)list; if(exprCell != nilCell) { if((exprRes = evaluateExpressionSafe(exprCell, &errNo)) == NULL) { pushResult(result); /* push for later deletion */ longjmp(errorJump, errNo); } } else exprRes = list; exprRes = copyCell(exprRes); if(result == nilCell) { cell = exprRes; result = makeCell(CELL_EXPRESSION, (UINT)cell); } else { cell->next = exprRes; cell = cell->next; } CONTINUE_NEXT: list = list->next; } if(result == nilCell) return(getCell(CELL_EXPRESSION)); itSymbol->contents = (UINT)nilCell; return(result); }
CELL * p_replace(CELL * params) { CELL * keyCell; CELL * repCell; CELL * funcCell = NULL; CELL * list; CELL * cell; CELL * newList; char * keyStr; char * buff; char * newBuff; UINT cnt; size_t newLen; long options; UINT * resultIdxSave; SYMBOL * refSymbol; keyCell = copyCell(evaluateExpression(params)); pushResult(keyCell); params = getEvalDefault(params->next, &cell); newList = cell; refSymbol = symbolCheck; if(symbolCheck && (isProtected(symbolCheck->flags) || isBuiltin(symbolCheck->flags))) return(errorProcExt2(ERR_SYMBOL_PROTECTED, stuffSymbol(symbolCheck))); cnt = 0; resultIdxSave = resultStackIdx; if(isList(cell->type)) { cell->aux = (UINT)nilCell; /* undo last element optimization */ list = (CELL *)cell->contents; if(params != nilCell) { repCell = params; if(params->next != nilCell) funcCell = evaluateExpression(params->next); } else repCell = NULL; COMPARE_START: if(compareFunc(keyCell, list, funcCell) == 0) { if(repCell != NULL) { /* take out usage of sysSymbol0] in 10.2 should only be used for regex replacements then $it doesn't need to be a copy */ deleteList((CELL*)sysSymbol[0]->contents); itSymbol->contents = (UINT)copyCell(list); sysSymbol[0]->contents = itSymbol->contents; cell->contents = (UINT)copyCell(evaluateExpression(repCell)); cell = (CELL*)cell->contents; cell->next = list->next; } else /* remove mode */ cell->contents = (UINT)list->next; list->next = nilCell; deleteList(list); cnt++; if(repCell != NULL) list = cell; else /* remove mode */ { list = (CELL*)cell->contents; if(list != nilCell) goto COMPARE_START; } } while(list->next != nilCell) { if(compareFunc(keyCell, list->next, funcCell) == 0) { cell = list->next; /* cell = old elmnt */ if(repCell != NULL) { /* take out usage of sysSymbol0] in 10.2 should only be used for regex replacements */ deleteList((CELL*)sysSymbol[0]->contents); itSymbol->contents = (UINT)copyCell(cell); sysSymbol[0]->contents = itSymbol->contents; list->next = copyCell(evaluateExpression(repCell)); list = list->next; } list->next = cell->next; cell->next = nilCell; deleteList(cell); cnt++; } else list = list->next; cleanupResults(resultIdxSave); } deleteList((CELL*)sysSymbol[0]->contents); /* sysSymbol[0] should not be used here, introduce $count */ sysSymbol[0]->contents = (UINT)stuffInteger(cnt); itSymbol->contents = (UINT)nilCell; symbolCheck = refSymbol; pushResultFlag = FALSE; return(newList); } if(cell->type == CELL_STRING) { if(keyCell->type != CELL_STRING) return(errorProc(ERR_STRING_EXPECTED)); keyStr = (char *)keyCell->contents; buff = (char *)cell->contents; repCell = params; if(repCell == nilCell) return(errorProc(ERR_MISSING_ARGUMENT)); options = -1; if(repCell->next != nilCell) getInteger(repCell->next, (UINT*)&options); newBuff = replaceString(keyStr, keyCell->aux - 1, buff, (size_t)cell->aux -1, repCell, &cnt, options, &newLen); if(newBuff != NULL) { freeMemory(buff); cell->contents = (UINT)newBuff; cell->aux = newLen + 1; } deleteList((CELL*)sysSymbol[0]->contents); sysSymbol[0]->contents = (UINT)stuffInteger(cnt); symbolCheck = refSymbol; pushResultFlag = FALSE; return(cell); } return(errorProcExt(ERR_LIST_OR_STRING_EXPECTED, cell)); }
CELL * p_find(CELL * params) { char * key; char * str; ssize_t found; CELL * next; CELL * keyCell; CELL * funcCell; size_t size; long options = -1; size_t offset = 0; UINT * resultIdxSave; keyCell = evaluateExpression(params); params = getEvalDefault(params->next, &next); if(keyCell->type == CELL_STRING && next->type == CELL_STRING) { key = (char *)keyCell->contents; str = (char *)next->contents; size = next->aux - 1; if(params != nilCell) { if(params->next != nilCell) getInteger(params->next, (UINT*)&offset); if(offset > size) offset = size; params = evaluateExpression(params); if(!isNil(params)) getIntegerExt(params, (UINT *)&options, FALSE); } if(options == -1) found = searchBuffer(str + offset, size - offset, key, keyCell->aux - 1, TRUE); else found = searchBufferRegex(str, (int)offset, key, (int)size, options, NULL) - offset; if(found < 0) return(nilCell); } else { /* list mode with optional functor */ if(!isList(next->type)) return(nilCell); next = (CELL *)next->contents; found = 0; if(params != nilCell) funcCell = evaluateExpression(params); else funcCell = NULL; /* do regex when first arg is string and option# is present */ if(funcCell && isNumber(funcCell->type) && keyCell->type == CELL_STRING) { getIntegerExt(funcCell, (UINT*)&options, FALSE); key = (char *)keyCell->contents; while(next != nilCell) { if(next->type == CELL_STRING) { if(searchBufferRegex((char *)next->contents, 0, key, next->aux - 1 , options, NULL) != -1) break; } found++; next = next->next; } if(next == nilCell) return(nilCell); else return(stuffInteger(found)); } resultIdxSave = resultStackIdx; while(next != nilCell) { if(compareFunc(keyCell, next, funcCell) == 0) { if(funcCell) { deleteList((CELL*)sysSymbol[0]->contents); sysSymbol[0]->contents = (UINT)copyCell(next); } break; } found++; next = next->next; cleanupResults(resultIdxSave); } if(next == nilCell) return(nilCell); } return(stuffInteger(found + offset)); }
int main(void) { VILLA *villa; int size; char *s; printf("compareFunc(\"a\", \"b\") = %i\n", compareFunc("a", 1, "b", 1)); printf("compareFunc(\"b\", \"a\") = %i\n", compareFunc("b", 1, "a", 1)); printf("compareFunc(\"a\", \"a\") = %i\n", compareFunc("a", 1, "a", 1)); printf("compareFunc(\"b\", \"b\") = %i\n", compareFunc("b", 1, "b", 1)); remove("test.qdbm"); if(!(villa = vlopen("test.qdbm", VL_OWRITER | VL_OCREAT, compareFunc))) { printf("vlopen failed %s\n", dperrmsg(dpecode)); return 1; } if(!vltranbegin(villa)) { printf("vltranbegin failed %s\n", dperrmsg(dpecode)); return 1; } if(!vlput(villa, "a", 1, "1", 1, DP_DOVER)) { printf("vlput failed %s\n", dperrmsg(dpecode)); return 1; } if(!vlput(villa, "b", 1, "2", 1, DP_DOVER)) { printf("vlput failed %s\n", dperrmsg(dpecode)); return 1; } if(!vltrancommit(villa)) { printf("vltrancommit failed %s\n", dperrmsg(dpecode)); return 1; } if(!vlclose(villa)) { printf("vlclose failed %s\n", dperrmsg(dpecode)); return 1; } if(!(villa = vlopen("test.qdbm", VL_OWRITER | VL_OCREAT, compareFunc))) { printf("vlopen failed %s\n", dperrmsg(dpecode)); return 1; } s = vlget(villa, "a", 1, &size); printf("a = '%s'\n", s ? s : "NULL"); s = vlget(villa, "b", 1, &size); printf("b = '%s'\n", s ? s : "NULL"); if(!vlclose(villa)) { printf("vlclose failed %s\n", dperrmsg(dpecode)); return 1; } return 0; }
INT_PTR ExtraIcon_Register(WPARAM wParam, LPARAM lParam) { if (wParam == 0) return 0; EXTRAICON_INFO *ei = (EXTRAICON_INFO *) wParam; if (ei->cbSize < (int) sizeof(EXTRAICON_INFO)) return 0; if (ei->type != EXTRAICON_TYPE_CALLBACK && ei->type != EXTRAICON_TYPE_ICOLIB) return 0; if (IsEmpty(ei->name) || IsEmpty(ei->description)) return 0; if (ei->type == EXTRAICON_TYPE_CALLBACK && (ei->ApplyIcon == NULL || ei->RebuildIcons == NULL)) return 0; const char *desc = Translate(ei->description); BaseExtraIcon *extra = GetExtraIconByName(ei->name); if (extra != NULL) { if (ei->type != extra->getType() || ei->type != EXTRAICON_TYPE_ICOLIB) return 0; // Found one, now merge it if (_stricmp(extra->getDescription(), desc)) { string newDesc = extra->getDescription(); newDesc += " / "; newDesc += desc; extra->setDescription(newDesc.c_str()); } if (!IsEmpty(ei->descIcon)) extra->setDescIcon(ei->descIcon); if (ei->OnClick != NULL) extra->setOnClick(ei->OnClick, ei->onClickParam); if (extra->getSlot() > 0) { if (clistRebuildAlreadyCalled) extra->rebuildIcons(); if (clistApplyAlreadyCalled) extraIconsByHandle[extra->getID() - 1]->applyIcons(); } return extra->getID(); } size_t id = registeredExtraIcons.size() + 1; switch (ei->type) { case EXTRAICON_TYPE_CALLBACK: extra = new CallbackExtraIcon(id, ei->name, desc, ei->descIcon == NULL ? "" : ei->descIcon, ei->RebuildIcons, ei->ApplyIcon, ei->OnClick, ei->onClickParam); break; case EXTRAICON_TYPE_ICOLIB: extra = new IcolibExtraIcon(id, ei->name, desc, ei->descIcon == NULL ? "" : ei->descIcon, ei->OnClick, ei->onClickParam); break; default: return 0; } char setting[512]; mir_snprintf(setting, MAX_REGS(setting), "Position_%s", ei->name); extra->setPosition(DBGetContactSettingWord(NULL, MODULE_NAME, setting, 1000)); mir_snprintf(setting, MAX_REGS(setting), "Slot_%s", ei->name); int slot = DBGetContactSettingWord(NULL, MODULE_NAME, setting, 1); if (slot == (WORD) -1) slot = -1; extra->setSlot(slot); registeredExtraIcons.push_back(extra); extraIconsByHandle.push_back(extra); vector<ExtraIconGroup *> groups; LoadGroups(groups); ExtraIconGroup *group = IsInGroup(groups, extra); if (group != NULL) { RebuildListsBasedOnGroups(groups); } else { for (unsigned int i = 0; i < groups.size(); ++i) delete groups[i]; extraIconsBySlot.push_back(extra); std::sort(extraIconsBySlot.begin(), extraIconsBySlot.end(), compareFunc()); } if (slot >= 0 || group != NULL) { if (clistRebuildAlreadyCalled) extra->rebuildIcons(); slot = 0; for (unsigned int i = 0; i < extraIconsBySlot.size(); ++i) { ExtraIcon *ex = extraIconsBySlot[i]; if (ex->getSlot() < 0) continue; int oldSlot = ex->getSlot(); ex->setSlot(slot++); if (clistApplyAlreadyCalled && (ex == group || ex == extra || oldSlot != slot)) extra->applyIcons(); } } return id; }