-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
142 lines (115 loc) · 3.42 KB
/
main.cc
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
134
135
136
137
138
139
/**
* Main Entry -
* Copyright (C) 2010 Sian Cao <sycao@redflag-linux.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "qview.h"
#include "util.h"
#include "xview.h"
#include <unistd.h>
#include <getopt.h>
#include <iostream>
#include <libgen.h>
#include <dlfcn.h>
static char *progname = NULL;
void usage()
{
std::cerr << "USAGE: " << progname << " [options]" << std::endl
<< "OPTIONS: " << std::endl
<< " -qview, -Q \t use qt based views\n"
<< " -xview, -X \t use raw x based views\n"
<< " -im \t\t specify im to use\n";
exit(1);
}
bool loadMode()
{
dlerror();
void *hnd = dlopen( "./libccmode.so", RTLD_NOW | RTLD_GLOBAL );
if ( !hnd ) {
se_debug( "load mode failed" );
return false;
}
se_forward_char_command = (CMD_TYPE)dlsym( hnd, "se_forward_char_hook_command" );
char* err_msg = dlerror();
if ( err_msg ) {
se_debug( err_msg );
dlclose( hnd );
return false;
}
//dlclose( hnd );
return true;
}
int parse_args(int argc, char *argv[])
{
progname = strdup( basename(argv[0]) );
struct option long_opts[] = {
{"qview", no_argument, 0, 0 },
{"xview", no_argument, 0, 0 },
{"im", required_argument, 0, 0},
{"help", no_argument, 0, 'h'},
};
int long_idx = 0;
gboolean flag_qview = FALSE;
char *im = NULL;
while ( 1 ) {
int c = getopt_long( argc, argv, "QXh", long_opts, &long_idx );
if ( c == -1 )
break;
switch( c ) {
case 0:
se_debug( "long option: %s with arg: %s", long_opts[long_idx].name, optarg );
switch ( long_idx ) {
case 0: flag_qview = TRUE; break;
case 1: flag_qview = FALSE; break;
case 2:
if ( !optarg )
usage();
im = strdup( optarg ); break;
default: usage(); break;
}
break;
case 'Q':
se_debug( "QView" );
flag_qview = TRUE;
break;
case 'X':
se_debug( "XView" );
break;
case 'h':
usage();
break;
default:
break;
}
}
if ( optind < argc ) {
}
loadMode();
if ( flag_qview ) {
QApplication app(argc, argv);
app.setQuitOnLastWindowClosed( true );
SEView view;
view.setFocus();
view.show();
return app.exec();
} else
return main_loop( argc, argv );
return TRUE;
}
int main(int argc, char *argv[])
{
return parse_args( argc, argv );
}