/* Executes current file of the view by program specification that does not * include any macros (hence file name is appended implicitly. */ static void run_implicit_prog(FileView *view, const char prog_spec[], int pause, int force_bg) { int bg; char cmd[NAME_MAX + 1 + NAME_MAX + 1]; const char *name_macro; char *file_name; char spec[strlen(prog_spec) + 1]; strcpy(spec, prog_spec); bg = cut_suffix(spec, " &") || force_bg; if(curr_stats.shell_type == ST_CMD) { name_macro = (view == curr_view) ? "%\"c" : "%\"C"; } else { name_macro = (view == curr_view) ? "%c" : "%C"; } file_name = expand_macros(name_macro, NULL, NULL, 1); snprintf(cmd, sizeof(cmd), "%s %s", spec, file_name); free(file_name); if(bg) { (void)start_background_job(cmd, 0); } else { (void)shellout(cmd, pause ? PAUSE_ALWAYS : PAUSE_ON_ERROR, 1); } }
void cgit_print_summary() { html("<table summary='repository info' class='list nowrap'>"); cgit_print_branches(ctx.cfg.summary_branches); html("<tr class='nohover'><td colspan='4'> </td></tr>"); cgit_print_tags(ctx.cfg.summary_tags); if (ctx.cfg.summary_log > 0) { html("<tr class='nohover'><td colspan='4'> </td></tr>"); cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, NULL, NULL, 0, 0); } if (ctx.repo->clone_url) { char *full_clone = expand_macros(ctx.repo->clone_url); char *pound = full_clone; while (1) { pound = strchr(pound, '#'); if (pound == NULL) break; *pound = ' '; pound++; } print_url(full_clone, NULL); /*print_urls(expand_macros(ctx.repo->clone_url), NULL);*/ } else if (ctx.cfg.clone_prefix) print_urls(ctx.cfg.clone_prefix, ctx.repo->url); html("</table>"); }
/* Executes current file of the current view by program specification that * includes at least one macro. */ static void run_explicit_prog(const char prog_spec[], int pause, int force_bg) { int bg; MacroFlags flags; int save_msg; char *const cmd = expand_macros(prog_spec, NULL, &flags, 1); bg = cut_suffix(cmd, " &"); bg = !pause && (bg || force_bg); save_msg = 0; if(run_ext_command(cmd, flags, bg, &save_msg) != 0) { if(save_msg) { curr_stats.save_msg = 1; } } else if(bg) { assert(flags != MF_IGNORE && "This case is for run_ext_command()"); (void)start_background_job(cmd, flags == MF_IGNORE); } else { (void)shellout(cmd, pause ? PAUSE_ALWAYS : PAUSE_ON_ERROR, flags != MF_NO_TERM_MUX); } free(cmd); }
/* Formats a command to edit selected files of the current view in an editor. * Returns a newly allocated string, which should be freed by the caller. */ TSTATIC char * format_edit_selection_cmd(int *bg) { char *const files = expand_macros("%f", NULL, NULL, 1); char *const cmd = format_str("%s %s", cfg_get_vicmd(bg), files); free(files); return cmd; }
int main(int argc, const char **argv) { const char *path; char *qry; int err, ttl; prepare_context(&ctx); cgit_repolist.length = 0; cgit_repolist.count = 0; cgit_repolist.repos = NULL; cgit_parse_args(argc, argv); parse_configfile(expand_macros(ctx.env.cgit_config), config_cb); ctx.repo = NULL; http_parse_querystring(ctx.qry.raw, querystring_cb); /* If virtual-root isn't specified in cgitrc, lets pretend * that virtual-root equals SCRIPT_NAME, minus any possibly * trailing slashes. */ if (!ctx.cfg.virtual_root && ctx.cfg.script_name) { ctx.cfg.virtual_root = trim_end(ctx.cfg.script_name, '/'); if (!ctx.cfg.virtual_root) ctx.cfg.virtual_root = ""; } /* If no url parameter is specified on the querystring, lets * use PATH_INFO as url. This allows cgit to work with virtual * urls without the need for rewriterules in the webserver (as * long as PATH_INFO is included in the cache lookup key). */ path = ctx.env.path_info; if (!ctx.qry.url && path) { if (path[0] == '/') path++; ctx.qry.url = xstrdup(path); if (ctx.qry.raw) { qry = ctx.qry.raw; ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry)); free(qry); } else ctx.qry.raw = xstrdup(ctx.qry.url); cgit_parse_url(ctx.qry.url); } ttl = calc_ttl(); ctx.page.expires += ttl * 60; if (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD")) ctx.cfg.nocache = 1; if (ctx.cfg.nocache) ctx.cfg.cache_size = 0; err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, ctx.qry.raw, ttl, process_request, &ctx); if (err) cgit_print_error(fmt("Error processing page: %s (%d)", strerror(err), err)); return err; }
/* Implementation of macros expansion callback for cmds unit. Returns newly * allocated memory. */ static char * cmds_expand_macros(const char str[], int for_shell, int *usr1, int *usr2) { char *result; MacroFlags flags = MF_NONE; result = expand_macros(str, NULL, &flags, for_shell); *usr1 = flags; return result; }
char * prepare_targets(FileView *view) { if(view->selected_files > 0) { return expand_macros("%f", NULL, NULL, 1); } if(!flist_custom_active(view)) { return strdup("."); } return (vifm_chdir(flist_get_dir(view)) == 0) ? strdup(".") : NULL; }
/* Returns string after expanding expression. */ static var_t expand_builtin(const call_info_t *call_info) { var_t result; var_val_t var_val; char *str_val; str_val = var_to_string(call_info->argv[0]); var_val.string = expand_macros(str_val, NULL, NULL, 0); free(str_val); result = var_new(VTYPE_STRING, var_val); free(var_val.string); return result; }
void fs_mkdir(const char *name) { EUID_ASSERT(); // check directory name invalid_filename(name, 0); // no globbing char *expanded = expand_macros(name); if (strncmp(expanded, cfg.homedir, strlen(cfg.homedir)) != 0 && strncmp(expanded, "/tmp", 4) != 0) { fprintf(stderr, "Error: only directories in user home or /tmp are supported by mkdir\n"); exit(1); } struct stat s; if (stat(expanded, &s) == 0) { // file exists, do nothing goto doexit; } // create directory pid_t child = fork(); if (child < 0) errExit("fork"); if (child == 0) { // drop privileges drop_privs(0); // create directory mkdir_recursive(expanded); #ifdef HAVE_GCOV __gcov_flush(); #endif _exit(0); } // wait for the child to finish waitpid(child, NULL, 0); doexit: free(expanded); }
/* Returns a pointer to newly allocated memory, which should be released by the * caller. */ static char * get_viewer_command(const char viewer[]) { char *result; if(strchr(viewer, '%') == NULL) { char *escaped; FileView *view = curr_stats.preview_hint; if(view == NULL) { view = curr_view; } escaped = escape_filename(get_current_file_name(view), 0); result = format_str("%s %s", viewer, escaped); free(escaped); } else { result = expand_macros(viewer, NULL, NULL, 1); } return result; }
void fs_mkfile(const char *name) { EUID_ASSERT(); // check file name invalid_filename(name, 0); // no globbing char *expanded = expand_macros(name); if (strncmp(expanded, cfg.homedir, strlen(cfg.homedir)) != 0 && strncmp(expanded, "/tmp", 4) != 0) { fprintf(stderr, "Error: only files in user home or /tmp are supported by mkfile\n"); exit(1); } struct stat s; if (stat(expanded, &s) == 0) { // file exists, do nothing goto doexit; } // create file touch_file_as_user(expanded, 0600); doexit: free(expanded); }
int vim_run_choose_cmd(const FileView *view) { char *expanded_cmd; if(is_null_or_empty(curr_stats.on_choose)) { return 0; } if(!view->dir_entry[view->list_pos].selected) { erase_selection(curr_view); } expanded_cmd = expand_macros(curr_stats.on_choose, NULL, NULL, 1); if(vifm_system(expanded_cmd) != EXIT_SUCCESS) { free(expanded_cmd); return 1; } return 0; }
static bool decode(const Node& node, PlfsConf& pconf) { set_default_confs(&pconf); if(node["global_params"] && (node["global_params"].IsNull() || node["global_params"].as<string>() == "")) { if(node["num_hostdirs"]) { if(!conv(node["num_hostdirs"],pconf.num_hostdirs) || pconf.num_hostdirs > MAX_HOSTDIRS || pconf.num_hostdirs <= 0) pconf.err_msg = new string ("Illegal num_hostdirs"); } if(node["threadpool_size"]) { if(!conv(node["threadpool_size"], pconf.threadpool_size) || pconf.threadpool_size < 1) pconf.err_msg = new string ("Illegal threadpool_size"); pconf.threadpool_size = max(pconf.threadpool_size, 1); } if(node["lazy_stat"]) { if(!conv(node["lazy_stat"], pconf.lazy_stat)) pconf.err_msg = new string ("Illegal lazy_stat"); } if(node["lazy_droppings"]) { if(!conv(node["lazy_droppings"], pconf.lazy_droppings)) pconf.err_msg = new string ("Illegal lazy_droppings"); } if(node["compress_contiguous"]) { if(!conv(node["compress_contiguous"],pconf.compress_contiguous)) pconf.err_msg = new string ("Illegal compress_contiguous"); } if(node["index_buffer_mbs"]) { if(!conv(node["index_buffer_mbs"], pconf.buffer_mbs) || pconf.buffer_mbs < 0) pconf.err_msg = new string ("Illegal index_buffer_mbs"); } if(node["read_buffer_mbs"]) { if(!conv(node["read_buffer_mbs"],pconf.read_buffer_mbs) || pconf.read_buffer_mbs < 0) pconf.err_msg = new string ("Illegal read_buffer_mbs"); } if(node["global_summary_dir"]) { string temp; if(!conv(node["global_summary_dir"],temp) || temp.c_str()[0] != '/') pconf.err_msg = new string ("Illegal global_summary_dir"); else { pconf.global_summary_dir = strdup(temp.c_str()); pconf.global_sum_io.prefix = strdup(temp.c_str()); } } if(node["test_metalink"]) { if(!conv(node["test_metalink"],pconf.test_metalink)) pconf.err_msg = new string ("Illegal test_metalink"); } if(node["mlog_stderr"]) { bool temp; if(!conv(node["mlog_stderr"],temp)) pconf.err_msg = new string ("Illegal mlog_stderr"); else { if (temp) pconf.mlog_flags |= MLOG_STDERR; else pconf.mlog_flags &= ~MLOG_STDERR; } } if(node["mlog_ucon"]) { bool temp; if(!conv(node["mlog_ucon"],temp)) pconf.err_msg = new string ("Illegal mlog_ucon"); else { if (temp) pconf.mlog_flags |= (MLOG_UCON_ON|MLOG_UCON_ENV); else pconf.mlog_flags &= ~(MLOG_UCON_ON|MLOG_UCON_ENV); } } if(node["mlog_syslog"]) { bool temp; if(!conv(node["mlog_syslog"],temp)) pconf.err_msg = new string ("Illegal mlog_syslog"); else { if (temp) pconf.mlog_flags |= MLOG_SYSLOG; else pconf.mlog_flags &= ~MLOG_SYSLOG; } } if(node["mlog_defmask"]) { string temp; if(!conv(node["mlog_defmask"],temp)) pconf.err_msg = new string ("Illegal mlog_defmask"); else { pconf.mlog_defmask = mlog_str2pri(temp.c_str()); if(pconf.mlog_defmask < 0) pconf.err_msg = new string ("Bad mlog_defmask value"); } } if(node["mlog_stderrmask"]) { string temp; if(!conv(node["mlog_stderrmask"],temp)) pconf.err_msg = new string ("Illegal mlog_stderrmask"); else { pconf.mlog_stderrmask = mlog_str2pri(temp.c_str()); if(pconf.mlog_stderrmask < 0) pconf.err_msg = new string ("Bad mlog_stderrmask value"); } } if(node["mlog_file"]) { string temp; if(!conv(node["mlog_file"],temp)) pconf.err_msg = new string ("Illegal mlog_file"); else { if(!(strchr(temp.c_str(),'%') != NULL)) pconf.mlog_file = strdup(temp.c_str()); else { pconf.mlog_file_base = strdup(temp.c_str()); pconf.mlog_file = strdup(expand_macros(temp.c_str()).c_str()); } } } if(node["mlog_msgbuf_size"]) { if(!conv(node["mlog_msgbuf_size"],pconf.mlog_msgbuf_size) || pconf.mlog_msgbuf_size < 256) pconf.err_msg = new string ("Illegal mlog_msgbuf_size"); } if(node["mlog_syslogfac"]) { int temp = atoi(&node["mlog_syslogfac"].as<string>().c_str()[5]); switch (temp) { case 0: pconf.mlog_syslogfac = LOG_LOCAL0; break; case 1: pconf.mlog_syslogfac = LOG_LOCAL1; break; case 2: pconf.mlog_syslogfac = LOG_LOCAL2; break; case 3: pconf.mlog_syslogfac = LOG_LOCAL3; break; case 4: pconf.mlog_syslogfac = LOG_LOCAL4; break; case 5: pconf.mlog_syslogfac = LOG_LOCAL5; break; case 6: pconf.mlog_syslogfac = LOG_LOCAL6; break; case 7: pconf.mlog_syslogfac = LOG_LOCAL7; break; default: pconf.err_msg = new string("bad mlog_syslogfac value"); } } if(node["mlog_setmasks"]) { string temp; if(!conv(node["mlog_setmasks"],temp)) pconf.err_msg = new string ("Illegal mlog_setmasks"); else { find_replace(temp, " ", ","); pconf.mlog_setmasks = strdup(temp.c_str()); } } if(node["fuse_crash_log"]) { if(!conv(node["fuse_crash_log"],pconf.fuse_crash_log)) pconf.err_msg = new string ("Illegal fuse_crash_log"); } return true; } return false; }
void config_cb(const char *name, const char *value) { if (!strcmp(name, "section") || !strcmp(name, "repo.group")) ctx.cfg.section = xstrdup(value); else if (!strcmp(name, "repo.url")) ctx.repo = cgit_add_repo(value); else if (ctx.repo && !strcmp(name, "repo.path")) ctx.repo->path = trim_end(value, '/'); else if (ctx.repo && !prefixcmp(name, "repo.")) repo_config(ctx.repo, name + 5, value); else if (!strcmp(name, "readme")) ctx.cfg.readme = xstrdup(value); else if (!strcmp(name, "root-title")) ctx.cfg.root_title = xstrdup(value); else if (!strcmp(name, "root-desc")) ctx.cfg.root_desc = xstrdup(value); else if (!strcmp(name, "root-readme")) ctx.cfg.root_readme = xstrdup(value); else if (!strcmp(name, "css")) ctx.cfg.css = xstrdup(value); else if (!strcmp(name, "favicon")) ctx.cfg.favicon = xstrdup(value); else if (!strcmp(name, "footer")) ctx.cfg.footer = xstrdup(value); else if (!strcmp(name, "head-include")) ctx.cfg.head_include = xstrdup(value); else if (!strcmp(name, "header")) ctx.cfg.header = xstrdup(value); else if (!strcmp(name, "logo")) ctx.cfg.logo = xstrdup(value); else if (!strcmp(name, "index-header")) ctx.cfg.index_header = xstrdup(value); else if (!strcmp(name, "index-info")) ctx.cfg.index_info = xstrdup(value); else if (!strcmp(name, "logo-link")) ctx.cfg.logo_link = xstrdup(value); else if (!strcmp(name, "module-link")) ctx.cfg.module_link = xstrdup(value); else if (!strcmp(name, "strict-export")) ctx.cfg.strict_export = xstrdup(value); else if (!strcmp(name, "virtual-root")) { ctx.cfg.virtual_root = trim_end(value, '/'); if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) ctx.cfg.virtual_root = ""; } else if (!strcmp(name, "nocache")) ctx.cfg.nocache = atoi(value); else if (!strcmp(name, "noplainemail")) ctx.cfg.noplainemail = atoi(value); else if (!strcmp(name, "noheader")) ctx.cfg.noheader = atoi(value); else if (!strcmp(name, "snapshots")) ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); else if (!strcmp(name, "enable-filter-overrides")) ctx.cfg.enable_filter_overrides = atoi(value); else if (!strcmp(name, "enable-http-clone")) ctx.cfg.enable_http_clone = atoi(value); else if (!strcmp(name, "enable-index-links")) ctx.cfg.enable_index_links = atoi(value); else if (!strcmp(name, "enable-index-owner")) ctx.cfg.enable_index_owner = atoi(value); else if (!strcmp(name, "enable-commit-graph")) ctx.cfg.enable_commit_graph = atoi(value); else if (!strcmp(name, "enable-log-filecount")) ctx.cfg.enable_log_filecount = atoi(value); else if (!strcmp(name, "enable-log-linecount")) ctx.cfg.enable_log_linecount = atoi(value); else if (!strcmp(name, "enable-remote-branches")) ctx.cfg.enable_remote_branches = atoi(value); else if (!strcmp(name, "enable-subject-links")) ctx.cfg.enable_subject_links = atoi(value); else if (!strcmp(name, "enable-tree-linenumbers")) ctx.cfg.enable_tree_linenumbers = atoi(value); else if (!strcmp(name, "enable-git-config")) ctx.cfg.enable_git_config = atoi(value); else if (!strcmp(name, "max-stats")) ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); else if (!strcmp(name, "cache-size")) ctx.cfg.cache_size = atoi(value); else if (!strcmp(name, "cache-root")) ctx.cfg.cache_root = xstrdup(expand_macros(value)); else if (!strcmp(name, "cache-root-ttl")) ctx.cfg.cache_root_ttl = atoi(value); else if (!strcmp(name, "cache-repo-ttl")) ctx.cfg.cache_repo_ttl = atoi(value); else if (!strcmp(name, "cache-scanrc-ttl")) ctx.cfg.cache_scanrc_ttl = atoi(value); else if (!strcmp(name, "cache-static-ttl")) ctx.cfg.cache_static_ttl = atoi(value); else if (!strcmp(name, "cache-dynamic-ttl")) ctx.cfg.cache_dynamic_ttl = atoi(value); else if (!strcmp(name, "case-sensitive-sort")) ctx.cfg.case_sensitive_sort = atoi(value); else if (!strcmp(name, "about-filter")) ctx.cfg.about_filter = new_filter(value, ABOUT); else if (!strcmp(name, "commit-filter")) ctx.cfg.commit_filter = new_filter(value, COMMIT); else if (!strcmp(name, "embedded")) ctx.cfg.embedded = atoi(value); else if (!strcmp(name, "max-atom-items")) ctx.cfg.max_atom_items = atoi(value); else if (!strcmp(name, "max-message-length")) ctx.cfg.max_msg_len = atoi(value); else if (!strcmp(name, "max-repodesc-length")) ctx.cfg.max_repodesc_len = atoi(value); else if (!strcmp(name, "max-blob-size")) ctx.cfg.max_blob_size = atoi(value); else if (!strcmp(name, "max-repo-count")) ctx.cfg.max_repo_count = atoi(value); else if (!strcmp(name, "max-commit-count")) ctx.cfg.max_commit_count = atoi(value); else if (!strcmp(name, "project-list")) ctx.cfg.project_list = xstrdup(expand_macros(value)); else if (!strcmp(name, "scan-path")) if (!ctx.cfg.nocache && ctx.cfg.cache_size) process_cached_repolist(expand_macros(value)); else if (ctx.cfg.project_list) scan_projects(expand_macros(value), ctx.cfg.project_list, repo_config); else scan_tree(expand_macros(value), repo_config); else if (!strcmp(name, "scan-hidden-path")) ctx.cfg.scan_hidden_path = atoi(value); else if (!strcmp(name, "section-from-path")) ctx.cfg.section_from_path = atoi(value); else if (!strcmp(name, "repository-sort")) ctx.cfg.repository_sort = xstrdup(value); else if (!strcmp(name, "section-sort")) ctx.cfg.section_sort = atoi(value); else if (!strcmp(name, "source-filter")) ctx.cfg.source_filter = new_filter(value, SOURCE); else if (!strcmp(name, "summary-log")) ctx.cfg.summary_log = atoi(value); else if (!strcmp(name, "summary-branches")) ctx.cfg.summary_branches = atoi(value); else if (!strcmp(name, "summary-tags")) ctx.cfg.summary_tags = atoi(value); else if (!strcmp(name, "side-by-side-diffs")) ctx.cfg.ssdiff = atoi(value); else if (!strcmp(name, "agefile")) ctx.cfg.agefile = xstrdup(value); else if (!strcmp(name, "mimetype-file")) ctx.cfg.mimetype_file = xstrdup(value); else if (!strcmp(name, "renamelimit")) ctx.cfg.renamelimit = atoi(value); else if (!strcmp(name, "remove-suffix")) ctx.cfg.remove_suffix = atoi(value); else if (!strcmp(name, "robots")) ctx.cfg.robots = xstrdup(value); else if (!strcmp(name, "clone-prefix")) ctx.cfg.clone_prefix = xstrdup(value); else if (!strcmp(name, "clone-url")) ctx.cfg.clone_url = xstrdup(value); else if (!strcmp(name, "local-time")) ctx.cfg.local_time = atoi(value); else if (!strcmp(name, "commit-sort")) { if (!strcmp(value, "date")) ctx.cfg.commit_sort = 1; if (!strcmp(value, "topo")) ctx.cfg.commit_sort = 2; } else if (!prefixcmp(name, "mimetype.")) add_mimetype(name + 9, value); else if (!strcmp(name, "include")) parse_configfile(expand_macros(value), config_cb); }
char * get_cmd_target(void) { return (curr_view->selected_files > 0) ? expand_macros("%f", NULL, NULL, 1) : strdup("."); }