Exemple #1
0
LIST * regex_split( FRAME * frame, int flags )
{
    LIST * args = lol_get( frame->args, 0 );
    OBJECT * s;
    OBJECT * separator;
    regexp * re;
    const char * pos;
    LIST * result = L0;
    LISTITER iter = list_begin( args );
    s = list_item( iter );
    separator = list_item( list_next( iter ) );
    
    re = regex_compile( separator );

    pos = object_str( s );
    while ( regexec( re, pos ) )
    {
        result = list_push_back( result, object_new_range( pos, re->startp[ 0 ] - pos ) );
        pos = re->endp[ 0 ];
    }

    result = list_push_back( result, object_new( pos ) );

    return result;
}
Exemple #2
0
static SETTINGS * make1settings( struct module_t * module, LIST * vars )
{
    SETTINGS * settings = 0;

    LISTITER vars_iter = list_begin( vars );
    LISTITER const vars_end = list_end( vars );
    for ( ; vars_iter != vars_end; vars_iter = list_next( vars_iter ) )
    {
        LIST * const l = var_get( module, list_item( vars_iter ) );
        LIST * nl = L0;
        LISTITER iter = list_begin( l );
        LISTITER const end = list_end( l );

        for ( ; iter != end; iter = list_next( iter ) )
        {
            TARGET * const t = bindtarget( list_item( iter ) );

            /* Make sure the target is bound. */
            if ( t->binding == T_BIND_UNBOUND )
                make1bind( t );

            /* Build a new list. */
            nl = list_push_back( nl, object_copy( t->boundname ) );
        }

        /* Add to settings chain. */
        settings = addsettings( settings, VAR_SET, list_item( vars_iter ), nl );
    }

    return settings;
}
Exemple #3
0
void argv_from_shell( char const * * argv, LIST * shell, char const * command,
    int const slot )
{
    static char jobno[ 4 ];

    int i;
    int gotpercent = 0;
    LISTITER iter = list_begin( shell );
    LISTITER end = list_end( shell );

    assert( 0 <= slot );
    assert( slot < 999 );
    sprintf( jobno, "%d", slot + 1 );

    for ( i = 0; iter != end && i < MAXARGC; ++i, iter = list_next( iter ) )
    {
        switch ( object_str( list_item( iter ) )[ 0 ] )
        {
            case '%': argv[ i ] = command; ++gotpercent; break;
            case '!': argv[ i ] = jobno; break;
            default : argv[ i ] = object_str( list_item( iter ) );
        }
    }

    if ( !gotpercent )
        argv[ i++ ] = command;

    argv[ i ] = NULL;
}
Exemple #4
0
LIST *sequence_select_highest_ranked( FRAME *frame, int flags )
{
   /* Returns all of 'elements' for which corresponding element in parallel */
   /* list 'rank' is equal to the maximum value in 'rank'.                  */

    LIST* elements = lol_get( frame->args, 0 );    
    LIST* rank = lol_get( frame->args, 1 );    
    LISTITER iter, end, elements_iter, elements_end;
    
    LIST* result = L0;
    LIST* tmp;
    int highest_rank = -1;

    iter = list_begin(rank), end = list_end(rank);
    for (; iter != end; iter = list_next(iter))
        highest_rank = max(highest_rank, atoi(object_str(list_item(iter))));
    
    iter = list_begin(rank), end = list_end(rank);
    elements_iter = list_begin(elements), elements_end = list_end(elements);
    for (; iter != end; iter = list_next(iter), elements_iter = list_next(elements_iter))
        if (atoi(object_str(list_item(iter))) == highest_rank)
            result = list_push_back(result, object_copy(list_item(elements_iter)));

    return result;
}
Exemple #5
0
LIST * order( FRAME * frame, int flags )
{
    LIST * arg = lol_get( frame->args, 0 );
    LIST * result = L0;
    int src;
    LISTITER iter = list_begin( arg );
    LISTITER const end = list_end( arg );

    /* We need to create a graph of order dependencies between the passed
     * objects. We assume there are no duplicates passed to 'add_pair'.
     */
    int length = list_length( arg );
    int * * graph = ( int * * )BJAM_CALLOC( length, sizeof( int * ) );
    int * order = ( int * )BJAM_MALLOC( ( length + 1 ) * sizeof( int ) );

    for ( src = 0; iter != end; iter = list_next( iter ), ++src )
    {
        /* For all objects this one depends upon, add elements to 'graph'. */
        LIST * dependencies = var_get( frame->module, list_item( iter ) );
        int index = 0;
        LISTITER dep_iter = list_begin( dependencies );
        LISTITER const dep_end = list_end( dependencies );

        graph[ src ] = ( int * )BJAM_CALLOC( list_length( dependencies ) + 1,
            sizeof( int ) );
        for ( ; dep_iter != dep_end; dep_iter = list_next( dep_iter ) )
        {
            int const dst = list_index( arg, list_item( dep_iter ) );
            if ( dst != -1 )
                graph[ src ][ index++ ] = dst;
        }
        graph[ src ][ index ] = -1;
    }

    topological_sort( graph, length, order );

    {
        int index = length - 1;
        for ( ; index >= 0; --index )
        {
            int i;
            LISTITER iter = list_begin( arg );
            LISTITER const end = list_end( arg );
            for ( i = 0; i < order[ index ]; ++i, iter = list_next( iter ) );
            result = list_push_back( result, object_copy( list_item( iter ) ) );
        }
    }

    /* Clean up */
    {
        int i;
        for ( i = 0; i < length; ++i )
            BJAM_FREE( graph[ i ] );
        BJAM_FREE( graph );
        BJAM_FREE( order );
    }

    return result;
}
Exemple #6
0
void list_print( LIST * l )
{
    LISTITER iter = list_begin( l ), end = list_end( l );
    if ( iter != end )
    {
        out_printf( "%s", object_str( list_item( iter ) ) );
        iter = list_next( iter );
        for ( ; iter != end; iter = list_next( iter ) )
            out_printf( " %s", object_str( list_item( iter ) ) );
    }
}
Exemple #7
0
static void check_defined( LIST * class_names )
{
    LISTITER iter = list_begin( class_names ), end = list_end( class_names );
    for ( ; iter != end; iter = list_next( iter ) )
    {
        if ( !hash_find( classes, list_item( iter ) ) )
        {
            printf( "Class %s is not defined\n", object_str( list_item( iter ) ) );
            abort();
        }
    }
}
Exemple #8
0
OBJECT * make_class_module( LIST * xname, LIST * bases, FRAME * frame )
{
    OBJECT     * name = class_module_name( list_front( xname ) );
    OBJECT   * * pp;
    module_t   * class_module = 0;
    module_t   * outer_module = frame->module;
    int found;
    LISTITER iter, end;

    if ( !classes )
        classes = hashinit( sizeof( OBJECT * ), "classes" );

    pp = (OBJECT * *)hash_insert( classes, list_front( xname ), &found );
    if ( !found )
    {
        *pp = object_copy( list_front( xname ) );
    }
    else
    {
        printf( "Class %s already defined\n", object_str( list_front( xname ) ) );
        abort();
    }
    check_defined( bases );

    class_module = bindmodule( name );

    var_set( class_module, constant_name, xname, VAR_SET );
    var_set( class_module, constant_bases, bases, VAR_SET );

    iter = list_begin( bases ), end = list_end( bases );
    for ( ; iter != end; iter = list_next( iter ) )
        import_base_rules( class_module, list_item( iter ) );

    return name;
}
Exemple #9
0
TWstring * TWubiIMC::list_str(uint16_t index, TWstring * suffix)
{
	List_Item * li;
	li = list_item(index);
	
	ret_str.copy(li->wr.w);

	TWstring fullkey;
	fullkey.copy(li->wk.key);

	if (!suffix)
		return &ret_str;
	
	TWstring t;

	suffix->erase();

	size_t i = 0;
	if (input.find('z') >= 0){
		for(; i < input.length(); i++)
			if (input[i] == 'z')
				suffix->append(fullkey[i] & ~0x20);
				else
					suffix->append(fullkey[i]);
		}

	return &ret_str;
}
Exemple #10
0
LIST * list_unique( LIST * sorted_list )
{
    LIST * result = L0;
    OBJECT * last_added = 0;

    LISTITER iter = list_begin( sorted_list ), end = list_end( sorted_list );
    for ( ; iter != end; iter = list_next( iter ) )
    {
        if ( !last_added || !object_equal( list_item( iter ), last_added ) )
        {
            result = list_push_back( result, object_copy( list_item( iter ) ) );
            last_added = list_item( iter );
        }
    }
    return result;
}
Exemple #11
0
/* binary search for the property value */
LIST * property_set_contains_features( FRAME * frame, int flags )
{
    OBJECT * varname = object_new( "self.raw" );
    LIST * props = var_get( frame->module, varname );
    LIST * features = lol_get( frame->args, 0 );
    LIST * result = L0;
    LISTITER features_iter = list_begin( features );
    LISTITER features_end = list_end( features ) ;
    object_free( varname );

    for ( ; features_iter != features_end; ++features_iter )
    {
        const char * name = object_str( list_item( features_iter ) );
        size_t name_len = strlen( name );
        LISTITER begin, end;
        /* Assumes random access */
        begin = list_begin( props ), end = list_end( props );

        while ( 1 )
        {
            ptrdiff_t diff = (end - begin);
            LISTITER mid = begin + diff / 2;
            int res;
            if ( diff == 0 )
            {
                /* The feature is missing */
                return L0;
            }
            res = strncmp( object_str( list_item( mid ) ), name, name_len );
            if ( res < 0 )
            {
                begin = mid + 1;
            }
            else if ( res > 0 )
            {
                end = mid;
            }
            else /* We've found the property */
            {
                break;
            }
        }
    }
    return list_new( object_copy( constant_true ) );
}
Exemple #12
0
/* Use quite klugy approach: when we add order dependency from 'a' to 'b', just
 * append 'b' to of value of variable 'a'.
 */
