static enum nss_status internal_getgrent(struct group *gr, char *buffer, size_t buflen, int *errnop, void *cmpdata, int (*cmpFunc)(void *, void *)) { struct group *grpp; int r = 0; enum nss_status result = NSS_STATUS_SUCCESS; if ( (fgrent.stream == NULL) || (cmpdata != NULL) ) result = internal_setent(&fgrent); if (result != NSS_STATUS_SUCCESS) return result; while (!r) { r = fgetgrent_r(fgrent.stream, gr, buffer, buflen, &grpp); if ( (cmpFunc == NULL) || (cmpFunc(gr, cmpdata))) break; } if (r == ERANGE) { *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } if (r) return NSS_STATUS_NOTFOUND; return result; }
void SP_NKVector :: sort( int ( * cmpFunc )( const void *, const void * ) ) { for( int i = 0; i < mCount - 1; i++ ) { int min = i; for( int j = i + 1; j < mCount; j++ ) { if( cmpFunc( mFirst[ min ], mFirst[ j ] ) > 0 ) { min = j; } } if( min != i ) { void * temp = mFirst[ i ]; mFirst[ i ] = mFirst[ min ]; mFirst[ min ] = temp; } } }
HashItem* hashFindInternal( Hashtable tbl, void* key) { HashSegment segm; HashItem* itemPtr; HashItem item; uint keyLen = tbl->keyLen; hashCmpFunc cmpFunc = tbl->hashCmp; uint hash = tbl->hashFunc(key, keyLen); uint listId, sNum, sInd; listId = convertHashToListNumber(tbl, hash); /* Segment size always is a power of 2: 2^n. * SegmentSize is 2^n. * SegmentShift is n. * listId we can represent: listId = segmSize * sNum + sInd; * So sNum = listId/segmSize, sInd = listId mod segmSize; * When we operate with powers of 2, we can compute these operations * using only bitwise operations */ sNum = listId >> tbl->segmShift; sInd = listId & (tbl->segmSize - 1); segm = tbl->segments[sNum]; itemPtr = &segm[sInd]; item = *itemPtr; while (item != NULL) { if (item->hash == hash && cmpFunc(GET_HASH_KEY(item), key, keyLen) == 0) break; itemPtr = &(item->next); item = *itemPtr; } return itemPtr; }
bool CMatch::MatchWord(LPCWSTR asLine/*This may be NOT 0-terminated*/, int anLineLen/*Length of buffer*/, int anFrom/*Cursor pos*/, int& rnStart, int& rnEnd) { rnStart = rnEnd = anFrom; TODO("Проверить на ошибки после добавления горизонтальной прокрутки"); if (!asLine || !*asLine || (anFrom < 0) || (anLineLen <= anFrom)) return false; TODO("Setting to define word-break characters (was gh-328 issue)"); struct cmp { static bool isChar(ucs32 inChar) { return (isCharSpace(inChar) || isCharSeparate(inChar)); } }; bool (*cmpFunc)(ucs32 inChar) = isCharNonWord; // If user double-clicks on "═════════════" - try to select this block of characters? if (isCharNonWord(asLine[rnStart])) cmpFunc = cmp::isChar; while ((rnStart > 0) && !(cmpFunc(asLine[rnStart-1]))) { rnStart--; } const wchar_t szLeftBkt[] = L"<({[", szRightBkt[] = L">)}]"; int iStopOnRghtBkt = -1; // Trim leading punctuation except of "." (accept dot-files like ".bashrc") while (((rnStart+1) < rnEnd) && (asLine[rnStart] != L'.') && isCharPunctuation(asLine[rnStart])) { if (iStopOnRghtBkt == -1) { const wchar_t* pchLeftBkt = wcschr(szLeftBkt, asLine[rnStart]); iStopOnRghtBkt = (int)(pchLeftBkt - szLeftBkt); _ASSERTE(iStopOnRghtBkt > 0 && (size_t)iStopOnRghtBkt < wcslen(szRightBkt)); } rnStart++; } bool bStopOnBkt = false; while (((rnEnd+1) < anLineLen) && !(cmpFunc(asLine[rnEnd+1]))) { if ((iStopOnRghtBkt >= 0) && (asLine[rnEnd+1] == szRightBkt[iStopOnRghtBkt])) { bStopOnBkt = true; break; } rnEnd++; } if (!bStopOnBkt) { // Now trim trailing punctuation while (((rnEnd-1) > rnStart) && isCharPunctuation(asLine[rnEnd])) { rnEnd--; } // If part contains (leading) brackets - don't trim trailing brackets for (int i = rnStart; i <= rnEnd; i++) { if (wcschr(szLeftBkt, asLine[i])) { // Include trailing brackets while (((rnEnd+1) < anLineLen) && wcschr(szRightBkt, asLine[rnEnd+1])) { rnEnd++; } // Done break; } } } // Done StoreMatchText(NULL, NULL); return true; }