void ChangeList (struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights, enum rtype *artypep) { struct AclEntry *tlist; tlist = (plus ? al->pluslist : al->minuslist); tlist = FindList (tlist, aname); if (tlist) { /* Found the item already in the list. */ /* modify rights in case of reladd */ /* and reladd only, use standard - */ /* add, ie. set - otherwise */ if ( artypep == NULL ) tlist->rights = arights; else if ( *artypep == reladd ) tlist->rights |= arights; else if ( *artypep == reldel ) tlist->rights &= ~arights; else tlist->rights = arights; if (plus) al->nplus -= PruneList(&al->pluslist, al->dfs); else al->nminus -= PruneList(&al->minuslist, al->dfs); return; } if ( artypep != NULL && *artypep == reldel ) /* can't reduce non-existing rights */ return; /* Otherwise we make a new item and plug in the new data. */ tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry)); assert(tlist); if( FAILED(StringCbCopy(tlist->name, sizeof(tlist->name), aname))) { fprintf (stderr, "name - not enough space"); exit(1); } tlist->rights = arights; if (plus) { tlist->next = al->pluslist; al->pluslist = tlist; al->nplus++; if (arights == 0 || arights == -1) al->nplus -= PruneList(&al->pluslist, al->dfs); } else { tlist->next = al->minuslist; al->minuslist = tlist; al->nminus++; if (arights == 0) al->nminus -= PruneList(&al->minuslist, al->dfs); } }
/*---------------------------------------------------------------------------*/ void ReadTrainingSamples ( FILE *File, LIST* TrainingSamples) /* ** Parameters: ** File open text file to read samples from ** Globals: none ** Operation: ** This routine reads training samples from a file and ** places them into a data structure which organizes the ** samples by FontName and CharName. It then returns this ** data structure. ** Return: none ** Exceptions: none ** History: Fri Aug 18 13:11:39 1989, DSJ, Created. ** Tue May 17 1998 simplifications to structure, illiminated ** font, and feature specification levels of structure. */ { char unichar[UNICHAR_LEN + 1]; LABELEDLIST CharSample; FEATURE_SET FeatureSamples; CHAR_DESC CharDesc; int Type, i; while (fscanf (File, "%s %s", FontName, unichar) == 2) { CharSample = FindList (*TrainingSamples, unichar); if (CharSample == NULL) { CharSample = NewLabeledList (unichar); *TrainingSamples = push (*TrainingSamples, CharSample); } CharDesc = ReadCharDescription (File); Type = ShortNameToFeatureType(PROGRAM_FEATURE_TYPE); FeatureSamples = CharDesc->FeatureSets[Type]; for (int feature = 0; feature < FeatureSamples->NumFeatures; ++feature) { FEATURE f = FeatureSamples->Features[feature]; for (int dim =0; dim < f->Type->NumParams; ++dim) f->Params[dim] += UniformRandomNumber(-MINSD, MINSD); } CharSample->List = push (CharSample->List, FeatureSamples); CharSample->SampleCount++; for (i = 0; i < CharDesc->NumFeatureSets; i++) if (Type != i) FreeFeatureSet(CharDesc->FeatureSets[i]); free (CharDesc); } } // ReadTrainingSamples
SHORT CFreeLists::CreateList(CString strFileName) { SHORT nNewEntry; CString strShortFileName; SHORT nHandle; strShortFileName = GetShortFileName(strFileName); LoadFileList(); nHandle = FindList(strShortFileName); if(nHandle >= 0) return nHandle; // Assert if trying to create list that already exists ASSERT(nHandle < 0); nNewEntry = m_FileList.AddEntry(strShortFileName) + 1; SaveFileList(); return nNewEntry; }
TValueKeeper* VariableTable::Find(char* name) { List* list = nullptr; if (list = FindList(name)) { TValueKeeper* keeper = nullptr; for (int i = 0; i < list->Count(); i++) { if (strcmp((keeper = ((TValueKeeper*)(list->GetAccessor(i))))->GetName(), name) == 0) { return keeper; } } } return nullptr; }
static void ChangeList(struct Acl *a_al, afs_int32 a_plus, char *a_name, afs_int32 a_rights) { /*ChangeList */ struct AclEntry *tlist; tlist = (a_plus ? a_al->pluslist : a_al->minuslist); tlist = FindList(tlist, a_name); if (tlist) { /* * Found the item already in the list. */ tlist->rights = a_rights; if (a_plus) a_al->nplus -= PruneList(&a_al->pluslist); else a_al->nminus -= PruneList(&a_al->minuslist); return; } /* * Otherwise, we make a new item and plug in the new data. */ tlist = malloc(sizeof(struct AclEntry)); strcpy(tlist->name, a_name); tlist->rights = a_rights; if (a_plus) { tlist->next = a_al->pluslist; a_al->pluslist = tlist; a_al->nplus++; if (a_rights == 0) a_al->nplus -= PruneList(&a_al->pluslist); } else { tlist->next = a_al->minuslist; a_al->minuslist = tlist; a_al->nminus++; if (a_rights == 0) a_al->nminus -= PruneList(&a_al->minuslist); } } /*ChangeList */
/*---------------------------------------------------------------------------*/ LIST ReadTrainingSamples ( FILE *File) /* ** Parameters: ** File open text file to read samples from ** Globals: none ** Operation: ** This routine reads training samples from a file and ** places them into a data structure which organizes the ** samples by FontName and CharName. It then returns this ** data structure. ** Return: none ** Exceptions: none ** History: Fri Aug 18 13:11:39 1989, DSJ, Created. ** Tue May 17 1998 simplifications to structure, illiminated ** font, and feature specification levels of structure. */ { char unichar[UNICHAR_LEN + 1]; LABELEDLIST CharSample; FEATURE_SET FeatureSamples; LIST TrainingSamples = NIL; CHAR_DESC CharDesc; int Type, i; while (fscanf (File, "%s %s", CTFontName, unichar) == 2) { if (!unicharset_training.contains_unichar(unichar)) { unicharset_training.unichar_insert(unichar); if (unicharset_training.size() > MAX_NUM_CLASSES) { cprintf("Error: Size of unicharset of mftraining is " "greater than MAX_NUM_CLASSES\n"); exit(1); } } CharSample = FindList (TrainingSamples, unichar); if (CharSample == NULL) { CharSample = NewLabeledList (unichar); TrainingSamples = push (TrainingSamples, CharSample); } CharDesc = ReadCharDescription (File); Type = ShortNameToFeatureType(PROGRAM_FEATURE_TYPE); FeatureSamples = CharDesc->FeatureSets[Type]; for (int feature = 0; feature < FeatureSamples->NumFeatures; ++feature) { FEATURE f = FeatureSamples->Features[feature]; for (int dim =0; dim < f->Type->NumParams; ++dim) f->Params[dim] += dim == MFDirection ? UniformRandomNumber(-MINSD_ANGLE, MINSD_ANGLE) : UniformRandomNumber(-MINSD, MINSD); } CharSample->List = push (CharSample->List, FeatureSamples); CharSample->SampleCount++; for (i = 0; i < CharDesc->NumFeatureSets; i++) if (Type != i) FreeFeatureSet(CharDesc->FeatureSets[i]); free (CharDesc); } return (TrainingSamples); } /* ReadTrainingSamples */