extern int attr_set_int(attr attrs, const char *name, int val) { char buf[64]; snprintf(buf, sizeof buf, "%d", val); return attr_set_str(attrs, name, buf); }
static struct pane *do_render_format_attach(struct pane *parent) { struct rf_data *rf = calloc(1, sizeof(*rf)); struct pane *p; if (!rf_map) render_format_register_map(); rf->home_field = -1; p = pane_register(parent, 0, &render_format_handle.c, rf, NULL); attr_set_str(&p->attrs, "render-wrap", "no"); return render_attach("lines", p); }
/* * attr_create_from_str * * Parse the passed string into an attr structure and return a pointer to a list of * attr_entry structs. * * Attribute strings are formatted much like URL arguments: * foo=bar&blah=humbug&blorg=42&test=one * You cannot, currently, have an "=" or "&" character in the value for an * attribute. */ extern attr attr_create_from_str(const char *attr_str) { char *tmp; char *cur; char *name; char *val; attr res = NULL; if(!str_length(attr_str)) { return NULL; } /* make a copy for a destructive read. */ tmp = str_dup(attr_str); if(!tmp) { return NULL; } res = attr_create(); if(!res) { mem_free(tmp); return NULL; } /* * walk the pointer along the input and copy the * names and values along the way. */ cur = tmp; while(*cur) { /* read the name */ name = cur; while(*cur && *cur != '=') cur++; /* did we run off the end of the string? * That is an error because we need to have a value. */ if(*cur == 0) { if(res) attr_destroy(res); mem_free(tmp); return NULL; } /* terminate the name string */ *cur = 0; /* read the value */ cur++; val = cur; while(*cur && *cur != '&') cur++; /* we do not care if we ran off the end, much. */ if(*cur) { *cur = 0; cur++; } if(attr_set_str(res, name, val)) { if(res) attr_destroy(res); mem_free(tmp); return NULL; } } mem_free(tmp); return res; }