static enum status_code load_option_file(const char *path) { struct config_state config = { path, 0, FALSE }; struct io io; char buf[SIZEOF_STR]; /* Do not read configuration from stdin if set to "" */ if (!path || !strlen(path)) return SUCCESS; if (!prefixcmp(path, "~/")) { const char *home = getenv("HOME"); if (!home || !string_format(buf, "%s/%s", home, path + 2)) return ERROR_HOME_UNRESOLVABLE; path = buf; } /* It's OK that the file doesn't exist. */ if (!io_open(&io, "%s", path)) return ERROR_FILE_DOES_NOT_EXIST; if (io_load(&io, " \t", read_option, &config) == ERR || config.errors == TRUE) warn("Errors while loading %s.", path); return SUCCESS; }
static enum status_code load_option_file(const char *path) { struct config_state config = { path, 0, FALSE }; struct io io; char buf[SIZEOF_STR]; /* Do not read configuration from stdin if set to "" */ if (!path || !strlen(path)) return SUCCESS; if (!prefixcmp(path, "~/")) { const char *home = getenv("HOME"); if (!home || !string_format(buf, "%s/%s", home, path + 2)) return error("Failed to expand ~ to user home directory"); path = buf; } /* It's OK that the file doesn't exist. */ if (!io_open(&io, "%s", path)) { /* XXX: Must return ERROR_FILE_DOES_NOT_EXIST so missing * system tigrc is detected properly. */ if (io_error(&io) == ENOENT) return ERROR_FILE_DOES_NOT_EXIST; return error("Error loading file %s: %s", path, strerror(io_error(&io))); } if (io_load(&io, " \t", read_option, &config) == ERR || config.errors == TRUE) warn("Errors while loading %s.", path); return SUCCESS; }
/* * NAME: cmdbuf->read() * DESCRIPTION: insert a file in the current edit buffer */ int cb_read(cmdbuf *cb) { char buffer[STRINGSZ]; io iob; not_in_global(cb); if (!getfname(cb, buffer)) { if (cb->fname[0] == '\0') { error("No current filename"); } /* read current file, by default. I don't know why, but ex has it that way. */ strcpy(buffer, cb->fname); } cb_do(cb, cb->first); output("\"%s\" ", buffer); if (!io_load(cb->edbuf, buffer, cb->first, &iob)) { error("is unreadable"); } io_show(&iob); cb->edit++; cb->cthis = cb->first + iob.lines; return 0; }
int io_run_load(const char **argv, const char *separators, io_read_fn read_property, void *data) { struct io io; if (!io_run(&io, IO_RD, NULL, NULL, argv)) return ERR; return io_load(&io, separators, read_property, data); }
int load_options(void) { const char *tigrc_user = getenv("TIGRC_USER"); const char *tigrc_system = getenv("TIGRC_SYSTEM"); const char *tig_diff_opts = getenv("TIG_DIFF_OPTS"); const bool diff_opts_from_args = !!opt_diff_options; bool custom_tigrc_system = !!tigrc_system; opt_file_filter = TRUE; if (!custom_tigrc_system) tigrc_system = SYSCONFDIR "/tigrc"; if (load_option_file(tigrc_system) == ERROR_FILE_DOES_NOT_EXIST && !custom_tigrc_system) { struct config_state config = { "<built-in>", 0, FALSE }; struct io io; if (!io_from_string(&io, builtin_config) || !io_load(&io, " \t", read_option, &config) == ERR || config.errors == TRUE) die("Error in built-in config"); } if (!tigrc_user) tigrc_user = "******"; load_option_file(tigrc_user); if (!diff_opts_from_args && tig_diff_opts && *tig_diff_opts) { static const char *diff_opts[SIZEOF_ARG] = { NULL }; char buf[SIZEOF_STR]; int argc = 0; if (!string_format(buf, "%s", tig_diff_opts) || !argv_from_string(diff_opts, &argc, buf)) die("TIG_DIFF_OPTS contains too many arguments"); else if (!argv_copy(&opt_diff_options, diff_opts)) die("Failed to format TIG_DIFF_OPTS arguments"); } return OK; }
/* * NAME: cmdbuf->edit() * DESCRIPTION: edit a new file */ int cb_edit(cmdbuf *cb) { io iob; not_in_global(cb); if (cb->edit > 0 && !(cb->flags & CB_EXCL)) { error("No write since last change (edit! overrides)"); } getfname(cb, cb->fname); if (cb->fname[0] == '\0') { error("No current filename"); } Alloc::staticMode(); eb_clear(cb->edbuf); Alloc::dynamicMode(); cb->flags &= ~CB_NOIMAGE; cb->edit = 0; cb->first = cb->cthis = 0; memset(cb->mark, '\0', sizeof(cb->mark)); cb->buf = 0; memset(cb->zbuf, '\0', sizeof(cb->zbuf)); cb->undo = (block) -1; /* not 0! */ output("\"%s\" ", cb->fname); if (!io_load(cb->edbuf, cb->fname, cb->first, &iob)) { error("is unreadable"); } io_show(&iob); if (iob.zero > 0 || iob.split > 0 || iob.ill) { /* the editbuffer in memory is not a perfect image of the file read */ cb->flags |= CB_NOIMAGE; } cb->cthis = iob.lines; return 0; }