int input_mapping_erase( const wchar_t *sequence ) { int ok = 0; int i; size_t sz = al_get_count( &mappings ); for( i=0; i<sz; i++ ) { input_mapping_t *m = (input_mapping_t *)al_get( &mappings, i ); if( !wcscmp( sequence, m->seq ) ) { if( i != (sz-1 ) ) { al_set( &mappings, i, al_get( &mappings, sz -1 ) ); } al_truncate( &mappings, sz-1 ); ok = 1; free( m ); break; } } return ok; }
/** \brief Sorts objects of list, use compare pFunc * \param pList ArrayList* Pointer to arrayList * \param pFunc (*pFunc) Pointer to fuction to compare elements of arrayList * \param order int [1] indicate UP - [0] indicate DOWN * \return int Return (-1) if Error [pList or pFunc are NULL pointer] * - (0) if ok */ int al_sort(ArrayList* pList, int (*pFunc)(void*,void*), int order) { int i,j; int retornFuncion; int retorno=-1; int tam = al_len(pList); int flag=0; void* aux; if (pList != NULL && pFunc != NULL && (order==1 || order==0)) { for (i=0; i< tam-1; i++ ) { for(j=i+1; j< tam; j++ ) { retornFuncion = pFunc(al_get(pList, i), al_get(pList, j)); if(retornFuncion ==1 && order == 1) { aux=al_get(pList,i); al_set(pList,i,al_get(pList,j)); al_set(pList,j,aux); } else if(retornFuncion == -1 && order == 0) { aux=al_get(pList,i); al_set(pList,i,al_get(pList,j)); al_set(pList,j,aux); } } } flag=1; } if (flag) { retorno=0; } return retorno; }
static void anna_mid_put(wchar_t *name, mid_t mid) { size_t *offset_ptr = hash_get(&anna_mid_identifier, name); if(offset_ptr) { anna_message(L"Tried to reassign mid!\n"); exit(1); } name = anna_intern(name); offset_ptr = malloc(sizeof(size_t)); *offset_ptr = mid; hash_put(&anna_mid_identifier, name, offset_ptr); al_set(&anna_mid_identifier_reverse, mid, name); }
/** \brief Remove an element by index * \param pList ArrayList* Pointer to arrayList * \param index int Index of the element * \return int Return (-1) if Error [pList is NULL pointer or invalid index] * - ( 0) if Ok */ int al_remove(ArrayList* pList,int index) { int returnAux = -1; int i; if (pList !=NULL && index<al_len(pList) && index >=0) { for (i=index; i<al_len(pList); i++) { al_set(pList,index,al_get(pList,index+1)); } pList->size--; returnAux = 0; } return returnAux; }
/** \brief Remove the item at the given position in the list, and return it. * \param pList ArrayList* Pointer to arrayList * \param index int Index of the element * \return int Return (NULL) if Error [pList is NULL pointer or invalid index] * - ( element pointer) if Ok */ void* al_pop(ArrayList* pList,int index) { void* returnAux=NULL; int i; if ( pList != NULL && index<al_len(pList) && index >= 0 ) { returnAux=al_get(pList,index); for (i=index; i<pList->size; i++) { al_set(pList,index,al_get(pList,index+1)); } pList->size--; } return returnAux; }
/** \brief Inserts the element at the specified position * \param pList ArrayList* Pointer to arrayList * \param index int Index of the element * \param pElement void* Pointer to element * \return int Return (-1) if Error [pList or pElement are NULL pointer or invalid index] * - ( 0) if Ok */ int al_push(ArrayList* pList, int index, void* pElement) { int returnAux = -1; // printf("Size es: %d",pList->size); if(pList != NULL && pElement != NULL && index >=0 && index <= pList->size ) { // if(pList->size > 0&& !resizeUp(pList)) // { // for (i=pList->size-1; i>index; i--) // { // pList->set(pList,i,pList->get(pList,(pList->pElements) + (i-1) )); /* *((pList->pElements) + i )=*((pList->pElements) + (i-1) );*/ // } // } if(!resizeUp(pList)) { expand(pList,index); pList->size++; al_set(pList,index,pElement); returnAux=0; } } return returnAux; }
void modificar(ArrayList* lista,ArrayList* listaDirec) { char opcion; int i; int auxIden; int auxDirec; int auxFlag=-1; ePelicula* auxPeli; showMessage("Ingrese identificador de la pelicula"); fflush(stdin); scanf("%d",&auxIden); for(i=0; i<lista->size; i++) { auxPeli=al_get(lista,i); if(auxIden==auxPeli->identificador) { auxFlag=0; system("cls"); showMessage("PELICULA ENCONTRADA"); system("pause"); printf("\nTitulo de la pelicula: %s\nAnio de la pelicula: %d\nNacionalidad de la pelicula: %s\nCodigo de Director de la pelicula: %d\n",auxPeli->titulo,auxPeli->anioPelicula,auxPeli->nacionalidad,auxPeli->director); showMessage("Desea modificarla? s/n"); fflush(stdin); scanf("%c",&opcion); if(opcion=='s') { system("cls"); showMessage("Ingrese titulo"); fflush(stdin); gets(auxPeli->titulo); showMessage("Ingrese nacionalidad"); fflush(stdin); gets(auxPeli->nacionalidad); showMessage("Ingrese anio de la pelicula"); fflush(stdin); scanf("%d",&auxPeli->anioPelicula); showMessage("Ingrese Puntaje de la pelicula xx/100"); fflush(stdin); scanf("%d",&auxPeli->puntaje); showMessage("Ingrese Codigo de director"); fflush(stdin); scanf("%d",&auxPeli->director); auxDirec=validarDirector(listaDirec,auxPeli->director); while(auxDirec<0) { showMessage("ERROR,DIRECTOR INEXISTENTE REINGRESE"); fflush(stdin); scanf("%d",&auxPeli->director); auxDirec=validarDirector(listaDirec,auxPeli->director); } al_set(lista,i,auxPeli); system("cls"); showMessage("PELICULA MODIFICADA CON EXITO"); system("pause"); system("cls"); } else { system("cls"); showMessage("PELICULA NO MODIFICADA"); system("pause"); system("cls"); } } } if(auxFlag==-1) { system("cls"); showMessage("PELICULA INEXISTENTE"); system("pause"); system("cls"); } }