rstr_t * rstr_spn(rstr_t *s, const char *set, int offset) { size_t len = strlen(rstr_get(s)); if(offset >= len) return rstr_dup(s); size_t l = strcspn(rstr_get(s) + offset, set) + offset; if(l == len) return rstr_dup(s); return rstr_allocl(rstr_get(s), l); }
static void fa_probe_exif(metadata_t *md, const char *url, uint8_t *pb, fa_handle_t *fh) { jpeginfo_t ji; if(jpeg_info(&ji, jpeginfo_reader, fh, JPEG_INFO_DIMENSIONS | JPEG_INFO_ORIENTATION | JPEG_INFO_METADATA, pb, 256, NULL, 0)) return; md->md_time = ji.ji_time; md->md_manufacturer = rstr_dup(ji.ji_manufacturer); md->md_equipment = rstr_dup(ji.ji_equipment); jpeg_info_clear(&ji); }
static void set_source(glw_t *w, rstr_t *filename) { glw_image_t *gi = (glw_image_t *)w; const rstr_t *curname; if(gi->gi_pending_url != NULL) curname = gi->gi_pending_url; else if(gi->gi_pending != NULL) curname = gi->gi_pending->glt_url; else if(gi->gi_current != NULL) curname = gi->gi_current->glt_url; else curname = NULL; if(curname != NULL && filename != NULL && !strcmp(rstr_get(filename), rstr_get(curname))) return; if(gi->gi_pending_url != NULL) rstr_release(gi->gi_pending_url); gi->gi_pending_url = filename ? rstr_dup(filename) : rstr_alloc(""); }
rstr_t * backend_prop_make(prop_t *model, const char *suggest) { proppage_t *pp; rstr_t *r; hts_mutex_lock(&pp_mutex); pp = calloc(1, sizeof(proppage_t)); if(suggest == NULL) { char url[50]; pp_tally++; snprintf(url, sizeof(url), "prop:%d", pp_tally); r = rstr_alloc(url); } else { r = rstr_alloc(suggest); } pp->pp_url = rstr_dup(r); pp->pp_model = prop_ref_inc(model); pp->pp_model_sub = prop_subscribe(PROP_SUB_TRACK_DESTROY, PROP_TAG_CALLBACK, pp_cb, pp, PROP_TAG_MUTEX, &pp_mutex, PROP_TAG_ROOT, model, NULL); LIST_INSERT_HEAD(&proppages, pp, pp_link); hts_mutex_unlock(&pp_mutex); return r; }
static void lexer_link_token(token_t *prev, rstr_t *f, int line, token_t *t, token_type_t type) { t->type = type; prev->next = t; t->file = rstr_dup(f); t->line = line; }
event_t * event_create_prop_action(prop_t *p, rstr_t *action) { event_prop_action_t *e = event_create(EVENT_PROP_ACTION, sizeof(event_prop_action_t)); e->p = prop_ref_inc(p); e->action = rstr_dup(action); e->h.e_dtor = event_prop_action_dtor; return &e->h; }
static void lexer_link_token(token_t *prev, rstr_t *f, int line, token_t *t, token_type_t type) { t->type = type; prev->next = t; #ifdef GLW_VIEW_ERRORINFO t->file = rstr_dup(f); t->line = line; #endif }
rstr_t * metadata_remove_postfix_rstr(rstr_t *name) { if(!gconf.show_filename_extensions) { const char *str = rstr_get(name); int len = strlen(str); if(len > 4 && str[len - 4] == '.') return rstr_allocl(str, len - 4); if(len > 5 && !strcasecmp(str + len - 5, ".m2ts")) return rstr_allocl(str, len - 5); } return rstr_dup(name); }
void rstr_vec_append(rstr_vec_t **rvp, rstr_t *str) { rstr_vec_t *rv = *rvp; if(rv == NULL) { rv = malloc(sizeof(rstr_vec_t) + sizeof(rstr_t *) * 16); rv->capacity = 16; rv->size = 0; *rvp = rv; } else if(rv->size == rv->capacity) { rv->capacity = rv->capacity * 2; rv = realloc(rv, sizeof(rstr_vec_t) + sizeof(rstr_t *) * rv->capacity); *rvp = rv; } rv->v[rv->size++] = rstr_dup(str); }
static JSBool js_appendItem0(JSContext *cx, js_model_t *model, prop_t *parent, const char *url, const char *type, JSObject *metaobj, jsval *data, jsval *rval, int enabled, const char *metabind) { install_nodesub(model); prop_t *item = prop_create_root(NULL); rstr_t *rurl = url ? rstr_alloc(url) : NULL; if(url != NULL) prop_set(item, "url", PROP_SET_RSTRING, rurl); if(data != NULL) js_prop_set_from_jsval(cx, prop_create(item, "data"), *data); *rval = JSVAL_VOID; if(metabind != NULL) playinfo_bind_url_to_prop(metabind, item); if(type != NULL) { prop_set_string(prop_create(item, "type"), type); if(metaobj) js_prop_from_object(cx, metaobj, prop_create(item, "metadata")); } else if(url != NULL) { if(backend_resolve_item(url, item)) { prop_destroy(item); rstr_release(rurl); return JS_TRUE; } } prop_set_int(prop_create(item, "enabled"), enabled); prop_t *p = prop_ref_inc(item); if(prop_set_parent(item, parent)) { prop_destroy(item); prop_ref_dec(p); } else { JSObject *robj = JS_NewObjectWithGivenProto(cx, &item_class, JSVAL_TO_OBJECT(model->jm_item_proto), NULL); *rval = OBJECT_TO_JSVAL(robj); js_item_t *ji = calloc(1, sizeof(js_item_t)); atomic_add(&model->jm_refcount, 1); ji->ji_url = rstr_dup(rurl); ji->ji_model = model; ji->ji_root = p; TAILQ_INSERT_TAIL(&model->jm_items, ji, ji_link); JS_SetPrivate(cx, robj, ji); ji->ji_enable_set_property = 1; ji->ji_eventsub = prop_subscribe(PROP_SUB_TRACK_DESTROY, PROP_TAG_CALLBACK, js_item_eventsub, ji, PROP_TAG_ROOT, ji->ji_root, PROP_TAG_COURIER, model->jm_pc, NULL); model->jm_subs++; ji->ji_this = OBJECT_TO_JSVAL(robj); JS_AddNamedRoot(cx, &ji->ji_this, "item_this"); prop_tag_set(ji->ji_root, model, ji); } rstr_release(rurl); return JS_TRUE; }
/** * Clone a token */ token_t * glw_view_token_copy(glw_root_t *gr, token_t *src) { token_t *dst = pool_get(gr->gr_token_pool); dst->file = rstr_dup(src->file); dst->line = src->line; dst->type = src->type; switch(src->type) { case TOKEN_FLOAT: dst->t_float = src->t_float; break; case TOKEN_INT: dst->t_int = src->t_int; break; case TOKEN_PROPERTY_REF: dst->t_prop = prop_ref_inc(src->t_prop); break; case TOKEN_PROPERTY_OWNER: dst->t_prop = prop_xref_addref(src->t_prop); break; case TOKEN_PROPERTY_SUBSCRIPTION: case TOKEN_DIRECTORY: dst->propsubr = src->propsubr; break; case TOKEN_FUNCTION: dst->t_func = src->t_func; if(dst->t_func->ctor != NULL) dst->t_func->ctor(dst); case TOKEN_LEFT_BRACKET: dst->t_num_args = src->t_num_args; break; case TOKEN_OBJECT_ATTRIBUTE: dst->t_attrib = src->t_attrib; break; case TOKEN_CSTRING: dst->t_cstring = src->t_cstring; break; case TOKEN_RSTRING: dst->t_rstrtype = src->t_rstrtype; // FALLTHRU case TOKEN_IDENTIFIER: case TOKEN_PROPERTY_VALUE_NAME: case TOKEN_PROPERTY_CANONICAL_NAME: dst->t_rstring = rstr_dup(src->t_rstring); break; case TOKEN_START: case TOKEN_END: case TOKEN_HASH: case TOKEN_ASSIGNMENT: case TOKEN_COND_ASSIGNMENT: case TOKEN_END_OF_EXPR: case TOKEN_SEPARATOR: case TOKEN_BLOCK_OPEN: case TOKEN_BLOCK_CLOSE: case TOKEN_LEFT_PARENTHESIS: case TOKEN_RIGHT_PARENTHESIS: case TOKEN_RIGHT_BRACKET: case TOKEN_DOT: case TOKEN_ADD: case TOKEN_SUB: case TOKEN_MULTIPLY: case TOKEN_DIVIDE: case TOKEN_MODULO: case TOKEN_DOLLAR: case TOKEN_AMPERSAND: case TOKEN_BOOLEAN_AND: case TOKEN_BOOLEAN_OR: case TOKEN_BOOLEAN_XOR: case TOKEN_BOOLEAN_NOT: case TOKEN_EQ: case TOKEN_NEQ: case TOKEN_LT: case TOKEN_GT: case TOKEN_NULL_COALESCE: case TOKEN_EXPR: case TOKEN_RPN: case TOKEN_BLOCK: case TOKEN_NOP: case TOKEN_VOID: case TOKEN_COLON: break; case TOKEN_LINK: dst->t_link_rtitle = rstr_dup(src->t_link_rtitle); dst->t_link_rurl = rstr_dup(src->t_link_rurl); break; case TOKEN_VECTOR_FLOAT: case TOKEN_EVENT: case TOKEN_VECTOR: case TOKEN_num: abort(); } return dst; }