static int binfile_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) { struct map_rect_priv *mr=priv_data; struct tile *t=mr->t; enum attr_type type; int i,size; if (attr_type != mr->attr_last) { t->pos_attr=t->pos_attr_start; mr->attr_last=attr_type; } while (t->pos_attr < t->pos_next) { size=le32_to_cpu(*(t->pos_attr++)); type=le32_to_cpu(t->pos_attr[0]); if (type == attr_label) mr->label=1; if (type == attr_town_name) mr->label_attr[0]=t->pos_attr; if (type == attr_street_name) mr->label_attr[0]=t->pos_attr; if (type == attr_street_name_systematic) mr->label_attr[1]=t->pos_attr; if (type == attr_type || attr_type == attr_any) { if (attr_type == attr_any) { dbg(1,"pos %p attr %s size %d\n", t->pos_attr-1, attr_to_name(type), size); } attr->type=type; attr_data_set(attr, t->pos_attr+1); if (type == attr_url_local) { g_free(mr->url); mr->url=binfile_extract(mr->m, mr->m->cachedir, attr->u.str, 1); attr->u.str=mr->url; } t->pos_attr+=size; return 1; } else { t->pos_attr+=size; } } if (!mr->label && (attr_type == attr_any || attr_type == attr_label)) { for (i = 0 ; i < sizeof(mr->label_attr)/sizeof(int *) ; i++) { if (mr->label_attr[i]) { mr->label=1; attr->type=attr_label; attr_data_set(attr, mr->label_attr[i]+1); return 1; } } } return 0; }
static int cmd_prog(cproc_t cp, char **arg) { device_t dev = cproc_device(cp); stab_t stab = cproc_stab(cp); FILE *in; struct prog_data prog; if (cproc_prompt_abort(cp, CPROC_MODIFY_SYMS)) return 0; in = fopen(*arg, "r"); if (!in) { fprintf(stderr, "prog: %s: %s\n", *arg, strerror(errno)); return -1; } if (dev->ctl(dev, DEVICE_CTL_HALT) < 0) { fclose(in); return -1; } prog_init(&prog, dev); if (binfile_extract(in, prog_feed, &prog) < 0) { fclose(in); return -1; } if (binfile_info(in) & BINFILE_HAS_SYMS) { stab_clear(stab); binfile_syms(in, stab); } fclose(in); if (prog_flush(&prog) < 0) return -1; if (dev->ctl(dev, DEVICE_CTL_RESET) < 0) { fprintf(stderr, "prog: failed to reset after programming\n"); return -1; } cproc_unmodify(cp, CPROC_MODIFY_SYMS); return 0; }