Joao Luis Meloni Assirati wrote:
> There is the problem of reading the prefs to know where are lyxpipes,
> though.
Well that's pretty simple. Why not the attached.
--
Angus
#include <iostream>
#include <fstream>
#include <string>
using std::getline;
using std::string;
using std::cerr;
using std::cout;
using std::endl;
using std::ifstream;
bool prefixIs(string const &, string const &);
string const trim(string const & a, char const * p = " ");
string const ltrim(string const & a, char const * p = " ");
string const split(string const & a, char delim);
int main (int argc, char * argv[]) {
if (argc != 2) {
cerr << "Expected a file name" << endl;
return 1;
}
ifstream ifs(argv[1]);
if (!ifs.good()) {
cerr << "Unable to open file '" << argv[1] << '\'' << endl;
return 1;
}
string pipe;
while (ifs.good()) {
string buffer;
getline(ifs, buffer);
trim(buffer, " ");
if (prefixIs(buffer, "\\serverpipe")) {
pipe = split(buffer, ' ');
pipe = ltrim(pipe, " ");
pipe = trim(pipe, "\"");
break;
}
}
if (pipe.empty()) {
cerr << "Unable to find the serverpipe" << endl;
return 1;
}
cout << "Pipe is '" << pipe <<'\'' << endl;
return 0;
}
bool prefixIs(string const & a, string const & pre)
{
string::size_type const prelen = pre.length();
string::size_type const alen = a.length();
if (prelen > alen || a.empty())
return false;
else {
return a.compare(0, prelen, pre) == 0;
}
}
string const trim(string const & a, char const * p)
{
if (a.empty() || !p || !*p)
return a;
string::size_type r = a.find_last_not_of(p);
string::size_type l = a.find_first_not_of(p);
// Is this the minimal test? (lgb)
if (r == string::npos && l == string::npos)
return string();
return a.substr(l, r - l + 1);
}
string const ltrim(string const & a, char const * p)
{
if (a.empty() || !p || !*p)
return a;
string::size_type l = a.find_first_not_of(p);
if (l == string::npos)
return string();
return a.substr(l, string::npos);
}
string const split(string const & a, char delim)
{
string tmp;
string::size_type i = a.find(delim);
if (i != string::npos) // found delim
tmp = a.substr(i + 1);
return tmp;
}