char *xcap_uri_for_rls_resource(const str_t *xcap_root, const str_t *uri) { dstring_t s; int l; str_t c_uri; char *dst = NULL; if (!xcap_root) return NULL; dstr_init(&s, 2 * xcap_root->len + 32); dstr_append_str(&s, xcap_root); if (xcap_root->s[xcap_root->len - 1] != '/') dstr_append(&s, "/", 1); dstr_append_zt(&s, "rls-services/global/index/~~/rls-services/service[@uri=%22"); canonicalize_uri(uri, &c_uri); dstr_append_str(&s, &c_uri); if (c_uri.s) cds_free(c_uri.s); dstr_append_zt(&s, "%22]"); l = dstr_get_data_length(&s); if (l > 0) { dst = (char *)cds_malloc(l + 1); if (dst) { dstr_get_data(&s, dst); dst[l] = 0; } } dstr_destroy(&s); return dst; }
/** * The x server was changed */ static bool xshm_server_changed(obs_properties_t *props, obs_property_t *p, obs_data_t *settings) { UNUSED_PARAMETER(p); bool advanced = obs_data_get_bool(settings, "advanced"); int_fast32_t old_screen = obs_data_get_int(settings, "screen"); const char *server = obs_data_get_string(settings, "server"); obs_property_t *screens = obs_properties_get(props, "screen"); /* we want a real NULL here in case there is no string here */ server = (advanced && *server) ? server : NULL; obs_property_list_clear(screens); Display *dpy = XOpenDisplay(server); if (!dpy) { obs_property_set_enabled(screens, false); return true; } struct dstr screen_info; dstr_init(&screen_info); bool xinerama = xinerama_is_active(dpy); int_fast32_t count = (xinerama) ? xinerama_screen_count(dpy) : XScreenCount(dpy); for (int_fast32_t i = 0; i < count; ++i) { int_fast32_t x, y, w, h; x = y = w = h = 0; if (xinerama) xinerama_screen_geo(dpy, i, &x, &y, &w, &h); else x11_screen_geo(dpy, i, &w, &h); dstr_printf(&screen_info, "Screen %"PRIuFAST32" (%"PRIuFAST32 "x%"PRIuFAST32" @ %"PRIuFAST32 ",%"PRIuFAST32")", i, w, h, x, y); obs_property_list_add_int(screens, screen_info.array, i); } /* handle missing screen */ if (old_screen + 1 > count) { dstr_printf(&screen_info, "Screen %"PRIuFAST32" (not found)", old_screen); size_t index = obs_property_list_add_int(screens, screen_info.array, old_screen); obs_property_list_item_disable(screens, index, true); } dstr_free(&screen_info); XCloseDisplay(dpy); obs_property_set_enabled(screens, true); return true; }
int create_lpidf_document(presentity_info_t *p, str_t *dst, str_t *dst_content_type) { dstring_t buf; int err; if (!dst) return -1; str_clear(dst); if (dst_content_type) str_clear(dst_content_type); if (!p) return -1; if (dst_content_type) { if (str_dup_zt(dst_content_type, "text/lpidf") < 0) { return -1; } } /* if (!p->first_tuple) return 0;*/ /* no tuples => nothing to say */ dstr_init(&buf, 2048); doc_add_presentity(&buf, p); err = dstr_get_str(&buf, dst); dstr_destroy(&buf); if (err != 0) { str_free_content(dst); if (dst_content_type) str_free_content(dst_content_type); } return err; }
static void ep_write_main(struct effect_parser *ep, struct dstr *shader, struct ep_func *func, struct dstr *call_str) { struct dstr param_str; struct dstr adjusted_call; dstr_init(¶m_str); dstr_init_copy_dstr(&adjusted_call, call_str); dstr_cat(shader, "\n"); dstr_cat(shader, func->ret_type); dstr_cat(shader, " main("); ep_write_main_params(ep, shader, ¶m_str, func); dstr_cat(shader, ")"); if (func->mapping) { dstr_cat(shader, " : "); dstr_cat(shader, func->mapping); } dstr_cat(shader, "\n{\n\treturn "); dstr_cat_dstr(shader, &adjusted_call); dstr_cat(shader, "\n}\n"); dstr_free(&adjusted_call); dstr_free(¶m_str); }
/* * List formats for device */ static void v4l2_format_list(int dev, obs_property_t *prop) { struct v4l2_fmtdesc fmt; fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fmt.index = 0; struct dstr buffer; dstr_init(&buffer); obs_property_list_clear(prop); while (v4l2_ioctl(dev, VIDIOC_ENUM_FMT, &fmt) == 0) { dstr_copy(&buffer, (char *) fmt.description); if (fmt.flags & V4L2_FMT_FLAG_EMULATED) dstr_cat(&buffer, " (Emulated)"); if (v4l2_to_obs_video_format(fmt.pixelformat) != VIDEO_FORMAT_NONE) { obs_property_list_add_int(prop, buffer.array, fmt.pixelformat); blog(LOG_INFO, "Pixelformat: %s (available)", buffer.array); } else { blog(LOG_INFO, "Pixelformat: %s (unavailable)", buffer.array); } fmt.index++; } dstr_free(&buffer); }
/* * List dv timings for the device */ static void v4l2_dv_timing_list(int dev, obs_property_t *prop) { struct v4l2_dv_timings dvt; struct dstr buf; int index = 0; dstr_init(&buf); obs_property_list_clear(prop); obs_property_list_add_int(prop, obs_module_text("LeaveUnchanged"), -1); while (v4l2_enum_dv_timing(dev, &dvt, index) == 0) { /* i do not pretend to understand, this is from qv4l2 ... */ double h = (double) dvt.bt.height + dvt.bt.vfrontporch + dvt.bt.vsync + dvt.bt.vbackporch + dvt.bt.il_vfrontporch + dvt.bt.il_vsync + dvt.bt.il_vbackporch; double w = (double) dvt.bt.width + dvt.bt.hfrontporch + dvt.bt.hsync + dvt.bt.hbackporch; double i = (dvt.bt.interlaced) ? 2.0f : 1.0f; double rate = (double) dvt.bt.pixelclock / (w * (h / i)); dstr_printf(&buf, "%ux%u%c %.2f", dvt.bt.width, dvt.bt.height, (dvt.bt.interlaced) ? 'i' : 'p', rate); obs_property_list_add_int(prop, buf.array, index); index++; } dstr_free(&buf); }
void config_set_default_double(config_t config, const char *section, const char *name, double value) { struct dstr str; dstr_init(&str); dstr_printf(&str, "%g", value); config_set_item(&config->defaults, section, name, str.array); }
void dstr_right(struct dstr *dst, const struct dstr *str, const size_t pos) { struct dstr temp; dstr_init(&temp); dstr_ncopy(&temp, str->array+pos, str->len-pos); dstr_copy_dstr(dst, &temp); dstr_free(&temp); }
void config_set_int(config_t *config, const char *section, const char *name, int64_t value) { struct dstr str; dstr_init(&str); dstr_printf(&str, "%lld", value); config_set_item(&config->sections, section, name, str.array); }
void dstr_vcatf(struct dstr *dst, const char *format, va_list args) { struct dstr temp; dstr_init(&temp); dstr_vprintf(&temp, format, args); dstr_cat_dstr(dst, &temp); dstr_free(&temp); }
void config_set_default_uint(config_t config, const char *section, const char *name, uint64_t value) { struct dstr str; dstr_init(&str); dstr_printf(&str, "%llu", value); config_set_item(&config->defaults, section, name, str.array); }
void dstr_mid(struct dstr *dst, const struct dstr *str, const size_t start, const size_t count) { struct dstr temp; dstr_init(&temp); dstr_copy_dstr(&temp, str); dstr_ncopy(dst, temp.array+start, count); dstr_free(&temp); }
static inline int create_headers(struct watcher* _w, str *dst, str *content_type) { dstring_t buf; time_t t; int err = 0; dstr_init(&buf, 256); str_clear(dst); /* required by RFC 3261 */ dstr_append_zt(&buf, "Max-Forwards: 70\r\n"); /* Event header */ dstr_append_zt(&buf, "Event: "); dstr_append_zt(&buf, event_package2str(_w->event_package)); dstr_append_zt(&buf, "\r\n"); /* Content-Type header */ /* content types can have dynamical parameters (multipart/related) * => don't generate them "staticaly"; use values created in the * time of document creation */ if (!is_str_empty(content_type)) { /* documents without body doesn't need it */ dstr_append_zt(&buf, "Content-Type: "); dstr_append_str(&buf, content_type); dstr_append_zt(&buf, "\r\n"); } /* Contact header */ if (is_str_empty(&_w->server_contact)) { LOG(L_WARN, "add_contact_hf(): Can't add empty contact to NOTIFY.\n"); } else { dstr_append_zt(&buf, "Contact: "); dstr_append_str(&buf, &_w->server_contact); dstr_append_zt(&buf, "\r\n"); } /* Subscription-State header */ if (_w->expires) t = _w->expires - time(0); else t = 0; if (add_subs_state_hf(&buf, _w->status, t) < 0) { LOG(L_ERR, "create_headers(): Error while adding Subscription-State\n"); dstr_destroy(&buf); return -3; } err = dstr_get_str(&buf, dst); dstr_destroy(&buf); return err; }
int init_output_sstream(sstream_t *ss, int out_buff_resize) { if (!ss) return -1; ss->type = sstream_out; str_clear(&ss->in); ss->in_pos = 0; dstr_init(&ss->out, out_buff_resize); return 0; }
/* on windows, data files should always be in [base directory]/data */ char *obs_find_plugin_file(const char *file) { struct dstr path; dstr_init(&path); if (check_path(file, "data/obs-plugins/", &path)) return path.array; if (check_path(file, "../../data/obs-plugins/", &path)) return path.array; dstr_free(&path); return NULL; }
/* on windows, points to [base directory]/libobs */ char *find_libobs_data_file(const char *file) { struct dstr path; dstr_init(&path); if (check_path(file, "data/libobs/", &path)) return path.array; if (check_path(file, "../../data/libobs/", &path)) return path.array; dstr_free(&path); return NULL; }
int config_save(config_t config) { FILE *f; struct dstr str; size_t i, j; if (!config) return CONFIG_ERROR; dstr_init(&str); f = os_fopen(config->file, "wb"); if (!f) return CONFIG_FILENOTFOUND; for (i = 0; i < config->sections.num; i++) { struct config_section *section = darray_item( sizeof(struct config_section), &config->sections, i); if (i) dstr_cat(&str, "\n"); dstr_cat(&str, "{"); dstr_cat(&str, section->name); dstr_cat(&str, "]\n"); for (j = 0; j < section->items.num; j++) { struct config_item *item = darray_item( sizeof(struct config_item), §ion->items, i); dstr_cat(&str, item->name); dstr_cat(&str, "="); dstr_cat(&str, item->value); dstr_cat(&str, "\n"); } } #ifdef _WIN32 fwrite("\xEF\xBB\xBF", 1, 3, f); #endif fwrite(str.array, 1, str.len, f); fclose(f); dstr_free(&str); return CONFIG_SUCCESS; }
/* * List framerates for device and resolution */ static void v4l2_framerate_list(int dev, uint_fast32_t pixelformat, uint_fast32_t width, uint_fast32_t height, obs_property_t *prop) { struct v4l2_frmivalenum frmival; frmival.pixel_format = pixelformat; frmival.width = width; frmival.height = height; frmival.index = 0; struct dstr buffer; dstr_init(&buffer); obs_property_list_clear(prop); obs_property_list_add_int(prop, obs_module_text("LeaveUnchanged"), -1); v4l2_ioctl(dev, VIDIOC_ENUM_FRAMEINTERVALS, &frmival); switch(frmival.type) { case V4L2_FRMIVAL_TYPE_DISCRETE: while (v4l2_ioctl(dev, VIDIOC_ENUM_FRAMEINTERVALS, &frmival) == 0) { float fps = (float) frmival.discrete.denominator / frmival.discrete.numerator; int pack = v4l2_pack_tuple(frmival.discrete.numerator, frmival.discrete.denominator); dstr_printf(&buffer, "%.2f", fps); obs_property_list_add_int(prop, buffer.array, pack); frmival.index++; } break; default: blog(LOG_INFO, "Stepwise and Continuous framerates " "are currently hardcoded"); for (const int *packed = v4l2_framerates; *packed; ++packed) { int num; int denom; v4l2_unpack_tuple(&num, &denom, *packed); float fps = (float) denom / num; dstr_printf(&buffer, "%.2f", fps); obs_property_list_add_int(prop, buffer.array, *packed); } break; } dstr_free(&buffer); }
static void cf_include_file(struct cf_preprocessor *pp, const struct cf_token *file_token) { struct cf_lexer new_lex; struct dstr str_file; FILE *file; char *file_data; struct cf_token *tokens; size_t i; dstr_init(&str_file); dstr_copy_strref(&str_file, &file_token->str); dstr_mid(&str_file, &str_file, 1, str_file.len-2); /* if dependency already exists, run preprocessor on it */ for (i = 0; i < pp->dependencies.num; i++) { struct cf_lexer *dep = pp->dependencies.array+i; if (strcmp(dep->file, str_file.array) == 0) { tokens = cf_lexer_gettokens(dep); cf_preprocess_tokens(pp, false, &tokens); goto exit; } } file = os_fopen(str_file.array, "rb"); if (!file) { cf_adderror(pp, file_token, "Could not open file '$1'", file_token->str.array, NULL, NULL); goto exit; } os_fread_utf8(file, &file_data); fclose(file); cf_lexer_init(&new_lex); cf_lexer_lex(&new_lex, file_data, str_file.array); tokens = cf_lexer_gettokens(&new_lex); cf_preprocess_tokens(pp, false, &tokens); bfree(file_data); da_push_back(pp->dependencies, &new_lex); exit: dstr_free(&str_file); }
static void ep_makeshaderstring(struct effect_parser *ep, struct dstr *shader, struct darray *shader_call, struct darray *used_params) { struct cf_token *token = shader_call->array; struct cf_token *func_name; struct ep_func *func; struct dstr call_str; dstr_init(&call_str); if (!token) return; while (token->type != CFTOKEN_NONE && is_whitespace(*token->str.array)) token++; if (token->type == CFTOKEN_NONE || strref_cmp(&token->str, "NULL") == 0) return; func_name = token; while (token->type != CFTOKEN_NONE) { struct ep_param *param = ep_getparam_strref(ep, &token->str); if (param) ep_write_param(shader, param, used_params); dstr_cat_strref(&call_str, &token->str); token++; } func = ep_getfunc_strref(ep, &func_name->str); if (!func) return; ep_write_func(ep, shader, func, used_params); ep_write_main(ep, shader, func, &call_str); dstr_free(&call_str); ep_reset_written(ep); }
/* * List resolutions for device and format */ static void v4l2_resolution_list(int dev, uint_fast32_t pixelformat, obs_property_t *prop) { struct v4l2_frmsizeenum frmsize; frmsize.pixel_format = pixelformat; frmsize.index = 0; struct dstr buffer; dstr_init(&buffer); obs_property_list_clear(prop); obs_property_list_add_int(prop, obs_module_text("LeaveUnchanged"), -1); v4l2_ioctl(dev, VIDIOC_ENUM_FRAMESIZES, &frmsize); switch(frmsize.type) { case V4L2_FRMSIZE_TYPE_DISCRETE: while (v4l2_ioctl(dev, VIDIOC_ENUM_FRAMESIZES, &frmsize) == 0) { dstr_printf(&buffer, "%dx%d", frmsize.discrete.width, frmsize.discrete.height); obs_property_list_add_int(prop, buffer.array, v4l2_pack_tuple(frmsize.discrete.width, frmsize.discrete.height)); frmsize.index++; } break; default: blog(LOG_INFO, "Stepwise and Continuous framesizes " "are currently hardcoded"); for (const int *packed = v4l2_framesizes; *packed; ++packed) { int width; int height; v4l2_unpack_tuple(&width, &height, *packed); dstr_printf(&buffer, "%dx%d", width, height); obs_property_list_add_int(prop, buffer.array, *packed); } break; } dstr_free(&buffer); }
static void cf_addew(struct cf_preprocessor *pp, const struct cf_token *token, const char *message, int error_level, const char *val1, const char *val2, const char *val3) { uint32_t row, col; cf_gettokenoffset(pp, token, &row, &col); if (!val1 && !val2 && !val3) { error_data_add(pp->ed, token->lex->file, row, col, message, error_level); } else { struct dstr formatted; dstr_init(&formatted); dstr_safe_printf(&formatted, message, val1, val2, val3, NULL); error_data_add(pp->ed, token->lex->file, row, col, formatted.array, error_level); dstr_free(&formatted); } }
/* unwraps a structure that's used for input/output */ static void gl_unwrap_storage_struct(struct gl_shader_parser *glsp, struct shader_struct *st, const char *name, bool input, const char *prefix) { struct dstr prefix_str; size_t i; dstr_init(&prefix_str); if (prefix) dstr_copy(&prefix_str, prefix); dstr_cat(&prefix_str, name); dstr_cat(&prefix_str, "_"); for (i = 0; i < st->vars.num; i++) { struct shader_var *st_var = st->vars.array+i; gl_write_storage_var(glsp, st_var, input, prefix_str.array); } dstr_free(&prefix_str); }
static inline bool create_proccess(const char *cmd_line, HANDLE stdin_handle, HANDLE stdout_handle, HANDLE *process) { PROCESS_INFORMATION pi = {0}; wchar_t *cmd_line_w = NULL; STARTUPINFOW si = {0}; bool success = false; struct dstr root_dir; wchar_t *root_dir_w = NULL; dstr_init(&root_dir); biliobs_get_root_path(&root_dir); si.cb = sizeof(si); si.dwFlags = STARTF_USESTDHANDLES; si.hStdInput = stdin_handle; si.hStdOutput = stdout_handle; os_utf8_to_wcs_ptr(cmd_line, 0, &cmd_line_w); os_utf8_to_wcs_ptr(root_dir.array, 0, &root_dir_w); if (cmd_line_w && root_dir_w) { success = !!CreateProcessW(NULL, cmd_line_w, NULL, NULL, true, CREATE_NO_WINDOW, NULL, root_dir_w, &si, &pi); if (success) { *process = pi.hProcess; CloseHandle(pi.hThread); } } if( cmd_line_w ){ bfree(cmd_line_w); cmd_line_w = NULL; } if (root_dir_w){ bfree(root_dir_w); root_dir_w = NULL; } return success; }
/* on windows, plugin files are located in [base directory]/plugins/[bit] */ char *find_plugin(const char *plugin) { struct dstr path; dstr_init(&path); #ifdef _WIN64 if (check_lib_path(plugin, "obs-plugins/64bit/", &path)) #else if (check_lib_path(plugin, "obs-plugins/32bit/", &path)) #endif return path.array; #ifdef _WIN64 if (check_lib_path(plugin, "../../obs-plugins/64bit/", &path)) #else if (check_lib_path(plugin, "../../obs-plugins/32bit/", &path)) #endif return path.array; dstr_free(&path); return NULL; }
char *xcap_uri_for_rls_services(const str_t *xcap_root) { dstring_t s; int l; char *dst = NULL; if (!xcap_root) return NULL; dstr_init(&s, 2 * xcap_root->len + 32); dstr_append_str(&s, xcap_root); if (xcap_root->s[xcap_root->len - 1] != '/') dstr_append(&s, "/", 1); dstr_append_zt(&s, "rls-services/global/index"); l = dstr_get_data_length(&s); if (l > 0) { dst = (char *)cds_malloc(l + 1); if (dst) { dstr_get_data(&s, dst); dst[l] = 0; } } dstr_destroy(&s); return dst; }
static int rls_generate_notify_ext(rl_subscription_t *s, int full_info) { /* !!! the main mutex must be locked here !!! */ int res; str doc; dstring_t dstr; str headers, content_type; static str method = STR_STATIC_INIT(METHOD_NOTIFY); dlg_t *dlg; int exp_time = 0; char expiration[32]; str body = STR_STATIC_INIT(""); int removed = 0; dlg = s->u.external.dialog; if (!dlg) return -1; DEBUG("generating external notify\n"); str_clear(&doc); str_clear(&content_type); if (sm_subscription_pending(&s->u.external) != 0) { /* create the document only for non-pending subscriptions */ if (create_rlmi_document(&doc, &content_type, s, full_info) != 0) { return -1; } } exp_time = sm_subscription_expires_in(rls_manager, &s->u.external); sprintf(expiration, ";expires=%d\r\n", exp_time); dstr_init(&dstr, 256); dstr_append_zt(&dstr, "Subscription-State: "); switch (s->u.external.status) { case subscription_active: dstr_append_zt(&dstr, "active"); dstr_append_zt(&dstr, expiration); break; case subscription_pending: dstr_append_zt(&dstr, "pending"); dstr_append_zt(&dstr, expiration); break; case subscription_terminated_pending: case subscription_terminated: dstr_append_zt(&dstr, "terminated\r\n"); break; case subscription_terminated_pending_to: case subscription_terminated_to: dstr_append_zt(&dstr, "terminated;reason=timeout\r\n"); break; case subscription_uninitialized: dstr_append_zt(&dstr, "pending\r\n"); /* this is an error ! */ LOG(L_ERR, "sending NOTIFY for an unitialized subscription!\n"); break; } dstr_append_str(&dstr, &s->u.external.contact); /* required by RFC 3261 */ dstr_append_zt(&dstr, "Max-Forwards: 70\r\n"); dstr_append_zt(&dstr, "Event: "); dstr_append_str(&dstr, rls_get_package(s)); dstr_append_zt(&dstr, "\r\n"); dstr_append_zt(&dstr, "Require: eventlist\r\nContent-Type: "); dstr_append_str(&dstr, &content_type); dstr_append_zt(&dstr, "\r\n"); res = dstr_get_str(&dstr, &headers); dstr_destroy(&dstr); if (res >= 0) { /* DEBUG("sending NOTIFY message to %.*s (subscription %p)\n", dlg->rem_uri.len, ZSW(dlg->rem_uri.s), s); */ if (!is_str_empty(&doc)) body = doc; if (sm_subscription_terminated(&s->u.external) == 0) { /* doesn't matter if delivered or not, it will be freed otherwise !!! */ res = tmb.t_request_within(&method, &headers, &body, dlg, 0, 0); if (res >= 0) clear_change_flags(s); } else { rls_notify_cb_param_t *cbd = create_notify_cb_param(s); if (!cbd) { ERR("Can't create notify cb data! Freeing RL subscription.\n"); rls_remove(s); /* ?????? */ removed = 1; res = -13; } else { /* the subscritpion will be destroyed if NOTIFY delivery problems */ /* rls_unlock(); the callback locks this mutex ! */ /* !!!! FIXME: callbacks can't be safely used (may be called or not, * may free memory automaticaly or not) !!! */ res = tmb.t_request_within(&method, &headers, &body, dlg, rls_notify_cb, cbd); /* res = tmb.t_request_within(&method, &headers, &body, dlg, rls_notify_cb, s); */ /* rls_lock(); the callback locks this mutex ! */ if (res < 0) { /* does this mean, that the callback was not called ??? */ ERR("t_request_within FAILED: %d! Freeing RL subscription.\n", res); rls_remove(s); /* ?????? */ removed = 1; } else clear_change_flags(s); } } } if (doc.s) cds_free(doc.s); if (content_type.s) cds_free(content_type.s); if (headers.s) cds_free(headers.s); if ((!removed) && use_db) rls_db_update(s); if (res < 0) DEBUG("external notify NOT generated\n"); else DEBUG("external notify generated\n"); return res; }
static inline bool ep_compile_pass_shader(struct effect_parser *ep, struct gs_effect_technique *tech, struct gs_effect_pass *pass, struct ep_pass *pass_in, size_t pass_idx, enum gs_shader_type type) { struct dstr shader_str; struct dstr location; struct darray used_params; /* struct dstr */ struct darray *pass_params = NULL; /* struct pass_shaderparam */ gs_shader_t *shader = NULL; bool success = true; dstr_init(&shader_str); darray_init(&used_params); dstr_init(&location); dstr_copy(&location, ep->cfp.lex.file); if (type == GS_SHADER_VERTEX) dstr_cat(&location, " (Vertex "); else if (type == GS_SHADER_PIXEL) dstr_cat(&location, " (Pixel "); /*else if (type == SHADER_GEOMETRY) dstr_cat(&location, " (Geometry ");*/ assert(pass_idx <= UINT_MAX); dstr_catf(&location, "shader, technique %s, pass %u)", tech->name, (unsigned)pass_idx); if (type == GS_SHADER_VERTEX) { ep_makeshaderstring(ep, &shader_str, &pass_in->vertex_program.da, &used_params); pass->vertshader = gs_vertexshader_create(shader_str.array, location.array, NULL); shader = pass->vertshader; pass_params = &pass->vertshader_params.da; } else if (type == GS_SHADER_PIXEL) { ep_makeshaderstring(ep, &shader_str, &pass_in->fragment_program.da, &used_params); pass->pixelshader = gs_pixelshader_create(shader_str.array, location.array, NULL); shader = pass->pixelshader; pass_params = &pass->pixelshader_params.da; } #if 0 blog(LOG_DEBUG, "+++++++++++++++++++++++++++++++++++"); blog(LOG_DEBUG, " %s", location.array); blog(LOG_DEBUG, "-----------------------------------"); blog(LOG_DEBUG, "%s", shader_str.array); blog(LOG_DEBUG, "+++++++++++++++++++++++++++++++++++"); #endif if (shader) success = ep_compile_pass_shaderparams(ep, pass_params, &used_params, shader); else success = false; dstr_free(&location); dstr_array_free(used_params.array, used_params.num); darray_free(&used_params); dstr_free(&shader_str); return success; }
/* * NAME: process() * DESCRIPTION: sort and display results */ static int process(hfsvol *vol, darray *dirs, darray *files, int flags, int options, int width) { int i, dsz, fsz; queueent *ents; int result = 0; dsz = darr_size(dirs); fsz = darr_size(files); if (fsz) { sortfiles(files, flags, options); if (showfiles(files, flags, options, width) == -1) result = -1; flags |= HLS_NAME | HLS_SPACE; } else if (dsz > 1) flags |= HLS_NAME; ents = darr_array(dirs); for (i = 0; i < dsz; ++i) { const char *path; hfsdir *dir; queueent ent; darr_shrink(files, 0); path = PATH(ents[i]); dir = hfs_opendir(vol, path); if (dir == 0) { hfsutil_perrorp(path); result = -1; continue; } while (hfs_readdir(dir, &ent.dirent) != -1) { if ((ent.dirent.fdflags & HFS_FNDR_ISINVISIBLE) && ! (flags & HLS_ALL_FILES)) continue; ent.path = 0; ent.free = 0; if (darr_append(files, &ent) == 0) { fprintf(stderr, "%s: not enough memory\n", argv0); result = -1; break; } if ((ent.dirent.flags & HFS_ISDIR) && (flags & HLS_RECURSIVE)) { dstring str; dstr_init(&str); if (strchr(path, ':') == 0 && dstr_append(&str, ":", 1) == -1) result = -1; if (dstr_append(&str, path, -1) == -1) result = -1; if (path[strlen(path) - 1] != ':' && dstr_append(&str, ":", 1) == -1) result = -1; if (dstr_append(&str, ent.dirent.name, -1) == -1) result = -1; ent.path = strdup(dstr_string(&str)); if (ent.path) ent.free = dpfree; else result = -1; dstr_free(&str); if (darr_append(dirs, &ent) == 0) { result = -1; if (ent.path) free(ent.path); } if (result) { fprintf(stderr, "%s: not enough memory\n", argv0); break; } dsz = darr_size(dirs); ents = darr_array(dirs); } } hfs_closedir(dir); if (result) break; if (flags & HLS_SPACE) printf("\n"); if (flags & HLS_NAME) printf("%s%s", path, path[strlen(path) - 1] == ':' ? "\n" : ":\n"); sortfiles(files, flags, options); if (showfiles(files, flags, options, width) == -1) result = -1; flags |= HLS_NAME | HLS_SPACE; } return result; }
void dstr_init_strref(struct dstr *dst, const struct strref *src) { dstr_init(dst); dstr_copy_strref(dst, src); }