Exemple #1
0
void halloc_free( void *context )
{
	halloc_t *me;
	int i;
	
	if( !context )
		return;

	
	me = halloc_from_data( context );

#ifdef HALLOC_DEBUG
	alloc_spill += me->scratch_free;
#endif
	for( i=0; i<al_get_count(&me->children); i+=2 )
	{
		void (*func)(void *) = (void (*)(void *))al_get( &me->children, i );
		void * data = (void *)al_get( &me->children, i+1 );
		if( func != &late_free )
			func( data );
	}
	for( i=0; i<al_get_count(&me->children); i+=2 )
	{
		void (*func)(void *) = (void (*)(void *))al_get_func( &me->children, i );
		void * data = (void *)al_get( &me->children, i+1 );
		if( func == &late_free )
			free( data );
	}
	al_destroy( &me->children );
	free(me);
}
Exemple #2
0
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;
	
}
Exemple #3
0
/*
 * print info of Edges in/out given BasicBlock
 */
void printEdges(BasicBlock *block){
	BlockEdge *edge = NULL;
	int i;
	printf("inbound Edges of block #%d:\n", block->id);
	for(i=0;i<al_size(block->preds);i++){
		edge = al_get(block->preds, i);
		printf("%c%c%c%c%c %d -> %d  : %d\n",
				EDGE_HAS_FLAG(edge, EDGE_IN_DFST)?'*':'-',
				EDGE_HAS_FLAG(edge, EDGE_IS_RETREAT)?'R':'-',
				EDGE_HAS_FLAG(edge, EDGE_IS_BACK_EDGE)?'B':'-',
				EDGE_HAS_FLAG(edge, EDGE_IS_BRANCHED_PATH)?'J':'-',
				EDGE_HAS_FLAG(edge, EDGE_IS_ADJACENT_PATH)?'A':'-',
				edge->tail->id, edge->head->id, edge->count);
	}
	printf("outbound Edges of block #%d:\n", block->id);
	for(i=0;i<al_size(block->succs);i++){
		edge = al_get(block->succs, i);
		printf("%c%c%c%c%c %d -> %d  : %d\n",
				EDGE_HAS_FLAG(edge, EDGE_IN_DFST)?'*':'-',
				EDGE_HAS_FLAG(edge, EDGE_IS_RETREAT)?'R':'-',
				EDGE_HAS_FLAG(edge, EDGE_IS_BACK_EDGE)?'B':'-',
				EDGE_HAS_FLAG(edge, EDGE_IS_BRANCHED_PATH)?'J':'-',
				EDGE_HAS_FLAG(edge, EDGE_IS_ADJACENT_PATH)?'A':'-',

				edge->tail->id, edge->head->id, edge->count);
	}
}
Exemple #4
0
int guardarEnArchivo(ArrayList* lista,ArrayList* listaDirec)
{
    int i;
    FILE *f;
    FILE *f2;
    ePelicula* pAux;
    eDirector* pAux2;
    f=fopen("peliculas.dat","wb");
    f2=fopen("directores.dat","wb");
    if(f == NULL)
    {
        return -1;
    }
    for(i=0;i<lista->size;i++)
    {
        pAux=al_get(lista,i);
        fwrite(pAux,sizeof(ePelicula),1,f);
    }
    for(i=0;i<listaDirec->size;i++)
    {
        pAux2=al_get(listaDirec,i);
        fwrite(pAux2,sizeof(eDirector),1,f2);
    }
    fclose(f);
    return 0;
}
Exemple #5
0
/**
   Silly function
*/
static void	builtin_complete_remove( array_list_t *cmd, 
									 array_list_t *path,
									 const wchar_t *short_opt,
									 array_list_t *gnu_opt,
									 array_list_t *old_opt )
{
	
	int i;
	
	for( i=0; i<al_get_count( cmd ); i++ )
	{
		builtin_complete_remove2( (wchar_t *)al_get( cmd, i ),
								  COMMAND,
								  short_opt, 
								  gnu_opt,
								  old_opt );
	}
	
	for( i=0; i<al_get_count( path ); i++ )
	{
		builtin_complete_remove2( (wchar_t *)al_get( path, i ),
								  PATH,
								  short_opt, 
								  gnu_opt,
								  old_opt );
	}
	
}
Exemple #6
0
/**
   Silly function
*/
static void	builtin_complete_add( array_list_t *cmd, 
								  array_list_t *path,
								  const wchar_t *short_opt,
								  array_list_t *gnu_opt,
								  array_list_t *old_opt, 
								  int result_mode, 
								  int authoritative,
								  const wchar_t *condition,
								  const wchar_t *comp,
								  const wchar_t *desc,
								  int flags )
{
	int i;
	
	for( i=0; i<al_get_count( cmd ); i++ )
	{
		builtin_complete_add2( al_get( cmd, i ),
							   COMMAND,
							   short_opt, 
							   gnu_opt,
							   old_opt, 
							   result_mode, 
							   condition, 
							   comp, 
							   desc,
							   flags );

		if( authoritative != -1 )
		{
			complete_set_authoritative( al_get( cmd, i ),
									  COMMAND,
									  authoritative );
		}
		
	}
	
	for( i=0; i<al_get_count( path ); i++ )
	{
		builtin_complete_add2( al_get( path, i ),
							   PATH,
							   short_opt, 
							   gnu_opt,
							   old_opt, 
							   result_mode, 
							   condition, 
							   comp, 
							   desc,
							   flags );

		if( authoritative != -1 )
		{
			complete_set_authoritative( al_get( path, i ),
									  PATH,
									  authoritative );
		}
		
	}	
}
/** \brief Returns an array containing all of the elements in this list in proper sequence
 * \param pList ArrayList* Pointer to arrayList
 * \return ArrayList* Return  (NULL) if Error [pList is NULL pointer]
 *                          - (New array) if Ok
 */
