summaryrefslogtreecommitdiffstats
path: root/languages/csharp/csharpdoc.cpp
blob: 3b1c9450e5281605dd33b6e865e2c37fd1d060cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "csharpdoc.h"

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>

#include <tqtextstream.h>
#include <kdebug.h>
#include <tdelocale.h>
#include <kstandarddirs.h>
#include <kinstance.h>
#include <kprocess.h>
#include <tdeversion.h>
#include <tdeglobal.h>

using namespace TDEIO;


CSharpdocProtocol::CSharpdocProtocol(const TQCString &pool, const TQCString &app)
    : SlaveBase("csharpdoc", pool, app)
{}


CSharpdocProtocol::~CSharpdocProtocol()
{}


void CSharpdocProtocol::get(const KURL& url)
{
    TQStringList l = TQStringList::split('/', url.path());

    mimeType("text/html");

    bool plain = false;
    TQString cmd = "csharpdoc ";
    if (l[0] == "functions") {
        plain = true;
        cmd += "-t -f ";
        cmd += TDEProcess::quote(l[1]);
    } else if (l[0] == "faq") {
        cmd += "-u -q ";
        cmd += TDEProcess::quote(l[1]);
        cmd += " | pod2html";
    } else {
        TQCString errstr(i18n("The only existing directories are functions and faq.").local8Bit());
        data(errstr);
        finished();
        return;
    }

    kdDebug() << "Command: " << cmd << endl;

    if (plain)
        data(TQCString("<blockquote>"));

    FILE *fd = popen(cmd.local8Bit().data(), "r");
    char buffer[4090];
    TQByteArray array;

    while (!feof(fd)) {
        int n = fread(buffer, 1, 2048, fd);
        if (n == -1) {
            pclose(fd);
            return;
        }
        array.setRawData(buffer, n);
        data(array);
        array.resetRawData(buffer, n);
    }

    pclose(fd);

    if (plain)
        data(TQCString("</blockquote>"));

    finished();
}


void CSharpdocProtocol::mimetype(const KURL &url)
{
    TQStringList l = TQStringList::split('/', url.path());
    mimeType((l[0] == "faq")? "text/html" : "text/plain");
    finished();
}


TQCString CSharpdocProtocol::errorMessage()
{
    return TQCString( "<html><body bgcolor=\"#FFFFFF\">" + i18n("Error in csharpdoc").local8Bit() + "</body></html>" );
}


void CSharpdocProtocol::stat(const KURL &/*url*/)
{
    UDSAtom uds_atom;
    uds_atom.m_uds = TDEIO::UDS_FILE_TYPE;
    uds_atom.m_long = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;

    UDSEntry uds_entry;
    uds_entry.append(uds_atom);

    statEntry(uds_entry);
    finished();
}


void CSharpdocProtocol::listDir(const KURL &url)
{
    error( TDEIO::ERR_CANNOT_ENTER_DIRECTORY, url.path() );
}


extern "C" {

    int kdemain(int argc, char **argv)
    {
        TDEInstance instance( "tdeio_csharpdoc" );
        TDEGlobal::locale()->setMainCatalogue("tdevelop");

        if (argc != 4) {
            fprintf(stderr, "Usage: tdeio_csharpdoc protocol domain-socket1 domain-socket2\n");
            exit(-1);
        }

        CSharpdocProtocol slave(argv[2], argv[3]);
        slave.dispatchLoop();

        return 0;
    }

}