/** * Sets the list_iter to the last item of the list. If the list is * empty, the function returns false and the list_iter must not be * used for operations like get_ptr or delete. */ bool list_iter_last(list_iter_t *iter, list_t *list) { RUNTIME_ASSERT(iter != NULL); LIST_CHECK(list); return list_iter_init(iter, list, false); }
void game_lifespan_checks(game_t *gm) { list_iter_t iter; player_t *pl; list_iter_init(&iter, gm->ga_players, FWD); while ((pl = list_iter_next(&iter))) { player_lifespan_check(pl, gm->ga_freq); } }
symbol_t* symbol_get_in_scope(symbol_table_t* symbol_table, char* name) { if (!symbol_table) return NULL; list_item_t* iter = list_iter_init(symbol_table->symbols); for (; iter; iter = list_iter(iter)) { symbol_t* candidate = iter->val; if (strcmp(candidate->name, name) == 0) { return candidate; } } return NULL; }
player_t *game_find_pl(game_t *gm, unsigned int id) { list_iter_t it; player_t *pl = NULL; for (list_iter_init(&it, gm->ga_players, FWD); (pl = list_iter_access(&it)); list_iter_next(&it)) { if (pl->p_id == id) return (pl); } return (pl); }
/** * Sets the list_iter to the first item of the list. If the list is * empty, the function returns false and the list_iter must not be * used for operations like get_ptr or delete. * * @param iter a list_iter struct. * @param list a valid list */ bool list_iter_first(list_iter_t *iter, list_t *list) { RUNTIME_ASSERT(iter != NULL); if (list) { LIST_CHECK(list); return list_iter_init(iter, list, true); } else { return false; } }
void read_library( struct parse* parse, struct pos* pos ) { p_test_tk( parse, TK_LIT_STRING ); if ( ! parse->tk_length ) { p_diag( parse, DIAG_POS_ERR, &parse->tk_pos, "library name is blank" ); p_bail( parse ); } int length = parse->tk_length; if ( length > MAX_LIB_NAME_LENGTH ) { p_diag( parse, DIAG_WARN | DIAG_FILE | DIAG_LINE | DIAG_COLUMN, &parse->tk_pos, "library name too long" ); p_diag( parse, DIAG_FILE, &parse->tk_pos, "library name can be up to %d characters long", MAX_LIB_NAME_LENGTH ); length = MAX_LIB_NAME_LENGTH; } char name[ MAX_LIB_NAME_LENGTH + 1 ]; memcpy( name, parse->tk_text, length ); name[ length ] = 0; p_read_tk( parse ); // Different #library directives in the same library must have the same // name. if ( parse->task->library->name.length && strcmp( parse->task->library->name.value, name ) != 0 ) { p_diag( parse, DIAG_POS_ERR, pos, "library has multiple names" ); p_diag( parse, DIAG_FILE | DIAG_LINE | DIAG_COLUMN, &parse->task->library->name_pos, "first name given here" ); p_bail( parse ); } // Each library must have a unique name. list_iter_t i; list_iter_init( &i, &parse->task->libraries ); while ( ! list_end( &i ) ) { struct library* lib = list_data( &i ); if ( lib != parse->task->library && strcmp( name, lib->name.value ) == 0 ) { p_diag( parse, DIAG_POS_ERR, pos, "duplicate library name" ); p_diag( parse, DIAG_FILE | DIAG_LINE | DIAG_COLUMN, &lib->name_pos, "library name previously found here" ); p_bail( parse ); } list_next( &i ); } str_copy( &parse->task->library->name, name, length ); parse->task->library->importable = true; parse->task->library->name_pos = *pos; }