KDevelop API Documentation

languages/perl/perldoc.cpp

Go to the documentation of this file.
00001 #include "perldoc.h" 00002 00003 #include <stdio.h> 00004 #include <stdlib.h> 00005 #include <sys/stat.h> 00006 #include <unistd.h> 00007 00008 #include <qtextstream.h> 00009 #include <kdebug.h> 00010 #include <klocale.h> 00011 #include <kstandarddirs.h> 00012 #include <kinstance.h> 00013 #include <kprocess.h> 00014 #include <kdeversion.h> 00015 #include <kglobal.h> 00016 00017 using namespace KIO; 00018 00019 00020 PerldocProtocol::PerldocProtocol(const QCString &pool, const QCString &app) 00021 : SlaveBase("perldoc", pool, app) 00022 {} 00023 00024 00025 PerldocProtocol::~PerldocProtocol() 00026 {} 00027 00028 00029 void PerldocProtocol::get(const KURL& url) 00030 { 00031 QStringList l = QStringList::split('/', url.path()); 00032 00033 mimeType("text/html"); 00034 00035 bool plain = false; 00036 QString cmd = "perldoc "; 00037 if (l[0] == "functions") { 00038 plain = true; 00039 cmd += "-t -f "; 00040 #if (KDE_VERSION > 305) 00041 cmd += KProcess::quote(l[1]); 00042 #else 00043 cmd += KShellProcess::quote(l[1]); 00044 #endif 00045 } else if (l[0] == "faq") { 00046 cmd += "-u -q "; 00047 #if (KDE_VERSION > 305) 00048 cmd += KProcess::quote(l[1]); 00049 #else 00050 cmd += KShellProcess::quote(l[1]); 00051 #endif 00052 cmd += " | pod2html"; 00053 } else { 00054 QCString errstr(i18n("The only existing directories are functions and faq.").local8Bit()); 00055 data(errstr); 00056 finished(); 00057 return; 00058 } 00059 00060 kdDebug() << "Command: " << cmd << endl; 00061 00062 if (plain) 00063 data(QCString("<blockquote>")); 00064 00065 FILE *fd = popen(cmd.local8Bit().data(), "r"); 00066 char buffer[4090]; 00067 QByteArray array; 00068 00069 while (!feof(fd)) { 00070 int n = fread(buffer, 1, 2048, fd); 00071 if (n == -1) { 00072 pclose(fd); 00073 return; 00074 } 00075 array.setRawData(buffer, n); 00076 data(array); 00077 array.resetRawData(buffer, n); 00078 } 00079 00080 pclose(fd); 00081 00082 if (plain) 00083 data(QCString("</blockquote>")); 00084 00085 finished(); 00086 } 00087 00088 00089 void PerldocProtocol::mimetype(const KURL &url) 00090 { 00091 QStringList l = QStringList::split('/', url.path()); 00092 mimeType((l[0] == "faq")? "text/html" : "text/plain"); 00093 finished(); 00094 } 00095 00096 00097 QCString PerldocProtocol::errorMessage() 00098 { 00099 return QCString( "<html><body bgcolor=\"#FFFFFF\">" + i18n("Error in perldoc").local8Bit() + "</body></html>" ); 00100 } 00101 00102 00103 void PerldocProtocol::stat(const KURL &/*url*/) 00104 { 00105 UDSAtom uds_atom; 00106 uds_atom.m_uds = KIO::UDS_FILE_TYPE; 00107 uds_atom.m_long = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO; 00108 00109 UDSEntry uds_entry; 00110 uds_entry.append(uds_atom); 00111 00112 statEntry(uds_entry); 00113 finished(); 00114 } 00115 00116 00117 void PerldocProtocol::listDir(const KURL &url) 00118 { 00119 error( KIO::ERR_CANNOT_ENTER_DIRECTORY, url.path() ); 00120 } 00121 00122 00123 extern "C" { 00124 00125 int kdemain(int argc, char **argv) 00126 { 00127 KInstance instance( "kio_perldoc" ); 00128 KGlobal::locale()->setMainCatalogue("kdevelop"); 00129 00130 if (argc != 4) { 00131 fprintf(stderr, "Usage: kio_perldoc protocol domain-socket1 domain-socket2\n"); 00132 exit(-1); 00133 } 00134 00135 PerldocProtocol slave(argv[2], argv[3]); 00136 slave.dispatchLoop(); 00137 00138 return 0; 00139 } 00140 00141 }
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 6 17:39:05 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003