~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/csharp/csharpdoc.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "csharpdoc.h"
2
 
 
3
 
#include <stdio.h>
4
 
#include <stdlib.h>
5
 
#include <sys/stat.h>
6
 
#include <unistd.h>
7
 
 
8
 
#include <qtextstream.h>
9
 
#include <kdebug.h>
10
 
#include <klocale.h>
11
 
#include <kstandarddirs.h>
12
 
#include <kinstance.h>
13
 
#include <kprocess.h>
14
 
#include <kdeversion.h>
15
 
#include <kglobal.h>
16
 
 
17
 
using namespace KIO;
18
 
 
19
 
 
20
 
CSharpdocProtocol::CSharpdocProtocol(const QCString &pool, const QCString &app)
21
 
    : SlaveBase("csharpdoc", pool, app)
22
 
{}
23
 
 
24
 
 
25
 
CSharpdocProtocol::~CSharpdocProtocol()
26
 
{}
27
 
 
28
 
 
29
 
void CSharpdocProtocol::get(const KURL& url)
30
 
{
31
 
    QStringList l = QStringList::split('/', url.path());
32
 
 
33
 
    mimeType("text/html");
34
 
 
35
 
    bool plain = false;
36
 
    QString cmd = "csharpdoc ";
37
 
    if (l[0] == "functions") {
38
 
        plain = true;
39
 
        cmd += "-t -f ";
40
 
        cmd += KProcess::quote(l[1]);
41
 
    } else if (l[0] == "faq") {
42
 
        cmd += "-u -q ";
43
 
        cmd += KProcess::quote(l[1]);
44
 
        cmd += " | pod2html";
45
 
    } else {
46
 
        QCString errstr(i18n("The only existing directories are functions and faq.").local8Bit());
47
 
        data(errstr);
48
 
        finished();
49
 
        return;
50
 
    }
51
 
 
52
 
    kdDebug() << "Command: " << cmd << endl;
53
 
 
54
 
    if (plain)
55
 
        data(QCString("<blockquote>"));
56
 
 
57
 
    FILE *fd = popen(cmd.local8Bit().data(), "r");
58
 
    char buffer[4090];
59
 
    QByteArray array;
60
 
 
61
 
    while (!feof(fd)) {
62
 
        int n = fread(buffer, 1, 2048, fd);
63
 
        if (n == -1) {
64
 
            pclose(fd);
65
 
            return;
66
 
        }
67
 
        array.setRawData(buffer, n);
68
 
        data(array);
69
 
        array.resetRawData(buffer, n);
70
 
    }
71
 
 
72
 
    pclose(fd);
73
 
 
74
 
    if (plain)
75
 
        data(QCString("</blockquote>"));
76
 
 
77
 
    finished();
78
 
}
79
 
 
80
 
 
81
 
void CSharpdocProtocol::mimetype(const KURL &url)
82
 
{
83
 
    QStringList l = QStringList::split('/', url.path());
84
 
    mimeType((l[0] == "faq")? "text/html" : "text/plain");
85
 
    finished();
86
 
}
87
 
 
88
 
 
89
 
QCString CSharpdocProtocol::errorMessage()
90
 
{
91
 
    return QCString( "<html><body bgcolor=\"#FFFFFF\">" + i18n("Error in csharpdoc").local8Bit() + "</body></html>" );
92
 
}
93
 
 
94
 
 
95
 
void CSharpdocProtocol::stat(const KURL &/*url*/)
96
 
{
97
 
    UDSAtom uds_atom;
98
 
    uds_atom.m_uds = KIO::UDS_FILE_TYPE;
99
 
    uds_atom.m_long = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
100
 
 
101
 
    UDSEntry uds_entry;
102
 
    uds_entry.append(uds_atom);
103
 
 
104
 
    statEntry(uds_entry);
105
 
    finished();
106
 
}
107
 
 
108
 
 
109
 
void CSharpdocProtocol::listDir(const KURL &url)
110
 
{
111
 
    error( KIO::ERR_CANNOT_ENTER_DIRECTORY, url.path() );
112
 
}
113
 
 
114
 
 
115
 
extern "C" {
116
 
 
117
 
    int kdemain(int argc, char **argv)
118
 
    {
119
 
        KInstance instance( "kio_csharpdoc" );
120
 
        KGlobal::locale()->setMainCatalogue("kdevelop");
121
 
 
122
 
        if (argc != 4) {
123
 
            fprintf(stderr, "Usage: kio_csharpdoc protocol domain-socket1 domain-socket2\n");
124
 
            exit(-1);
125
 
        }
126
 
 
127
 
        CSharpdocProtocol slave(argv[2], argv[3]);
128
 
        slave.dispatchLoop();
129
 
 
130
 
        return 0;
131
 
    }
132
 
 
133
 
}