Exemplo n.º 1
0
static void mp_load_per_file_config(struct MPContext *mpctx)
{
    struct MPOpts *opts = mpctx->opts;
    char *confpath;
    char cfg[512];
    const char *file = mpctx->filename;

    if (snprintf(cfg, sizeof(cfg), "%s.conf", file) >= sizeof(cfg)) {
        MP_WARN(mpctx, "Filename is too long, "
                "can not load file or directory specific config files\n");
        return;
    }

    char *name = mp_basename(cfg);

    if (opts->use_filedir_conf) {
        bstr dir = mp_dirname(cfg);
        char *dircfg = mp_path_join(NULL, dir, bstr0("mpv.conf"));
        try_load_config(mpctx, dircfg, FILE_LOCAL_FLAGS);
        talloc_free(dircfg);

        if (try_load_config(mpctx, cfg, FILE_LOCAL_FLAGS))
            return;
    }

    if ((confpath = mp_find_user_config_file(NULL, mpctx->global, name))) {
        try_load_config(mpctx, confpath, FILE_LOCAL_FLAGS);

        talloc_free(confpath);
    }
}
Exemplo n.º 2
0
bool try_load_config_sub(string& conf_name, vector<string>& triedLocations) {
	StripDirSep(GLE_TOP_DIR);
	string conf_name2 = GLE_TOP_DIR + DIR_SEP + "glerc";
	triedLocations.push_back(conf_name2);
	bool has_config = try_load_config(conf_name2);
	if (has_config) {
		// only update name if configuration file found here
		conf_name = conf_name2;
	}
	return has_config;
}
Exemplo n.º 3
0
void mp_load_playback_resume(struct MPContext *mpctx, const char *file)
{
    char *fname = mp_get_playback_resume_config_filename(mpctx->global, file);
    if (fname && mp_path_exists(fname)) {
        // Never apply the saved start position to following files
        m_config_backup_opt(mpctx->mconfig, "start");
        MP_INFO(mpctx, "Resuming playback. This behavior can "
                "be disabled with --no-resume-playback.\n");
        try_load_config(mpctx, fname, M_SETOPT_PRESERVE_CMDLINE);
        unlink(fname);
    }
    talloc_free(fname);
}
Exemplo n.º 4
0
bool do_load_config(const char* appname, char **argv, CmdLineObj& cmdline, ConfigCollection& coll) {
	// Set GLE_TOP
	// -> prefer environment var GLE_TOP
	// -> otherwise, locate relative to executable location
	string conf_name;
	bool has_top = false;
	bool has_config = false;
	const char* top = getenv("GLE_TOP");
	vector<string> triedLocations;
	if (top == NULL || top[0] == 0) {
		string exe_name;
		bool has_exe_name = GetExeName(appname, argv, exe_name);
		if (has_exe_name) {
			GetDirName(exe_name, GLE_BIN_DIR);
			StripDirSep(GLE_BIN_DIR);
			#ifdef GLETOP_CD
				// Try relative path
				GLE_TOP_DIR = GLEAddRelPath(exe_name, GLETOP_CD+1, GLETOP_REL);
				has_config = try_load_config_sub(conf_name, triedLocations);
				// Try one level higher as executable
				if (!has_config) {
					GLE_TOP_DIR = GLEAddRelPath(exe_name, 2, NULL);
					has_config = try_load_config_sub(conf_name, triedLocations);
				}
				// Try with absolute path
				if (!has_config) {
					GLE_TOP_DIR = GLETOP_ABS;
					has_config = try_load_config_sub(conf_name, triedLocations);
				}
			#else
				GLE_TOP_DIR = exe_name;
				StripPathComponents(&GLE_TOP_DIR, 2);
			#endif
		} else {
			// The user will see as error messege: "$GLE_TOP/some_file" not found.
			GLE_TOP_DIR = "$GLE_TOP";
		}
	} else {
		has_top = true;
		GLE_TOP_DIR = top;
	}
	StripDirSep(GLE_TOP_DIR);
	if (!has_config) {
		// Try load config file
		// -> first $GLE_TOP/glerc
		if (conf_name == "") {
			// Only update conf_name if it was not yet set
			// To make error message if glerc not found more interpretable
			conf_name = GLE_TOP_DIR + DIR_SEP + "glerc";
			if (std::find(triedLocations.begin(), triedLocations.end(), conf_name) == triedLocations.end()) {
				triedLocations.push_back(conf_name);
				has_config = try_load_config(conf_name);
			}
		}
	}
	if (!check_correct_version(conf_name, has_top, has_config, triedLocations, coll)) {
		return false;
	}
	GLEInterface* iface = GLEGetInterfacePointer();
	string uconf = iface->getUserConfigLocation();
	if (uconf != "") {
		// -> on Unix also $HOME/.glerc
		try_load_config(uconf);
	}
	// Set values for -v option
	init_installed_versions(cmdline, &coll);
	return has_config;
}
Exemplo n.º 5
0
void find_deps(const string& loc, GLEInterface* iface) {
	vector<GLEFindEntry*> tofind;
	vector<string*> result;
	string gle_paths = ";";
	ConfigCollection* collection = iface->getConfig()->getRCFile();
#ifdef __WIN32__
	GLEFindEntry* findGLE = new GLEFindEntry(&gle_paths);
	findGLE->addToFind("gle.exe");
	findGLE->addToFind("gle_ps.exe");
	tofind.push_back(findGLE);
#endif
	// Create GLEFindEntry for each tool (ghostscript, pdflatex, ...)
	ConfigSection* tools = collection->getSection(GLE_CONFIG_TOOLS);
	for (int j = 0; j <= GLE_TOOL_GHOSTSCRIPT_LIB; j++) {
		CmdLineArgString* strarg = (CmdLineArgString*)tools->getOption(j)->getArg(0);
		GLEFindEntry* findTool = new GLEFindEntry(strarg->getValuePtr());
		char_separator separator(",", ";");
		tokenizer<char_separator> tokens(strarg->getDefault(), separator);
		while (tokens.has_more()) {
			const string& toolName = tokens.next_token();
			if (toolName == ";") {
				if (tokens.has_more() && strarg->isDefault()) {
					findTool->setNotFound(tokens.next_token());
				}
				break;
			} else {
				if (!IsAbsPath(toolName)) {
					findTool->addToFind(toolName);
				}
			}
		}
		if (findTool->getNbFind() != 0) tofind.push_back(findTool);
		else delete findTool;
	}
	// Initialize output and progress indicator
	GLEOutputStream* output = iface->getOutput();
	ostringstream out1;
	out1 << "Running GLE -finddeps \"";
	out1 << loc;
	out1 << ("\" to locate installed software (e.g., Ghostscript and LaTeX): ");
	output->println(out1.str().c_str());
	GLEProgressIndicatorInterface progress(iface);
	// Perform search at specified location
	if (loc != "") {
		if (IsDirectory(loc, true)) {
			GLEFindFiles(loc, tofind, &progress);
			for (unsigned int i = 0; i < tofind.size(); i++) {
				tofind[i]->updateResult(false);
			}
		} else {
			// Name of old GLERC file given
			if (try_load_config(loc)) {
				// Override old version number
				collection->setStringValue(GLE_CONFIG_GLE, GLE_CONFIG_GLE_VERSION, GLEVN);
			} else {
				ostringstream err;
				err << "Can't load configuration from '" << loc << "'" << endl;
				output->println(err.str().c_str());
			}
		}
	}
	#ifdef __UNIX__
		// Find programs in search path on Unix
		GLEFindPrograms(tofind, &progress);
	#endif
	#ifdef __MACOS__
		// Search for frameworks on Mac
		GLEFindFiles(string("/Library/Frameworks"), tofind, &progress);
		string home = GetHomeDir();
		if (home != "") {
			home += "Library/Frameworks";
			GLEFindFiles(home, tofind, &progress);
		}
	#endif
	for (unsigned int i = 0; i < tofind.size(); i++) {
		tofind[i]->updateResult(true);
	}
	#ifdef __UNIX__
		// Search for libraries in typical directories and in LD_LIBRARY_PATH
		string gslibloc = GLEFindLibrary("libgs", &progress);
		if (gslibloc != "") {
			CmdLineArgString* gslib_stra = (CmdLineArgString*)tools->getOption(GLE_TOOL_GHOSTSCRIPT_LIB)->getArg(0);
			gslib_stra->setValue(gslibloc.c_str());
		}
	#endif
	output->println();
	// Write installed GLE's to config section
	ConfigSection* gle = collection->getSection(GLE_CONFIG_GLE);
	CmdLineArgSPairList* installs = (CmdLineArgSPairList*)gle->getOption(GLE_CONFIG_GLE_INSTALL)->getArg(0);
	char_separator separator(";", "");
	tokenizer<char_separator> tokens(gle_paths, separator);
	while (tokens.has_more()) {
		string path = tokens.next_token();
		if (path.length() > 0 && !installs->hasValue2(path)) {
			installs->addPair("?", path);
		}
	}
	// Find versions of installed GLEs and set value of gleexe
	ostringstream out;
	string gle_version = GLEVN;
	if (installs->size() > 1) {
		// Only need to find out versions if more than one installed
		// otherwise assume it is "this" version
		for (int i = 0; i < installs->size(); i++) {
			const string& cr_gle = installs->getValue2(i);
			string& version = installs->getValue1(i);
			if (version == "?") {
				get_version_soft(cr_gle, version);
				if (version == "?") {
					// cout << "Use hard method for: " << cr_gle << endl;
					get_version_hard(cr_gle, version);
				}
			}
			if (str_i_equals(version, gle_version)) {
				out << "Found: GLE " << version << " in " << cr_gle << " (*)" << endl;
			} else {
				out << "Found: GLE " << version << " in " << cr_gle << endl;
			}
		}
	} else if (installs->size() == 1) {
		out << "Found: GLE in " << installs->getValue2(0) << endl;
		// Do not need to remember installed GLEs if there is only one
		// because then the "-v" option makes no sense
		installs->reset();
	}
	// Show locations of other tools
	for (int j = 0; j <= GLE_TOOL_GHOSTSCRIPT_LIB; j++) {
		CmdLineOption* opt = tools->getOption(j);
		CmdLineArgString* strarg = (CmdLineArgString*)opt->getArg(0);
		if (strarg->isDefault()) {
			out << "Found: " << opt->getName() << " in '?'" << endl;
		} else {
			out << "Found: " << opt->getName() << " in '" << strarg->getValue() << "'" << endl;
		}
	}
	output->println(out.str().c_str());
	for (unsigned int i = 0; i < tofind.size(); i++) {
		delete tofind[i];
	}
}