void tsb_link_add_entry(tsb_link_t *tsb_link, uint64_t tag, uint64_t data, tsb_entry_t *tsb_entry, block_t *block, block_tsb_t *block_tsb) { tsb_link_entry_t *link_entry; if(tsb_entry->tag == TSB_LINK_TAG) { uint64_t index; /* add to chain */ index = (tsb_entry->data - tsb_link->start_addr) / LINK_SIZE; link_entry = VECTOR_ELEM(tsb_link->entries, index, tsb_link_entry_vector_el_t); /* chase to the end of the chain */ while(link_entry->next) { if((link_entry->tag == tag) && !Suppress_dup_tags_error) { gf_error(M_DUPLICATETAG, "Conflict in TSB_Link '%s'.\n" "Tag 0x%llx being added twice.\n" FLINE_f "First from block '%s'\n" FLINE_f "Again from block '%s'\n", tsb_link->name, tag, SRC_FLINE(link_entry->block), link_entry->block->name, SRC_FLINE(block), block->name); } link_entry = link_entry->next; } add_to_chain(tsb_link, link_entry, tag, data, block, block_tsb); } else { /* create new chain */ link_entry = start_new_chain(tsb_link, tsb_entry->tag, tsb_entry->data, block, block_tsb); add_to_chain(tsb_link, link_entry, tag, data, block, block_tsb); if((link_entry->tag == tag) && !Suppress_dup_tags_error) { gf_error(M_DUPLICATETAG, "Conflict in TSB_Link '%s'.\n" "Tag 0x%llx being added twice.\n" FLINE_f "First from block '%s'\n" FLINE_f "Again from block '%s'\n", tsb_link->name, tag, SRC_FLINE(tsb_entry->block), tsb_entry->block->name, SRC_FLINE(block), block->name); } tsb_entry->tag = TSB_LINK_TAG; tsb_entry->data = link_entry->my_link; } }
gfxfilterchain_t* gfxfilterchain_parse(const char*_filterexpr) { char*filterexpr = strdup(_filterexpr); char*f = filterexpr; char*end = filterexpr+strlen(filterexpr); dict_t* params = dict_new2(&charptr_type); char*cmd = 0; gfxfilterchain_t*chain = 0; gfxfilterchain_t*next = 0; while(*f) { char* eq = strchr(f, '='); char* colon = strchr(f, ':'); if(!colon) { colon = end; } *colon = 0; if(eq && eq < colon) { // parameter *eq = 0; if(!cmd) { fprintf(stderr, "Error: need a filter before specifying parameters (%s=%s)\n", f, eq+1); return 0; } dict_put(params, f, strdup(eq+1)); } else { if(cmd) { add_to_chain(cmd, params, &chain, &next); cmd = 0; } cmd = f; } if(colon == end) break; f = colon+1; } if(cmd) { add_to_chain(cmd, params, &chain, &next); } free(filterexpr); dict_destroy(params); return chain; }
int main(int argc, char const *argv[]) { size_t m, n; printf("Input N: "); scanf("%lu", &n); printf("and M: "); scanf("%lu", &m); Node* chain = initChain(); add_to_chain(chain, n); show_chain(chain); run(chain, n, m); show_chain(chain); return 0; }
/* * A parser for values, inspired somewhat by Scheme/LISP S-expressions * and Prolog/Erlang terms. */ int value_discern(struct value *top, struct scanner *sc) { if (scanner_tokeq(sc, "<")) { struct chain *front, *back; struct value tag, inner; unsigned int size = 1; /* Tuple. */ scanner_scan(sc); value_discern(&tag, sc); scanner_expect(sc, ":"); value_discern(&inner, sc); back = front = add_to_chain(NULL, &inner); while (scanner_tokeq(sc, ",")) { scanner_scan(sc); value_discern(&inner, sc); back = add_to_chain(back, &inner); size++; } scanner_expect(sc, ">"); value_tuple_new(top, &tag, size); populate_tuple_from_chain(top, front); free_chain(front); return 1; } else if (scanner_tokeq(sc, "[")) { struct value inner, *left, right; /* List: Sequence of tail-nested Pairs. */ scanner_scan(sc); if (scanner_tokeq(sc, "]")) { scanner_scan(sc); value_copy(top, &VNULL); return 1; } value_tuple_new(top, &tag_list, 2); value_discern(&inner, sc); value_tuple_store(top, 0, &inner); /*value_tuple_store(top, 1, VNULL);*/ left = top; while (scanner_tokeq(sc, ",")) { scanner_scan(sc); value_tuple_new(&right, &tag_list, 2); value_discern(&inner, sc); value_tuple_store(&right, 0, &inner); /*value_set_index(right, 1, VNULL);*/ value_tuple_store(left, 1, &right); left = value_tuple_fetch(left, 1); } if (scanner_tokeq(sc, "|")) { scanner_scan(sc); value_discern(&right, sc); value_tuple_store(left, 1, &right); } scanner_expect(sc, "]"); return 1; } else if (scanner_tokeq(sc, "{")) { struct value left, right; /* Dictionary: associations between keys and values. */ scanner_scan(sc); value_dict_new(top, 31); value_discern(&left, sc); scanner_expect(sc, "="); value_discern(&right, sc); value_dict_store(top, &left, &right); while (scanner_tokeq(sc, ",")) { scanner_scan(sc); value_discern(&left, sc); scanner_expect(sc, "="); value_discern(&right, sc); value_dict_store(top, &left, &right); } scanner_expect(sc, "}"); return 1; } else if (k_isdigit(scanner_token_string(sc)[0])) { /* Integer. */ value_integer_set(top, k_atoi(scanner_token_string(sc), scanner_token_length(sc))); scanner_scan(sc); return 1; } else { /* Symbol. */ value_symbol_new(top, scanner_token_string(sc), scanner_token_length(sc)); scanner_scan(sc); return 1; } }