Commit 18016816fc286ffda94bffea3bf82162104fe514

Authored by Leonardo Domingues
1 parent 57df7a78
Exists in master

release v1.0

@@ -22,14 +22,15 @@ VERSION = 0.2 @@ -22,14 +22,15 @@ VERSION = 0.2
22 22
23 CFLAGS =\ 23 CFLAGS =\
24 -I$(INCDIR)\ 24 -I$(INCDIR)\
25 - `python-config --cflags`\ 25 + `python-config --cflags`
26 26
27 LDFLAGS =\ 27 LDFLAGS =\
28 - `python-config --ldflags` 28 + `python-config --ldflags`\
  29 + -lX11
29 30
30 HEADERS = \ 31 HEADERS = \
31 py_tradutor.h\ 32 py_tradutor.h\
32 - core_plugin.h 33 + core_plugin.h
33 34
34 SOURCES = \ 35 SOURCES = \
35 $(SRCDIR)/py_tradutor.cpp\ 36 $(SRCDIR)/py_tradutor.cpp\
include/core_plugin.h
@@ -21,10 +21,10 @@ @@ -21,10 +21,10 @@
21 #include "py_tradutor.h" 21 #include "py_tradutor.h"
22 22
23 #define MAX_BUFFER_SELECTION 1024 23 #define MAX_BUFFER_SELECTION 1024
  24 + #define REPLACE_CHARACTERS "\r\n"
24 25
25 #ifdef __cplusplus 26 #ifdef __cplusplus
26 -extern "C"  
27 -{ 27 +extern "C" {
28 #endif 28 #endif
29 29
30 PyTradutor *tradutor; 30 PyTradutor *tradutor;
@@ -54,6 +54,7 @@ extern "C" @@ -54,6 +54,7 @@ extern "C"
54 int coreFinalize(); 54 int coreFinalize();
55 55
56 char * get_text_selection(); 56 char * get_text_selection();
  57 + void remove_special_chars(std::string *_word, std::string _chars);
57 58
58 #ifdef __cplusplus 59 #ifdef __cplusplus
59 } 60 }
plugin/libCorePlugin-0.2.so 0 → 100755
No preview for this file type
plugin/libCorePlugin.so 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +libCorePlugin-0.2.so
0 \ No newline at end of file 2 \ No newline at end of file
src/core_plugin.cpp
@@ -9,13 +9,15 @@ @@ -9,13 +9,15 @@
9 9
10 /** 10 /**
11 * \file corePlugin.cpp 11 * \file corePlugin.cpp
12 - * \author Gustavo Sobral, Leonardo Araújo  
13 - * \date Janeiro 2015 12 + * \author Leonardo Araújo
  13 + * \date Maio 2015
14 */ 14 */
15 15
16 #include "core_plugin.h" 16 #include "core_plugin.h"
17 17
18 18
  19 +
  20 +
19 int coreInitialize() 21 int coreInitialize()
20 { 22 {
21 tradutor = new PyTradutor(); 23 tradutor = new PyTradutor();
@@ -24,7 +26,6 @@ int coreInitialize() @@ -24,7 +26,6 @@ int coreInitialize()
24 26
25 const char* coreExecute() 27 const char* coreExecute()
26 { 28 {
27 -  
28 return tradutor->convertStringToGlosa((const char*) get_text_selection()); 29 return tradutor->convertStringToGlosa((const char*) get_text_selection());
29 } 30 }
30 31
@@ -38,15 +39,39 @@ int coreFinalize() @@ -38,15 +39,39 @@ int coreFinalize()
38 39
39 char * get_text_selection() 40 char * get_text_selection()
40 { 41 {
  42 +
41 FILE *comm_file_p = popen("xsel -o ", "r"); 43 FILE *comm_file_p = popen("xsel -o ", "r");
42 if (!comm_file_p) 44 if (!comm_file_p)
43 { 45 {
44 - /* FIXME: add exception */  
45 return NULL; 46 return NULL;
46 } 47 }
47 char line_buff [MAX_BUFFER_SELECTION]; 48 char line_buff [MAX_BUFFER_SELECTION];
48 - char *output_str_p = fgets(line_buff, sizeof(line_buff), comm_file_p);  
49 - pclose(comm_file_p); 49 + std::string line_str = "";
50 50
51 - return output_str_p; 51 + if (comm_file_p == NULL) perror ("Error opening file");
  52 + else
  53 + {
  54 + while ( ! feof (comm_file_p) )
  55 + {
  56 + if ( fgets (line_buff , (int) sizeof(line_buff) , comm_file_p) == NULL ) break;
  57 + line_str.append((std::string) line_buff);
  58 + }
  59 + fclose (comm_file_p);
  60 + }
  61 + remove_special_chars(&line_str, (std::string) REPLACE_CHARACTERS);
  62 +
  63 + return (char*) line_str.c_str();
  64 +
  65 +}
  66 +
  67 +void remove_special_chars(std::string *_word, std::string _chars)
  68 +{
  69 + int index = -1;
  70 + for (int i = 0; i < _chars.size(); i++)
  71 + {
  72 + while ( (index = (int) _word->find(_chars[i])) != std::string::npos)
  73 + {
  74 + _word->replace(index, 1, " "); // remove chars replacing your position by " "
  75 + }
  76 + }
52 } 77 }
53 \ No newline at end of file 78 \ No newline at end of file