ArrayList* al_clone(ArrayList* pList)
{
    ArrayList* returnAux;
    returnAux = al_newArrayList();
    int i;


    if(pList != NULL && returnAux!= NULL)
    {
        for(i=0;i<pList->size;i++)
        {
            al_add(returnAux,al_get(pList,i));
        }
    } else{
             if(pList == NULL)
             {
                 returnAux = NULL;
             }

            }

      //printf("% p / %p \n", pList, returnAux );

    return returnAux;
}
/** \brief Returns true if pList list contains all of the elements of pList2
* \param pList ArrayList* Pointer to arrayList
* \param pList2 ArrayList* Pointer to arrayList
* \return int Return (-1) if Error [pList or pList2 are NULL pointer]
*                  - (0) if Not contains All - (1) if is contains All
*/
int al_containsAll(ArrayList* pList,ArrayList* pList2)
{
    int returnAux = -1;
    int contador = 0;
    int i;
    void* dato;

    if(pList != NULL && pList2 != NULL)
    {
        //int size = pList2->size;

        for(i=0; i<=pList2->size; i++)
        {
            dato = al_get(pList2,i);
            if(al_contains(pList,dato) == 1)
            {
                contador = contador +1;
            }
        }

        if(contador==pList2->size)
        {
            returnAux=1;
        }
        else
        {
            returnAux=0;
        }

    }

    return returnAux;
}
Exemple #9
0
static void complete_strings( array_list_t *comp_out,
							  const wchar_t *wc_escaped,
							  const wchar_t *desc,
							  const wchar_t *(*desc_func)(const wchar_t *),
							  array_list_t *possible_comp,
							  int flags )
{
	int i;
	wchar_t *wc, *tmp;

	tmp = expand_one( 0,
					  wcsdup(wc_escaped), EXPAND_SKIP_CMDSUBST | EXPAND_SKIP_WILDCARDS);
	if(!tmp)
		return;

	wc = parse_util_unescape_wildcards( tmp );
	free(tmp);

	for( i=0; i<al_get_count( possible_comp ); i++ )
	{
		wchar_t *next_str = (wchar_t *)al_get( possible_comp, i );

		if( next_str )
		{
			wildcard_complete( next_str, wc, desc, desc_func, comp_out, flags );
		}
	}

	free( wc );
}
Exemple #10
0
const wchar_t *history_next_match( const wchar_t *needle)
{
    if( current_mode )
    {
        /*
          The index of previous search matches are saved in the 'used'
          list. We just need to pop the top item and set the new
          position. Easy!
        */
        if( al_get_count( &current_mode->used ) )
        {
            al_pop( &current_mode->used );
            if( al_get_count( &current_mode->used ) )
            {
                current_mode->pos = (int) al_peek_long( &current_mode->used );
                item_t *i = item_get( current_mode, al_get( &current_mode->item, current_mode->pos ) );
                return i->data;
            }
        }

        /*
          The used-list is empty. Set position to 'past end of list'
          and return the search string.
        */
        current_mode->pos = al_get_count( &current_mode->item );

    }
    return needle;
}
Exemple #11
0
Employee* pushEmployee(int* Index, ArrayList* lista)
{
    int auxId;
    int auxInt;
    int auxIndex;
    char auxName[52];
    char auxLastname[52];
    int i;
    Employee* auxEmployee = NULL;
    Employee* isEmployee;
    if(lista != NULL)
    {

        auxInt = getInt(&auxIndex, "Ingrese el indice: ", "ERROR: Numero no valido", 0, 1001);
        if(auxInt !=0)
        {
            return NULL;
        }
        *Index = auxIndex;
        datosEmployee(&auxId, auxName, auxLastname);

        for(i=0; i<lista->len(lista); i++)
        {
            isEmployee = (Employee*) al_get(lista, i);
            if(isEmployee->id == auxId)
            {
                printf("Ya existe alguien con ese id!\n");
                return auxEmployee;
            }
        }
        auxEmployee = newEmployee(auxId, auxName, auxLastname);

    }
    return auxEmployee;
}
Exemple #12
0
const wchar_t *input_terminfo_get_name( const wchar_t *seq )
{
	int i;	
	static string_buffer_t *buff = 0;

	CHECK( seq, 0 );
	input_init();
		
	if( !buff )
	{
		buff = sb_halloc( global_context );
	}
	
	for( i=0; i<al_get_count( terminfo_mappings ); i++ )
	{
		terminfo_mapping_t *m = (terminfo_mapping_t *)al_get( terminfo_mappings, i );
		
		if( !m->seq )
		{
			continue;
		}
		
		sb_clear( buff );
		sb_printf( buff, L"%s", m->seq );
		
		if( !wcscmp( seq, (wchar_t *)buff->buff ) )
		{
			return m->name;
		}
	}
	
	return 0;
	
}
Exemple #13
0
void input_mapping_add( const wchar_t *sequence,
			const wchar_t *command )
{
	int i;

	CHECK( sequence, );
	CHECK( command, );
	
	//	debug( 0, L"Add mapping from %ls to %ls", escape(sequence, 1), escape(command, 1 ) );
	

	for( i=0; i<al_get_count( &mappings); i++ )
	{
		input_mapping_t *m = (input_mapping_t *)al_get( &mappings, i );
		if( wcscmp( m->seq, sequence ) == 0 )
		{
			m->command = intern(command);
			return;
		}
	}
	
	input_mapping_t *m = malloc( sizeof( input_mapping_t ) );
	m->seq = intern( sequence );
	m->command = intern(command);
	al_push( &mappings, m );	
	
}
Exemple #14
0
DATA al_pop_front(smb_al *list, smb_status *status)
{
  // On failure, returns dummy and sets INDEX_ERROR.
  DATA toReturn = al_get(list, 0, status);
  // On failure, sets INDEX_ERROR and does nothing.
  al_remove(list, 0, status);
  return toReturn;
}
Exemple #15
0
/**
   @brief Return the next item in the array list.
   @param iter The iterator being used.
   @param[out] status Status variable.
   @return The next item in the array list.
   @exception SMB_STOP_ITERATION If the list has no more elements.
 */
