static int dom_filter_ranges( dom *d, range_array *ranges )
{
    // first range must be root
    range *root = range_array_get(ranges,0);
    if ( root != NULL )
    {
        if ( !queue_push(d->q,root) )
            return 0;
        else
        {
            d->ranges = range_array_create();
            if ( d->ranges != NULL )
            {
                int i,num_ranges = range_array_size( ranges );
                for ( i=1;i<num_ranges;i++ )
                {
                    range *r = range_array_get( ranges, i );
                    char *r_name = range_name( r );
                    hashset *pruned = matrix_get_lookup(d->pm);
                    if ( hashset_contains(pruned,r_name) )
                    {
                        css_rule *rule = hashmap_get( d->css_rules,r_name );
                        char *html_name = css_rule_get_element(rule);
                        if ( range_html_name(r) != NULL||
                            range_set_html_name(r,html_name) )
                        {
                            // this should duplicate the range
                            range *r_dup = range_copy( r );
                            if ( r_dup == NULL || !dom_store_range(d,r_dup) )
                            {
                                warning("dom: failed to push onto queue\n");
                                return 0;
                            }      
                        }
                        else
                        {
                            warning("dom: couldn't set html name for %s\n", 
                                r_name);
                            return 0;
                        }
                    }
                }
            }
            return 1;
        }
    }
    else
        return 0;
}
Example #2
0
/**
 * Initialise a matrix with a set of ranges that may be within one another
 * @param m the matrix in question
 * @param ranges the array of range object pointers
 */
void matrix_init( matrix *m, range_array *ranges )
{
    int i;
    int n_ranges = range_array_size( ranges );
    matrix_queue *mq = matrix_queue_create();
    for ( i=0;i<n_ranges;i++ )
    {
        if ( !matrix_queue_add(mq,m,range_array_get(ranges,i)) )
            break;
    }
    matrix_queue_dispose( mq );
    m->inited = 1;
}