LIST * add_pair( FRAME * frame, int flags )
{
    LIST * arg = lol_get( frame->args, 0 );
    LISTITER iter = list_begin( arg );
    LISTITER const end = list_end( arg );
    var_set( frame->module, list_item( iter ), list_copy_range( arg, list_next(
        iter ), end ), VAR_APPEND );
    return L0;
}
Exemple #13
0
int list_in( LIST * l, OBJECT * value )
{
    LISTITER iter = list_begin( l );
    LISTITER end = list_end( l );
    for ( ; iter != end; iter = list_next( iter ) )
        if ( object_equal( list_item( iter ), value ) )
            return 1;
    return 0;
}
Exemple #14
0
int list_is_sublist( LIST * sub, LIST * l )
{
    LISTITER iter = list_begin( sub );
    LISTITER const end = list_end( sub );
    for ( ; iter != end; iter = list_next( iter ) )
        if ( !list_in( l, list_item( iter ) ) )
            return 0;
    return 1;
}
Exemple #15
0
static void remove_files_atexit( void )
{
    LISTITER iter = list_begin( files_to_remove );
    LISTITER const end = list_end( files_to_remove );
    for ( ; iter != end; iter = list_next( iter ) )
        remove( object_str( list_item( iter ) ) );
    list_free( files_to_remove );
    files_to_remove = L0;
}
Exemple #16
0
static int list_equal( LIST * lhs, LIST * rhs )
{
    LISTITER lhs_iter, lhs_end, rhs_iter;
    if ( list_length( lhs ) != list_length( rhs ) )
    {
        return 0;
    }
    lhs_iter = list_begin( lhs );
    lhs_end = list_end( lhs );
    rhs_iter = list_begin( rhs );
    for ( ; lhs_iter != lhs_end; ++lhs_iter, ++rhs_iter )
    {
        if ( ! object_equal( list_item( lhs_iter ), list_item( rhs_iter ) ) )
        {
            return 0;
        }
    }
    return 1;
}
Exemple #17
0
static unsigned list_hash(LIST * key)
{
    unsigned int hash = 0;
    LISTITER iter = list_begin( key ), end = list_end( key );
    for ( ; iter != end; ++iter )
    {
        hash = hash * 2147059363 + object_hash( list_item( iter ) );
    }
    return hash;
}
Exemple #18
0
XMsg *unseen_XMsg(User *usr) {
PList *pl;

	if (usr->seen_xmsgs == usr->recv_xmsgs.list.prev)
		return NULL;

	pl = list_item(usr->seen_xmsgs->next, PList, list);
	usr->seen_xmsgs = &(pl->list);
	return (XMsg *)(pl->p);
}
Exemple #19
0
/* Given a list and a value, returns position of that value in the list, or -1
 * if not found.
 */
