static int afd_parse_trans(struct list_t *l, char *str, char **save) { char *p; struct afd_tran *tran; p = strtok_r(NULL, ";", save); while(p) { debug("Nueva transición %s", p); if(!(tran = malloc(sizeof(struct afd_tran)))) { debug("malloc"); return -1; } if(afd_parse_tran_str(tran, p)) { debug("afd_parse_tran_str"); return -1; } if(list_add(l, tran)) { debug("list_add"); return -1; } p = strtok_r(NULL, ";", save); } #ifndef NDEBUG list_map(l, afd_print_tran); #endif return 0; }
static void update_md(gpointer data, gpointer user_data) { pentry_t *pe = NULL; char *path = NULL; dpl_ftype_t type; dpl_ino_t ino; dpl_status_t rc; dpl_dict_t *metadata = NULL; struct list *dirent = NULL; (void)user_data; pe = data; path = pentry_get_path(pe); LOG(LOG_DEBUG, "path=%s", path); ino = dpl_cwd(ctx, ctx->cur_bucket); rc = dfs_namei_timeout(ctx, path, ctx->cur_bucket, ino, NULL, NULL, &type); LOG(LOG_DEBUG, "path=%s, dpl_namei: %s, type=%s", path, dpl_status_str(rc), ftype_to_str(type)); if (DPL_SUCCESS != rc) { LOG(LOG_NOTICE, "dfs_namei_timeout: %s", dpl_status_str(rc)); goto end; } rc = dfs_getattr_timeout(ctx, path, &metadata); if (DPL_SUCCESS != rc && DPL_EISDIR != rc) { LOG(LOG_ERR, "dfs_getattr_timeout: %s", dpl_status_str(rc)); goto end; } /* If this is a directory, update its entries' metadata */ if (DPL_FTYPE_DIR == type) { dirent = pentry_get_dirents(pe); if (dirent) list_map(dirent, cb_map_dirents, pe); } if (pentry_md_trylock(pe)) goto end; if (metadata) pentry_set_metadata(pe, metadata); pentry_set_atime(pe); (void)pentry_md_unlock(pe); end: if (metadata) dpl_dict_free(metadata); }
void grammar_print(struct grammar_t *g) { printf("---- BEGIN GRAMMAR ----\n"); #ifndef NDEBUG debug("Printing grammar"); debug("CONNECTORS:"); #endif list_map(&(g->connectors), (void (*)(void *)) grammar_connector_print); #ifndef NDEBUG debug("VARIABLES:"); #endif list_map(&(g->variables), (void (*)(void *)) grammar_symbol_print); #ifndef NDEBUG debug("TERMINALS:"); #endif list_map(&(g->terminals), (void (*)(void *)) grammar_symbol_print); printf("---- END GRAMMAR ----\n"); }
static int afd_parse_list(struct list_t *l, char *str) { char *p, *save; debug("afd_parse_list(, %s)", str); p = strtok_r(str, " ", &save); while(p) { debug("Nuevo elemento %s", p); if(list_add(l, p)) { debug("list_add"); return -1; } p = strtok_r(NULL, " ", &save); } #ifndef NDEBUG list_map(l, afd_print_str); #endif return 0; }
void leerPrimerRegistroDeTodosLosArchivos(ArchivoApareado *archivo) { archivo->listaRegistrosLeidos = list_map(archivo->listaArchivos, obtenerRegistroDeArchivo); }
void list_destruct(linked_list_t* list, list_elem_fun f) { list_map(list,f); list_free_all(list); }
int afd_reduce(struct afd *afd) { struct queue_t estados; struct list_t visitados; struct list_t nuevas_trans; struct list_node_t *node; struct afd_tran *tran, *tran2; void *st; debug("AFD ptr = %p", afd); queue_empty(&estados); list_empty(&visitados); list_empty(&nuevas_trans); if(queue_push(&estados, afd->sti)) { debug("queue_push"); return -1; } if(list_add(&visitados, afd->sti)) { debug("list_add"); return -1; } while(!queue_pop(&estados, &st)) { debug("Estado %s", (char *) st); for(node = afd->trans.start; node != NULL; node = node->next) { debug("Transición %p", node->ptr); #ifndef NDEBUG afd_print_tran(node->ptr); #endif tran = (struct afd_tran *) node->ptr; if(strcmp(tran->ini, st) == 0) { if((tran2 = malloc(sizeof(struct afd_tran))) == NULL) { perror("malloc"); return -1; } memcpy(tran2, tran, sizeof(struct afd_tran)); if(list_add(&nuevas_trans, tran2)) { debug("list_add"); return -1; } if(list_find(&visitados, tran2->fin, afd_cmp) == NULL) { debug("Añadiendo %s a visitados", tran2->fin); if(list_add(&visitados, tran2->fin)) { debug("list_add"); return -1; } if(queue_push(&estados, tran2->fin)) { debug("queue_push"); return -1; } } } } } #ifndef NDEBUG debug("Antiguas transiciones"); list_map(&afd->trans, afd_print_tran); debug("Nuevas transiciones"); list_map(&nuevas_trans, afd_print_tran); #endif list_clear_func(&afd->trans, afd_free_tran); list_clear(&visitados); memcpy(&afd->trans, &nuevas_trans, sizeof(struct list_t)); return 0; }
void *snake_thread(void *dummy) { while(1) { // first advance snake parts, delete tail, add head if (!got_apple) { snake_part *tail = (snake_part *)list_front(&snake); free(tail); } got_apple = 0; snake_direction = next_snake_direction; snake_part *head = (snake_part *)snake.lastNode->data; snake_part *new_head = (snake_part *)malloc(sizeof(snake_part)); switch (snake_direction) { case DIR_UP: new_head->x = head->x; new_head->y = head->y-1; break; case DIR_DOWN: new_head->x = head->x; new_head->y = head->y+1; break; case DIR_LEFT: new_head->x = head->x-1; new_head->y = head->y; break; case DIR_RIGHT: new_head->x = head->x+1; new_head->y = head->y; break; } list_append(&snake, new_head); head = new_head; // check new head doesnt hit any walls if (head->x < 1 || head->x >= BOARD_WIDTH || head->y < 1 || head->y >= BOARD_HEIGHT) { end_game(); } // check if we hit ourself... list_map(&snake, collision_check); // apple logic if (head->x == apple_x && head->y == apple_y) { got_apple = 1; score++; put_apple(); } // then draw CLS(); draw_board(); list_map(&snake, draw_part); GOTO(apple_x+1, apple_y+1); printf("0"); GOTO(0, BOARD_HEIGHT+2); printf("Score: %d", score); HOME(); fflush(stdout); usleep(100000); } }