core_plugin.cpp
1.62 KB
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
//*****************************************************************
/*
VLibras: Automatic contents translator from Portuguese to LIBRAS
Copyright (c) 2015 Gustavo Sobral, Erickson Silva, Leonardo Araújo
VLibras-Core group at LAViD, Federal University of Paraiba
*/
//*****************************************************************
/**
* \file corePlugin.cpp
* \author Leonardo Araújo
* \date Maio 2015
*/
#include "core_plugin.h"
int coreInitialize()
{
tradutor = new PyTradutor();
return 1;
}
const char* coreExecute()
{
return tradutor->convertStringToGlosa((const char*) get_text_selection());
}
int coreFinalize()
{
if (!tradutor)
return -1;
delete tradutor;
return 1;
}
char * get_text_selection()
{
FILE *comm_file_p = popen("xsel -o ", "r");
if (!comm_file_p)
{
return NULL;
}
char line_buff [MAX_BUFFER_SELECTION];
std::string line_str = "";
if (comm_file_p == NULL) perror ("Error opening file");
else
{
while ( ! feof (comm_file_p) )
{
if ( fgets (line_buff , (int) sizeof(line_buff) , comm_file_p) == NULL ) break;
line_str.append((std::string) line_buff);
}
fclose (comm_file_p);
}
remove_special_chars(&line_str, (std::string) REPLACE_CHARACTERS);
return (char*) line_str.c_str();
}
void remove_special_chars(std::string *_word, std::string _chars)
{
int index = -1;
for (int i = 0; i < _chars.size(); i++)
{
while ( (index = (int) _word->find(_chars[i])) != std::string::npos)
{
_word->replace(index, 1, " "); // remove chars replacing your position by " "
}
}
}