DATA al_iter_next(smb_iter *iter, smb_status *status)
{
  DATA ret_val = al_get((const smb_al *)iter->ds, iter->index++, status);
  if (*status == SMB_INDEX_ERROR) {
    *status = SMB_STOP_ITERATION;
  }
  return ret_val;
}
Exemple #16
0
DATA al_pop_back(smb_al *list, smb_status *status)
{
  // On failure, returns dummy and sets INDEX_ERROR:
  DATA toReturn = al_get(list, list->length - 1, status);
  // On failure, sets INDEX_ERROR and does nothing:
  al_remove(list, list->length - 1, status);
  return toReturn;
}
/** \brief Funcion para la guardar datos en un archivo,
 * \param pList: arrayList donde se encuentra la data a guardar
 * \param nombreArchivo: Nombre del archivo.
 * \param opcion: parametro utilizado para diferenciar si el dato es un usuario (1) o comentario (2)
 */
int guardarEnArchivo(ArrayList* pList, char* nombreArchivo, int opcion)
{
    int i;
    int retorno=1;
    FILE *archivo;
    User* users;
    EComments* comentarios;

    if(pList != NULL)
    {
        archivo = fopen(nombreArchivo, "wb");
        if( archivo != NULL)
        {
            if(opcion ==1)
            {
                for(i = 0; i< pList->len(pList); i++)
                {
                    users = al_get(pList, i);
                    if(users != NULL)
                    {
                        fwrite(users, sizeof(User),1, archivo);
                    }
                }
            }
            if(opcion ==2)
            {
                for(i = 0; i< pList->len(pList); i++)
                {
                    comentarios = al_get(pList, i);
                    if(comentarios != NULL)
                    {
                        fwrite(comentarios, sizeof(EComments), 1, archivo);
                    }
                }
            }
            fclose(archivo);
        }
        else
        {
            retorno = -1;
        }
    }
    return retorno;
}
Exemple #18
0
wint_t input_readch()
{
	
	int i;

	CHECK_BLOCK( R_NULL );
	
	/*
	  Clear the interrupted flag
	*/
	reader_interrupted();
	
	/*
	  Search for sequence in mapping tables
	*/

	while( 1 )
	{
		input_mapping_t *generic = 0;
		for( i=0; i<al_get_count( &mappings); i++ )
		{
			input_mapping_t *m = (input_mapping_t *)al_get( &mappings, i );
			wint_t res = input_try_mapping( m );		
			if( res )
				return res;
			
			if( wcslen( m->seq) == 0 )
			{
				generic = m;
			}
			
		}
		
		/*
		  No matching exact mapping, try to find generic mapping.
		*/

		if( generic )
		{	
			wchar_t arr[2]=
				{
					0, 
					0
				}
			;
			arr[0] = input_common_readch(0);
			
			return input_exec_binding( generic, arr );				
		}
				
		/*
		  No action to take on specified character, ignore it
		  and move to next one.
		*/
		input_common_readch( 0 );	}	
}
Exemple #19
0
static void anna_hash_add_all_extra_methods(anna_type_t *hash)
{
    int i;
    for(i=0; i<al_get_count(&anna_hash_additional_methods); i++)
    {
	anna_function_t *fun =
	    (anna_function_t *)al_get(&anna_hash_additional_methods, i);
	anna_hash_add_method_internal(hash, fun);
    }
}
Exemple #20
0
int al_push_all( array_list_t *a, array_list_t *b )
{
    int k;
    for( k=0; k<al_get_count( b ); k++ )
    {
        if( !al_push( a, al_get( b, k ) ) )
            return 0;
    }
    return 1;
}
/** \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;
}
Exemple #22
0
void input_mapping_get_names( array_list_t *list )
{
	int i;
	
	for( i=0; i<al_get_count( &mappings ); i++ )
	{
		input_mapping_t *m = (input_mapping_t *)al_get( &mappings, i );
		al_push( list, m->seq );
	}
	
}
Exemple #23
0
/*
 * print detail info of given BasicBlock list
 */
