dicty: return reader feature

git-svn-id: svn://kolibrios.org@8923 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2021-06-22 12:28:03 +00:00
parent 1c7586b267
commit e7c761fb21
5 changed files with 95 additions and 66 deletions

View File

@ -0,0 +1,5 @@
@c-- /D=LANG_ENG dicty.c
@del dicty
@rename dicty.com dicty
@del warning.txt
@pause

View File

@ -0,0 +1,5 @@
@c-- /D=LANG_RUS dicty.c
@del dicty
@rename dicty.com dicty
@del warning.txt
@pause

View File

@ -1,9 +0,0 @@
@del lang.h--
@echo #define LANG_ENG 1 >lang.h--
C-- dicty.c
@del dicty
@rename dicty.com dicty
@del warning.txt
@del lang.h--
@pause

View File

@ -1,9 +0,0 @@
@del lang.h--
@echo #define LANG_RUS 1 >lang.h--
@C-- dicty.c
@del dicty
@rename dicty.com dicty
@del warning.txt
@del lang.h--
@pause

View File

@ -1,81 +1,98 @@
#ifndef AUTOBUILD
#include "lang.h--"
#endif
#define MEMSIZE 4096 * 1024 * 2 #define MEMSIZE 4096 * 1024 * 2
#define NO_DLL_INIT
#include "../lib/strings.h" #include "../lib/strings.h"
#include "../lib/gui.h" #include "../lib/gui.h"
#include "../lib/obj/box_lib.h" #include "../lib/obj/box_lib.h"
#ifdef LANG_RUS #ifdef LANG_RUS
#define WINDOW_TITLE "‘«®¢ à¨ª 2.3" #define WINDOW_TITLE "‘«®¢ à¨ª 2.4"
#define DICTIONARY_LOADED "‘«®¢ àì § £à㦥­" #define DICTIONARY_LOADED "‘«®¢ àì § £à㦥­"
#define WORD_NOT_FOUND "‘«®¢® ­¥ ­ ©¤¥­® ¢ á«®¢ à¥" #define WORD_NOT_FOUND "‘«®¢® ­¥ ­ ©¤¥­® ¢ á«®¢ à¥"
#define ERROR "Žè¨¡ª  #%d" #define ERROR "Žè¨¡ª  #%d"
#else #else
#define WINDOW_TITLE "Dictionary v2.3" #define WINDOW_TITLE "Dictionary v2.4"
#define DICTIONARY_LOADED "Dictionary loaded" #define DICTIONARY_LOADED "Dictionary loaded"
#define WORD_NOT_FOUND "Word isn't found in the dictionary" #define WORD_NOT_FOUND "Word isn't found in the dictionary"
#define ERROR "Error #%d" #define ERROR "Error #%d"
#endif #endif
#define TEXT_ENG_RUS "ENG\26RUS"
#define TEXT_RUS_ENG "RUS\26ENG"
#define TEXT_RU2EN "ENG RUS"
#define TEXT_EN2RU "RUS ENG"
unsigned char speaker[23*40*3]= FROM "speaker.raw";
proc_info Form; proc_info Form;
char edit_text[256], search_word[256], translate_result[4096]; char search_word[256], translate_result[4096];
#define TOPH 45 #define TOPH 45
#define PRONOUNCED_FILE "/tmp0/1/pronounced.txt"
#define SPEECH_PATH "/kolibrios/media/speech/speech"
dword speaker_id;
unsigned char eng_rus[] = FROM "eng_rus.dict""\0"; unsigned char eng_rus[] = FROM "eng_rus.dict""\0";
unsigned char rus_eng[] = FROM "rus_eng.dict""\0"; unsigned char rus_eng[] = FROM "rus_eng.dict""\0";
dword io_buffer_data; dword io_buffer_data;
#define TEXT_ENG_RUS "ENG\26RUS"
#define TEXT_RUS_ENG "RUS\26ENG"
#define TEXT_VOC_R_E "ENG RUS"
#define TEXT_VOC_E_R "RUS ENG"
#define ENG_RUS 0 #define ENG_RUS 0
#define RUS_ENG 1 #define RUS_ENG 1
#define BUTTON_CHANGE_LANGUAGE 10
int active_dict=2; int active_dict=2;
edit_box edit1= {200,13,13,0xffffff,0x94AECE,0xffffff,0x94AECE,0x10000000,248,#edit_text,0,100000000000010b}; #define BTN_CHANGE_LANGUAGE 10
#define BTN_SPEAKER 11
char edit_text[256];
edit_box edit1 = {0,13,13,0xffffff,0x94AECE,0xffffff,0xffffff,
0x10000000,248,#edit_text,0,ed_focus+ed_always_focus};
void main() void main()
{ {
int id; int btnid;
load_dll(boxlib, #box_lib_init,0); load_dll(boxlib, #box_lib_init,0);
OpenDictionary(ENG_RUS); OpenDictionary(ENG_RUS);
if (param) if (param) {
{
strcpy(#edit_text, #param); strcpy(#edit_text, #param);
edit1.size=edit1.pos=strlen(#edit_text); edit_box_set_text stdcall (#edit1, #param);
Translate(); Translate();
} }
SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); @SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
loop() loop() switch(@WaitEvent())
{ {
switch(WaitEvent())
{
case evMouse: case evMouse:
edit_box_mouse stdcall (#edit1); edit_box_mouse stdcall (#edit1);
break; break;
case evButton: case evButton:
id=GetButtonID(); btnid = @GetButtonID();
if (id==01) ExitProcess(); if (btnid==01) ExitProcess();
if (id==BUTTON_CHANGE_LANGUAGE) { if (btnid==BTN_CHANGE_LANGUAGE) {
if (active_dict == ENG_RUS) OpenDictionary(RUS_ENG); else OpenDictionary(ENG_RUS); if (active_dict == ENG_RUS) {
OpenDictionary(RUS_ENG);
} else {
OpenDictionary(ENG_RUS);
}
DrawLangButtons(); DrawLangButtons();
} }
if (btnid==BTN_SPEAKER) {
if (GetProcessSlot(speaker_id)!=0) {
KillProcess(speaker_id);
pause(50);
} else {
if (CreateFile(strlen(#translate_result)+1, #translate_result, PRONOUNCED_FILE)!=0) break;
pause(50);
speaker_id = RunProgram(SPEECH_PATH, PRONOUNCED_FILE);
}
SpeakerDraw();
}
break; break;
case evKey: case evKey:
GetKeys(); @GetKey();
edit_box_key stdcall(#edit1); edit_box_key stdcall(#edit1);
Translate(); Translate();
break; break;
case evReDraw: case evReDraw:
sc.get(); sc.get();
DefineAndDrawWindow(215,120,500,350,0x73,sc.work,WINDOW_TITLE,0); DefineAndDrawWindow(215,120,500,350,0x73,sc.work,WINDOW_TITLE,0);
GetProcessInfo(#Form, SelfInfo); GetProcessInfo(#Form, SelfInfo);
@ -84,46 +101,47 @@ void main()
if (Form.width<400) { MoveSize(OLD,OLD,400,OLD); break; } if (Form.width<400) { MoveSize(OLD,OLD,400,OLD); break; }
DrawBar(0, 0, Form.cwidth, TOPH, sc.work); //top bg DrawBar(0, 0, Form.cwidth, TOPH, sc.work); //top bg
DrawBar(0, TOPH, Form.cwidth, 1, sc.work_graph); DrawBar(0, TOPH, Form.cwidth, 1, sc.work_graph);
edit1.width=Form.cwidth-edit1.left-edit1.left - 116; edit1.width = Form.cwidth-edit1.left-edit1.left - 116;
edit_box_draw stdcall(#edit1); edit_box_draw stdcall(#edit1);
DrawWideRectangle(edit1.left-2, edit1.top-2, edit1.width+3, 25, 2, 0xffffff); DrawWideRectangle(edit1.left-2, edit1.top-2, edit1.width+3, 25, 2, 0xffffff);
DrawRectangle(edit1.left-3, edit1.top-3, edit1.width+4, 26, sc.work_graph); DrawRectangle(edit1.left-3, edit1.top-3, edit1.width+4, 26, sc.work_graph);
DrawTranslation(); DrawTranslation();
DrawLangButtons(); DrawLangButtons();
} }
}
} }
void DrawLangButtons() void DrawLangButtons()
{ {
dword direction; dword direction;
DrawBar(Form.cwidth-111, edit1.top+3, 100, 25, sc.work); int y = edit1.top+3;
DefineButton(Form.cwidth-79, edit1.top-4+3, 20, 20, BUTTON_CHANGE_LANGUAGE, sc.button); DrawBar(Form.cwidth-111, y, 100, 25, sc.work);
WriteText(Form.cwidth-73, edit1.top-1+3, 10000001b, sc.button_text, "\26"); DefineButton(Form.cwidth-79, y-4, 20, 20, BTN_CHANGE_LANGUAGE, sc.button);
if (active_dict == ENG_RUS) direction = TEXT_VOC_R_E; else direction = TEXT_VOC_E_R; WriteText(Form.cwidth-73, y-1, 10000001b, sc.work_text, "\26");
WriteText(Form.cwidth-111, edit1.top+3, 0x90, sc.work_text, direction); if (active_dict == ENG_RUS) {
direction = TEXT_RU2EN;
} else {
direction = TEXT_EN2RU;
}
WriteText(Form.cwidth-111, y, 0x90, sc.work_text, direction);
} }
void Translate() void Translate()
{ {
dword translation_start, translation_end; dword tr_start, tr_end;
sprintf(#search_word, "\10%s\13", #edit_text); sprintf(#search_word, "\10%s\13", #edit_text);
strupr(#search_word); strupr(#search_word);
if (!edit_text) goto _TR_END; if (!edit_text) goto _TR_END;
translation_start = strstr(io_buffer_data, #search_word); tr_start = strstr(io_buffer_data, #search_word);
if (!translation_start) if (!tr_start) {
{
strcpy(#translate_result, WORD_NOT_FOUND); strcpy(#translate_result, WORD_NOT_FOUND);
} } else {
else tr_start = strchr(tr_start, '"') + 1;
{ tr_end = strchr(tr_start, '"');
translation_start = strchr(translation_start, '"') + 1; strlcpy(#translate_result, tr_start, tr_end - tr_start);
translation_end = strchr(translation_start, '"');
strlcpy(#translate_result, translation_start, translation_end - translation_start);
} }
_TR_END: _TR_END:
strcpy(#search_word, #search_word+1); strcpy(#search_word, #search_word+1);
@ -162,7 +180,26 @@ void DrawTranslation()
DrawTextViewArea(10, y_pos+31, Form.cwidth-20, Form.cheight-30, DrawTextViewArea(10, y_pos+31, Form.cwidth-20, Form.cheight-30,
#draw_buf, -1, 0x000000); #draw_buf, -1, 0x000000);
SpeakerDraw();
} }
void SpeakerDraw()
{
dword x = Form.cwidth-38;
dword y = Form.cheight-32;
if (active_dict == RUS_ENG)
{
DeleteButton(15);
DrawBar(x,y,23,20,0xFFFFFF);
} else {
DefineHiddenButton(x-5, y-5, 23+10, 20+9, BTN_SPEAKER);
if (!GetProcessSlot(speaker_id)) {
_PutImage(x, y, 23,20, #speaker);
} else {
_PutImage(x, y, 23,20, 23*20*3+#speaker);
}
}
}
stop: stop: