Commit 18016816fc286ffda94bffea3bf82162104fe514
1 parent
57df7a78
Exists in
master
release v1.0
Showing
5 changed files
with
40 additions
and
12 deletions
Show diff stats
Makefile
| ... | ... | @@ -22,14 +22,15 @@ VERSION = 0.2 |
| 22 | 22 | |
| 23 | 23 | CFLAGS =\ |
| 24 | 24 | -I$(INCDIR)\ |
| 25 | - `python-config --cflags`\ | |
| 25 | + `python-config --cflags` | |
| 26 | 26 | |
| 27 | 27 | LDFLAGS =\ |
| 28 | - `python-config --ldflags` | |
| 28 | + `python-config --ldflags`\ | |
| 29 | + -lX11 | |
| 29 | 30 | |
| 30 | 31 | HEADERS = \ |
| 31 | 32 | py_tradutor.h\ |
| 32 | - core_plugin.h | |
| 33 | + core_plugin.h | |
| 33 | 34 | |
| 34 | 35 | SOURCES = \ |
| 35 | 36 | $(SRCDIR)/py_tradutor.cpp\ | ... | ... |
include/core_plugin.h
| ... | ... | @@ -21,10 +21,10 @@ |
| 21 | 21 | #include "py_tradutor.h" |
| 22 | 22 | |
| 23 | 23 | #define MAX_BUFFER_SELECTION 1024 |
| 24 | + #define REPLACE_CHARACTERS "\r\n" | |
| 24 | 25 | |
| 25 | 26 | #ifdef __cplusplus |
| 26 | -extern "C" | |
| 27 | -{ | |
| 27 | +extern "C" { | |
| 28 | 28 | #endif |
| 29 | 29 | |
| 30 | 30 | PyTradutor *tradutor; |
| ... | ... | @@ -54,6 +54,7 @@ extern "C" |
| 54 | 54 | int coreFinalize(); |
| 55 | 55 | |
| 56 | 56 | char * get_text_selection(); |
| 57 | + void remove_special_chars(std::string *_word, std::string _chars); | |
| 57 | 58 | |
| 58 | 59 | #ifdef __cplusplus |
| 59 | 60 | } | ... | ... |
No preview for this file type
src/core_plugin.cpp
| ... | ... | @@ -9,13 +9,15 @@ |
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 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 | 16 | #include "core_plugin.h" |
| 17 | 17 | |
| 18 | 18 | |
| 19 | + | |
| 20 | + | |
| 19 | 21 | int coreInitialize() |
| 20 | 22 | { |
| 21 | 23 | tradutor = new PyTradutor(); |
| ... | ... | @@ -24,7 +26,6 @@ int coreInitialize() |
| 24 | 26 | |
| 25 | 27 | const char* coreExecute() |
| 26 | 28 | { |
| 27 | - | |
| 28 | 29 | return tradutor->convertStringToGlosa((const char*) get_text_selection()); |
| 29 | 30 | } |
| 30 | 31 | |
| ... | ... | @@ -38,15 +39,39 @@ int coreFinalize() |
| 38 | 39 | |
| 39 | 40 | char * get_text_selection() |
| 40 | 41 | { |
| 42 | + | |
| 41 | 43 | FILE *comm_file_p = popen("xsel -o ", "r"); |
| 42 | 44 | if (!comm_file_p) |
| 43 | 45 | { |
| 44 | - /* FIXME: add exception */ | |
| 45 | 46 | return NULL; |
| 46 | 47 | } |
| 47 | 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 | 78 | \ No newline at end of file | ... | ... |