summaryrefslogtreecommitdiff
path: root/src/Main.cc
blob: e874fcf23a07d52a78a39fbbc973b243aa36bee6 (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
#include <unistd.h>
#include <list>
#include "Action.h"
#include "Handle.h"
#include "HttpServ.h"
#include "Socket.h"
#include "config.h"
#include "Message.h"
#include "Menu.h"
#include "Exceptions.h"
#include "Form.h"
#include "Confirm.h"
#include "Table.h"
#include "IRC.h"

class InPipe : public Handle {
  public:
      InPipe(int in, int out) : Handle(in), m_out(out) { };
      virtual ~InPipe() {}
    int GetOut(void) { return m_out; }
    virtual bool CanWrite(void) { return false; }
    virtual bool CanRead(void) { return true; }
    virtual String GetName(void) { return "Input pipe"; }
  private:
    int m_out;
} * in;

int main(int argc, char ** argv) {
    int p[2], c;
    list<String> testlist;
    IRC ircclient("botalacon");
    
    testlist.push_front("poide");
    
    if (pipe(p)) {
	cerr << "Error creating pipe.\n";
	exit(-1);
    }
    
    close(1);
    dup(p[1]);
    in = new InPipe(p[0], p[1]);
    
    String test = "poide\n", r;
    cout << test;
    cout.flush();
    (*in) >> r;
    if (r != "poide") {
	cerr << "The stdout redirect has failed.\n";
	exit(-1);
    }
    
    while ((c = getopt(argc, argv, "p:")) != EOF) {
	switch (c) {
	case 'p':
	    break;
	default:
	    cerr << "Usage: " << argv[0] << " [-p port]\n";
	    exit(-1);
	}
    }
    
    try {
	cerr << "Connecting..." << endl;
	if (ircclient.Connect()) {
	    cerr << "Doing main loop..." << endl;
	    ircclient.MainLoop();
	} else {
	    cerr << "Error connecting..." << endl;
	}
    }
    catch (GeneralException e) {
	cerr << e.GetMsg() << endl;
	delete in;
	exit(-1);
    }
    
    delete in;
    exit(0);
}