From 18016816fc286ffda94bffea3bf82162104fe514 Mon Sep 17 00:00:00 2001 From: Leonardo Domingues Date: Tue, 2 Jun 2015 16:56:02 -0300 Subject: [PATCH] release v1.0 --- Makefile | 7 ++++--- include/core_plugin.h | 5 +++-- plugin/libCorePlugin-0.2.so | Bin 0 -> 57381 bytes plugin/libCorePlugin.so | 1 + src/core_plugin.cpp | 39 ++++++++++++++++++++++++++++++++------- 5 files changed, 40 insertions(+), 12 deletions(-) create mode 100755 plugin/libCorePlugin-0.2.so create mode 120000 plugin/libCorePlugin.so diff --git a/Makefile b/Makefile index cdb30a0..868d8fb 100644 --- a/Makefile +++ b/Makefile @@ -22,14 +22,15 @@ VERSION = 0.2 CFLAGS =\ -I$(INCDIR)\ - `python-config --cflags`\ + `python-config --cflags` LDFLAGS =\ - `python-config --ldflags` + `python-config --ldflags`\ + -lX11 HEADERS = \ py_tradutor.h\ - core_plugin.h + core_plugin.h SOURCES = \ $(SRCDIR)/py_tradutor.cpp\ diff --git a/include/core_plugin.h b/include/core_plugin.h index 07fc468..7e31c15 100644 --- a/include/core_plugin.h +++ b/include/core_plugin.h @@ -21,10 +21,10 @@ #include "py_tradutor.h" #define MAX_BUFFER_SELECTION 1024 + #define REPLACE_CHARACTERS "\r\n" #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif PyTradutor *tradutor; @@ -54,6 +54,7 @@ extern "C" int coreFinalize(); char * get_text_selection(); + void remove_special_chars(std::string *_word, std::string _chars); #ifdef __cplusplus } diff --git a/plugin/libCorePlugin-0.2.so b/plugin/libCorePlugin-0.2.so new file mode 100755 index 0000000..f302865 Binary files /dev/null and b/plugin/libCorePlugin-0.2.so differ diff --git a/plugin/libCorePlugin.so b/plugin/libCorePlugin.so new file mode 120000 index 0000000..a37bec0 --- /dev/null +++ b/plugin/libCorePlugin.so @@ -0,0 +1 @@ +libCorePlugin-0.2.so \ No newline at end of file diff --git a/src/core_plugin.cpp b/src/core_plugin.cpp index 676f22d..9292a78 100644 --- a/src/core_plugin.cpp +++ b/src/core_plugin.cpp @@ -9,13 +9,15 @@ /** * \file corePlugin.cpp - * \author Gustavo Sobral, Leonardo Araújo - * \date Janeiro 2015 + * \author Leonardo Araújo + * \date Maio 2015 */ #include "core_plugin.h" + + int coreInitialize() { tradutor = new PyTradutor(); @@ -24,7 +26,6 @@ int coreInitialize() const char* coreExecute() { - return tradutor->convertStringToGlosa((const char*) get_text_selection()); } @@ -38,15 +39,39 @@ int coreFinalize() char * get_text_selection() { + FILE *comm_file_p = popen("xsel -o ", "r"); if (!comm_file_p) { - /* FIXME: add exception */ return NULL; } char line_buff [MAX_BUFFER_SELECTION]; - char *output_str_p = fgets(line_buff, sizeof(line_buff), comm_file_p); - pclose(comm_file_p); + std::string line_str = ""; - return output_str_p; + 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 " " + } + } } \ No newline at end of file -- libgit2 0.21.2