void printBasicBlockList(ArrayList *blockList) {
  int i, sz = al_size(blockList);
  BasicBlock *block;

  printf("\nBasic Block List:\n");
  for (i = 0; i < sz; i++) {
	  block = (BasicBlock *)al_get(blockList, i);
    printBasicBlock(block);
  }
  printf("=================================================================\n");
}
/** \brief Returns an array containing all of the elements in this list in proper sequence
 * \param pList ArrayList* Pointer to arrayList
 * \return ArrayList* Return  (NULL) if Error [pList is NULL pointer]
 *                          - (New array) if Ok
 */
ArrayList* al_clone(ArrayList* pList)
{
    ArrayList* returnAux = NULL;
    int i;
    if(pList!=NULL)
    {
        returnAux =al_newArrayList();
        for(i=0;i<pList->size;i++)
            al_add(returnAux,al_get(pList,i));
    }
    return returnAux;
}
Exemple #25
0
void baja(ArrayList* lista)
{
    char opcion;
    int i;
    int auxIden;
    int flag=0;
    int auxContains;
    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);
        auxContains=al_contains(lista,auxPeli);
        if(auxIden==auxPeli->identificador&&auxContains==1)
        {
            flag=1;
            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 eliminarla? s/n");
            fflush(stdin);
            scanf("%c",&opcion);
            if(opcion=='s')
            {
                system("cls");
                al_remove(lista,i);
                showMessage("PELICULA BORRADA");
                system("pause");
                system("cls");
            }
            else
            {
                system("cls");
                showMessage("PELICULA NO BORRADA");
                system("pause");
                system("cls");
            }
            break;
        }

    }
    if(flag==0)
    {
        system("cls");
        showMessage("PELICULA INEXISTENTE");
        system("pause");
        system("cls");
    }
}
Exemple #26
0
void listar(ArrayList* lista,ArrayList* listaDirec)
{
    int i,j;
    ArrayList* listaOrdenada;
    listaOrdenada=al_clone(lista);
    al_sort(listaOrdenada,compareFilms,0);
    ePelicula* pAuxP;
    eDirector* pAuxD;
    for(i=0; i<lista->size; i++)
    {
        pAuxP=al_get(listaOrdenada,i);
        for(j=0; j<listaDirec->size; j++)
        {
            pAuxD=al_get(listaDirec,j);
            if(pAuxP->director==pAuxD->codDirec)
            {
                break;
            }
        }
        printf("\nTitulo de la pelicula: %s\nDirector de la pelicula: %s\nNacionalidad de la pelicula: %s\nPuntaje: %d/100\n",pAuxP->titulo,pAuxD->nombre,pAuxP->nacionalidad,pAuxP->puntaje);
    }
    al_deleteArrayList(listaOrdenada);
}
Exemple #27
0
void printFc(ArrayList* pList)
{
  int i=0;
  int intAux;
  sMovie* movieAux;
  for(i=0;i<pList->len(pList);i++)
  {
      //movieAux=*(pList->pElements+i);
      movieAux=al_get(pList, i);
      intAux=al_indexOf(pList, movieAux);
      printf("titulo:%s, puntaje:%d, indice:%d\n", movieAux->titulo, movieAux->puntaje, intAux);

  }
}
Exemple #28
0
/**
   Silly function
*/
static void builtin_complete_remove3( wchar_t *cmd,
									  int cmd_type,
									  wchar_t short_opt,
									  array_list_t *long_opt )		
{
	int i;
	
	for( i=0; i<al_get_count( long_opt ); i++ )
	{
		complete_remove( cmd,
						 cmd_type,
						 short_opt,
						 (wchar_t *)al_get( long_opt, i ) );
	}	
}
Exemple #29
0
const wchar_t *input_mapping_get( const wchar_t *sequence )
{
	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 ) )
		{
			return m->command;
		}
	}
	return 0;
}
Exemple #30
0
void input_terminfo_get_names( array_list_t *lst, int skip_null )
{
	int i;	

	CHECK( lst, );
	input_init();
		
	for( i=0; i<al_get_count( terminfo_mappings ); i++ )
	{
		terminfo_mapping_t *m = (terminfo_mapping_t *)al_get( terminfo_mappings, i );
		
		if( skip_null && !m->seq )
		{
			continue;
		}
		al_push( lst, m->name );
	}
}