#include <cctype>
#include <utility>
-using std::make_pair;
-using std::pair;
+#include <fstream>
+
+#ifdef HAVE_SSTREAM
+#include <sstream>
+#else
+#include <strstream>
+#endif
#ifdef __GNUG__
#pragma implementation "filetools.h"
# endif
#endif
+using std::make_pair;
+using std::pair;
+using std::endl;
+using std::ifstream;
+
extern string system_lyxdir;
extern string build_lyxdir;
extern string user_lyxdir;
}
-bool IsSGMLFilename(string const & filename)
-{
- return contains(filename, ".sgml");
-}
-
-
// Substitutes spaces with underscores in filename (and path)
string MakeLatexName(string const & file)
{
// Substitutes spaces with underscores in filename (and path)
string QuoteName(string const & name)
{
-#ifdef WITH_WARNINGS
-#warning Add proper emx support here!
-#endif
+ // CHECK Add proper emx support here!
#ifndef __EMX__
return '\'' + name + '\'';
#else
bool PutEnv(string const & envstr)
{
-#ifdef WITH_WARNINGS
-#warning Look at and fix this.
-#endif
+ // CHECK Look at and fix this.
// f.ex. what about error checking?
+
#if HAVE_PUTENV
// this leaks, but what can we do about it?
// Is doing a getenv() and a free() of the older value
string varname;
string str = envstr.split(varname,'=');
int retval = setenv(varname.c_str(), str.c_str(), true);
+#else
+ // No environment setting function. Can this happen?
+ int retval = 1; //return an error condition.
#endif
#endif
return retval == 0;
#endif
}
+string GetFileContents(string const & fname) {
+ FileInfo finfo(fname);
+ if (finfo.exist()) {
+ ifstream ifs(fname.c_str());
+#ifdef HAVE_SSTREAM
+ std::ostringstream ofs;
+#else
+#warning The rumour goes that this might leak, but who really cares?
+ ostrstream ofs;
+#endif
+ if (ifs && ofs) {
+ ofs << ifs.rdbuf();
+ ifs.close();
+#ifdef HAVE_SSTREAM
+ return ofs.str().c_str();
+#else
+ ofs << '\0';
+ char const * tmp = ofs.str();
+ string ret(tmp);
+ delete[] tmp;
+ return ret;
+#endif
+ }
+ }
+ lyxerr << "LyX was not able to read file '" << fname << "'" << endl;
+ return string();
+}
+
//
// Search ${...} as Variable-Name inside the string and replace it with
if (!regexMatch(copy1, RegExp)) {
// No EndChar inside. So we are finished
result1 += CompareString + result0;
- result0.clear();
+ result0.erase();
continue;
}
Strips path off if no_path == true.
If no extension on oldname, just appends.
*/
-string ChangeExtension(string const & oldname, string const & extension,
- bool no_path)
+string ChangeExtension(string const & oldname, string const & extension)
{
string::size_type last_slash = oldname.rfind('/');
string::size_type last_dot = oldname.rfind('.');
ext= '.' + extension;
else
ext = extension;
- string ret_str;
- if (no_path && last_slash != string::npos) {
- ++last_slash; // step it
- ret_str = oldname.substr(last_slash,
- last_dot - last_slash) + ext;
- } else
- ret_str = oldname.substr(0, last_dot) + ext;
- return CleanupPath(ret_str);
+
+ return CleanupPath(oldname.substr(0, last_dot) + ext);
}
typedef pair<int, string> cmdret;
-static cmdret do_popen(string const & cmd)
+static
+cmdret do_popen(string const & cmd)
{
// One question is if we should use popen or
// create our own popen based on fork, exec, pipe