static token_list * create_label( token_list *t ) { int loc; token_list *tok = t; label_loc_map *new_entry, *map; op_list *list = ops; /* Check for duplicate label entry */ map = lmap; while( map ) { if( ident_compare(map->name, t->ident) ) { /* Duplicate entry, error */ error_line = t->line_number; error = err_duplabel; return NULL; } map = map->prev; } /* Create label entry */ new_entry = (label_loc_map*)malloc(sizeof(label_loc_map)); new_entry->name = tok->ident; loc = 0; while( list->next ) { list = list->next; loc += 5000; } new_entry->location = loc + list->length; new_entry->prev = lmap; lmap = new_entry; /* Correct any instructions that are waiting for this label */ map = fmap; while( map ) { if( ident_compare(map->name, new_entry->name) ) { /* Found a match, update with correct location */ map = update_branch_instruction(map, new_entry->location); } else { map = map->prev; } } /* Eat a colon */ tok = tok->next; if( !tok ) { error = err_unexpected_eof; return NULL; } else if( tok->t != token_colon ) { /* Syntax error */ error_line = tok->line_number; error = err_colon_expected; return NULL; } return tok->next; }
static int check_label( token_list *t ) { label_loc_map *map; op_list *list; int loc; /* Check the label->location map */ map = lmap; while( map && !ident_compare(map->name, t->ident) ) { map = map->prev; } if( map ) { /* Found a match */ return map->location; } else { /* No match, add to waiting list */ map = (label_loc_map*)malloc(sizeof(label_loc_map)); map->name = t->ident; map->prev = fmap; loc = 0; list = ops; while( list->next ) { list = list->next; loc += 5000; } loc += list->length; map->location = loc; fmap = map; return 0; } }
static int branch_compare(const void *l1, const void *l2) { const struct branch *branch1 = ((const struct line *) l1)->data; const struct branch *branch2 = ((const struct line *) l2)->data; if (branch_is_all(branch1)) return -1; else if (branch_is_all(branch2)) return 1; switch (get_sort_field(branch_sort_state)) { case SORT_FIELD_DATE: return sort_order(branch_sort_state, timecmp(&branch1->time, &branch2->time)); case SORT_FIELD_AUTHOR: return sort_order(branch_sort_state, ident_compare(branch1->author, branch2->author)); case SORT_FIELD_NAME: default: return sort_order(branch_sort_state, strcmp(branch1->ref->name, branch2->ref->name)); } }