/*! Iterate through all except first cligen variables in a cvec list * * @param[in] cvv Cligen variable vector * @param[in] prev Last cgv (or NULL) * @retval cv Next variable structure. * @retval NULL When end of list reached. * Common in many cvecs where [0] is the command-line and all * others are arguments. * @see cvec_each For all elements, dont skip first */ cg_var * cvec_each1(cvec *cvv, cg_var *prev) { if (prev == NULL){ /* Initialization */ if (cvv->vr_len > 1) return &cvv->vr_vec[1]; else return NULL; } return cvec_next(cvv, prev); }
CVector* divideFam(CVector *wordVec, int wordLength, char ch, int *max_index) { int n = 1; for (int i = 0; i < wordLength; i++) { n += n; } CVector **fam = malloc(n * sizeof(CVector*)); for (int i = 0; i < n; i++) { fam[i] = NULL; } int *arr = calloc(n, sizeof(int)); int index = 0; for (void *cur = cvec_first(wordVec); cur != NULL; cur = cvec_next(wordVec, cur)) { char *word = (char*)cur; int check = 0; for (int i = wordLength -1; i >= 0; i--) { if (word[i] == ch) { if(check != 0) { // means the character appears more than once. // remove it from the current family cvec_remove(fam[check], cvec_count(fam[check]) - 1); arr[check]--; check = check | (1 << (wordLength -i - 1)); } check = check | (1 << (wordLength -i - 1)); appendElem(fam, check, wordLength, arr, word); } } if (check == 0) { appendElem(fam, check, wordLength, arr, word); } } *max_index = getMaxIndex(arr, n); free(arr); return fam[*max_index]; }