Ejemplo n.º 1
0
image_t *image_create(void)
{
  image_t *i;

  i = calloc(1, sizeof(*i));
  if (i == NULL)
    return i;

  i->refcount = 1;
  i->background_colour = os_COLOUR_TRANSPARENT;

  list_add_to_head(&list_anchor, &i->list);

  return i;
}
Ejemplo n.º 2
0
error wire_register(wire_register_flags  flags,
                    wire_callback       *cb,
                    void                *opaque,
                    wire_id             *id)
{
  wire_client_t *client;

  client = malloc(sizeof(*client));
  if (client == NULL)
    return error_OOM;

  client->flags  = flags;
  client->cb     = cb;
  client->opaque = opaque;

  list_add_to_head(&LOCALS.anchor, &client->list);

  if (id)
    *id = (unsigned int) client;

  return error_OK;
}
Ejemplo n.º 3
0
/*
 * Aggiorna le finestre sulla genomica di list_of_factors con il fattore factor,
 * costruendo una lista ordinata per left crescente
 */
plist update_windows(plist list_of_factors, pfactor factor)
{
    pfactor copy;

    if(list_is_empty(list_of_factors)) {
        copy=factor_create();
        copy->GEN_start=factor->GEN_start;
        copy->GEN_end=factor->GEN_end;
        copy->EST_start=-1;
        copy->EST_end=-1;
        list_add_to_head(list_of_factors, copy);

        return list_of_factors;
    }

    plistit list_it_for_start, list_it_for_end;
    pfactor start_current_window, end_current_window;
    bool stop_for_start, stop_for_end;
    bool start_inside, end_inside;

    list_it_for_start=list_first(list_of_factors);
    stop_for_start=false;
    start_inside=false;
    while(stop_for_start == false && listit_has_next(list_it_for_start)) {
        start_current_window=listit_next(list_it_for_start);
        if(factor->GEN_start <= start_current_window->GEN_end) {
            stop_for_start=true;
            //lo start di factor cade all'interno di current_factor (sulla genomica)
            if(factor->GEN_start >= start_current_window->GEN_start)
                start_inside=true;
            //altrimenti lo start di factor cade prima dello start di current_factor (sulla genomica)
        }
    }
    //All'uscita da questo ciclo:
    //se stop_for_start e' true
    //list_it_for_start punta alla finestra in cui cade lo start di factor se start_inside e' true,
    //altrimenti lo start di factor cade prima dello start del fattore puntato da list_it_for_start
    //e sicuramente dopo l'end della eventuale finestra precedente
    //se stop_for_start e' false
    //significa che lo start di factor cade dopo l'end dell'ultima finestra di list_of_factors


    //Se lo start di factor cade dopo l'end dell'ultima finestra
    if(stop_for_start == false) {
        copy=factor_create();
        copy->GEN_start=factor->GEN_start;
        copy->GEN_end=factor->GEN_end;
        copy->EST_start=-1;
        copy->EST_end=-1;
        list_add_to_tail(list_of_factors, copy);
        listit_destroy(list_it_for_start);

        return list_of_factors;
    }

    //fprintf(stdout, "%d %d (%d-%d)\n", stop_for_start, start_inside, start_current_window->GEN_start, start_current_window->GEN_end);

    list_it_for_end=list_first(list_of_factors);
    stop_for_end=false;
    end_inside=false;
    int count_window=0;
    while(stop_for_end == false && listit_has_next(list_it_for_end)) {
        end_current_window=listit_next(list_it_for_end);
        count_window++;
        if(factor->GEN_end <= end_current_window->GEN_end) {
            stop_for_end=true;
            //l'end di factor cade all'interno di current_factor (sulla genomica)
            if(factor->GEN_end >= end_current_window->GEN_start) {
                end_inside=true;
            }
            //altrimenti l'end di factor cade prima dello start di current_factor (sulla genomica)
        }
    }
    //All'uscita da questo ciclo:
    //se stop_for_end e' true
    //list_it_for_end punta alla finestra in cui cade l'end di factor se end_inside e' true,
    //altrimenti l'end factor cade prima dello start del fattore puntato da list_it_for_end
    //e sicuramente dopo l'end della eventuale finestra precedente
    //se stop_for_end e' false
    //significa che l'end di factor cade dopo l'end dell'ultima finestra di list_of_factors

    //Se l'end di factor cade prima dello start della prima finestra
    if(stop_for_end == true &&  end_inside == false && count_window == 1) {
        copy=factor_create();
        copy->GEN_start=factor->GEN_start;
        copy->GEN_end=factor->GEN_end;
        copy->EST_start=-1;
        copy->EST_end=-1;
        list_add_to_head(list_of_factors, copy);
        listit_destroy(list_it_for_start);
        listit_destroy(list_it_for_end);

        return list_of_factors;
    }

    //fprintf(stdout, "%d %d (%d-%d)\n", stop_for_start, start_inside, start_current_window->GEN_start, start_current_window->GEN_end);

    if(start_inside == false && end_inside == false) {
        //factor sta in mezzo a due finestre senza sovrapporsi ad alcuna di esse (va quindi aggiunto a list_of_factors)
        if(stop_for_end == true && start_current_window->GEN_start == end_current_window->GEN_start) {
            //Aggiungo factor a list_of_factors appena prima di list_it_for_start
            copy=factor_create();
            copy->GEN_start=factor->GEN_start;
            copy->GEN_end=factor->GEN_end;
            copy->EST_start=-1;
            copy->EST_end=-1;
            list_add_before_iterator(list_it_for_start, list_of_factors, copy);
        }
        //factor ricopre una o piu' finestre consecutive estendendole a sx e a dx
        else {
            //Aggiorno la finestra in list_it_for_start con lo start e l'end di factor
            start_current_window->GEN_start=factor->GEN_start;
            start_current_window->GEN_end=factor->GEN_end;
            //Rimuovo le finestre iterando dalla successiva a list_it_for_start
            //a quella prima di list_it_for_end
            int end_curr_win_start=end_current_window->GEN_start;
            bool stop=false;
            while(listit_has_next(list_it_for_start) && stop == false) {
                pfactor current_window=listit_next(list_it_for_start);
                if(current_window->GEN_start >= end_curr_win_start)
                    stop=true;
                else
                    list_remove_at_iterator(list_it_for_start, (delete_function)factor_destroy);
            }
        }
    }
    else {
        if(start_inside == true) {
            if(end_inside == true) {
                //factor ha lo start in una finestra e l'end in un'altra successiva
                if(start_current_window->GEN_start != end_current_window->GEN_start) {
                    //Aggiorno l'end della finestra in list_it_for_start con l'end della finestra in list_it_for_end
                    start_current_window->GEN_end=end_current_window->GEN_end;

                    //Rimuovo le finestre iterando dalla successiva a list_it_for_start
                    //fino alla list_it_for_end (compresa)
                    int end_curr_win_start=end_current_window->GEN_start;
                    bool stop=false;
                    while(stop == false && listit_has_next(list_it_for_start)) {
                        pfactor current_window=listit_next(list_it_for_start);
                        /*list_remove_at_iterator(list_of_factors, list_it_for_start, (delete_function)factor_destroy);
                        if(current_window->GEN_start == end_current_window->GEN_start)
                        	stop=true;*/
                        if(current_window->GEN_start > end_curr_win_start)
                            stop=true;
                        else {
                            list_remove_at_iterator(list_it_for_start, (delete_function)factor_destroy);
                        }
                    }
                }
            }
            //factor ha lo start in una finestra e l'end in mezzo a due finestre o dopo l'end
            //dell'ultima
            else {
                //Aggiorno l'end della finestra in list_it_for_start con l'end di factor
                start_current_window->GEN_end=factor->GEN_end;
                //Rimuovo le finestre iterando dalla successiva a list_it_for_start
                //a quella prima di list_it_for_end (rimuovo anche quella di list_it_for_end
                //se stop_for_end e' false (cioe' se l'end di factor e' oltre l'end
                //dell'ultima finestra)
                int end_curr_win_start=end_current_window->GEN_start;
                bool stop=false;
                while(listit_has_next(list_it_for_start) && stop == false) {
                    pfactor current_window=listit_next(list_it_for_start);
                    if(stop_for_end == true && current_window->GEN_start >= end_curr_win_start)
                        stop=true;
                    else
                        list_remove_at_iterator(list_it_for_start, (delete_function)factor_destroy);
                }
            }
        }
        //factor ha lo start in mezzo a due finestre (o prima dello start della prima)
        //e l'end in una finestra
        else {
            //Aggiorno lo start della finestra in list_it_for_start con lo start di factor
            start_current_window->GEN_start=factor->GEN_start;

            //Aggiorno l'end della finestra in list_it_for_start con l'end di list_it_for_end
            start_current_window->GEN_end=end_current_window->GEN_end;
            //Rimuovo le finestre iterando dalla successiva a list_it_for_start
            //fino alla list_it_for_end (compresa)
            int end_curr_win_start=end_current_window->GEN_start;
            bool stop=false;
            while(listit_has_next(list_it_for_start) && stop == false) {
                pfactor current_window=listit_next(list_it_for_start);
                /*list_remove_at_iterator(list_of_factors, list_it_for_start, (delete_function)factor_destroy);
                if(current_window->GEN_start == end_current_window->GEN_start)
                	stop=true;*/
                if(current_window->GEN_start > end_curr_win_start)
                    stop=true;
                else
                    list_remove_at_iterator(list_it_for_start, (delete_function)factor_destroy);
            }
        }
    }

    listit_destroy(list_it_for_start);
    listit_destroy(list_it_for_end);

    return list_of_factors;
}