summaryrefslogtreecommitdiffstats
path: root/tdeioslave/man/tdeio_man.cpp
diff options
context:
space:
mode:
authorAlexander Golubev <fatzer2@gmail.com>2013-07-29 12:42:16 -0500
committerDarrell Anderson <humanreadable@yahoo.com>2013-07-29 12:42:16 -0500
commit14ffd77b37186e7defbc11730c35700fc21e9fbb (patch)
tree5a1c4c2c9439b419e71b5fbdfd436f3c466a7731 /tdeioslave/man/tdeio_man.cpp
parent5a7a258f87bde70c23367a95a3af747379623afd (diff)
downloadtdebase-14ffd77b37186e7defbc11730c35700fc21e9fbb.tar.gz
tdebase-14ffd77b37186e7defbc11730c35700fc21e9fbb.zip
Update method used to detect man page interface.
Diffstat (limited to 'tdeioslave/man/tdeio_man.cpp')
-rw-r--r--tdeioslave/man/tdeio_man.cpp75
1 files changed, 45 insertions, 30 deletions
diff --git a/tdeioslave/man/tdeio_man.cpp b/tdeioslave/man/tdeio_man.cpp
index d6574f064..92530facb 100644
--- a/tdeioslave/man/tdeio_man.cpp
+++ b/tdeioslave/man/tdeio_man.cpp
@@ -581,47 +581,62 @@ char *MANProtocol::readManPage(const char *_filename)
}
lastdir = filename.left(filename.findRev('/'));
-#ifdef WITH_MAKEWHATIS
- TQIODevice *fd= KFilterDev::deviceForFile(filename);
+ size_t len;
- if ( !fd || !fd->open(IO_ReadOnly))
- {
- delete fd;
- return 0;
- }
- TQByteArray array(fd->readAll());
- kdDebug(7107) << "read " << array.size() << endl;
- fd->close();
- delete fd;
+ if( hasManRecode() ) {
+ myStdStream = TQString::null;
+ TDEProcess proc;
- if (array.isEmpty())
- return 0;
+ proc << "man" << "--recode" << "UTF-8" << filename;
- const int len = array.size();
- buf = new char[len + 4];
- tqmemmove(buf + 1, array.data(), len);
-#else
- myStdStream = TQString::null;
- TDEProcess proc;
- /* TODO: detect availability of 'man --recode' so that this can go
- * upstream */
- proc << "man" << "--recode" << "UTF-8" << filename;
+ TQApplication::connect(&proc, TQT_SIGNAL(receivedStdout (TDEProcess *, char *, int)),
+ this, TQT_SLOT(slotGetStdOutputUtf8(TDEProcess *, char *, int)));
+ proc.start(TDEProcess::Block, TDEProcess::All);
- TQApplication::connect(&proc, TQT_SIGNAL(receivedStdout (TDEProcess *, char *, int)),
- this, TQT_SLOT(slotGetStdOutputUtf8(TDEProcess *, char *, int)));
- proc.start(TDEProcess::Block, TDEProcess::All);
+ const TQCString cstr=myStdStream.utf8();
+ len = cstr.size() != 0 ? cstr.size() - 1 : 0;
+ buf = new char[len + 4];
+ tqmemmove(buf + 1, cstr.data(), len);
+ } else {
+ TQIODevice *fd= KFilterDev::deviceForFile(filename);
- const TQCString cstr=myStdStream.utf8();
- const int len = cstr.size()-1;
- buf = new char[len + 4];
- tqmemmove(buf + 1, cstr.data(), len);
-#endif
+ if ( !fd || !fd->open(IO_ReadOnly))
+ {
+ delete fd;
+ return 0;
+ }
+ TQByteArray array(fd->readAll());
+ kdDebug(7107) << "read " << array.size() << endl;
+ fd->close();
+ delete fd;
+
+ if (array.isEmpty())
+ return 0;
+
+ len = array.size();
+ buf = new char[len + 4];
+ tqmemmove(buf + 1, array.data(), len);
+ }
buf[0]=buf[len]='\n'; // Start and end with a end of line
buf[len+1]=buf[len+2]='\0'; // Two NUL characters at end
}
return buf;
}
+bool MANProtocol::hasManRecode(bool force) {
+ static bool rv=0, wasChecked=0;
+ if ( !wasChecked || force ) {
+ TDEProcess proc;
+ // lets' try to recode the man page of man.
+ // that should be enough to be sure that man-db is installed.
+ proc << "man" << "--recode" << "UTF-8" << "man";
+
+ proc.start(TDEProcess::Block, TDEProcess::All);
+ rv = proc.exitStatus() == 0;
+ wasChecked = 1;
+ }
+ return rv;
+}
void MANProtocol::outputError(const TQString& errmsg)
{