Пример #1
0
Node *list_insert_end(Node *list, void *data)
{
    if(list == NULL)
	return list_insert_beginning(list, data);


    Node *newnode;
    newnode = list_create(data);
      
    if(newnode == NULL)
	return NULL;

    Node *curnode = list;

    while(curnode)
    {
	if(curnode->next == NULL)
	{
	    curnode->next = newnode;
	    newnode->next = NULL;
	    break;
	}
	curnode = curnode->next;
    }
    return list;
}
Пример #2
0
int add_jump(int from,int to){
	jump *j = malloc (sizeof(jump));
	j->from=from;
	j->to=to;
	list_insert_beginning(table_des_jump,j);
	return 0;
}
// mettre un element dans la table renvoie son id si succès -1 sinon
int insert(char * nom,type_state state,char * nom_fonction){

	if (nom ==NULL){
		return -1;
	}

	if (state ==TMP){
		nb_tmp++;
		nom = malloc(sizeof(char)*50);
		sprintf(nom,"tmp_%d",nb_tmp);
	}



	if (get_id_for_name(nom)==-1){
		id_courant++;
		symbole *new_symb=malloc(sizeof(symbole));

		new_symb->nom=nom;
		strcpy(new_symb->fonction,nom_fonction);
		new_symb->id =id_courant;
		new_symb->state=state;
		list_insert_beginning(table_des_symboles,new_symb);
	} else {
		return -1;
	}

	return id_courant;
}
Function* add_function(llist * functions_table, const char * p_name, unsigned int ui_implementation_address, unsigned int ui_argument_number, bool return_value){
	Function * p_function = (Function *) malloc(sizeof(Function));
	list_node * node = list_insert_beginning(functions_table, p_function);
	p_function->p_name = p_name;
	p_function->ui_implementation_address = ui_implementation_address;
	p_function->ui_argument_number = ui_argument_number;
	p_function->return_value = return_value;
	return (node ? (Function*)node->data : NULL);	
}
int smart_insert(char * nom,type_state state,char * nom_fonction){

	if (nom ==NULL){
		return -1;
	}

	if (state ==TMP){
		// Les symboles temporaires on les insère sans vérifier.
		nb_tmp++;
		nom = malloc(sizeof(char)*50);
		sprintf(nom,"tmp_%d",nb_tmp);
		id_courant++;
		symbole *new_symb=malloc(sizeof(symbole));
		new_symb->nom=nom;
		new_symb->fonction=nom_fonction;
		new_symb->id =id_courant;
		new_symb->state=state;
		list_insert_beginning(table_des_symboles,new_symb);
		return id_courant;
	} else {
		if (smart_get(nom,nom_fonction)==-1){
			printf("Existe pas :)\n");
			//Si le symbole n'existe pas déja !
			id_courant++;
			symbole *new_symb=malloc(sizeof(symbole));
			new_symb->nom=nom;
			new_symb->fonction=nom_fonction;
			new_symb->id =id_courant;
			new_symb->state=state;
			list_insert_beginning(table_des_symboles,new_symb);
			return id_courant;
		} else {
			printf("Existe :(\n");
			return -1;
		}
	}

	return -1;
}
Пример #6
0
int main(int argc, char **argv)
{
  int x = 1;
  int y = 2;
  int z = 3;
  
  list_node_t *list = list_create(&x);
  list_dump(list, &output);

  list = list_insert_end(list, &y);
  list_dump(list, &output);
  
  list = list_insert_beginning(list, &z);
  list_dump(list, &output);

  list = list_insert_beginning(list, &z);
  list_dump(list, &output);

  list = list_insert_after(list, &y);
  list_dump(list, &output);

  return 0;
}