diff options
author | Eduardo Chappa <chappa@washington.edu> | 2015-11-15 17:56:28 -0700 |
---|---|---|
committer | Eduardo Chappa <chappa@washington.edu> | 2015-11-15 17:56:28 -0700 |
commit | b3ad27e8991fdbd64fd4db58c0c89538b5f02959 (patch) | |
tree | db96448acc54c9893d17970c4dfffbcc95279eec /pico | |
parent | abf5b4cfbff3150ad3340679b80dc1ff5adf6298 (diff) | |
download | alpine-b3ad27e8991fdbd64fd4db58c0c89538b5f02959.tar.xz |
* PC-Alpine: New configuration option "Aspell Dictionaries" allows a
user to choose the dictionary used to spell, in case the user
communicates in more than one language. Examples of values for the
variable are "en_US" or "de_DE", etc. Only the first 10 dictionaries
are offered.
Diffstat (limited to 'pico')
-rw-r--r-- | pico/display.c | 195 | ||||
-rw-r--r-- | pico/edef.h | 8 | ||||
-rw-r--r-- | pico/efunc.h | 2 | ||||
-rw-r--r-- | pico/osdep/mswin_spell.c | 35 | ||||
-rw-r--r-- | pico/pico.c | 4 | ||||
-rw-r--r-- | pico/pico.h | 4 |
6 files changed, 233 insertions, 15 deletions
diff --git a/pico/display.c b/pico/display.c index 96e3adb8..23b6f62d 100644 --- a/pico/display.c +++ b/pico/display.c @@ -1307,6 +1307,201 @@ mlerase(void) mpresf = FALSE; } +/* returns the chosen dictionary. If one was already chosen + * return that one + */ +char * +speller_choice(char **sp_list, int *choice) +{ + int ch_dict = -1; + int cnt; + + if(sp_list == NULL || sp_list[0] == NULL || sp_list[0][0] == '\0') + return NULL; + + if(choice && *choice >= 0) + return sp_list[*choice]; + + for(cnt = 0; sp_list[cnt] != NULL && sp_list[cnt][0] != '\0'; cnt++) + ; + + if(cnt > 10) /* only the first 10 dictionaries */ + cnt = 10; + + if(cnt == 1) /* only one dictionary? choose it! */ + ch_dict = 0; + + if(ch_dict > cnt - 1) /* choose again in case something changed */ + ch_dict = -1; + + if(ch_dict < 0){ /* not a choice yet? do one now! */ + UCS buf[128]; + int i; + char *utf8_prompt; + UCS *ucs4_prompt; + EXTRAKEYS menu_dictionary[] = { + {"0", NULL, '0'}, + {"1", NULL, '1'}, + {"2", NULL, '2'}, + {"3", NULL, '3'}, + {"4", NULL, '4'}, + {"5", NULL, '5'}, + {"6", NULL, '6'}, + {"7", NULL, '7'}, + {"8", NULL, '8'}, + {"9", NULL, '9'} + }; + + for(i = 0; i < cnt; i++) + menu_dictionary[i].label = sp_list[i]; + + if(cnt < 10) + menu_dictionary[cnt].name = NULL; + + buf[0] = '\0'; + /* write the prompt in utf8, and let internal functions translate it to ucs4 */ + ucs4_prompt = utf8_to_ucs4_cpystr(_("Choose Dictionary: ")); + + i = mlchoose(ucs4_prompt, menu_dictionary); + + if(i >= '0' && i <= '9') + ch_dict = i - '0'; + + if (i == -2) /* user cancelled */ + ch_dict = -2; + + if(ucs4_prompt) + fs_give((void **)&ucs4_prompt); + } + else ch_dict = -1; + + if(choice) + *choice = ch_dict; + + return ch_dict >= 0 ? sp_list[ch_dict] : NULL; +} + +/* just like mlreplyd, but user cannot fill a prompt */ +int +mlchoose(UCS *prompt, EXTRAKEYS *extras) +{ + UCS c; + UCS buf[NLINE]; + int i; + int changed = FALSE; + int return_val = 0; + KEYMENU menu_choose[12]; + COLOR_PAIR *lastc = NULL; + + for(i = 0; i < 12; i++){ + menu_choose[i].name = NULL; + KS_OSDATASET(&menu_choose[i], KS_NONE); + } + + menu_choose[0].name = "^G"; + menu_choose[0].label = N_("Get Help"); + KS_OSDATASET(&menu_choose[0], KS_SCREENHELP); + + menu_choose[6].name = "^C"; + menu_choose[6].label = N_("Cancel"); + KS_OSDATASET(&menu_choose[6], KS_NONE); + + for(i = 0; i < 10; i++){ + if((i % 2) == 0){ + menu_choose[i / 2 + 1].name = extras[i].name; + menu_choose[i / 2 + 1].label = extras[i].label; + } + else{ + menu_choose[(i + 13) / 2].name = extras[i].name; + menu_choose[(i + 13) / 2].label = extras[i].label; + } + } + wkeyhelp(menu_choose); /* paint generic menu */ + sgarbk = TRUE; /* mark menu dirty */ + if(Pmaster && curwp) + curwp->w_flag |= WFMODE; + + ucs4_strncpy(buf, prompt, NLINE); + buf[NLINE-1] = '\0'; + mlwrite(buf, NULL); + if(Pmaster && Pmaster->colors && Pmaster->colors->prcp + && pico_is_good_colorpair(Pmaster->colors->prcp)){ + lastc = pico_get_cur_color(); + (void) pico_set_colorp(Pmaster->colors->prcp, PSC_NONE); + } + else + (*term.t_rev)(1); + + return_val = -1; + while(1){ + c = GetKey(); + for(i = 0; i < 10 && extras[i].name != NULL && extras[i].key != c; i++) + ; + if(i < 10 && extras[i].name) + return_val = c; + else switch(c){ + case (CTRL|'C') : /* Bail out! */ + case F2 : + pputs_utf8(_("Cancel"), 1); + return_val = -2; + break; + + case (CTRL|'G') : + if(term.t_mrow == 0 && km_popped == 0){ + movecursor(term.t_nrow-2, 0); + peeol(); + term.t_mrow = 2; + if(lastc){ + (void) pico_set_colorp(lastc, PSC_NONE); + free_color_pair(&lastc); + } + else + (*term.t_rev)(0); + + wkeyhelp(menu_choose); /* paint generic menu */ + mlwrite(buf, NULL); + if(Pmaster && Pmaster->colors && Pmaster->colors->prcp + && pico_is_good_colorpair(Pmaster->colors->prcp)){ + lastc = pico_get_cur_color(); + (void) pico_set_colorp(Pmaster->colors->prcp, PSC_NONE); + } + else + (*term.t_rev)(1); + + sgarbk = TRUE; /* mark menu dirty */ + km_popped++; + break; + } + /* else fall through */ + + default: + (*term.t_beep)(); + case NODATA : + break; + } + + (*term.t_flush)(); + if (return_val != -1){ /* abort sets rv = -2, other return values are positive */ + if(lastc){ + (void) pico_set_colorp(lastc, PSC_NONE); + free_color_pair(&lastc); + } + else + (*term.t_rev)(0); + + if(km_popped){ + term.t_mrow = 0; + movecursor(term.t_nrow, 0); + peeol(); + sgarbf = 1; + km_popped = 0; + } + + return(return_val); + } + } +} + int mlyesno_utf8(char *utf8prompt, int dflt) diff --git a/pico/edef.h b/pico/edef.h index 3cc7fd3e..5d0c1155 100644 --- a/pico/edef.h +++ b/pico/edef.h @@ -56,6 +56,10 @@ char *display_character_set = NULL; char *keyboard_character_set = NULL; UCS *glo_wordseps = NULL; /* points to word separators if set */ char *glo_wordseps_orig = NULL; +#ifdef _WINDOWS +char **dictionary = NULL; /* speller dictionary */ +int chosen_dict = -1; /* the dictionary chosen */ +#endif /* _WINDOWS */ /* uninitialized global definitions */ int currow; /* Cursor row */ @@ -111,6 +115,10 @@ extern char *display_character_set; extern char *keyboard_character_set; extern UCS *glo_wordseps; extern char *glo_wordseps_orig; +#ifdef _WINDOWS +extern char **dictionary; +extern int chosen_dict; +#endif /* _WINDOWS */ /* initialized global external declarations */ extern int currow; /* Cursor row */ extern int curcol; /* Cursor column */ diff --git a/pico/efunc.h b/pico/efunc.h index e0d457aa..14a16d61 100644 --- a/pico/efunc.h +++ b/pico/efunc.h @@ -124,6 +124,8 @@ extern void modeline(struct WINDOW *); extern void movecursor(int, int); extern void clearcursor(void); extern void mlerase(void); +extern char *speller_choice(char **, int *); +extern int mlchoose(UCS *, EXTRAKEYS *); extern int mlyesno_utf8(char *, int); extern int mlyesno(UCS *, int); extern int mlreply_utf8(char *, char *, int, int, EXTRAKEYS *); diff --git a/pico/osdep/mswin_spell.c b/pico/osdep/mswin_spell.c index ac899421..f0392cf4 100644 --- a/pico/osdep/mswin_spell.c +++ b/pico/osdep/mswin_spell.c @@ -53,12 +53,21 @@ spell(int f, int n) LINE *w_markp_bak; WORD_INFO word_info; ASPELLINFO *aspellinfo; + char *lang = NULL; emlwrite(_("Checking spelling..."), NULL); /* greetings! */ memset(&word_info, 0, sizeof(WORD_INFO)); - aspellinfo = speller_init(NULL); + lang = speller_choice(dictionary, &chosen_dict); + + if (chosen_dict == -2){ /* user cancelled */ + chosen_dict = -1; + emlwrite(_("Speller Cancelled"), NULL); + return 1; + } + + aspellinfo = speller_init(lang); if(!aspellinfo || (word_info.utf8_err_message = speller_get_error_message(aspellinfo))) { @@ -67,6 +76,7 @@ spell(int f, int n) else emlwrite(_("Spelling: initializing Aspell failed"), NULL); + chosen_dict = -1; /* try a different one next time */ speller_close(aspellinfo); return -1; } @@ -437,8 +447,8 @@ spell_dlg_proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) static int get_next_word(WORD_INFO *word_info) { - UCS *ucst; - int i, hibit; + UCS *tmp = NULL; + int i; // Skip quoted lines while(lgetc(curwp->w_dotp, 0).c == '>') @@ -482,19 +492,14 @@ get_next_word(WORD_INFO *word_info) break; } - ucst = (UCS *)&word_info->word_dotp->l_text[word_info->word_doto]; - for(i = 0, hibit = 0; i < word_info->word_size; i++) - if(ucst[i] & 0xff000000) - hibit++; - - if(hibit > 0){ - ucst = ucs4_cpystr(ucst); - for(i = 0; i < word_info->word_size; i++) - ucst[i] &= 0xffffff; + tmp = fs_get((word_info->word_size+1)*sizeof(UCS)); + if(tmp != NULL){ + for(i = 0; i < word_info->word_size; i++) + tmp[i] = word_info->word_dotp->l_text[word_info->word_doto+i].c; + tmp[i] = 0; + word_info->word_utf8 = ucs4_to_utf8_cpystr_n(tmp, word_info->word_size); + fs_give((void **)&tmp); } - word_info->word_utf8 = ucs4_to_utf8_cpystr_n(ucst, word_info->word_size); - if(hibit > 0) - fs_give((void **)&ucst); return 1; } diff --git a/pico/pico.c b/pico/pico.c index 93d555d4..0d087281 100644 --- a/pico/pico.c +++ b/pico/pico.c @@ -165,6 +165,10 @@ pico(PICO *pm) gmode |= pm->pine_flags; /* high 4 bits rsv'd for pine */ alt_speller = pm->alt_spell; +#ifdef _WINDOWS + dictionary = pm->dict; + chosen_dict = pm->chosen_dict; +#endif /* _WINDOWS */ pico_all_done = 0; km_popped = 0; diff --git a/pico/pico.h b/pico/pico.h index 0605f992..04ad126e 100644 --- a/pico/pico.h +++ b/pico/pico.h @@ -190,6 +190,10 @@ typedef struct pico_struct { char *ctrlr_label; /* Label for ^R in keymenu */ char *alt_spell; /* Checker to use other than "spell" */ char **alt_ed; /* name of alternate editor or NULL */ +#ifdef _WINDOWS + char **dict; /* list of dictionaries to choose */ + int chosen_dict; /* chosen default dictionary */ +#endif /* WINDOWS */ UCS *wordseps; /* word separator characters other than space */ int fillcolumn; /* where to wrap */ int menu_rows; /* number of rows in menu (0 or 2) */ |