int list_index( LIST * list, OBJECT * value )
{
    int result = 0;
    LISTITER iter = list_begin( list );
    LISTITER const end = list_end( list );
    for ( ; iter != end; iter = list_next( iter ), ++result )
        if ( object_equal( list_item( iter ), value ) )
            return result;
    return -1;
}
Exemple #20
0
void
headers( TARGET * t )
{
    LIST   * hdrscan;
    LIST   * hdrrule;
	#ifndef OPT_HEADER_CACHE_EXT
    LIST   * headlist = L0;
	#endif
    regexp * re[ MAXINC ];
    int rec = 0;
    LISTITER iter, end;

    hdrscan = var_get( root_module(), constant_HDRSCAN );
    if ( list_empty( hdrscan ) )
        return;

    hdrrule = var_get( root_module(), constant_HDRRULE );
    if ( list_empty( hdrrule ) )
        return;

    if ( DEBUG_HEADER )
        printf( "header scan %s\n", object_str( t->name ) );

    /* Compile all regular expressions in HDRSCAN */
    iter = list_begin( hdrscan ), end = list_end( hdrscan );
    for ( ; ( rec < MAXINC ) && iter != end; iter = list_next( iter ) )
    {
        re[ rec++ ] = regex_compile( list_item( iter ) );
    }

    /* Doctor up call to HDRRULE rule */
    /* Call headers1() to get LIST of included files. */
    {
        FRAME   frame[1];
        frame_init( frame );
        lol_add( frame->args, list_new( object_copy( t->name ) ) );
#ifdef OPT_HEADER_CACHE_EXT
        lol_add( frame->args, hcache( t, rec, re, hdrscan ) );
#else
        lol_add( frame->args, headers1( headlist, t->boundname, rec, re ) );
#endif

        if ( lol_get( frame->args, 1 ) )
        {
            /* The third argument to HDRRULE is the bound name of
             * $(<) */
            lol_add( frame->args, list_new( object_copy( t->boundname ) ) );

            list_free( evaluate_rule( list_front( hdrrule ), frame ) );
        }

        /* Clean up. */
        frame_free( frame );
    }
}
Exemple #21
0
void list_free( LIST * head )
{
    if ( !list_empty( head ) )
    {
        LISTITER iter = list_begin( head );
        LISTITER const end = list_end( head );
        for ( ; iter != end; iter = list_next( iter ) )
            object_free( list_item( iter ) );
        list_dealloc( head );
    }
}
Exemple #22
0
int list_cmp( LIST * t, LIST * s )
{
    int status = 0;
    LISTITER t_it = list_begin( t );
    LISTITER const t_end = list_end( t );
    LISTITER s_it = list_begin( s );
    LISTITER const s_end = list_end( s );

    while ( !status && ( t_it != t_end || s_it != s_end ) )
    {
        char const * st = t_it != t_end ? object_str( list_item( t_it ) ) : "";
        char const * ss = s_it != s_end ? object_str( list_item( s_it ) ) : "";

        status = strcmp( st, ss );

        t_it = t_it != t_end ? list_next( t_it ) : t_it;
        s_it = s_it != s_end ? list_next( s_it ) : s_it;
    }

    return status;
}
Exemple #23
0
int river_animation_iterate()
{
    /** VARIÁVEIS *****************************************************/
    float flux = Config.flux;       /* Fluxo do rio              */
    int length = Config.length;     /* Largura do grid           */
    int zone = Config.zone;         /* Zona de conforto          */
    Link new_node;                  /* Nódulo novo da lista      */
    TStrip top;                     /* Faixa superior do rio     */

    frame_height = 0; /* Zera altura do frame que imprime o rio */

    /** AVANÇA FAIXA DE TERRENO ***************************************/
    /* Libera linha do topo do grid ('saindo da tela') */
    new_node = list_prev(list_head(river));
    list_remove(river, new_node);

    /* Cria linha da base do grid ('entrando na tela') */
    top = tstrip_generate(length, zone, flux, base, list_item(new_node));
    base = top;
    list_insert(river, new_node);

    /** IMPRIME RIO ***************************************************/
    if(gui_event_get() == CLOSE) return EXIT_FAILURE;
    gui_window_clear();
    list_select(river, HEAD, strip_print);

    gui_boat_draw(&boat_hpos, &boat_vpos, 5);
    /* Velocidade */
    speedy = 0.6 * strip1[boat_hpos].v + (sqrt(cos(boat_angle)*cos(boat_angle))+1) * speedy*0.4;

    /* Barco bateu, recomeça do meio */
    if(strip1[boat_hpos].t == LAND
            || strip1[boat_hpos-1].t == LAND
            || strip1[boat_hpos-2].t == LAND
            || strip1[boat_hpos+1].t == LAND)
    {
        P1.lifes--;
        move = 0;
        boat_hpos = (int) (Config.length/2.0);
        boat_vpos = frame_height/5;
    }
    else
    {
        boat_angle = (pi/2.0)*(1- (10.0 * move/Config.length));
    }

    gui_window_update(P1.lifes);

    /* Fim de Jogo */
    if(P1.lifes == 0) return GAME_OVER;
    return EXIT_SUCCESS;
}
Exemple #24
0
static int in_child_list(proc_t *myproc){
    list_link_t *link;
    list_t *child_list = &myproc->p_pproc->p_children;

    for (link = child_list->l_next; link != child_list; link = link->l_next){
        proc_t *p = list_item(link, proc_t, p_child_link);
        if (p == myproc){
            return 1;
        }
    }

    return 0;
}
Exemple #25
0
PyObject * list_to_python( LIST * l )
{
    PyObject * result = PyList_New( 0 );
    LISTITER iter = list_begin( l );
    LISTITER const end = list_end( l );
    for ( ; iter != end; iter = list_next( iter ) )
    {
        PyObject * s = PyString_FromString( object_str( list_item( iter ) ) );
        PyList_Append( result, s );
        Py_DECREF( s );
    }

    return result;
}
Exemple #26
0
void *roundRobinScheduler(void *pc)
{
	pktcore_t *pcore = (pktcore_t *)pc;
	List *keylst;
	int nextqid, qcount, rstatus, pktsize;
	char *nextqkey;
	gpacket_t *in_pkt;
	simplequeue_t *nextq;


	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
	while (1)
	{
		verbose(2, "[roundRobinScheduler]:: Round robin scheduler processing... ");
		keylst = map_keys(pcore->queues);
		nextqid = pcore->lastqid;
		qcount = list_length(keylst);

		pthread_mutex_lock(&(pcore->qlock));
		if (pcore->packetcnt == 0)
			pthread_cond_wait(&(pcore->schwaiting), &(pcore->qlock));
		pthread_mutex_unlock(&(pcore->qlock));

		pthread_testcancel();
		do
		{
			nextqid = (1 + nextqid) % qcount;
			nextqkey = list_item(keylst, nextqid);
			// get the queue..
			nextq = map_get(pcore->queues, nextqkey);
			// read the queue..
			rstatus = readQueue(nextq, (void **)&in_pkt, &pktsize);

			if (rstatus == EXIT_SUCCESS)
			{
				pcore->lastqid = nextqid;
				writeQueue(pcore->workQ, in_pkt, pktsize);
			}

		} while (nextqid != pcore->lastqid && rstatus == EXIT_FAILURE);
		list_release(keylst);

		pthread_mutex_lock(&(pcore->qlock));
		if (rstatus == EXIT_SUCCESS)
			pcore->packetcnt--;
		pthread_mutex_unlock(&(pcore->qlock));

		usleep(rconfig.schedcycle);
	}
}
Exemple #27
0
static void file_dirscan_impl( OBJECT * dir, scanback func, void * closure )
{
    file_info_t * const d = file_query( dir );
    if ( !d || !d->is_dir )
        return;

    /* Lazy collect the directory content information. */
    if ( list_empty( d->files ) )
    {
        if ( DEBUG_BINDSCAN )
            printf( "scan directory %s\n", object_str( d->name ) );
        if ( file_collect_dir_content_( d ) < 0 )
            return;
    }

    /* OS specific part of the file_dirscan operation. */
    file_dirscan_( d, func, closure );

    /* Report the collected directory content. */
    {
        LISTITER iter = list_begin( d->files );
        LISTITER const end = list_end( d->files );
        for ( ; iter != end; iter = list_next( iter ) )
        {
            OBJECT * const path = list_item( iter );
            file_info_t const * const ffq = file_query( path );
            /* The only way a file_query() call can fail is if its internal OS
             * file information gathering API (e.g. stat()) failed. If that
             * happens we should treat the file as if it no longer exists. We
             * then request the raw cached file_info_t structure for that file
             * and use the file name from there.
             */
            file_info_t const * const ff = ffq ? ffq : file_info( path );
            /* Using a file name read from a file_info_t structure allows OS
             * specific implementations to store some kind of a normalized file
             * name there. Using such a normalized file name then allows us to
             * correctly recognize different file paths actually identifying the
             * same file. For instance, an implementation may:
             *  - convert all file names internally to lower case on a case
             *    insensitive file system
             *  - convert the NTFS paths to their long path variants as that
             *    file system each file system entity may have a long and a
             *    short path variant thus allowing for many different path
             *    strings identifying the same file.
             */
            (*func)( closure, ff->name, 1 /* stat()'ed */, &ff->time );
        }
    }
}
Exemple #28
0
OBJECT * make_class_module( LIST * xname, LIST * bases, FRAME * frame )
{
    OBJECT     * name = class_module_name( list_front( xname ) );
    OBJECT   * * pp;
    module_t   * class_module = 0;
    module_t   * outer_module = frame->module;
    int found;

    if ( !classes )
        classes = hashinit( sizeof( OBJECT * ), "classes" );

    pp = (OBJECT * *)hash_insert( classes, list_front( xname ), &found );
    if ( !found )
    {
        *pp = object_copy( list_front( xname ) );
    }
    else
    {
        out_printf( "Class %s already defined\n", object_str( list_front( xname ) )
            );
        abort();
    }
    check_defined( bases );

    class_module = bindmodule( name );

    {
        /*
            Initialize variables that Boost.Build inserts in every object.
            We want to avoid creating the object's hash if it isn't needed.
         */
        int num = class_module->num_fixed_variables;
        module_add_fixed_var( class_module, constant_name, &num );
        module_add_fixed_var( class_module, constant_class, &num );
        module_set_fixed_variables( class_module, num );
    }

    var_set( class_module, constant_name, xname, VAR_SET );
    var_set( class_module, constant_bases, bases, VAR_SET );

    {
        LISTITER iter = list_begin( bases );
        LISTITER const end = list_end( bases );
        for ( ; iter != end; iter = list_next( iter ) )
            import_base_rules( class_module, list_item( iter ) );
    }

    return name;
}
Exemple #29
0
LIST * regex_replace( FRAME * frame, int flags )
{
    LIST * args = lol_get( frame->args, 0 );
    OBJECT * s;
    OBJECT * match;
    OBJECT * replacement;
    regexp * re;
    const char * pos;
    string buf[ 1 ];
    LIST * result;
    LISTITER iter = list_begin( args );
    s = list_item( iter );
    iter = list_next( iter );
    match = list_item( iter );
    iter = list_next( iter );
    replacement = list_item(iter );
    
    re = regex_compile( match );
    
    string_new( buf );

    pos = object_str( s );
    while ( regexec( re, pos ) )
    {
        string_append_range( buf, pos, re->startp[ 0 ] );
        string_append( buf, object_str( replacement ) );
        pos = re->endp[ 0 ];
    }
    string_append( buf, pos );

    result = list_new( object_new( buf->value ) );

    string_free( buf );

    return result;
}
Exemple #30
0
/* Calculates goto (I, X), storing the result into J.  I and J may
   specify the same list. */
static void
calc_goto (struct list *J, struct list *I, int X)
{
  int i;

  if (I != J)
    list_init (J);
  for (i = 0; i < list_count (I); i++)
    {
      const struct item *item = list_item (I, i);
      if (item_n_after_dot (item) > 0
	  && item_symbol_after_dot (item) == X)
	list_add (J, item->prod, item->dot + 1);
    }
  calc_closure (J, J);
}