Mercurial > vim
comparison src/spell.c @ 7835:4d7ce6c03fda v7.4.1214
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 30 21:10:09 2016 +0100
patch 7.4.1214
Problem: Using old style function declarations.
Solution: Change to new style function declarations. (script by Hirohito
Higashi)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 30 Jan 2016 21:15:04 +0100 |
parents | 0b6c37dd858d |
children | 2f57bbe870ea |
comparison
equal
deleted
inserted
replaced
7834:2d1dc9ec41ce | 7835:4d7ce6c03fda |
---|---|
1024 * | 1024 * |
1025 * Returns the length of the word in bytes, also when it's OK, so that the | 1025 * Returns the length of the word in bytes, also when it's OK, so that the |
1026 * caller can skip over the word. | 1026 * caller can skip over the word. |
1027 */ | 1027 */ |
1028 int | 1028 int |
1029 spell_check(wp, ptr, attrp, capcol, docount) | 1029 spell_check( |
1030 win_T *wp; /* current window */ | 1030 win_T *wp, /* current window */ |
1031 char_u *ptr; | 1031 char_u *ptr, |
1032 hlf_T *attrp; | 1032 hlf_T *attrp, |
1033 int *capcol; /* column to check for Capital */ | 1033 int *capcol, /* column to check for Capital */ |
1034 int docount; /* count good words */ | 1034 int docount) /* count good words */ |
1035 { | 1035 { |
1036 matchinf_T mi; /* Most things are put in "mi" so that it can | 1036 matchinf_T mi; /* Most things are put in "mi" so that it can |
1037 be passed to functions quickly. */ | 1037 be passed to functions quickly. */ |
1038 int nrlen = 0; /* found a number first */ | 1038 int nrlen = 0; /* found a number first */ |
1039 int c; | 1039 int c; |
1245 * tree. | 1245 * tree. |
1246 * | 1246 * |
1247 * For a match mip->mi_result is updated. | 1247 * For a match mip->mi_result is updated. |
1248 */ | 1248 */ |
1249 static void | 1249 static void |
1250 find_word(mip, mode) | 1250 find_word(matchinf_T *mip, int mode) |
1251 matchinf_T *mip; | |
1252 int mode; | |
1253 { | 1251 { |
1254 idx_T arridx = 0; | 1252 idx_T arridx = 0; |
1255 int endlen[MAXWLEN]; /* length at possible word endings */ | 1253 int endlen[MAXWLEN]; /* length at possible word endings */ |
1256 idx_T endidx[MAXWLEN]; /* possible word endings */ | 1254 idx_T endidx[MAXWLEN]; /* possible word endings */ |
1257 int endidxcnt = 0; | 1255 int endidxcnt = 0; |
1765 * word. | 1763 * word. |
1766 * A match means that the first part of CHECKCOMPOUNDPATTERN matches at the | 1764 * A match means that the first part of CHECKCOMPOUNDPATTERN matches at the |
1767 * end of ptr[wlen] and the second part matches after it. | 1765 * end of ptr[wlen] and the second part matches after it. |
1768 */ | 1766 */ |
1769 static int | 1767 static int |
1770 match_checkcompoundpattern(ptr, wlen, gap) | 1768 match_checkcompoundpattern( |
1771 char_u *ptr; | 1769 char_u *ptr, |
1772 int wlen; | 1770 int wlen, |
1773 garray_T *gap; /* &sl_comppat */ | 1771 garray_T *gap) /* &sl_comppat */ |
1774 { | 1772 { |
1775 int i; | 1773 int i; |
1776 char_u *p; | 1774 char_u *p; |
1777 int len; | 1775 int len; |
1778 | 1776 |
1795 /* | 1793 /* |
1796 * Return TRUE if "flags" is a valid sequence of compound flags and "word" | 1794 * Return TRUE if "flags" is a valid sequence of compound flags and "word" |
1797 * does not have too many syllables. | 1795 * does not have too many syllables. |
1798 */ | 1796 */ |
1799 static int | 1797 static int |
1800 can_compound(slang, word, flags) | 1798 can_compound(slang_T *slang, char_u *word, char_u *flags) |
1801 slang_T *slang; | |
1802 char_u *word; | |
1803 char_u *flags; | |
1804 { | 1799 { |
1805 #ifdef FEAT_MBYTE | 1800 #ifdef FEAT_MBYTE |
1806 char_u uflags[MAXWLEN * 2]; | 1801 char_u uflags[MAXWLEN * 2]; |
1807 int i; | 1802 int i; |
1808 #endif | 1803 #endif |
1839 * Return TRUE when the sequence of flags in "compflags" plus "flag" can | 1834 * Return TRUE when the sequence of flags in "compflags" plus "flag" can |
1840 * possibly form a valid compounded word. This also checks the COMPOUNDRULE | 1835 * possibly form a valid compounded word. This also checks the COMPOUNDRULE |
1841 * lines if they don't contain wildcards. | 1836 * lines if they don't contain wildcards. |
1842 */ | 1837 */ |
1843 static int | 1838 static int |
1844 can_be_compound(sp, slang, compflags, flag) | 1839 can_be_compound( |
1845 trystate_T *sp; | 1840 trystate_T *sp, |
1846 slang_T *slang; | 1841 slang_T *slang, |
1847 char_u *compflags; | 1842 char_u *compflags, |
1848 int flag; | 1843 int flag) |
1849 { | 1844 { |
1850 /* If the flag doesn't appear in sl_compstartflags or sl_compallflags | 1845 /* If the flag doesn't appear in sl_compstartflags or sl_compallflags |
1851 * then it can't possibly compound. */ | 1846 * then it can't possibly compound. */ |
1852 if (!byte_in_str(sp->ts_complen == sp->ts_compsplit | 1847 if (!byte_in_str(sp->ts_complen == sp->ts_compsplit |
1853 ? slang->sl_compstartflags : slang->sl_compallflags, flag)) | 1848 ? slang->sl_compstartflags : slang->sl_compallflags, flag)) |
1876 * compound rule. This is used to stop trying a compound if the flags | 1871 * compound rule. This is used to stop trying a compound if the flags |
1877 * collected so far can't possibly match any compound rule. | 1872 * collected so far can't possibly match any compound rule. |
1878 * Caller must check that slang->sl_comprules is not NULL. | 1873 * Caller must check that slang->sl_comprules is not NULL. |
1879 */ | 1874 */ |
1880 static int | 1875 static int |
1881 match_compoundrule(slang, compflags) | 1876 match_compoundrule(slang_T *slang, char_u *compflags) |
1882 slang_T *slang; | |
1883 char_u *compflags; | |
1884 { | 1877 { |
1885 char_u *p; | 1878 char_u *p; |
1886 int i; | 1879 int i; |
1887 int c; | 1880 int c; |
1888 | 1881 |
1931 * Return non-zero if the prefix indicated by "arridx" matches with the prefix | 1924 * Return non-zero if the prefix indicated by "arridx" matches with the prefix |
1932 * ID in "flags" for the word "word". | 1925 * ID in "flags" for the word "word". |
1933 * The WF_RAREPFX flag is included in the return value for a rare prefix. | 1926 * The WF_RAREPFX flag is included in the return value for a rare prefix. |
1934 */ | 1927 */ |
1935 static int | 1928 static int |
1936 valid_word_prefix(totprefcnt, arridx, flags, word, slang, cond_req) | 1929 valid_word_prefix( |
1937 int totprefcnt; /* nr of prefix IDs */ | 1930 int totprefcnt, /* nr of prefix IDs */ |
1938 int arridx; /* idx in sl_pidxs[] */ | 1931 int arridx, /* idx in sl_pidxs[] */ |
1939 int flags; | 1932 int flags, |
1940 char_u *word; | 1933 char_u *word, |
1941 slang_T *slang; | 1934 slang_T *slang, |
1942 int cond_req; /* only use prefixes with a condition */ | 1935 int cond_req) /* only use prefixes with a condition */ |
1943 { | 1936 { |
1944 int prefcnt; | 1937 int prefcnt; |
1945 int pidx; | 1938 int pidx; |
1946 regprog_T **rp; | 1939 regprog_T **rp; |
1947 int prefid; | 1940 int prefid; |
1985 * prefix in a compound word. | 1978 * prefix in a compound word. |
1986 * | 1979 * |
1987 * For a match mip->mi_result is updated. | 1980 * For a match mip->mi_result is updated. |
1988 */ | 1981 */ |
1989 static void | 1982 static void |
1990 find_prefix(mip, mode) | 1983 find_prefix(matchinf_T *mip, int mode) |
1991 matchinf_T *mip; | |
1992 int mode; | |
1993 { | 1984 { |
1994 idx_T arridx = 0; | 1985 idx_T arridx = 0; |
1995 int len; | 1986 int len; |
1996 int wlen = 0; | 1987 int wlen = 0; |
1997 int flen; | 1988 int flen; |
2108 * Need to fold at least one more character. Do until next non-word character | 2099 * Need to fold at least one more character. Do until next non-word character |
2109 * for efficiency. Include the non-word character too. | 2100 * for efficiency. Include the non-word character too. |
2110 * Return the length of the folded chars in bytes. | 2101 * Return the length of the folded chars in bytes. |
2111 */ | 2102 */ |
2112 static int | 2103 static int |
2113 fold_more(mip) | 2104 fold_more(matchinf_T *mip) |
2114 matchinf_T *mip; | |
2115 { | 2105 { |
2116 int flen; | 2106 int flen; |
2117 char_u *p; | 2107 char_u *p; |
2118 | 2108 |
2119 p = mip->mi_fend; | 2109 p = mip->mi_fend; |
2137 /* | 2127 /* |
2138 * Check case flags for a word. Return TRUE if the word has the requested | 2128 * Check case flags for a word. Return TRUE if the word has the requested |
2139 * case. | 2129 * case. |
2140 */ | 2130 */ |
2141 static int | 2131 static int |
2142 spell_valid_case(wordflags, treeflags) | 2132 spell_valid_case( |
2143 int wordflags; /* flags for the checked word. */ | 2133 int wordflags, /* flags for the checked word. */ |
2144 int treeflags; /* flags for the word in the spell tree */ | 2134 int treeflags) /* flags for the word in the spell tree */ |
2145 { | 2135 { |
2146 return ((wordflags == WF_ALLCAP && (treeflags & WF_FIXCAP) == 0) | 2136 return ((wordflags == WF_ALLCAP && (treeflags & WF_FIXCAP) == 0) |
2147 || ((treeflags & (WF_ALLCAP | WF_KEEPCAP)) == 0 | 2137 || ((treeflags & (WF_ALLCAP | WF_KEEPCAP)) == 0 |
2148 && ((treeflags & WF_ONECAP) == 0 | 2138 && ((treeflags & WF_ONECAP) == 0 |
2149 || (wordflags & WF_ONECAP) != 0))); | 2139 || (wordflags & WF_ONECAP) != 0))); |
2151 | 2141 |
2152 /* | 2142 /* |
2153 * Return TRUE if spell checking is not enabled. | 2143 * Return TRUE if spell checking is not enabled. |
2154 */ | 2144 */ |
2155 static int | 2145 static int |
2156 no_spell_checking(wp) | 2146 no_spell_checking(win_T *wp) |
2157 win_T *wp; | |
2158 { | 2147 { |
2159 if (!wp->w_p_spell || *wp->w_s->b_p_spl == NUL | 2148 if (!wp->w_p_spell || *wp->w_s->b_p_spl == NUL |
2160 || wp->w_s->b_langp.ga_len == 0) | 2149 || wp->w_s->b_langp.ga_len == 0) |
2161 { | 2150 { |
2162 EMSG(_("E756: Spell checking is not enabled")); | 2151 EMSG(_("E756: Spell checking is not enabled")); |
2172 * For Insert mode completion "dir" is BACKWARD and "curline" is TRUE: move | 2161 * For Insert mode completion "dir" is BACKWARD and "curline" is TRUE: move |
2173 * to after badly spelled word before the cursor. | 2162 * to after badly spelled word before the cursor. |
2174 * Return 0 if not found, length of the badly spelled word otherwise. | 2163 * Return 0 if not found, length of the badly spelled word otherwise. |
2175 */ | 2164 */ |
2176 int | 2165 int |
2177 spell_move_to(wp, dir, allwords, curline, attrp) | 2166 spell_move_to( |
2178 win_T *wp; | 2167 win_T *wp, |
2179 int dir; /* FORWARD or BACKWARD */ | 2168 int dir, /* FORWARD or BACKWARD */ |
2180 int allwords; /* TRUE for "[s"/"]s", FALSE for "[S"/"]S" */ | 2169 int allwords, /* TRUE for "[s"/"]s", FALSE for "[S"/"]S" */ |
2181 int curline; | 2170 int curline, |
2182 hlf_T *attrp; /* return: attributes of bad word or NULL | 2171 hlf_T *attrp) /* return: attributes of bad word or NULL |
2183 (only when "dir" is FORWARD) */ | 2172 (only when "dir" is FORWARD) */ |
2184 { | 2173 { |
2185 linenr_T lnum; | 2174 linenr_T lnum; |
2186 pos_T found_pos; | 2175 pos_T found_pos; |
2187 int found_len = 0; | 2176 int found_len = 0; |
2419 * "buf", blanking-out special characters. Copy less then "maxlen" bytes. | 2408 * "buf", blanking-out special characters. Copy less then "maxlen" bytes. |
2420 * Keep the blanks at the start of the next line, this is used in win_line() | 2409 * Keep the blanks at the start of the next line, this is used in win_line() |
2421 * to skip those bytes if the word was OK. | 2410 * to skip those bytes if the word was OK. |
2422 */ | 2411 */ |
2423 void | 2412 void |
2424 spell_cat_line(buf, line, maxlen) | 2413 spell_cat_line(char_u *buf, char_u *line, int maxlen) |
2425 char_u *buf; | |
2426 char_u *line; | |
2427 int maxlen; | |
2428 { | 2414 { |
2429 char_u *p; | 2415 char_u *p; |
2430 int n; | 2416 int n; |
2431 | 2417 |
2432 p = skipwhite(line); | 2418 p = skipwhite(line); |
2459 /* | 2445 /* |
2460 * Load word list(s) for "lang" from Vim spell file(s). | 2446 * Load word list(s) for "lang" from Vim spell file(s). |
2461 * "lang" must be the language without the region: e.g., "en". | 2447 * "lang" must be the language without the region: e.g., "en". |
2462 */ | 2448 */ |
2463 static void | 2449 static void |
2464 spell_load_lang(lang) | 2450 spell_load_lang(char_u *lang) |
2465 char_u *lang; | |
2466 { | 2451 { |
2467 char_u fname_enc[85]; | 2452 char_u fname_enc[85]; |
2468 int r; | 2453 int r; |
2469 spelload_T sl; | 2454 spelload_T sl; |
2470 #ifdef FEAT_AUTOCMD | 2455 #ifdef FEAT_AUTOCMD |
2541 /* | 2526 /* |
2542 * Return the encoding used for spell checking: Use 'encoding', except that we | 2527 * Return the encoding used for spell checking: Use 'encoding', except that we |
2543 * use "latin1" for "latin9". And limit to 60 characters (just in case). | 2528 * use "latin1" for "latin9". And limit to 60 characters (just in case). |
2544 */ | 2529 */ |
2545 static char_u * | 2530 static char_u * |
2546 spell_enc() | 2531 spell_enc(void) |
2547 { | 2532 { |
2548 | 2533 |
2549 #ifdef FEAT_MBYTE | 2534 #ifdef FEAT_MBYTE |
2550 if (STRLEN(p_enc) < 60 && STRCMP(p_enc, "iso-8859-15") != 0) | 2535 if (STRLEN(p_enc) < 60 && STRCMP(p_enc, "iso-8859-15") != 0) |
2551 return p_enc; | 2536 return p_enc; |
2556 /* | 2541 /* |
2557 * Get the name of the .spl file for the internal wordlist into | 2542 * Get the name of the .spl file for the internal wordlist into |
2558 * "fname[MAXPATHL]". | 2543 * "fname[MAXPATHL]". |
2559 */ | 2544 */ |
2560 static void | 2545 static void |
2561 int_wordlist_spl(fname) | 2546 int_wordlist_spl(char_u *fname) |
2562 char_u *fname; | |
2563 { | 2547 { |
2564 vim_snprintf((char *)fname, MAXPATHL, SPL_FNAME_TMPL, | 2548 vim_snprintf((char *)fname, MAXPATHL, SPL_FNAME_TMPL, |
2565 int_wordlist, spell_enc()); | 2549 int_wordlist, spell_enc()); |
2566 } | 2550 } |
2567 | 2551 |
2568 /* | 2552 /* |
2569 * Allocate a new slang_T for language "lang". "lang" can be NULL. | 2553 * Allocate a new slang_T for language "lang". "lang" can be NULL. |
2570 * Caller must fill "sl_next". | 2554 * Caller must fill "sl_next". |
2571 */ | 2555 */ |
2572 static slang_T * | 2556 static slang_T * |
2573 slang_alloc(lang) | 2557 slang_alloc(char_u *lang) |
2574 char_u *lang; | |
2575 { | 2558 { |
2576 slang_T *lp; | 2559 slang_T *lp; |
2577 | 2560 |
2578 lp = (slang_T *)alloc_clear(sizeof(slang_T)); | 2561 lp = (slang_T *)alloc_clear(sizeof(slang_T)); |
2579 if (lp != NULL) | 2562 if (lp != NULL) |
2592 | 2575 |
2593 /* | 2576 /* |
2594 * Free the contents of an slang_T and the structure itself. | 2577 * Free the contents of an slang_T and the structure itself. |
2595 */ | 2578 */ |
2596 static void | 2579 static void |
2597 slang_free(lp) | 2580 slang_free(slang_T *lp) |
2598 slang_T *lp; | |
2599 { | 2581 { |
2600 vim_free(lp->sl_name); | 2582 vim_free(lp->sl_name); |
2601 vim_free(lp->sl_fname); | 2583 vim_free(lp->sl_fname); |
2602 slang_clear(lp); | 2584 slang_clear(lp); |
2603 vim_free(lp); | 2585 vim_free(lp); |
2605 | 2587 |
2606 /* | 2588 /* |
2607 * Clear an slang_T so that the file can be reloaded. | 2589 * Clear an slang_T so that the file can be reloaded. |
2608 */ | 2590 */ |
2609 static void | 2591 static void |
2610 slang_clear(lp) | 2592 slang_clear(slang_T *lp) |
2611 slang_T *lp; | |
2612 { | 2593 { |
2613 garray_T *gap; | 2594 garray_T *gap; |
2614 fromto_T *ftp; | 2595 fromto_T *ftp; |
2615 salitem_T *smp; | 2596 salitem_T *smp; |
2616 int i; | 2597 int i; |
2712 | 2693 |
2713 /* | 2694 /* |
2714 * Clear the info from the .sug file in "lp". | 2695 * Clear the info from the .sug file in "lp". |
2715 */ | 2696 */ |
2716 static void | 2697 static void |
2717 slang_clear_sug(lp) | 2698 slang_clear_sug(slang_T *lp) |
2718 slang_T *lp; | |
2719 { | 2699 { |
2720 vim_free(lp->sl_sbyts); | 2700 vim_free(lp->sl_sbyts); |
2721 lp->sl_sbyts = NULL; | 2701 lp->sl_sbyts = NULL; |
2722 vim_free(lp->sl_sidxs); | 2702 vim_free(lp->sl_sidxs); |
2723 lp->sl_sidxs = NULL; | 2703 lp->sl_sidxs = NULL; |
2730 /* | 2710 /* |
2731 * Load one spell file and store the info into a slang_T. | 2711 * Load one spell file and store the info into a slang_T. |
2732 * Invoked through do_in_runtimepath(). | 2712 * Invoked through do_in_runtimepath(). |
2733 */ | 2713 */ |
2734 static void | 2714 static void |
2735 spell_load_cb(fname, cookie) | 2715 spell_load_cb(char_u *fname, void *cookie) |
2736 char_u *fname; | |
2737 void *cookie; | |
2738 { | 2716 { |
2739 spelload_T *slp = (spelload_T *)cookie; | 2717 spelload_T *slp = (spelload_T *)cookie; |
2740 slang_T *slang; | 2718 slang_T *slang; |
2741 | 2719 |
2742 slang = spell_load_file(fname, slp->sl_lang, NULL, FALSE); | 2720 slang = spell_load_file(fname, slp->sl_lang, NULL, FALSE); |
2765 * "old_lp" is NULL and "lang" is NULL. Will allocate an slang_T. | 2743 * "old_lp" is NULL and "lang" is NULL. Will allocate an slang_T. |
2766 * | 2744 * |
2767 * Returns the slang_T the spell file was loaded into. NULL for error. | 2745 * Returns the slang_T the spell file was loaded into. NULL for error. |
2768 */ | 2746 */ |
2769 static slang_T * | 2747 static slang_T * |
2770 spell_load_file(fname, lang, old_lp, silent) | 2748 spell_load_file( |
2771 char_u *fname; | 2749 char_u *fname, |
2772 char_u *lang; | 2750 char_u *lang, |
2773 slang_T *old_lp; | 2751 slang_T *old_lp, |
2774 int silent; /* no error if file doesn't exist */ | 2752 int silent) /* no error if file doesn't exist */ |
2775 { | 2753 { |
2776 FILE *fd; | 2754 FILE *fd; |
2777 char_u buf[VIMSPELLMAGICL]; | 2755 char_u buf[VIMSPELLMAGICL]; |
2778 char_u *p; | 2756 char_u *p; |
2779 int i; | 2757 int i; |
3023 * Returns NULL when the count is zero. | 3001 * Returns NULL when the count is zero. |
3024 * Sets "*cntp" to SP_*ERROR when there is an error, length of the result | 3002 * Sets "*cntp" to SP_*ERROR when there is an error, length of the result |
3025 * otherwise. | 3003 * otherwise. |
3026 */ | 3004 */ |
3027 static char_u * | 3005 static char_u * |
3028 read_cnt_string(fd, cnt_bytes, cntp) | 3006 read_cnt_string(FILE *fd, int cnt_bytes, int *cntp) |
3029 FILE *fd; | |
3030 int cnt_bytes; | |
3031 int *cntp; | |
3032 { | 3007 { |
3033 int cnt = 0; | 3008 int cnt = 0; |
3034 int i; | 3009 int i; |
3035 char_u *str; | 3010 char_u *str; |
3036 | 3011 |
3055 /* | 3030 /* |
3056 * Read SN_REGION: <regionname> ... | 3031 * Read SN_REGION: <regionname> ... |
3057 * Return SP_*ERROR flags. | 3032 * Return SP_*ERROR flags. |
3058 */ | 3033 */ |
3059 static int | 3034 static int |
3060 read_region_section(fd, lp, len) | 3035 read_region_section(FILE *fd, slang_T *lp, int len) |
3061 FILE *fd; | |
3062 slang_T *lp; | |
3063 int len; | |
3064 { | 3036 { |
3065 int i; | 3037 int i; |
3066 | 3038 |
3067 if (len > 16) | 3039 if (len > 16) |
3068 return SP_FORMERROR; | 3040 return SP_FORMERROR; |
3076 * Read SN_CHARFLAGS section: <charflagslen> <charflags> | 3048 * Read SN_CHARFLAGS section: <charflagslen> <charflags> |
3077 * <folcharslen> <folchars> | 3049 * <folcharslen> <folchars> |
3078 * Return SP_*ERROR flags. | 3050 * Return SP_*ERROR flags. |
3079 */ | 3051 */ |
3080 static int | 3052 static int |
3081 read_charflags_section(fd) | 3053 read_charflags_section(FILE *fd) |
3082 FILE *fd; | |
3083 { | 3054 { |
3084 char_u *flags; | 3055 char_u *flags; |
3085 char_u *fol; | 3056 char_u *fol; |
3086 int flagslen, follen; | 3057 int flagslen, follen; |
3087 | 3058 |
3114 /* | 3085 /* |
3115 * Read SN_PREFCOND section. | 3086 * Read SN_PREFCOND section. |
3116 * Return SP_*ERROR flags. | 3087 * Return SP_*ERROR flags. |
3117 */ | 3088 */ |
3118 static int | 3089 static int |
3119 read_prefcond_section(fd, lp) | 3090 read_prefcond_section(FILE *fd, slang_T *lp) |
3120 FILE *fd; | |
3121 slang_T *lp; | |
3122 { | 3091 { |
3123 int cnt; | 3092 int cnt; |
3124 int i; | 3093 int i; |
3125 int n; | 3094 int n; |
3126 char_u *p; | 3095 char_u *p; |
3162 /* | 3131 /* |
3163 * Read REP or REPSAL items section from "fd": <repcount> <rep> ... | 3132 * Read REP or REPSAL items section from "fd": <repcount> <rep> ... |
3164 * Return SP_*ERROR flags. | 3133 * Return SP_*ERROR flags. |
3165 */ | 3134 */ |
3166 static int | 3135 static int |
3167 read_rep_section(fd, gap, first) | 3136 read_rep_section(FILE *fd, garray_T *gap, short *first) |
3168 FILE *fd; | |
3169 garray_T *gap; | |
3170 short *first; | |
3171 { | 3137 { |
3172 int cnt; | 3138 int cnt; |
3173 fromto_T *ftp; | 3139 fromto_T *ftp; |
3174 int i; | 3140 int i; |
3175 | 3141 |
3214 /* | 3180 /* |
3215 * Read SN_SAL section: <salflags> <salcount> <sal> ... | 3181 * Read SN_SAL section: <salflags> <salcount> <sal> ... |
3216 * Return SP_*ERROR flags. | 3182 * Return SP_*ERROR flags. |
3217 */ | 3183 */ |
3218 static int | 3184 static int |
3219 read_sal_section(fd, slang) | 3185 read_sal_section(FILE *fd, slang_T *slang) |
3220 FILE *fd; | |
3221 slang_T *slang; | |
3222 { | 3186 { |
3223 int i; | 3187 int i; |
3224 int cnt; | 3188 int cnt; |
3225 garray_T *gap; | 3189 garray_T *gap; |
3226 salitem_T *smp; | 3190 salitem_T *smp; |
3367 /* | 3331 /* |
3368 * Read SN_WORDS: <word> ... | 3332 * Read SN_WORDS: <word> ... |
3369 * Return SP_*ERROR flags. | 3333 * Return SP_*ERROR flags. |
3370 */ | 3334 */ |
3371 static int | 3335 static int |
3372 read_words_section(fd, lp, len) | 3336 read_words_section(FILE *fd, slang_T *lp, int len) |
3373 FILE *fd; | |
3374 slang_T *lp; | |
3375 int len; | |
3376 { | 3337 { |
3377 int done = 0; | 3338 int done = 0; |
3378 int i; | 3339 int i; |
3379 int c; | 3340 int c; |
3380 char_u word[MAXWLEN]; | 3341 char_u word[MAXWLEN]; |
3404 /* | 3365 /* |
3405 * Add a word to the hashtable of common words. | 3366 * Add a word to the hashtable of common words. |
3406 * If it's already there then the counter is increased. | 3367 * If it's already there then the counter is increased. |
3407 */ | 3368 */ |
3408 static void | 3369 static void |
3409 count_common_word(lp, word, len, count) | 3370 count_common_word( |
3410 slang_T *lp; | 3371 slang_T *lp, |
3411 char_u *word; | 3372 char_u *word, |
3412 int len; /* word length, -1 for upto NUL */ | 3373 int len, /* word length, -1 for upto NUL */ |
3413 int count; /* 1 to count once, 10 to init */ | 3374 int count) /* 1 to count once, 10 to init */ |
3414 { | 3375 { |
3415 hash_T hash; | 3376 hash_T hash; |
3416 hashitem_T *hi; | 3377 hashitem_T *hi; |
3417 wordcount_T *wc; | 3378 wordcount_T *wc; |
3418 char_u buf[MAXWLEN]; | 3379 char_u buf[MAXWLEN]; |
3447 | 3408 |
3448 /* | 3409 /* |
3449 * Adjust the score of common words. | 3410 * Adjust the score of common words. |
3450 */ | 3411 */ |
3451 static int | 3412 static int |
3452 score_wordcount_adj(slang, score, word, split) | 3413 score_wordcount_adj( |
3453 slang_T *slang; | 3414 slang_T *slang, |
3454 int score; | 3415 int score, |
3455 char_u *word; | 3416 char_u *word, |
3456 int split; /* word was split, less bonus */ | 3417 int split) /* word was split, less bonus */ |
3457 { | 3418 { |
3458 hashitem_T *hi; | 3419 hashitem_T *hi; |
3459 wordcount_T *wc; | 3420 wordcount_T *wc; |
3460 int bonus; | 3421 int bonus; |
3461 int newscore; | 3422 int newscore; |
3484 /* | 3445 /* |
3485 * SN_SOFO: <sofofromlen> <sofofrom> <sofotolen> <sofoto> | 3446 * SN_SOFO: <sofofromlen> <sofofrom> <sofotolen> <sofoto> |
3486 * Return SP_*ERROR flags. | 3447 * Return SP_*ERROR flags. |
3487 */ | 3448 */ |
3488 static int | 3449 static int |
3489 read_sofo_section(fd, slang) | 3450 read_sofo_section(FILE *fd, slang_T *slang) |
3490 FILE *fd; | |
3491 slang_T *slang; | |
3492 { | 3451 { |
3493 int cnt; | 3452 int cnt; |
3494 char_u *from, *to; | 3453 char_u *from, *to; |
3495 int res; | 3454 int res; |
3496 | 3455 |
3526 * Read the compound section from the .spl file: | 3485 * Read the compound section from the .spl file: |
3527 * <compmax> <compminlen> <compsylmax> <compoptions> <compflags> | 3486 * <compmax> <compminlen> <compsylmax> <compoptions> <compflags> |
3528 * Returns SP_*ERROR flags. | 3487 * Returns SP_*ERROR flags. |
3529 */ | 3488 */ |
3530 static int | 3489 static int |
3531 read_compound(fd, slang, len) | 3490 read_compound(FILE *fd, slang_T *slang, int len) |
3532 FILE *fd; | |
3533 slang_T *slang; | |
3534 int len; | |
3535 { | 3491 { |
3536 int todo = len; | 3492 int todo = len; |
3537 int c; | 3493 int c; |
3538 int atstart; | 3494 int atstart; |
3539 char_u *pat; | 3495 char_u *pat; |
3726 /* | 3682 /* |
3727 * Return TRUE if byte "n" appears in "str". | 3683 * Return TRUE if byte "n" appears in "str". |
3728 * Like strchr() but independent of locale. | 3684 * Like strchr() but independent of locale. |
3729 */ | 3685 */ |
3730 static int | 3686 static int |
3731 byte_in_str(str, n) | 3687 byte_in_str(char_u *str, int n) |
3732 char_u *str; | |
3733 int n; | |
3734 { | 3688 { |
3735 char_u *p; | 3689 char_u *p; |
3736 | 3690 |
3737 for (p = str; *p != NUL; ++p) | 3691 for (p = str; *p != NUL; ++p) |
3738 if (*p == n) | 3692 if (*p == n) |
3750 /* | 3704 /* |
3751 * Truncate "slang->sl_syllable" at the first slash and put the following items | 3705 * Truncate "slang->sl_syllable" at the first slash and put the following items |
3752 * in "slang->sl_syl_items". | 3706 * in "slang->sl_syl_items". |
3753 */ | 3707 */ |
3754 static int | 3708 static int |
3755 init_syl_tab(slang) | 3709 init_syl_tab(slang_T *slang) |
3756 slang_T *slang; | |
3757 { | 3710 { |
3758 char_u *p; | 3711 char_u *p; |
3759 char_u *s; | 3712 char_u *s; |
3760 int l; | 3713 int l; |
3761 syl_item_T *syl; | 3714 syl_item_T *syl; |
3789 * Count the number of syllables in "word". | 3742 * Count the number of syllables in "word". |
3790 * When "word" contains spaces the syllables after the last space are counted. | 3743 * When "word" contains spaces the syllables after the last space are counted. |
3791 * Returns zero if syllables are not defines. | 3744 * Returns zero if syllables are not defines. |
3792 */ | 3745 */ |
3793 static int | 3746 static int |
3794 count_syllables(slang, word) | 3747 count_syllables(slang_T *slang, char_u *word) |
3795 slang_T *slang; | |
3796 char_u *word; | |
3797 { | 3748 { |
3798 int cnt = 0; | 3749 int cnt = 0; |
3799 int skip = FALSE; | 3750 int skip = FALSE; |
3800 char_u *p; | 3751 char_u *p; |
3801 int len; | 3752 int len; |
3855 /* | 3806 /* |
3856 * Set the SOFOFROM and SOFOTO items in language "lp". | 3807 * Set the SOFOFROM and SOFOTO items in language "lp". |
3857 * Returns SP_*ERROR flags when there is something wrong. | 3808 * Returns SP_*ERROR flags when there is something wrong. |
3858 */ | 3809 */ |
3859 static int | 3810 static int |
3860 set_sofo(lp, from, to) | 3811 set_sofo(slang_T *lp, char_u *from, char_u *to) |
3861 slang_T *lp; | |
3862 char_u *from; | |
3863 char_u *to; | |
3864 { | 3812 { |
3865 int i; | 3813 int i; |
3866 | 3814 |
3867 #ifdef FEAT_MBYTE | 3815 #ifdef FEAT_MBYTE |
3868 garray_T *gap; | 3816 garray_T *gap; |
3947 | 3895 |
3948 /* | 3896 /* |
3949 * Fill the first-index table for "lp". | 3897 * Fill the first-index table for "lp". |
3950 */ | 3898 */ |
3951 static void | 3899 static void |
3952 set_sal_first(lp) | 3900 set_sal_first(slang_T *lp) |
3953 slang_T *lp; | |
3954 { | 3901 { |
3955 salfirst_T *sfirst; | 3902 salfirst_T *sfirst; |
3956 int i; | 3903 int i; |
3957 salitem_T *smp; | 3904 salitem_T *smp; |
3958 int c; | 3905 int c; |
4013 /* | 3960 /* |
4014 * Turn a multi-byte string into a wide character string. | 3961 * Turn a multi-byte string into a wide character string. |
4015 * Return it in allocated memory (NULL for out-of-memory) | 3962 * Return it in allocated memory (NULL for out-of-memory) |
4016 */ | 3963 */ |
4017 static int * | 3964 static int * |
4018 mb_str2wide(s) | 3965 mb_str2wide(char_u *s) |
4019 char_u *s; | |
4020 { | 3966 { |
4021 int *res; | 3967 int *res; |
4022 char_u *p; | 3968 char_u *p; |
4023 int i = 0; | 3969 int i = 0; |
4024 | 3970 |
4038 * Allocates the memory and stores pointers in "bytsp" and "idxsp". | 3984 * Allocates the memory and stores pointers in "bytsp" and "idxsp". |
4039 * This is skipped when the tree has zero length. | 3985 * This is skipped when the tree has zero length. |
4040 * Returns zero when OK, SP_ value for an error. | 3986 * Returns zero when OK, SP_ value for an error. |
4041 */ | 3987 */ |
4042 static int | 3988 static int |
4043 spell_read_tree(fd, bytsp, idxsp, prefixtree, prefixcnt) | 3989 spell_read_tree( |
4044 FILE *fd; | 3990 FILE *fd, |
4045 char_u **bytsp; | 3991 char_u **bytsp, |
4046 idx_T **idxsp; | 3992 idx_T **idxsp, |
4047 int prefixtree; /* TRUE for the prefix tree */ | 3993 int prefixtree, /* TRUE for the prefix tree */ |
4048 int prefixcnt; /* when "prefixtree" is TRUE: prefix count */ | 3994 int prefixcnt) /* when "prefixtree" is TRUE: prefix count */ |
4049 { | 3995 { |
4050 int len; | 3996 int len; |
4051 int idx; | 3997 int idx; |
4052 char_u *bp; | 3998 char_u *bp; |
4053 idx_T *ip; | 3999 idx_T *ip; |
4088 * Returns the index (>= 0) following the siblings. | 4034 * Returns the index (>= 0) following the siblings. |
4089 * Returns SP_TRUNCERROR if the file is shorter than expected. | 4035 * Returns SP_TRUNCERROR if the file is shorter than expected. |
4090 * Returns SP_FORMERROR if there is a format error. | 4036 * Returns SP_FORMERROR if there is a format error. |
4091 */ | 4037 */ |
4092 static idx_T | 4038 static idx_T |
4093 read_tree_node(fd, byts, idxs, maxidx, startidx, prefixtree, maxprefcondnr) | 4039 read_tree_node( |
4094 FILE *fd; | 4040 FILE *fd, |
4095 char_u *byts; | 4041 char_u *byts, |
4096 idx_T *idxs; | 4042 idx_T *idxs, |
4097 int maxidx; /* size of arrays */ | 4043 int maxidx, /* size of arrays */ |
4098 idx_T startidx; /* current index in "byts" and "idxs" */ | 4044 idx_T startidx, /* current index in "byts" and "idxs" */ |
4099 int prefixtree; /* TRUE for reading PREFIXTREE */ | 4045 int prefixtree, /* TRUE for reading PREFIXTREE */ |
4100 int maxprefcondnr; /* maximum for <prefcondnr> */ | 4046 int maxprefcondnr) /* maximum for <prefcondnr> */ |
4101 { | 4047 { |
4102 int len; | 4048 int len; |
4103 int i; | 4049 int i; |
4104 int n; | 4050 int n; |
4105 idx_T idx = startidx; | 4051 idx_T idx = startidx; |
4204 /* | 4150 /* |
4205 * Parse 'spelllang' and set w_s->b_langp accordingly. | 4151 * Parse 'spelllang' and set w_s->b_langp accordingly. |
4206 * Returns NULL if it's OK, an error message otherwise. | 4152 * Returns NULL if it's OK, an error message otherwise. |
4207 */ | 4153 */ |
4208 char_u * | 4154 char_u * |
4209 did_set_spelllang(wp) | 4155 did_set_spelllang(win_T *wp) |
4210 win_T *wp; | |
4211 { | 4156 { |
4212 garray_T ga; | 4157 garray_T ga; |
4213 char_u *splp; | 4158 char_u *splp; |
4214 char_u *region; | 4159 char_u *region; |
4215 char_u region_cp[3]; | 4160 char_u region_cp[3]; |
4528 | 4473 |
4529 /* | 4474 /* |
4530 * Clear the midword characters for buffer "buf". | 4475 * Clear the midword characters for buffer "buf". |
4531 */ | 4476 */ |
4532 static void | 4477 static void |
4533 clear_midword(wp) | 4478 clear_midword(win_T *wp) |
4534 win_T *wp; | |
4535 { | 4479 { |
4536 vim_memset(wp->w_s->b_spell_ismw, 0, 256); | 4480 vim_memset(wp->w_s->b_spell_ismw, 0, 256); |
4537 #ifdef FEAT_MBYTE | 4481 #ifdef FEAT_MBYTE |
4538 vim_free(wp->w_s->b_spell_ismw_mb); | 4482 vim_free(wp->w_s->b_spell_ismw_mb); |
4539 wp->w_s->b_spell_ismw_mb = NULL; | 4483 wp->w_s->b_spell_ismw_mb = NULL; |
4543 /* | 4487 /* |
4544 * Use the "sl_midword" field of language "lp" for buffer "buf". | 4488 * Use the "sl_midword" field of language "lp" for buffer "buf". |
4545 * They add up to any currently used midword characters. | 4489 * They add up to any currently used midword characters. |
4546 */ | 4490 */ |
4547 static void | 4491 static void |
4548 use_midword(lp, wp) | 4492 use_midword(slang_T *lp, win_T *wp) |
4549 slang_T *lp; | |
4550 win_T *wp; | |
4551 { | 4493 { |
4552 char_u *p; | 4494 char_u *p; |
4553 | 4495 |
4554 if (lp->sl_midword == NULL) /* there aren't any */ | 4496 if (lp->sl_midword == NULL) /* there aren't any */ |
4555 return; | 4497 return; |
4591 * Find the region "region[2]" in "rp" (points to "sl_regions"). | 4533 * Find the region "region[2]" in "rp" (points to "sl_regions"). |
4592 * Each region is simply stored as the two characters of it's name. | 4534 * Each region is simply stored as the two characters of it's name. |
4593 * Returns the index if found (first is 0), REGION_ALL if not found. | 4535 * Returns the index if found (first is 0), REGION_ALL if not found. |
4594 */ | 4536 */ |
4595 static int | 4537 static int |
4596 find_region(rp, region) | 4538 find_region(char_u *rp, char_u *region) |
4597 char_u *rp; | |
4598 char_u *region; | |
4599 { | 4539 { |
4600 int i; | 4540 int i; |
4601 | 4541 |
4602 for (i = 0; ; i += 2) | 4542 for (i = 0; ; i += 2) |
4603 { | 4543 { |
4615 * Word WF_ONECAP | 4555 * Word WF_ONECAP |
4616 * W WORD WF_ALLCAP | 4556 * W WORD WF_ALLCAP |
4617 * WoRd wOrd WF_KEEPCAP | 4557 * WoRd wOrd WF_KEEPCAP |
4618 */ | 4558 */ |
4619 static int | 4559 static int |
4620 captype(word, end) | 4560 captype( |
4621 char_u *word; | 4561 char_u *word, |
4622 char_u *end; /* When NULL use up to NUL byte. */ | 4562 char_u *end) /* When NULL use up to NUL byte. */ |
4623 { | 4563 { |
4624 char_u *p; | 4564 char_u *p; |
4625 int c; | 4565 int c; |
4626 int firstcap; | 4566 int firstcap; |
4627 int allcap; | 4567 int allcap; |
4671 * Like captype() but for a KEEPCAP word add ONECAP if the word starts with a | 4611 * Like captype() but for a KEEPCAP word add ONECAP if the word starts with a |
4672 * capital. So that make_case_word() can turn WOrd into Word. | 4612 * capital. So that make_case_word() can turn WOrd into Word. |
4673 * Add ALLCAP for "WOrD". | 4613 * Add ALLCAP for "WOrD". |
4674 */ | 4614 */ |
4675 static int | 4615 static int |
4676 badword_captype(word, end) | 4616 badword_captype(char_u *word, char_u *end) |
4677 char_u *word; | |
4678 char_u *end; | |
4679 { | 4617 { |
4680 int flags = captype(word, end); | 4618 int flags = captype(word, end); |
4681 int c; | 4619 int c; |
4682 int l, u; | 4620 int l, u; |
4683 int first; | 4621 int first; |
4718 | 4656 |
4719 /* | 4657 /* |
4720 * Delete the internal wordlist and its .spl file. | 4658 * Delete the internal wordlist and its .spl file. |
4721 */ | 4659 */ |
4722 void | 4660 void |
4723 spell_delete_wordlist() | 4661 spell_delete_wordlist(void) |
4724 { | 4662 { |
4725 char_u fname[MAXPATHL]; | 4663 char_u fname[MAXPATHL]; |
4726 | 4664 |
4727 if (int_wordlist != NULL) | 4665 if (int_wordlist != NULL) |
4728 { | 4666 { |
4737 #if defined(FEAT_MBYTE) || defined(EXITFREE) || defined(PROTO) | 4675 #if defined(FEAT_MBYTE) || defined(EXITFREE) || defined(PROTO) |
4738 /* | 4676 /* |
4739 * Free all languages. | 4677 * Free all languages. |
4740 */ | 4678 */ |
4741 void | 4679 void |
4742 spell_free_all() | 4680 spell_free_all(void) |
4743 { | 4681 { |
4744 slang_T *slang; | 4682 slang_T *slang; |
4745 buf_T *buf; | 4683 buf_T *buf; |
4746 | 4684 |
4747 /* Go through all buffers and handle 'spelllang'. <VN> */ | 4685 /* Go through all buffers and handle 'spelllang'. <VN> */ |
4768 /* | 4706 /* |
4769 * Clear all spelling tables and reload them. | 4707 * Clear all spelling tables and reload them. |
4770 * Used after 'encoding' is set and when ":mkspell" was used. | 4708 * Used after 'encoding' is set and when ":mkspell" was used. |
4771 */ | 4709 */ |
4772 void | 4710 void |
4773 spell_reload() | 4711 spell_reload(void) |
4774 { | 4712 { |
4775 win_T *wp; | 4713 win_T *wp; |
4776 | 4714 |
4777 /* Initialize the table for spell_iswordp(). */ | 4715 /* Initialize the table for spell_iswordp(). */ |
4778 init_spell_chartab(); | 4716 init_spell_chartab(); |
4801 | 4739 |
4802 /* | 4740 /* |
4803 * Reload the spell file "fname" if it's loaded. | 4741 * Reload the spell file "fname" if it's loaded. |
4804 */ | 4742 */ |
4805 static void | 4743 static void |
4806 spell_reload_one(fname, added_word) | 4744 spell_reload_one( |
4807 char_u *fname; | 4745 char_u *fname, |
4808 int added_word; /* invoked through "zg" */ | 4746 int added_word) /* invoked through "zg" */ |
4809 { | 4747 { |
4810 slang_T *slang; | 4748 slang_T *slang; |
4811 int didit = FALSE; | 4749 int didit = FALSE; |
4812 | 4750 |
4813 for (slang = first_lang; slang != NULL; slang = slang->sl_next) | 4751 for (slang = first_lang; slang != NULL; slang = slang->sl_next) |
5211 /* | 5149 /* |
5212 * Read the affix file "fname". | 5150 * Read the affix file "fname". |
5213 * Returns an afffile_T, NULL for complete failure. | 5151 * Returns an afffile_T, NULL for complete failure. |
5214 */ | 5152 */ |
5215 static afffile_T * | 5153 static afffile_T * |
5216 spell_read_aff(spin, fname) | 5154 spell_read_aff(spellinfo_T *spin, char_u *fname) |
5217 spellinfo_T *spin; | |
5218 char_u *fname; | |
5219 { | 5155 { |
5220 FILE *fd; | 5156 FILE *fd; |
5221 afffile_T *aff; | 5157 afffile_T *aff; |
5222 char_u rline[MAXLINELEN]; | 5158 char_u rline[MAXLINELEN]; |
5223 char_u *line; | 5159 char_u *line; |
6161 /* | 6097 /* |
6162 * Return TRUE when items[0] equals "rulename", there are "mincount" items or | 6098 * Return TRUE when items[0] equals "rulename", there are "mincount" items or |
6163 * a comment is following after item "mincount". | 6099 * a comment is following after item "mincount". |
6164 */ | 6100 */ |
6165 static int | 6101 static int |
6166 is_aff_rule(items, itemcnt, rulename, mincount) | 6102 is_aff_rule( |
6167 char_u **items; | 6103 char_u **items, |
6168 int itemcnt; | 6104 int itemcnt, |
6169 char *rulename; | 6105 char *rulename, |
6170 int mincount; | 6106 int mincount) |
6171 { | 6107 { |
6172 return (STRCMP(items[0], rulename) == 0 | 6108 return (STRCMP(items[0], rulename) == 0 |
6173 && (itemcnt == mincount | 6109 && (itemcnt == mincount |
6174 || (itemcnt > mincount && items[mincount][0] == '#'))); | 6110 || (itemcnt > mincount && items[mincount][0] == '#'))); |
6175 } | 6111 } |
6177 /* | 6113 /* |
6178 * For affix "entry" move COMPOUNDFORBIDFLAG and COMPOUNDPERMITFLAG from | 6114 * For affix "entry" move COMPOUNDFORBIDFLAG and COMPOUNDPERMITFLAG from |
6179 * ae_flags to ae_comppermit and ae_compforbid. | 6115 * ae_flags to ae_comppermit and ae_compforbid. |
6180 */ | 6116 */ |
6181 static void | 6117 static void |
6182 aff_process_flags(affile, entry) | 6118 aff_process_flags(afffile_T *affile, affentry_T *entry) |
6183 afffile_T *affile; | |
6184 affentry_T *entry; | |
6185 { | 6119 { |
6186 char_u *p; | 6120 char_u *p; |
6187 char_u *prevp; | 6121 char_u *prevp; |
6188 unsigned flag; | 6122 unsigned flag; |
6189 | 6123 |
6213 | 6147 |
6214 /* | 6148 /* |
6215 * Return TRUE if "s" is the name of an info item in the affix file. | 6149 * Return TRUE if "s" is the name of an info item in the affix file. |
6216 */ | 6150 */ |
6217 static int | 6151 static int |
6218 spell_info_item(s) | 6152 spell_info_item(char_u *s) |
6219 char_u *s; | |
6220 { | 6153 { |
6221 return STRCMP(s, "NAME") == 0 | 6154 return STRCMP(s, "NAME") == 0 |
6222 || STRCMP(s, "HOME") == 0 | 6155 || STRCMP(s, "HOME") == 0 |
6223 || STRCMP(s, "VERSION") == 0 | 6156 || STRCMP(s, "VERSION") == 0 |
6224 || STRCMP(s, "AUTHOR") == 0 | 6157 || STRCMP(s, "AUTHOR") == 0 |
6229 /* | 6162 /* |
6230 * Turn an affix flag name into a number, according to the FLAG type. | 6163 * Turn an affix flag name into a number, according to the FLAG type. |
6231 * returns zero for failure. | 6164 * returns zero for failure. |
6232 */ | 6165 */ |
6233 static unsigned | 6166 static unsigned |
6234 affitem2flag(flagtype, item, fname, lnum) | 6167 affitem2flag( |
6235 int flagtype; | 6168 int flagtype, |
6236 char_u *item; | 6169 char_u *item, |
6237 char_u *fname; | 6170 char_u *fname, |
6238 int lnum; | 6171 int lnum) |
6239 { | 6172 { |
6240 unsigned res; | 6173 unsigned res; |
6241 char_u *p = item; | 6174 char_u *p = item; |
6242 | 6175 |
6243 res = get_affitem(flagtype, &p); | 6176 res = get_affitem(flagtype, &p); |
6262 /* | 6195 /* |
6263 * Get one affix name from "*pp" and advance the pointer. | 6196 * Get one affix name from "*pp" and advance the pointer. |
6264 * Returns zero for an error, still advances the pointer then. | 6197 * Returns zero for an error, still advances the pointer then. |
6265 */ | 6198 */ |
6266 static unsigned | 6199 static unsigned |
6267 get_affitem(flagtype, pp) | 6200 get_affitem(int flagtype, char_u **pp) |
6268 int flagtype; | |
6269 char_u **pp; | |
6270 { | 6201 { |
6271 int res; | 6202 int res; |
6272 | 6203 |
6273 if (flagtype == AFT_NUM) | 6204 if (flagtype == AFT_NUM) |
6274 { | 6205 { |
6306 * spin->si_compflags. | 6237 * spin->si_compflags. |
6307 * The processing involves changing the affix names to ID numbers, so that | 6238 * The processing involves changing the affix names to ID numbers, so that |
6308 * they fit in one byte. | 6239 * they fit in one byte. |
6309 */ | 6240 */ |
6310 static void | 6241 static void |
6311 process_compflags(spin, aff, compflags) | 6242 process_compflags( |
6312 spellinfo_T *spin; | 6243 spellinfo_T *spin, |
6313 afffile_T *aff; | 6244 afffile_T *aff, |
6314 char_u *compflags; | 6245 char_u *compflags) |
6315 { | 6246 { |
6316 char_u *p; | 6247 char_u *p; |
6317 char_u *prevp; | 6248 char_u *prevp; |
6318 unsigned flag; | 6249 unsigned flag; |
6319 compitem_T *ci; | 6250 compitem_T *ci; |
6390 * each other. We have almost 255 available, but start at 0-127 to avoid | 6321 * each other. We have almost 255 available, but start at 0-127 to avoid |
6391 * using two bytes for utf-8. When the 0-127 range is used up go to 128-255. | 6322 * using two bytes for utf-8. When the 0-127 range is used up go to 128-255. |
6392 * When that is used up an error message is given. | 6323 * When that is used up an error message is given. |
6393 */ | 6324 */ |
6394 static void | 6325 static void |
6395 check_renumber(spin) | 6326 check_renumber(spellinfo_T *spin) |
6396 spellinfo_T *spin; | |
6397 { | 6327 { |
6398 if (spin->si_newprefID == spin->si_newcompID && spin->si_newcompID < 128) | 6328 if (spin->si_newprefID == spin->si_newcompID && spin->si_newcompID < 128) |
6399 { | 6329 { |
6400 spin->si_newprefID = 127; | 6330 spin->si_newprefID = 127; |
6401 spin->si_newcompID = 255; | 6331 spin->si_newcompID = 255; |
6404 | 6334 |
6405 /* | 6335 /* |
6406 * Return TRUE if flag "flag" appears in affix list "afflist". | 6336 * Return TRUE if flag "flag" appears in affix list "afflist". |
6407 */ | 6337 */ |
6408 static int | 6338 static int |
6409 flag_in_afflist(flagtype, afflist, flag) | 6339 flag_in_afflist(int flagtype, char_u *afflist, unsigned flag) |
6410 int flagtype; | |
6411 char_u *afflist; | |
6412 unsigned flag; | |
6413 { | 6340 { |
6414 char_u *p; | 6341 char_u *p; |
6415 unsigned n; | 6342 unsigned n; |
6416 | 6343 |
6417 switch (flagtype) | 6344 switch (flagtype) |
6456 | 6383 |
6457 /* | 6384 /* |
6458 * Give a warning when "spinval" and "affval" numbers are set and not the same. | 6385 * Give a warning when "spinval" and "affval" numbers are set and not the same. |
6459 */ | 6386 */ |
6460 static void | 6387 static void |
6461 aff_check_number(spinval, affval, name) | 6388 aff_check_number(int spinval, int affval, char *name) |
6462 int spinval; | |
6463 int affval; | |
6464 char *name; | |
6465 { | 6389 { |
6466 if (spinval != 0 && spinval != affval) | 6390 if (spinval != 0 && spinval != affval) |
6467 smsg((char_u *)_("%s value differs from what is used in another .aff file"), name); | 6391 smsg((char_u *)_("%s value differs from what is used in another .aff file"), name); |
6468 } | 6392 } |
6469 | 6393 |
6470 /* | 6394 /* |
6471 * Give a warning when "spinval" and "affval" strings are set and not the same. | 6395 * Give a warning when "spinval" and "affval" strings are set and not the same. |
6472 */ | 6396 */ |
6473 static void | 6397 static void |
6474 aff_check_string(spinval, affval, name) | 6398 aff_check_string(char_u *spinval, char_u *affval, char *name) |
6475 char_u *spinval; | |
6476 char_u *affval; | |
6477 char *name; | |
6478 { | 6399 { |
6479 if (spinval != NULL && STRCMP(spinval, affval) != 0) | 6400 if (spinval != NULL && STRCMP(spinval, affval) != 0) |
6480 smsg((char_u *)_("%s value differs from what is used in another .aff file"), name); | 6401 smsg((char_u *)_("%s value differs from what is used in another .aff file"), name); |
6481 } | 6402 } |
6482 | 6403 |
6483 /* | 6404 /* |
6484 * Return TRUE if strings "s1" and "s2" are equal. Also consider both being | 6405 * Return TRUE if strings "s1" and "s2" are equal. Also consider both being |
6485 * NULL as equal. | 6406 * NULL as equal. |
6486 */ | 6407 */ |
6487 static int | 6408 static int |
6488 str_equal(s1, s2) | 6409 str_equal(char_u *s1, char_u *s2) |
6489 char_u *s1; | |
6490 char_u *s2; | |
6491 { | 6410 { |
6492 if (s1 == NULL || s2 == NULL) | 6411 if (s1 == NULL || s2 == NULL) |
6493 return s1 == s2; | 6412 return s1 == s2; |
6494 return STRCMP(s1, s2) == 0; | 6413 return STRCMP(s1, s2) == 0; |
6495 } | 6414 } |
6497 /* | 6416 /* |
6498 * Add a from-to item to "gap". Used for REP and SAL items. | 6417 * Add a from-to item to "gap". Used for REP and SAL items. |
6499 * They are stored case-folded. | 6418 * They are stored case-folded. |
6500 */ | 6419 */ |
6501 static void | 6420 static void |
6502 add_fromto(spin, gap, from, to) | 6421 add_fromto( |
6503 spellinfo_T *spin; | 6422 spellinfo_T *spin, |
6504 garray_T *gap; | 6423 garray_T *gap, |
6505 char_u *from; | 6424 char_u *from, |
6506 char_u *to; | 6425 char_u *to) |
6507 { | 6426 { |
6508 fromto_T *ftp; | 6427 fromto_T *ftp; |
6509 char_u word[MAXWLEN]; | 6428 char_u word[MAXWLEN]; |
6510 | 6429 |
6511 if (ga_grow(gap, 1) == OK) | 6430 if (ga_grow(gap, 1) == OK) |
6521 | 6440 |
6522 /* | 6441 /* |
6523 * Convert a boolean argument in a SAL line to TRUE or FALSE; | 6442 * Convert a boolean argument in a SAL line to TRUE or FALSE; |
6524 */ | 6443 */ |
6525 static int | 6444 static int |
6526 sal_to_bool(s) | 6445 sal_to_bool(char_u *s) |
6527 char_u *s; | |
6528 { | 6446 { |
6529 return STRCMP(s, "1") == 0 || STRCMP(s, "true") == 0; | 6447 return STRCMP(s, "1") == 0 || STRCMP(s, "true") == 0; |
6530 } | 6448 } |
6531 | 6449 |
6532 /* | 6450 /* |
6533 * Free the structure filled by spell_read_aff(). | 6451 * Free the structure filled by spell_read_aff(). |
6534 */ | 6452 */ |
6535 static void | 6453 static void |
6536 spell_free_aff(aff) | 6454 spell_free_aff(afffile_T *aff) |
6537 afffile_T *aff; | |
6538 { | 6455 { |
6539 hashtab_T *ht; | 6456 hashtab_T *ht; |
6540 hashitem_T *hi; | 6457 hashitem_T *hi; |
6541 int todo; | 6458 int todo; |
6542 affheader_T *ah; | 6459 affheader_T *ah; |
6570 /* | 6487 /* |
6571 * Read dictionary file "fname". | 6488 * Read dictionary file "fname". |
6572 * Returns OK or FAIL; | 6489 * Returns OK or FAIL; |
6573 */ | 6490 */ |
6574 static int | 6491 static int |
6575 spell_read_dic(spin, fname, affile) | 6492 spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) |
6576 spellinfo_T *spin; | |
6577 char_u *fname; | |
6578 afffile_T *affile; | |
6579 { | 6493 { |
6580 hashtab_T ht; | 6494 hashtab_T ht; |
6581 char_u line[MAXLINELEN]; | 6495 char_u line[MAXLINELEN]; |
6582 char_u *p; | 6496 char_u *p; |
6583 char_u *afflist; | 6497 char_u *afflist; |
6787 /* | 6701 /* |
6788 * Check for affix flags in "afflist" that are turned into word flags. | 6702 * Check for affix flags in "afflist" that are turned into word flags. |
6789 * Return WF_ flags. | 6703 * Return WF_ flags. |
6790 */ | 6704 */ |
6791 static int | 6705 static int |
6792 get_affix_flags(affile, afflist) | 6706 get_affix_flags(afffile_T *affile, char_u *afflist) |
6793 afffile_T *affile; | |
6794 char_u *afflist; | |
6795 { | 6707 { |
6796 int flags = 0; | 6708 int flags = 0; |
6797 | 6709 |
6798 if (affile->af_keepcase != 0 && flag_in_afflist( | 6710 if (affile->af_keepcase != 0 && flag_in_afflist( |
6799 affile->af_flagtype, afflist, affile->af_keepcase)) | 6711 affile->af_flagtype, afflist, affile->af_keepcase)) |
6821 * Used for PFXPOSTPONE. | 6733 * Used for PFXPOSTPONE. |
6822 * Put the resulting flags in "store_afflist[MAXWLEN]" with a terminating NUL | 6734 * Put the resulting flags in "store_afflist[MAXWLEN]" with a terminating NUL |
6823 * and return the number of affixes. | 6735 * and return the number of affixes. |
6824 */ | 6736 */ |
6825 static int | 6737 static int |
6826 get_pfxlist(affile, afflist, store_afflist) | 6738 get_pfxlist( |
6827 afffile_T *affile; | 6739 afffile_T *affile, |
6828 char_u *afflist; | 6740 char_u *afflist, |
6829 char_u *store_afflist; | 6741 char_u *store_afflist) |
6830 { | 6742 { |
6831 char_u *p; | 6743 char_u *p; |
6832 char_u *prevp; | 6744 char_u *prevp; |
6833 int cnt = 0; | 6745 int cnt = 0; |
6834 int id; | 6746 int id; |
6863 * Get the list of compound IDs from the affix list "afflist" that are used | 6775 * Get the list of compound IDs from the affix list "afflist" that are used |
6864 * for compound words. | 6776 * for compound words. |
6865 * Puts the flags in "store_afflist[]". | 6777 * Puts the flags in "store_afflist[]". |
6866 */ | 6778 */ |
6867 static void | 6779 static void |
6868 get_compflags(affile, afflist, store_afflist) | 6780 get_compflags( |
6869 afffile_T *affile; | 6781 afffile_T *affile, |
6870 char_u *afflist; | 6782 char_u *afflist, |
6871 char_u *store_afflist; | 6783 char_u *store_afflist) |
6872 { | 6784 { |
6873 char_u *p; | 6785 char_u *p; |
6874 char_u *prevp; | 6786 char_u *prevp; |
6875 int cnt = 0; | 6787 int cnt = 0; |
6876 char_u key[AH_KEY_LEN]; | 6788 char_u key[AH_KEY_LEN]; |
6902 * the resulting words for combining affixes. | 6814 * the resulting words for combining affixes. |
6903 * | 6815 * |
6904 * Returns FAIL when out of memory. | 6816 * Returns FAIL when out of memory. |
6905 */ | 6817 */ |
6906 static int | 6818 static int |
6907 store_aff_word(spin, word, afflist, affile, ht, xht, condit, flags, | 6819 store_aff_word( |
6908 pfxlist, pfxlen) | 6820 spellinfo_T *spin, /* spell info */ |
6909 spellinfo_T *spin; /* spell info */ | 6821 char_u *word, /* basic word start */ |
6910 char_u *word; /* basic word start */ | 6822 char_u *afflist, /* list of names of supported affixes */ |
6911 char_u *afflist; /* list of names of supported affixes */ | 6823 afffile_T *affile, |
6912 afffile_T *affile; | 6824 hashtab_T *ht, |
6913 hashtab_T *ht; | 6825 hashtab_T *xht, |
6914 hashtab_T *xht; | 6826 int condit, /* CONDIT_SUF et al. */ |
6915 int condit; /* CONDIT_SUF et al. */ | 6827 int flags, /* flags for the word */ |
6916 int flags; /* flags for the word */ | 6828 char_u *pfxlist, /* list of prefix IDs */ |
6917 char_u *pfxlist; /* list of prefix IDs */ | 6829 int pfxlen) /* nr of flags in "pfxlist" for prefixes, rest |
6918 int pfxlen; /* nr of flags in "pfxlist" for prefixes, rest | |
6919 * is compound flags */ | 6830 * is compound flags */ |
6920 { | 6831 { |
6921 int todo; | 6832 int todo; |
6922 hashitem_T *hi; | 6833 hashitem_T *hi; |
6923 affheader_T *ah; | 6834 affheader_T *ah; |
7168 | 7079 |
7169 /* | 7080 /* |
7170 * Read a file with a list of words. | 7081 * Read a file with a list of words. |
7171 */ | 7082 */ |
7172 static int | 7083 static int |
7173 spell_read_wordfile(spin, fname) | 7084 spell_read_wordfile(spellinfo_T *spin, char_u *fname) |
7174 spellinfo_T *spin; | |
7175 char_u *fname; | |
7176 { | 7085 { |
7177 FILE *fd; | 7086 FILE *fd; |
7178 long lnum = 0; | 7087 long lnum = 0; |
7179 char_u rline[MAXLINELEN]; | 7088 char_u rline[MAXLINELEN]; |
7180 char_u *line; | 7089 char_u *line; |
7378 * track of them). | 7287 * track of them). |
7379 * The memory is cleared to all zeros. | 7288 * The memory is cleared to all zeros. |
7380 * Returns NULL when out of memory. | 7289 * Returns NULL when out of memory. |
7381 */ | 7290 */ |
7382 static void * | 7291 static void * |
7383 getroom(spin, len, align) | 7292 getroom( |
7384 spellinfo_T *spin; | 7293 spellinfo_T *spin, |
7385 size_t len; /* length needed */ | 7294 size_t len, /* length needed */ |
7386 int align; /* align for pointer */ | 7295 int align) /* align for pointer */ |
7387 { | 7296 { |
7388 char_u *p; | 7297 char_u *p; |
7389 sblock_T *bl = spin->si_blocks; | 7298 sblock_T *bl = spin->si_blocks; |
7390 | 7299 |
7391 if (align && bl != NULL) | 7300 if (align && bl != NULL) |
7426 /* | 7335 /* |
7427 * Make a copy of a string into memory allocated with getroom(). | 7336 * Make a copy of a string into memory allocated with getroom(). |
7428 * Returns NULL when out of memory. | 7337 * Returns NULL when out of memory. |
7429 */ | 7338 */ |
7430 static char_u * | 7339 static char_u * |
7431 getroom_save(spin, s) | 7340 getroom_save(spellinfo_T *spin, char_u *s) |
7432 spellinfo_T *spin; | |
7433 char_u *s; | |
7434 { | 7341 { |
7435 char_u *sc; | 7342 char_u *sc; |
7436 | 7343 |
7437 sc = (char_u *)getroom(spin, STRLEN(s) + 1, FALSE); | 7344 sc = (char_u *)getroom(spin, STRLEN(s) + 1, FALSE); |
7438 if (sc != NULL) | 7345 if (sc != NULL) |
7443 | 7350 |
7444 /* | 7351 /* |
7445 * Free the list of allocated sblock_T. | 7352 * Free the list of allocated sblock_T. |
7446 */ | 7353 */ |
7447 static void | 7354 static void |
7448 free_blocks(bl) | 7355 free_blocks(sblock_T *bl) |
7449 sblock_T *bl; | |
7450 { | 7356 { |
7451 sblock_T *next; | 7357 sblock_T *next; |
7452 | 7358 |
7453 while (bl != NULL) | 7359 while (bl != NULL) |
7454 { | 7360 { |
7461 /* | 7367 /* |
7462 * Allocate the root of a word tree. | 7368 * Allocate the root of a word tree. |
7463 * Returns NULL when out of memory. | 7369 * Returns NULL when out of memory. |
7464 */ | 7370 */ |
7465 static wordnode_T * | 7371 static wordnode_T * |
7466 wordtree_alloc(spin) | 7372 wordtree_alloc(spellinfo_T *spin) |
7467 spellinfo_T *spin; | |
7468 { | 7373 { |
7469 return (wordnode_T *)getroom(spin, sizeof(wordnode_T), TRUE); | 7374 return (wordnode_T *)getroom(spin, sizeof(wordnode_T), TRUE); |
7470 } | 7375 } |
7471 | 7376 |
7472 /* | 7377 /* |
7477 * For a keep-case word also store it in the keep-case tree. | 7382 * For a keep-case word also store it in the keep-case tree. |
7478 * When "pfxlist" is not NULL store the word for each postponed prefix ID and | 7383 * When "pfxlist" is not NULL store the word for each postponed prefix ID and |
7479 * compound flag. | 7384 * compound flag. |
7480 */ | 7385 */ |
7481 static int | 7386 static int |
7482 store_word(spin, word, flags, region, pfxlist, need_affix) | 7387 store_word( |
7483 spellinfo_T *spin; | 7388 spellinfo_T *spin, |
7484 char_u *word; | 7389 char_u *word, |
7485 int flags; /* extra flags, WF_BANNED */ | 7390 int flags, /* extra flags, WF_BANNED */ |
7486 int region; /* supported region(s) */ | 7391 int region, /* supported region(s) */ |
7487 char_u *pfxlist; /* list of prefix IDs or NULL */ | 7392 char_u *pfxlist, /* list of prefix IDs or NULL */ |
7488 int need_affix; /* only store word with affix ID */ | 7393 int need_affix) /* only store word with affix ID */ |
7489 { | 7394 { |
7490 int len = (int)STRLEN(word); | 7395 int len = (int)STRLEN(word); |
7491 int ct = captype(word, word + len); | 7396 int ct = captype(word, word + len); |
7492 char_u foldword[MAXWLEN]; | 7397 char_u foldword[MAXWLEN]; |
7493 int res = OK; | 7398 int res = OK; |
7524 * When "flags" < 0 we are adding to the prefix tree where "flags" is used for | 7429 * When "flags" < 0 we are adding to the prefix tree where "flags" is used for |
7525 * "rare" and "region" is the condition nr. | 7430 * "rare" and "region" is the condition nr. |
7526 * Returns FAIL when out of memory. | 7431 * Returns FAIL when out of memory. |
7527 */ | 7432 */ |
7528 static int | 7433 static int |
7529 tree_add_word(spin, word, root, flags, region, affixID) | 7434 tree_add_word( |
7530 spellinfo_T *spin; | 7435 spellinfo_T *spin, |
7531 char_u *word; | 7436 char_u *word, |
7532 wordnode_T *root; | 7437 wordnode_T *root, |
7533 int flags; | 7438 int flags, |
7534 int region; | 7439 int region, |
7535 int affixID; | 7440 int affixID) |
7536 { | 7441 { |
7537 wordnode_T *node = root; | 7442 wordnode_T *node = root; |
7538 wordnode_T *np; | 7443 wordnode_T *np; |
7539 wordnode_T *copyp, **copyprev; | 7444 wordnode_T *copyp, **copyprev; |
7540 wordnode_T **prev = NULL; | 7445 wordnode_T **prev = NULL; |
7704 /* | 7609 /* |
7705 * Check the 'mkspellmem' option. Return FAIL if it's wrong. | 7610 * Check the 'mkspellmem' option. Return FAIL if it's wrong. |
7706 * Sets "sps_flags". | 7611 * Sets "sps_flags". |
7707 */ | 7612 */ |
7708 int | 7613 int |
7709 spell_check_msm() | 7614 spell_check_msm(void) |
7710 { | 7615 { |
7711 char_u *p = p_msm; | 7616 char_u *p = p_msm; |
7712 long start = 0; | 7617 long start = 0; |
7713 long incr = 0; | 7618 long incr = 0; |
7714 long added = 0; | 7619 long added = 0; |
7746 * Get a wordnode_T, either from the list of previously freed nodes or | 7651 * Get a wordnode_T, either from the list of previously freed nodes or |
7747 * allocate a new one. | 7652 * allocate a new one. |
7748 * Returns NULL when out of memory. | 7653 * Returns NULL when out of memory. |
7749 */ | 7654 */ |
7750 static wordnode_T * | 7655 static wordnode_T * |
7751 get_wordnode(spin) | 7656 get_wordnode(spellinfo_T *spin) |
7752 spellinfo_T *spin; | |
7753 { | 7657 { |
7754 wordnode_T *n; | 7658 wordnode_T *n; |
7755 | 7659 |
7756 if (spin->si_first_free == NULL) | 7660 if (spin->si_first_free == NULL) |
7757 n = (wordnode_T *)getroom(spin, sizeof(wordnode_T), TRUE); | 7661 n = (wordnode_T *)getroom(spin, sizeof(wordnode_T), TRUE); |
7774 * siblings). If the reference count becomes zero free the node and its | 7678 * siblings). If the reference count becomes zero free the node and its |
7775 * siblings. | 7679 * siblings. |
7776 * Returns the number of nodes actually freed. | 7680 * Returns the number of nodes actually freed. |
7777 */ | 7681 */ |
7778 static int | 7682 static int |
7779 deref_wordnode(spin, node) | 7683 deref_wordnode(spellinfo_T *spin, wordnode_T *node) |
7780 spellinfo_T *spin; | |
7781 wordnode_T *node; | |
7782 { | 7684 { |
7783 wordnode_T *np; | 7685 wordnode_T *np; |
7784 int cnt = 0; | 7686 int cnt = 0; |
7785 | 7687 |
7786 if (--node->wn_refs == 0) | 7688 if (--node->wn_refs == 0) |
7800 /* | 7702 /* |
7801 * Free a wordnode_T for re-use later. | 7703 * Free a wordnode_T for re-use later. |
7802 * Only the "wn_child" field becomes invalid. | 7704 * Only the "wn_child" field becomes invalid. |
7803 */ | 7705 */ |
7804 static void | 7706 static void |
7805 free_wordnode(spin, n) | 7707 free_wordnode(spellinfo_T *spin, wordnode_T *n) |
7806 spellinfo_T *spin; | |
7807 wordnode_T *n; | |
7808 { | 7708 { |
7809 n->wn_child = spin->si_first_free; | 7709 n->wn_child = spin->si_first_free; |
7810 spin->si_first_free = n; | 7710 spin->si_first_free = n; |
7811 ++spin->si_free_count; | 7711 ++spin->si_free_count; |
7812 } | 7712 } |
7813 | 7713 |
7814 /* | 7714 /* |
7815 * Compress a tree: find tails that are identical and can be shared. | 7715 * Compress a tree: find tails that are identical and can be shared. |
7816 */ | 7716 */ |
7817 static void | 7717 static void |
7818 wordtree_compress(spin, root) | 7718 wordtree_compress(spellinfo_T *spin, wordnode_T *root) |
7819 spellinfo_T *spin; | |
7820 wordnode_T *root; | |
7821 { | 7719 { |
7822 hashtab_T ht; | 7720 hashtab_T ht; |
7823 int n; | 7721 int n; |
7824 int tot = 0; | 7722 int tot = 0; |
7825 int perc; | 7723 int perc; |
7856 /* | 7754 /* |
7857 * Compress a node, its siblings and its children, depth first. | 7755 * Compress a node, its siblings and its children, depth first. |
7858 * Returns the number of compressed nodes. | 7756 * Returns the number of compressed nodes. |
7859 */ | 7757 */ |
7860 static int | 7758 static int |
7861 node_compress(spin, node, ht, tot) | 7759 node_compress( |
7862 spellinfo_T *spin; | 7760 spellinfo_T *spin, |
7863 wordnode_T *node; | 7761 wordnode_T *node, |
7864 hashtab_T *ht; | 7762 hashtab_T *ht, |
7865 int *tot; /* total count of nodes before compressing, | 7763 int *tot) /* total count of nodes before compressing, |
7866 incremented while going through the tree */ | 7764 incremented while going through the tree */ |
7867 { | 7765 { |
7868 wordnode_T *np; | 7766 wordnode_T *np; |
7869 wordnode_T *tp; | 7767 wordnode_T *tp; |
7870 wordnode_T *child; | 7768 wordnode_T *child; |
7962 | 7860 |
7963 /* | 7861 /* |
7964 * Return TRUE when two nodes have identical siblings and children. | 7862 * Return TRUE when two nodes have identical siblings and children. |
7965 */ | 7863 */ |
7966 static int | 7864 static int |
7967 node_equal(n1, n2) | 7865 node_equal(wordnode_T *n1, wordnode_T *n2) |
7968 wordnode_T *n1; | |
7969 wordnode_T *n2; | |
7970 { | 7866 { |
7971 wordnode_T *p1; | 7867 wordnode_T *p1; |
7972 wordnode_T *p2; | 7868 wordnode_T *p2; |
7973 | 7869 |
7974 for (p1 = n1, p2 = n2; p1 != NULL && p2 != NULL; | 7870 for (p1 = n1, p2 = n2; p1 != NULL && p2 != NULL; |
7995 */ | 7891 */ |
7996 static int | 7892 static int |
7997 #ifdef __BORLANDC__ | 7893 #ifdef __BORLANDC__ |
7998 _RTLENTRYF | 7894 _RTLENTRYF |
7999 #endif | 7895 #endif |
8000 rep_compare(s1, s2) | 7896 rep_compare(const void *s1, const void *s2) |
8001 const void *s1; | |
8002 const void *s2; | |
8003 { | 7897 { |
8004 fromto_T *p1 = (fromto_T *)s1; | 7898 fromto_T *p1 = (fromto_T *)s1; |
8005 fromto_T *p2 = (fromto_T *)s2; | 7899 fromto_T *p2 = (fromto_T *)s2; |
8006 | 7900 |
8007 return STRCMP(p1->ft_from, p2->ft_from); | 7901 return STRCMP(p1->ft_from, p2->ft_from); |
8010 /* | 7904 /* |
8011 * Write the Vim .spl file "fname". | 7905 * Write the Vim .spl file "fname". |
8012 * Return FAIL or OK; | 7906 * Return FAIL or OK; |
8013 */ | 7907 */ |
8014 static int | 7908 static int |
8015 write_vim_spell(spin, fname) | 7909 write_vim_spell(spellinfo_T *spin, char_u *fname) |
8016 spellinfo_T *spin; | |
8017 char_u *fname; | |
8018 { | 7910 { |
8019 FILE *fd; | 7911 FILE *fd; |
8020 int regionmask; | 7912 int regionmask; |
8021 int round; | 7913 int round; |
8022 wordnode_T *tree; | 7914 wordnode_T *tree; |
8432 * Clear the index and wnode fields of "node", it siblings and its | 8324 * Clear the index and wnode fields of "node", it siblings and its |
8433 * children. This is needed because they are a union with other items to save | 8325 * children. This is needed because they are a union with other items to save |
8434 * space. | 8326 * space. |
8435 */ | 8327 */ |
8436 static void | 8328 static void |
8437 clear_node(node) | 8329 clear_node(wordnode_T *node) |
8438 wordnode_T *node; | |
8439 { | 8330 { |
8440 wordnode_T *np; | 8331 wordnode_T *np; |
8441 | 8332 |
8442 if (node != NULL) | 8333 if (node != NULL) |
8443 for (np = node; np != NULL; np = np->wn_sibling) | 8334 for (np = node; np != NULL; np = np->wn_sibling) |
8462 * in the file). | 8353 * in the file). |
8463 * | 8354 * |
8464 * Returns the number of nodes used. | 8355 * Returns the number of nodes used. |
8465 */ | 8356 */ |
8466 static int | 8357 static int |
8467 put_node(fd, node, idx, regionmask, prefixtree) | 8358 put_node( |
8468 FILE *fd; /* NULL when only counting */ | 8359 FILE *fd, /* NULL when only counting */ |
8469 wordnode_T *node; | 8360 wordnode_T *node, |
8470 int idx; | 8361 int idx, |
8471 int regionmask; | 8362 int regionmask, |
8472 int prefixtree; /* TRUE for PREFIXTREE */ | 8363 int prefixtree) /* TRUE for PREFIXTREE */ |
8473 { | 8364 { |
8474 int newindex = idx; | 8365 int newindex = idx; |
8475 int siblingcount = 0; | 8366 int siblingcount = 0; |
8476 wordnode_T *np; | 8367 wordnode_T *np; |
8477 int flags; | 8368 int flags; |
8592 /* | 8483 /* |
8593 * ":mkspell [-ascii] outfile infile ..." | 8484 * ":mkspell [-ascii] outfile infile ..." |
8594 * ":mkspell [-ascii] addfile" | 8485 * ":mkspell [-ascii] addfile" |
8595 */ | 8486 */ |
8596 void | 8487 void |
8597 ex_mkspell(eap) | 8488 ex_mkspell(exarg_T *eap) |
8598 exarg_T *eap; | |
8599 { | 8489 { |
8600 int fcount; | 8490 int fcount; |
8601 char_u **fnames; | 8491 char_u **fnames; |
8602 char_u *arg = eap->arg; | 8492 char_u *arg = eap->arg; |
8603 int ascii = FALSE; | 8493 int ascii = FALSE; |
8620 * Create the .sug file. | 8510 * Create the .sug file. |
8621 * Uses the soundfold info in "spin". | 8511 * Uses the soundfold info in "spin". |
8622 * Writes the file with the name "wfname", with ".spl" changed to ".sug". | 8512 * Writes the file with the name "wfname", with ".spl" changed to ".sug". |
8623 */ | 8513 */ |
8624 static void | 8514 static void |
8625 spell_make_sugfile(spin, wfname) | 8515 spell_make_sugfile(spellinfo_T *spin, char_u *wfname) |
8626 spellinfo_T *spin; | |
8627 char_u *wfname; | |
8628 { | 8516 { |
8629 char_u *fname = NULL; | 8517 char_u *fname = NULL; |
8630 int len; | 8518 int len; |
8631 slang_T *slang; | 8519 slang_T *slang; |
8632 int free_slang = FALSE; | 8520 int free_slang = FALSE; |
8709 | 8597 |
8710 /* | 8598 /* |
8711 * Build the soundfold trie for language "slang". | 8599 * Build the soundfold trie for language "slang". |
8712 */ | 8600 */ |
8713 static int | 8601 static int |
8714 sug_filltree(spin, slang) | 8602 sug_filltree(spellinfo_T *spin, slang_T *slang) |
8715 spellinfo_T *spin; | |
8716 slang_T *slang; | |
8717 { | 8603 { |
8718 char_u *byts; | 8604 char_u *byts; |
8719 idx_T *idxs; | 8605 idx_T *idxs; |
8720 int depth; | 8606 int depth; |
8721 idx_T arridx[MAXWLEN]; | 8607 idx_T arridx[MAXWLEN]; |
8817 * This is not unlike lines in a file, thus use a memfile to be able to access | 8703 * This is not unlike lines in a file, thus use a memfile to be able to access |
8818 * the table efficiently. | 8704 * the table efficiently. |
8819 * Returns FAIL when out of memory. | 8705 * Returns FAIL when out of memory. |
8820 */ | 8706 */ |
8821 static int | 8707 static int |
8822 sug_maketable(spin) | 8708 sug_maketable(spellinfo_T *spin) |
8823 spellinfo_T *spin; | |
8824 { | 8709 { |
8825 garray_T ga; | 8710 garray_T ga; |
8826 int res = OK; | 8711 int res = OK; |
8827 | 8712 |
8828 /* Allocate a buffer, open a memline for it and create the swap file | 8713 /* Allocate a buffer, open a memline for it and create the swap file |
8847 * Fill the table for one node and its children. | 8732 * Fill the table for one node and its children. |
8848 * Returns the wordnr at the start of the node. | 8733 * Returns the wordnr at the start of the node. |
8849 * Returns -1 when out of memory. | 8734 * Returns -1 when out of memory. |
8850 */ | 8735 */ |
8851 static int | 8736 static int |
8852 sug_filltable(spin, node, startwordnr, gap) | 8737 sug_filltable( |
8853 spellinfo_T *spin; | 8738 spellinfo_T *spin, |
8854 wordnode_T *node; | 8739 wordnode_T *node, |
8855 int startwordnr; | 8740 int startwordnr, |
8856 garray_T *gap; /* place to store line of numbers */ | 8741 garray_T *gap) /* place to store line of numbers */ |
8857 { | 8742 { |
8858 wordnode_T *p, *np; | 8743 wordnode_T *p, *np; |
8859 int wordnr = startwordnr; | 8744 int wordnr = startwordnr; |
8860 int nr; | 8745 int nr; |
8861 int prev_nr; | 8746 int prev_nr; |
8914 * Convert an offset into a minimal number of bytes. | 8799 * Convert an offset into a minimal number of bytes. |
8915 * Similar to utf_char2byters, but use 8 bits in followup bytes and avoid NUL | 8800 * Similar to utf_char2byters, but use 8 bits in followup bytes and avoid NUL |
8916 * bytes. | 8801 * bytes. |
8917 */ | 8802 */ |
8918 static int | 8803 static int |
8919 offset2bytes(nr, buf) | 8804 offset2bytes(int nr, char_u *buf) |
8920 int nr; | |
8921 char_u *buf; | |
8922 { | 8805 { |
8923 int rem; | 8806 int rem; |
8924 int b1, b2, b3, b4; | 8807 int b1, b2, b3, b4; |
8925 | 8808 |
8926 /* Split the number in parts of base 255. We need to avoid NUL bytes. */ | 8809 /* Split the number in parts of base 255. We need to avoid NUL bytes. */ |
8961 * Opposite of offset2bytes(). | 8844 * Opposite of offset2bytes(). |
8962 * "pp" points to the bytes and is advanced over it. | 8845 * "pp" points to the bytes and is advanced over it. |
8963 * Returns the offset. | 8846 * Returns the offset. |
8964 */ | 8847 */ |
8965 static int | 8848 static int |
8966 bytes2offset(pp) | 8849 bytes2offset(char_u **pp) |
8967 char_u **pp; | |
8968 { | 8850 { |
8969 char_u *p = *pp; | 8851 char_u *p = *pp; |
8970 int nr; | 8852 int nr; |
8971 int c; | 8853 int c; |
8972 | 8854 |
9000 | 8882 |
9001 /* | 8883 /* |
9002 * Write the .sug file in "fname". | 8884 * Write the .sug file in "fname". |
9003 */ | 8885 */ |
9004 static void | 8886 static void |
9005 sug_write(spin, fname) | 8887 sug_write(spellinfo_T *spin, char_u *fname) |
9006 spellinfo_T *spin; | |
9007 char_u *fname; | |
9008 { | 8888 { |
9009 FILE *fd; | 8889 FILE *fd; |
9010 wordnode_T *tree; | 8890 wordnode_T *tree; |
9011 int nodecount; | 8891 int nodecount; |
9012 int wcount; | 8892 int wcount; |
9099 * Most other fields are invalid! Esp. watch out for string options being | 8979 * Most other fields are invalid! Esp. watch out for string options being |
9100 * NULL and there is no undo info. | 8980 * NULL and there is no undo info. |
9101 * Returns NULL when out of memory. | 8981 * Returns NULL when out of memory. |
9102 */ | 8982 */ |
9103 static buf_T * | 8983 static buf_T * |
9104 open_spellbuf() | 8984 open_spellbuf(void) |
9105 { | 8985 { |
9106 buf_T *buf; | 8986 buf_T *buf; |
9107 | 8987 |
9108 buf = (buf_T *)alloc_clear(sizeof(buf_T)); | 8988 buf = (buf_T *)alloc_clear(sizeof(buf_T)); |
9109 if (buf != NULL) | 8989 if (buf != NULL) |
9121 | 9001 |
9122 /* | 9002 /* |
9123 * Close the buffer used for spell info. | 9003 * Close the buffer used for spell info. |
9124 */ | 9004 */ |
9125 static void | 9005 static void |
9126 close_spellbuf(buf) | 9006 close_spellbuf(buf_T *buf) |
9127 buf_T *buf; | |
9128 { | 9007 { |
9129 if (buf != NULL) | 9008 if (buf != NULL) |
9130 { | 9009 { |
9131 ml_close(buf, TRUE); | 9010 ml_close(buf, TRUE); |
9132 vim_free(buf); | 9011 vim_free(buf); |
9140 * "fnames[fcount - 1]" is the last input file name. | 9019 * "fnames[fcount - 1]" is the last input file name. |
9141 * Exception: when "fnames[0]" ends in ".add" it's used as the input file name | 9020 * Exception: when "fnames[0]" ends in ".add" it's used as the input file name |
9142 * and ".spl" is appended to make the output file name. | 9021 * and ".spl" is appended to make the output file name. |
9143 */ | 9022 */ |
9144 static void | 9023 static void |
9145 mkspell(fcount, fnames, ascii, over_write, added_word) | 9024 mkspell( |
9146 int fcount; | 9025 int fcount, |
9147 char_u **fnames; | 9026 char_u **fnames, |
9148 int ascii; /* -ascii argument given */ | 9027 int ascii, /* -ascii argument given */ |
9149 int over_write; /* overwrite existing output file */ | 9028 int over_write, /* overwrite existing output file */ |
9150 int added_word; /* invoked through "zg" */ | 9029 int added_word) /* invoked through "zg" */ |
9151 { | 9030 { |
9152 char_u *fname = NULL; | 9031 char_u *fname = NULL; |
9153 char_u *wfname; | 9032 char_u *wfname; |
9154 char_u **innames; | 9033 char_u **innames; |
9155 int incount; | 9034 int incount; |
9400 /* | 9279 /* |
9401 * Display a message for spell file processing when 'verbose' is set or using | 9280 * Display a message for spell file processing when 'verbose' is set or using |
9402 * ":mkspell". "str" can be IObuff. | 9281 * ":mkspell". "str" can be IObuff. |
9403 */ | 9282 */ |
9404 static void | 9283 static void |
9405 spell_message(spin, str) | 9284 spell_message(spellinfo_T *spin, char_u *str) |
9406 spellinfo_T *spin; | |
9407 char_u *str; | |
9408 { | 9285 { |
9409 if (spin->si_verbose || p_verbose > 2) | 9286 if (spin->si_verbose || p_verbose > 2) |
9410 { | 9287 { |
9411 if (!spin->si_verbose) | 9288 if (!spin->si_verbose) |
9412 verbose_enter(); | 9289 verbose_enter(); |
9421 * ":[count]spellgood {word}" | 9298 * ":[count]spellgood {word}" |
9422 * ":[count]spellwrong {word}" | 9299 * ":[count]spellwrong {word}" |
9423 * ":[count]spellundo {word}" | 9300 * ":[count]spellundo {word}" |
9424 */ | 9301 */ |
9425 void | 9302 void |
9426 ex_spell(eap) | 9303 ex_spell(exarg_T *eap) |
9427 exarg_T *eap; | |
9428 { | 9304 { |
9429 spell_add_word(eap->arg, (int)STRLEN(eap->arg), eap->cmdidx == CMD_spellwrong, | 9305 spell_add_word(eap->arg, (int)STRLEN(eap->arg), eap->cmdidx == CMD_spellwrong, |
9430 eap->forceit ? 0 : (int)eap->line2, | 9306 eap->forceit ? 0 : (int)eap->line2, |
9431 eap->cmdidx == CMD_spellundo); | 9307 eap->cmdidx == CMD_spellundo); |
9432 } | 9308 } |
9433 | 9309 |
9434 /* | 9310 /* |
9435 * Add "word[len]" to 'spellfile' as a good or bad word. | 9311 * Add "word[len]" to 'spellfile' as a good or bad word. |
9436 */ | 9312 */ |
9437 void | 9313 void |
9438 spell_add_word(word, len, bad, idx, undo) | 9314 spell_add_word( |
9439 char_u *word; | 9315 char_u *word, |
9440 int len; | 9316 int len, |
9441 int bad; | 9317 int bad, |
9442 int idx; /* "zG" and "zW": zero, otherwise index in | 9318 int idx, /* "zG" and "zW": zero, otherwise index in |
9443 'spellfile' */ | 9319 'spellfile' */ |
9444 int undo; /* TRUE for "zug", "zuG", "zuw" and "zuW" */ | 9320 int undo) /* TRUE for "zug", "zuG", "zuw" and "zuW" */ |
9445 { | 9321 { |
9446 FILE *fd = NULL; | 9322 FILE *fd = NULL; |
9447 buf_T *buf = NULL; | 9323 buf_T *buf = NULL; |
9448 int new_spf = FALSE; | 9324 int new_spf = FALSE; |
9449 char_u *fname; | 9325 char_u *fname; |
9602 | 9478 |
9603 /* | 9479 /* |
9604 * Initialize 'spellfile' for the current buffer. | 9480 * Initialize 'spellfile' for the current buffer. |
9605 */ | 9481 */ |
9606 static void | 9482 static void |
9607 init_spellfile() | 9483 init_spellfile(void) |
9608 { | 9484 { |
9609 char_u *buf; | 9485 char_u *buf; |
9610 int l; | 9486 int l; |
9611 char_u *fname; | 9487 char_u *fname; |
9612 char_u *rtp; | 9488 char_u *rtp; |
9683 /* | 9559 /* |
9684 * Init the chartab used for spelling for ASCII. | 9560 * Init the chartab used for spelling for ASCII. |
9685 * EBCDIC is not supported! | 9561 * EBCDIC is not supported! |
9686 */ | 9562 */ |
9687 static void | 9563 static void |
9688 clear_spell_chartab(sp) | 9564 clear_spell_chartab(spelltab_T *sp) |
9689 spelltab_T *sp; | |
9690 { | 9565 { |
9691 int i; | 9566 int i; |
9692 | 9567 |
9693 /* Init everything to FALSE. */ | 9568 /* Init everything to FALSE. */ |
9694 vim_memset(sp->st_isw, FALSE, sizeof(sp->st_isw)); | 9569 vim_memset(sp->st_isw, FALSE, sizeof(sp->st_isw)); |
9722 * The default is to use isalpha(), but the spell file should define the word | 9597 * The default is to use isalpha(), but the spell file should define the word |
9723 * characters to make it possible that 'encoding' differs from the current | 9598 * characters to make it possible that 'encoding' differs from the current |
9724 * locale. For utf-8 we don't use isalpha() but our own functions. | 9599 * locale. For utf-8 we don't use isalpha() but our own functions. |
9725 */ | 9600 */ |
9726 void | 9601 void |
9727 init_spell_chartab() | 9602 init_spell_chartab(void) |
9728 { | 9603 { |
9729 int i; | 9604 int i; |
9730 | 9605 |
9731 did_set_spelltab = FALSE; | 9606 did_set_spelltab = FALSE; |
9732 clear_spell_chartab(&spelltab); | 9607 clear_spell_chartab(&spelltab); |
9777 | 9652 |
9778 /* | 9653 /* |
9779 * Set the spell character tables from strings in the affix file. | 9654 * Set the spell character tables from strings in the affix file. |
9780 */ | 9655 */ |
9781 static int | 9656 static int |
9782 set_spell_chartab(fol, low, upp) | 9657 set_spell_chartab(char_u *fol, char_u *low, char_u *upp) |
9783 char_u *fol; | |
9784 char_u *low; | |
9785 char_u *upp; | |
9786 { | 9658 { |
9787 /* We build the new tables here first, so that we can compare with the | 9659 /* We build the new tables here first, so that we can compare with the |
9788 * previous one. */ | 9660 * previous one. */ |
9789 spelltab_T new_st; | 9661 spelltab_T new_st; |
9790 char_u *pf = fol, *pl = low, *pu = upp; | 9662 char_u *pf = fol, *pl = low, *pu = upp; |
9855 | 9727 |
9856 /* | 9728 /* |
9857 * Set the spell character tables from strings in the .spl file. | 9729 * Set the spell character tables from strings in the .spl file. |
9858 */ | 9730 */ |
9859 static void | 9731 static void |
9860 set_spell_charflags(flags, cnt, fol) | 9732 set_spell_charflags( |
9861 char_u *flags; | 9733 char_u *flags, |
9862 int cnt; /* length of "flags" */ | 9734 int cnt, /* length of "flags" */ |
9863 char_u *fol; | 9735 char_u *fol) |
9864 { | 9736 { |
9865 /* We build the new tables here first, so that we can compare with the | 9737 /* We build the new tables here first, so that we can compare with the |
9866 * previous one. */ | 9738 * previous one. */ |
9867 spelltab_T new_st; | 9739 spelltab_T new_st; |
9868 int i; | 9740 int i; |
9894 | 9766 |
9895 (void)set_spell_finish(&new_st); | 9767 (void)set_spell_finish(&new_st); |
9896 } | 9768 } |
9897 | 9769 |
9898 static int | 9770 static int |
9899 set_spell_finish(new_st) | 9771 set_spell_finish(spelltab_T *new_st) |
9900 spelltab_T *new_st; | |
9901 { | 9772 { |
9902 int i; | 9773 int i; |
9903 | 9774 |
9904 if (did_set_spelltab) | 9775 if (did_set_spelltab) |
9905 { | 9776 { |
9931 * As a special case we see "midword" characters as word character when it is | 9802 * As a special case we see "midword" characters as word character when it is |
9932 * followed by a word character. This finds they'there but not 'they there'. | 9803 * followed by a word character. This finds they'there but not 'they there'. |
9933 * Thus this only works properly when past the first character of the word. | 9804 * Thus this only works properly when past the first character of the word. |
9934 */ | 9805 */ |
9935 static int | 9806 static int |
9936 spell_iswordp(p, wp) | 9807 spell_iswordp( |
9937 char_u *p; | 9808 char_u *p, |
9938 win_T *wp; /* buffer used */ | 9809 win_T *wp) /* buffer used */ |
9939 { | 9810 { |
9940 #ifdef FEAT_MBYTE | 9811 #ifdef FEAT_MBYTE |
9941 char_u *s; | 9812 char_u *s; |
9942 int l; | 9813 int l; |
9943 int c; | 9814 int c; |
9974 /* | 9845 /* |
9975 * Return TRUE if "p" points to a word character. | 9846 * Return TRUE if "p" points to a word character. |
9976 * Unlike spell_iswordp() this doesn't check for "midword" characters. | 9847 * Unlike spell_iswordp() this doesn't check for "midword" characters. |
9977 */ | 9848 */ |
9978 static int | 9849 static int |
9979 spell_iswordp_nmw(p, wp) | 9850 spell_iswordp_nmw(char_u *p, win_T *wp) |
9980 char_u *p; | |
9981 win_T *wp; | |
9982 { | 9851 { |
9983 #ifdef FEAT_MBYTE | 9852 #ifdef FEAT_MBYTE |
9984 int c; | 9853 int c; |
9985 | 9854 |
9986 if (has_mbyte) | 9855 if (has_mbyte) |
10000 * Only for characters above 255. | 9869 * Only for characters above 255. |
10001 * Unicode subscript and superscript are not considered word characters. | 9870 * Unicode subscript and superscript are not considered word characters. |
10002 * See also dbcs_class() and utf_class() in mbyte.c. | 9871 * See also dbcs_class() and utf_class() in mbyte.c. |
10003 */ | 9872 */ |
10004 static int | 9873 static int |
10005 spell_mb_isword_class(cl, wp) | 9874 spell_mb_isword_class(int cl, win_T *wp) |
10006 int cl; | |
10007 win_T *wp; | |
10008 { | 9875 { |
10009 if (wp->w_s->b_cjk) | 9876 if (wp->w_s->b_cjk) |
10010 /* East Asian characters are not considered word characters. */ | 9877 /* East Asian characters are not considered word characters. */ |
10011 return cl == 2 || cl == 0x2800; | 9878 return cl == 2 || cl == 0x2800; |
10012 return cl >= 2 && cl != 0x2070 && cl != 0x2080; | 9879 return cl >= 2 && cl != 0x2070 && cl != 0x2080; |
10015 /* | 9882 /* |
10016 * Return TRUE if "p" points to a word character. | 9883 * Return TRUE if "p" points to a word character. |
10017 * Wide version of spell_iswordp(). | 9884 * Wide version of spell_iswordp(). |
10018 */ | 9885 */ |
10019 static int | 9886 static int |
10020 spell_iswordp_w(p, wp) | 9887 spell_iswordp_w(int *p, win_T *wp) |
10021 int *p; | |
10022 win_T *wp; | |
10023 { | 9888 { |
10024 int *s; | 9889 int *s; |
10025 | 9890 |
10026 if (*p < 256 ? wp->w_s->b_spell_ismw[*p] | 9891 if (*p < 256 ? wp->w_s->b_spell_ismw[*p] |
10027 : (wp->w_s->b_spell_ismw_mb != NULL | 9892 : (wp->w_s->b_spell_ismw_mb != NULL |
10046 /* | 9911 /* |
10047 * Write the table with prefix conditions to the .spl file. | 9912 * Write the table with prefix conditions to the .spl file. |
10048 * When "fd" is NULL only count the length of what is written. | 9913 * When "fd" is NULL only count the length of what is written. |
10049 */ | 9914 */ |
10050 static int | 9915 static int |
10051 write_spell_prefcond(fd, gap) | 9916 write_spell_prefcond(FILE *fd, garray_T *gap) |
10052 FILE *fd; | |
10053 garray_T *gap; | |
10054 { | 9917 { |
10055 int i; | 9918 int i; |
10056 char_u *p; | 9919 char_u *p; |
10057 int len; | 9920 int len; |
10058 int totlen; | 9921 int totlen; |
10089 * Uses the character definitions from the .spl file. | 9952 * Uses the character definitions from the .spl file. |
10090 * When using a multi-byte 'encoding' the length may change! | 9953 * When using a multi-byte 'encoding' the length may change! |
10091 * Returns FAIL when something wrong. | 9954 * Returns FAIL when something wrong. |
10092 */ | 9955 */ |
10093 static int | 9956 static int |
10094 spell_casefold(str, len, buf, buflen) | 9957 spell_casefold( |
10095 char_u *str; | 9958 char_u *str, |
10096 int len; | 9959 int len, |
10097 char_u *buf; | 9960 char_u *buf, |
10098 int buflen; | 9961 int buflen) |
10099 { | 9962 { |
10100 int i; | 9963 int i; |
10101 | 9964 |
10102 if (len >= buflen) | 9965 if (len >= buflen) |
10103 { | 9966 { |
10148 /* | 10011 /* |
10149 * Check the 'spellsuggest' option. Return FAIL if it's wrong. | 10012 * Check the 'spellsuggest' option. Return FAIL if it's wrong. |
10150 * Sets "sps_flags" and "sps_limit". | 10013 * Sets "sps_flags" and "sps_limit". |
10151 */ | 10014 */ |
10152 int | 10015 int |
10153 spell_check_sps() | 10016 spell_check_sps(void) |
10154 { | 10017 { |
10155 char_u *p; | 10018 char_u *p; |
10156 char_u *s; | 10019 char_u *s; |
10157 char_u buf[MAXPATHL]; | 10020 char_u buf[MAXPATHL]; |
10158 int f; | 10021 int f; |
10203 * Give suggestions for the properly spelled word. | 10066 * Give suggestions for the properly spelled word. |
10204 * In Visual mode use the highlighted word as the bad word. | 10067 * In Visual mode use the highlighted word as the bad word. |
10205 * When "count" is non-zero use that suggestion. | 10068 * When "count" is non-zero use that suggestion. |
10206 */ | 10069 */ |
10207 void | 10070 void |
10208 spell_suggest(count) | 10071 spell_suggest(int count) |
10209 int count; | |
10210 { | 10072 { |
10211 char_u *line; | 10073 char_u *line; |
10212 pos_T prev_cursor = curwin->w_cursor; | 10074 pos_T prev_cursor = curwin->w_cursor; |
10213 char_u wcopy[MAXWLEN + 2]; | 10075 char_u wcopy[MAXWLEN + 2]; |
10214 char_u *p; | 10076 char_u *p; |
10446 /* | 10308 /* |
10447 * Check if the word at line "lnum" column "col" is required to start with a | 10309 * Check if the word at line "lnum" column "col" is required to start with a |
10448 * capital. This uses 'spellcapcheck' of the current buffer. | 10310 * capital. This uses 'spellcapcheck' of the current buffer. |
10449 */ | 10311 */ |
10450 static int | 10312 static int |
10451 check_need_cap(lnum, col) | 10313 check_need_cap(linenr_T lnum, colnr_T col) |
10452 linenr_T lnum; | |
10453 colnr_T col; | |
10454 { | 10314 { |
10455 int need_cap = FALSE; | 10315 int need_cap = FALSE; |
10456 char_u *line; | 10316 char_u *line; |
10457 char_u *line_copy = NULL; | 10317 char_u *line_copy = NULL; |
10458 char_u *p; | 10318 char_u *p; |
10516 | 10376 |
10517 /* | 10377 /* |
10518 * ":spellrepall" | 10378 * ":spellrepall" |
10519 */ | 10379 */ |
10520 void | 10380 void |
10521 ex_spellrepall(eap) | 10381 ex_spellrepall(exarg_T *eap UNUSED) |
10522 exarg_T *eap UNUSED; | |
10523 { | 10382 { |
10524 pos_T pos = curwin->w_cursor; | 10383 pos_T pos = curwin->w_cursor; |
10525 char_u *frompat; | 10384 char_u *frompat; |
10526 int addlen; | 10385 int addlen; |
10527 char_u *line; | 10386 char_u *line; |
10589 /* | 10448 /* |
10590 * Find spell suggestions for "word". Return them in the growarray "*gap" as | 10449 * Find spell suggestions for "word". Return them in the growarray "*gap" as |
10591 * a list of allocated strings. | 10450 * a list of allocated strings. |
10592 */ | 10451 */ |
10593 void | 10452 void |
10594 spell_suggest_list(gap, word, maxcount, need_cap, interactive) | 10453 spell_suggest_list( |
10595 garray_T *gap; | 10454 garray_T *gap, |
10596 char_u *word; | 10455 char_u *word, |
10597 int maxcount; /* maximum nr of suggestions */ | 10456 int maxcount, /* maximum nr of suggestions */ |
10598 int need_cap; /* 'spellcapcheck' matched */ | 10457 int need_cap, /* 'spellcapcheck' matched */ |
10599 int interactive; | 10458 int interactive) |
10600 { | 10459 { |
10601 suginfo_T sug; | 10460 suginfo_T sug; |
10602 int i; | 10461 int i; |
10603 suggest_T *stp; | 10462 suggest_T *stp; |
10604 char_u *wcopy; | 10463 char_u *wcopy; |
10634 * The maximum number of suggestions is "maxcount". | 10493 * The maximum number of suggestions is "maxcount". |
10635 * Note: does use info for the current window. | 10494 * Note: does use info for the current window. |
10636 * This is based on the mechanisms of Aspell, but completely reimplemented. | 10495 * This is based on the mechanisms of Aspell, but completely reimplemented. |
10637 */ | 10496 */ |
10638 static void | 10497 static void |
10639 spell_find_suggest(badptr, badlen, su, maxcount, banbadword, need_cap, interactive) | 10498 spell_find_suggest( |
10640 char_u *badptr; | 10499 char_u *badptr, |
10641 int badlen; /* length of bad word or 0 if unknown */ | 10500 int badlen, /* length of bad word or 0 if unknown */ |
10642 suginfo_T *su; | 10501 suginfo_T *su, |
10643 int maxcount; | 10502 int maxcount, |
10644 int banbadword; /* don't include badword in suggestions */ | 10503 int banbadword, /* don't include badword in suggestions */ |
10645 int need_cap; /* word should start with capital */ | 10504 int need_cap, /* word should start with capital */ |
10646 int interactive; | 10505 int interactive) |
10647 { | 10506 { |
10648 hlf_T attr = HLF_COUNT; | 10507 hlf_T attr = HLF_COUNT; |
10649 char_u buf[MAXPATHL]; | 10508 char_u buf[MAXPATHL]; |
10650 char_u *p; | 10509 char_u *p; |
10651 int do_combine = FALSE; | 10510 int do_combine = FALSE; |
10767 #ifdef FEAT_EVAL | 10626 #ifdef FEAT_EVAL |
10768 /* | 10627 /* |
10769 * Find suggestions by evaluating expression "expr". | 10628 * Find suggestions by evaluating expression "expr". |
10770 */ | 10629 */ |
10771 static void | 10630 static void |
10772 spell_suggest_expr(su, expr) | 10631 spell_suggest_expr(suginfo_T *su, char_u *expr) |
10773 suginfo_T *su; | |
10774 char_u *expr; | |
10775 { | 10632 { |
10776 list_T *list; | 10633 list_T *list; |
10777 listitem_T *li; | 10634 listitem_T *li; |
10778 int score; | 10635 int score; |
10779 char_u *p; | 10636 char_u *p; |
10805 | 10662 |
10806 /* | 10663 /* |
10807 * Find suggestions in file "fname". Used for "file:" in 'spellsuggest'. | 10664 * Find suggestions in file "fname". Used for "file:" in 'spellsuggest'. |
10808 */ | 10665 */ |
10809 static void | 10666 static void |
10810 spell_suggest_file(su, fname) | 10667 spell_suggest_file(suginfo_T *su, char_u *fname) |
10811 suginfo_T *su; | |
10812 char_u *fname; | |
10813 { | 10668 { |
10814 FILE *fd; | 10669 FILE *fd; |
10815 char_u line[MAXWLEN * 2]; | 10670 char_u line[MAXWLEN * 2]; |
10816 char_u *p; | 10671 char_u *p; |
10817 int len; | 10672 int len; |
10863 | 10718 |
10864 /* | 10719 /* |
10865 * Find suggestions for the internal method indicated by "sps_flags". | 10720 * Find suggestions for the internal method indicated by "sps_flags". |
10866 */ | 10721 */ |
10867 static void | 10722 static void |
10868 spell_suggest_intern(su, interactive) | 10723 spell_suggest_intern(suginfo_T *su, int interactive) |
10869 suginfo_T *su; | |
10870 int interactive; | |
10871 { | 10724 { |
10872 /* | 10725 /* |
10873 * Load the .sug file(s) that are available and not done yet. | 10726 * Load the .sug file(s) that are available and not done yet. |
10874 */ | 10727 */ |
10875 suggest_load_files(); | 10728 suggest_load_files(); |
10957 | 10810 |
10958 /* | 10811 /* |
10959 * Load the .sug files for languages that have one and weren't loaded yet. | 10812 * Load the .sug files for languages that have one and weren't loaded yet. |
10960 */ | 10813 */ |
10961 static void | 10814 static void |
10962 suggest_load_files() | 10815 suggest_load_files(void) |
10963 { | 10816 { |
10964 langp_T *lp; | 10817 langp_T *lp; |
10965 int lpi; | 10818 int lpi; |
10966 slang_T *slang; | 10819 slang_T *slang; |
10967 char_u *dotp; | 10820 char_u *dotp; |
11098 /* | 10951 /* |
11099 * Fill in the wordcount fields for a trie. | 10952 * Fill in the wordcount fields for a trie. |
11100 * Returns the total number of words. | 10953 * Returns the total number of words. |
11101 */ | 10954 */ |
11102 static void | 10955 static void |
11103 tree_count_words(byts, idxs) | 10956 tree_count_words(char_u *byts, idx_T *idxs) |
11104 char_u *byts; | |
11105 idx_T *idxs; | |
11106 { | 10957 { |
11107 int depth; | 10958 int depth; |
11108 idx_T arridx[MAXWLEN]; | 10959 idx_T arridx[MAXWLEN]; |
11109 int curi[MAXWLEN]; | 10960 int curi[MAXWLEN]; |
11110 int c; | 10961 int c; |
11161 | 11012 |
11162 /* | 11013 /* |
11163 * Free the info put in "*su" by spell_find_suggest(). | 11014 * Free the info put in "*su" by spell_find_suggest(). |
11164 */ | 11015 */ |
11165 static void | 11016 static void |
11166 spell_find_cleanup(su) | 11017 spell_find_cleanup(suginfo_T *su) |
11167 suginfo_T *su; | |
11168 { | 11018 { |
11169 int i; | 11019 int i; |
11170 | 11020 |
11171 /* Free the suggestions. */ | 11021 /* Free the suggestions. */ |
11172 for (i = 0; i < su->su_ga.ga_len; ++i) | 11022 for (i = 0; i < su->su_ga.ga_len; ++i) |
11184 * Make a copy of "word", with the first letter upper or lower cased, to | 11034 * Make a copy of "word", with the first letter upper or lower cased, to |
11185 * "wcopy[MAXWLEN]". "word" must not be empty. | 11035 * "wcopy[MAXWLEN]". "word" must not be empty. |
11186 * The result is NUL terminated. | 11036 * The result is NUL terminated. |
11187 */ | 11037 */ |
11188 static void | 11038 static void |
11189 onecap_copy(word, wcopy, upper) | 11039 onecap_copy( |
11190 char_u *word; | 11040 char_u *word, |
11191 char_u *wcopy; | 11041 char_u *wcopy, |
11192 int upper; /* TRUE: first letter made upper case */ | 11042 int upper) /* TRUE: first letter made upper case */ |
11193 { | 11043 { |
11194 char_u *p; | 11044 char_u *p; |
11195 int c; | 11045 int c; |
11196 int l; | 11046 int l; |
11197 | 11047 |
11221 /* | 11071 /* |
11222 * Make a copy of "word" with all the letters upper cased into | 11072 * Make a copy of "word" with all the letters upper cased into |
11223 * "wcopy[MAXWLEN]". The result is NUL terminated. | 11073 * "wcopy[MAXWLEN]". The result is NUL terminated. |
11224 */ | 11074 */ |
11225 static void | 11075 static void |
11226 allcap_copy(word, wcopy) | 11076 allcap_copy(char_u *word, char_u *wcopy) |
11227 char_u *word; | |
11228 char_u *wcopy; | |
11229 { | 11077 { |
11230 char_u *s; | 11078 char_u *s; |
11231 char_u *d; | 11079 char_u *d; |
11232 int c; | 11080 int c; |
11233 | 11081 |
11275 | 11123 |
11276 /* | 11124 /* |
11277 * Try finding suggestions by recognizing specific situations. | 11125 * Try finding suggestions by recognizing specific situations. |
11278 */ | 11126 */ |
11279 static void | 11127 static void |
11280 suggest_try_special(su) | 11128 suggest_try_special(suginfo_T *su) |
11281 suginfo_T *su; | |
11282 { | 11129 { |
11283 char_u *p; | 11130 char_u *p; |
11284 size_t len; | 11131 size_t len; |
11285 int c; | 11132 int c; |
11286 char_u word[MAXWLEN]; | 11133 char_u word[MAXWLEN]; |
11359 | 11206 |
11360 /* | 11207 /* |
11361 * Try finding suggestions by adding/removing/swapping letters. | 11208 * Try finding suggestions by adding/removing/swapping letters. |
11362 */ | 11209 */ |
11363 static void | 11210 static void |
11364 suggest_try_change(su) | 11211 suggest_try_change(suginfo_T *su) |
11365 suginfo_T *su; | |
11366 { | 11212 { |
11367 char_u fword[MAXWLEN]; /* copy of the bad word, case-folded */ | 11213 char_u fword[MAXWLEN]; /* copy of the bad word, case-folded */ |
11368 int n; | 11214 int n; |
11369 char_u *p; | 11215 char_u *p; |
11370 int lpi; | 11216 int lpi; |
11432 * word splitting for now | 11278 * word splitting for now |
11433 * "similar_chars()" | 11279 * "similar_chars()" |
11434 * use "slang->sl_repsal" instead of "lp->lp_replang->sl_rep" | 11280 * use "slang->sl_repsal" instead of "lp->lp_replang->sl_rep" |
11435 */ | 11281 */ |
11436 static void | 11282 static void |
11437 suggest_trie_walk(su, lp, fword, soundfold) | 11283 suggest_trie_walk( |
11438 suginfo_T *su; | 11284 suginfo_T *su, |
11439 langp_T *lp; | 11285 langp_T *lp, |
11440 char_u *fword; | 11286 char_u *fword, |
11441 int soundfold; | 11287 int soundfold) |
11442 { | 11288 { |
11443 char_u tword[MAXWLEN]; /* good word collected so far */ | 11289 char_u tword[MAXWLEN]; /* good word collected so far */ |
11444 trystate_T stack[MAXWLEN]; | 11290 trystate_T stack[MAXWLEN]; |
11445 char_u preword[MAXWLEN * 3]; /* word found with proper case; | 11291 char_u preword[MAXWLEN * 3]; /* word found with proper case; |
11446 * concatenation of prefix compound | 11292 * concatenation of prefix compound |
12932 | 12778 |
12933 /* | 12779 /* |
12934 * Go one level deeper in the tree. | 12780 * Go one level deeper in the tree. |
12935 */ | 12781 */ |
12936 static void | 12782 static void |
12937 go_deeper(stack, depth, score_add) | 12783 go_deeper(trystate_T *stack, int depth, int score_add) |
12938 trystate_T *stack; | |
12939 int depth; | |
12940 int score_add; | |
12941 { | 12784 { |
12942 stack[depth + 1] = stack[depth]; | 12785 stack[depth + 1] = stack[depth]; |
12943 stack[depth + 1].ts_state = STATE_START; | 12786 stack[depth + 1].ts_state = STATE_START; |
12944 stack[depth + 1].ts_score = stack[depth].ts_score + score_add; | 12787 stack[depth + 1].ts_score = stack[depth].ts_score + score_add; |
12945 stack[depth + 1].ts_curi = 1; /* start just after length byte */ | 12788 stack[depth + 1].ts_curi = 1; /* start just after length byte */ |
12950 /* | 12793 /* |
12951 * Case-folding may change the number of bytes: Count nr of chars in | 12794 * Case-folding may change the number of bytes: Count nr of chars in |
12952 * fword[flen] and return the byte length of that many chars in "word". | 12795 * fword[flen] and return the byte length of that many chars in "word". |
12953 */ | 12796 */ |
12954 static int | 12797 static int |
12955 nofold_len(fword, flen, word) | 12798 nofold_len(char_u *fword, int flen, char_u *word) |
12956 char_u *fword; | |
12957 int flen; | |
12958 char_u *word; | |
12959 { | 12799 { |
12960 char_u *p; | 12800 char_u *p; |
12961 int i = 0; | 12801 int i = 0; |
12962 | 12802 |
12963 for (p = fword; p < fword + flen; mb_ptr_adv(p)) | 12803 for (p = fword; p < fword + flen; mb_ptr_adv(p)) |
12973 * words and put it in "kword". | 12813 * words and put it in "kword". |
12974 * Theoretically there could be several keep-case words that result in the | 12814 * Theoretically there could be several keep-case words that result in the |
12975 * same case-folded word, but we only find one... | 12815 * same case-folded word, but we only find one... |
12976 */ | 12816 */ |
12977 static void | 12817 static void |
12978 find_keepcap_word(slang, fword, kword) | 12818 find_keepcap_word(slang_T *slang, char_u *fword, char_u *kword) |
12979 slang_T *slang; | |
12980 char_u *fword; | |
12981 char_u *kword; | |
12982 { | 12819 { |
12983 char_u uword[MAXWLEN]; /* "fword" in upper-case */ | 12820 char_u uword[MAXWLEN]; /* "fword" in upper-case */ |
12984 int depth; | 12821 int depth; |
12985 idx_T tryidx; | 12822 idx_T tryidx; |
12986 | 12823 |
13132 /* | 12969 /* |
13133 * Compute the sound-a-like score for suggestions in su->su_ga and add them to | 12970 * Compute the sound-a-like score for suggestions in su->su_ga and add them to |
13134 * su->su_sga. | 12971 * su->su_sga. |
13135 */ | 12972 */ |
13136 static void | 12973 static void |
13137 score_comp_sal(su) | 12974 score_comp_sal(suginfo_T *su) |
13138 suginfo_T *su; | |
13139 { | 12975 { |
13140 langp_T *lp; | 12976 langp_T *lp; |
13141 char_u badsound[MAXWLEN]; | 12977 char_u badsound[MAXWLEN]; |
13142 int i; | 12978 int i; |
13143 suggest_T *stp; | 12979 suggest_T *stp; |
13187 /* | 13023 /* |
13188 * Combine the list of suggestions in su->su_ga and su->su_sga. | 13024 * Combine the list of suggestions in su->su_ga and su->su_sga. |
13189 * They are entwined. | 13025 * They are entwined. |
13190 */ | 13026 */ |
13191 static void | 13027 static void |
13192 score_combine(su) | 13028 score_combine(suginfo_T *su) |
13193 suginfo_T *su; | |
13194 { | 13029 { |
13195 int i; | 13030 int i; |
13196 int j; | 13031 int j; |
13197 garray_T ga; | 13032 garray_T ga; |
13198 garray_T *gap; | 13033 garray_T *gap; |
13300 /* | 13135 /* |
13301 * For the goodword in "stp" compute the soundalike score compared to the | 13136 * For the goodword in "stp" compute the soundalike score compared to the |
13302 * badword. | 13137 * badword. |
13303 */ | 13138 */ |
13304 static int | 13139 static int |
13305 stp_sal_score(stp, su, slang, badsound) | 13140 stp_sal_score( |
13306 suggest_T *stp; | 13141 suggest_T *stp, |
13307 suginfo_T *su; | 13142 suginfo_T *su, |
13308 slang_T *slang; | 13143 slang_T *slang, |
13309 char_u *badsound; /* sound-folded badword */ | 13144 char_u *badsound) /* sound-folded badword */ |
13310 { | 13145 { |
13311 char_u *p; | 13146 char_u *p; |
13312 char_u *pbad; | 13147 char_u *pbad; |
13313 char_u *pgood; | 13148 char_u *pgood; |
13314 char_u badsound2[MAXWLEN]; | 13149 char_u badsound2[MAXWLEN]; |
13370 | 13205 |
13371 /* | 13206 /* |
13372 * Prepare for calling suggest_try_soundalike(). | 13207 * Prepare for calling suggest_try_soundalike(). |
13373 */ | 13208 */ |
13374 static void | 13209 static void |
13375 suggest_try_soundalike_prep() | 13210 suggest_try_soundalike_prep(void) |
13376 { | 13211 { |
13377 langp_T *lp; | 13212 langp_T *lp; |
13378 int lpi; | 13213 int lpi; |
13379 slang_T *slang; | 13214 slang_T *slang; |
13380 | 13215 |
13393 /* | 13228 /* |
13394 * Find suggestions by comparing the word in a sound-a-like form. | 13229 * Find suggestions by comparing the word in a sound-a-like form. |
13395 * Note: This doesn't support postponed prefixes. | 13230 * Note: This doesn't support postponed prefixes. |
13396 */ | 13231 */ |
13397 static void | 13232 static void |
13398 suggest_try_soundalike(su) | 13233 suggest_try_soundalike(suginfo_T *su) |
13399 suginfo_T *su; | |
13400 { | 13234 { |
13401 char_u salword[MAXWLEN]; | 13235 char_u salword[MAXWLEN]; |
13402 langp_T *lp; | 13236 langp_T *lp; |
13403 int lpi; | 13237 int lpi; |
13404 slang_T *slang; | 13238 slang_T *slang; |
13430 | 13264 |
13431 /* | 13265 /* |
13432 * Finish up after calling suggest_try_soundalike(). | 13266 * Finish up after calling suggest_try_soundalike(). |
13433 */ | 13267 */ |
13434 static void | 13268 static void |
13435 suggest_try_soundalike_finish() | 13269 suggest_try_soundalike_finish(void) |
13436 { | 13270 { |
13437 langp_T *lp; | 13271 langp_T *lp; |
13438 int lpi; | 13272 int lpi; |
13439 slang_T *slang; | 13273 slang_T *slang; |
13440 int todo; | 13274 int todo; |
13467 /* | 13301 /* |
13468 * A match with a soundfolded word is found. Add the good word(s) that | 13302 * A match with a soundfolded word is found. Add the good word(s) that |
13469 * produce this soundfolded word. | 13303 * produce this soundfolded word. |
13470 */ | 13304 */ |
13471 static void | 13305 static void |
13472 add_sound_suggest(su, goodword, score, lp) | 13306 add_sound_suggest( |
13473 suginfo_T *su; | 13307 suginfo_T *su, |
13474 char_u *goodword; | 13308 char_u *goodword, |
13475 int score; /* soundfold score */ | 13309 int score, /* soundfold score */ |
13476 langp_T *lp; | 13310 langp_T *lp) |
13477 { | 13311 { |
13478 slang_T *slang = lp->lp_slang; /* language for sound folding */ | 13312 slang_T *slang = lp->lp_slang; /* language for sound folding */ |
13479 int sfwordnr; | 13313 int sfwordnr; |
13480 char_u *nrline; | 13314 char_u *nrline; |
13481 int orgnr; | 13315 int orgnr; |
13675 | 13509 |
13676 /* | 13510 /* |
13677 * Find word "word" in fold-case tree for "slang" and return the word number. | 13511 * Find word "word" in fold-case tree for "slang" and return the word number. |
13678 */ | 13512 */ |
13679 static int | 13513 static int |
13680 soundfold_find(slang, word) | 13514 soundfold_find(slang_T *slang, char_u *word) |
13681 slang_T *slang; | |
13682 char_u *word; | |
13683 { | 13515 { |
13684 idx_T arridx = 0; | 13516 idx_T arridx = 0; |
13685 int len; | 13517 int len; |
13686 int wlen = 0; | 13518 int wlen = 0; |
13687 int c; | 13519 int c; |
13751 | 13583 |
13752 /* | 13584 /* |
13753 * Copy "fword" to "cword", fixing case according to "flags". | 13585 * Copy "fword" to "cword", fixing case according to "flags". |
13754 */ | 13586 */ |
13755 static void | 13587 static void |
13756 make_case_word(fword, cword, flags) | 13588 make_case_word(char_u *fword, char_u *cword, int flags) |
13757 char_u *fword; | |
13758 char_u *cword; | |
13759 int flags; | |
13760 { | 13589 { |
13761 if (flags & WF_ALLCAP) | 13590 if (flags & WF_ALLCAP) |
13762 /* Make it all upper-case */ | 13591 /* Make it all upper-case */ |
13763 allcap_copy(fword, cword); | 13592 allcap_copy(fword, cword); |
13764 else if (flags & WF_ONECAP) | 13593 else if (flags & WF_ONECAP) |
13771 | 13600 |
13772 /* | 13601 /* |
13773 * Use map string "map" for languages "lp". | 13602 * Use map string "map" for languages "lp". |
13774 */ | 13603 */ |
13775 static void | 13604 static void |
13776 set_map_str(lp, map) | 13605 set_map_str(slang_T *lp, char_u *map) |
13777 slang_T *lp; | |
13778 char_u *map; | |
13779 { | 13606 { |
13780 char_u *p; | 13607 char_u *p; |
13781 int headc = 0; | 13608 int headc = 0; |
13782 int c; | 13609 int c; |
13783 int i; | 13610 int i; |
13856 /* | 13683 /* |
13857 * Return TRUE if "c1" and "c2" are similar characters according to the MAP | 13684 * Return TRUE if "c1" and "c2" are similar characters according to the MAP |
13858 * lines in the .aff file. | 13685 * lines in the .aff file. |
13859 */ | 13686 */ |
13860 static int | 13687 static int |
13861 similar_chars(slang, c1, c2) | 13688 similar_chars(slang_T *slang, int c1, int c2) |
13862 slang_T *slang; | |
13863 int c1; | |
13864 int c2; | |
13865 { | 13689 { |
13866 int m1, m2; | 13690 int m1, m2; |
13867 #ifdef FEAT_MBYTE | 13691 #ifdef FEAT_MBYTE |
13868 char_u buf[MB_MAXBYTES + 1]; | 13692 char_u buf[MB_MAXBYTES + 1]; |
13869 hashitem_T *hi; | 13693 hashitem_T *hi; |
13904 /* | 13728 /* |
13905 * Add a suggestion to the list of suggestions. | 13729 * Add a suggestion to the list of suggestions. |
13906 * For a suggestion that is already in the list the lowest score is remembered. | 13730 * For a suggestion that is already in the list the lowest score is remembered. |
13907 */ | 13731 */ |
13908 static void | 13732 static void |
13909 add_suggestion(su, gap, goodword, badlenarg, score, altscore, had_bonus, | 13733 add_suggestion( |
13910 slang, maxsf) | 13734 suginfo_T *su, |
13911 suginfo_T *su; | 13735 garray_T *gap, /* either su_ga or su_sga */ |
13912 garray_T *gap; /* either su_ga or su_sga */ | 13736 char_u *goodword, |
13913 char_u *goodword; | 13737 int badlenarg, /* len of bad word replaced with "goodword" */ |
13914 int badlenarg; /* len of bad word replaced with "goodword" */ | 13738 int score, |
13915 int score; | 13739 int altscore, |
13916 int altscore; | 13740 int had_bonus, /* value for st_had_bonus */ |
13917 int had_bonus; /* value for st_had_bonus */ | 13741 slang_T *slang, /* language for sound folding */ |
13918 slang_T *slang; /* language for sound folding */ | 13742 int maxsf) /* su_maxscore applies to soundfold score, |
13919 int maxsf; /* su_maxscore applies to soundfold score, | |
13920 su_sfmaxscore to the total score. */ | 13743 su_sfmaxscore to the total score. */ |
13921 { | 13744 { |
13922 int goodlen; /* len of goodword changed */ | 13745 int goodlen; /* len of goodword changed */ |
13923 int badlen; /* len of bad word changed */ | 13746 int badlen; /* len of bad word changed */ |
13924 suggest_T *stp; | 13747 suggest_T *stp; |
14041 /* | 13864 /* |
14042 * Suggestions may in fact be flagged as errors. Esp. for banned words and | 13865 * Suggestions may in fact be flagged as errors. Esp. for banned words and |
14043 * for split words, such as "the the". Remove these from the list here. | 13866 * for split words, such as "the the". Remove these from the list here. |
14044 */ | 13867 */ |
14045 static void | 13868 static void |
14046 check_suggestions(su, gap) | 13869 check_suggestions( |
14047 suginfo_T *su; | 13870 suginfo_T *su, |
14048 garray_T *gap; /* either su_ga or su_sga */ | 13871 garray_T *gap) /* either su_ga or su_sga */ |
14049 { | 13872 { |
14050 suggest_T *stp; | 13873 suggest_T *stp; |
14051 int i; | 13874 int i; |
14052 char_u longword[MAXWLEN + 1]; | 13875 char_u longword[MAXWLEN + 1]; |
14053 int len; | 13876 int len; |
14078 | 13901 |
14079 /* | 13902 /* |
14080 * Add a word to be banned. | 13903 * Add a word to be banned. |
14081 */ | 13904 */ |
14082 static void | 13905 static void |
14083 add_banned(su, word) | 13906 add_banned( |
14084 suginfo_T *su; | 13907 suginfo_T *su, |
14085 char_u *word; | 13908 char_u *word) |
14086 { | 13909 { |
14087 char_u *s; | 13910 char_u *s; |
14088 hash_T hash; | 13911 hash_T hash; |
14089 hashitem_T *hi; | 13912 hashitem_T *hi; |
14090 | 13913 |
14101 /* | 13924 /* |
14102 * Recompute the score for all suggestions if sound-folding is possible. This | 13925 * Recompute the score for all suggestions if sound-folding is possible. This |
14103 * is slow, thus only done for the final results. | 13926 * is slow, thus only done for the final results. |
14104 */ | 13927 */ |
14105 static void | 13928 static void |
14106 rescore_suggestions(su) | 13929 rescore_suggestions(suginfo_T *su) |
14107 suginfo_T *su; | |
14108 { | 13930 { |
14109 int i; | 13931 int i; |
14110 | 13932 |
14111 if (su->su_sallang != NULL) | 13933 if (su->su_sallang != NULL) |
14112 for (i = 0; i < su->su_ga.ga_len; ++i) | 13934 for (i = 0; i < su->su_ga.ga_len; ++i) |
14115 | 13937 |
14116 /* | 13938 /* |
14117 * Recompute the score for one suggestion if sound-folding is possible. | 13939 * Recompute the score for one suggestion if sound-folding is possible. |
14118 */ | 13940 */ |
14119 static void | 13941 static void |
14120 rescore_one(su, stp) | 13942 rescore_one(suginfo_T *su, suggest_T *stp) |
14121 suginfo_T *su; | |
14122 suggest_T *stp; | |
14123 { | 13943 { |
14124 slang_T *slang = stp->st_slang; | 13944 slang_T *slang = stp->st_slang; |
14125 char_u sal_badword[MAXWLEN]; | 13945 char_u sal_badword[MAXWLEN]; |
14126 char_u *p; | 13946 char_u *p; |
14127 | 13947 |
14157 */ | 13977 */ |
14158 static int | 13978 static int |
14159 #ifdef __BORLANDC__ | 13979 #ifdef __BORLANDC__ |
14160 _RTLENTRYF | 13980 _RTLENTRYF |
14161 #endif | 13981 #endif |
14162 sug_compare(s1, s2) | 13982 sug_compare(const void *s1, const void *s2) |
14163 const void *s1; | |
14164 const void *s2; | |
14165 { | 13983 { |
14166 suggest_T *p1 = (suggest_T *)s1; | 13984 suggest_T *p1 = (suggest_T *)s1; |
14167 suggest_T *p2 = (suggest_T *)s2; | 13985 suggest_T *p2 = (suggest_T *)s2; |
14168 int n = p1->st_score - p2->st_score; | 13986 int n = p1->st_score - p2->st_score; |
14169 | 13987 |
14181 * - Sort on score. | 13999 * - Sort on score. |
14182 * - Remove words that won't be displayed. | 14000 * - Remove words that won't be displayed. |
14183 * Returns the maximum score in the list or "maxscore" unmodified. | 14001 * Returns the maximum score in the list or "maxscore" unmodified. |
14184 */ | 14002 */ |
14185 static int | 14003 static int |
14186 cleanup_suggestions(gap, maxscore, keep) | 14004 cleanup_suggestions( |
14187 garray_T *gap; | 14005 garray_T *gap, |
14188 int maxscore; | 14006 int maxscore, |
14189 int keep; /* nr of suggestions to keep */ | 14007 int keep) /* nr of suggestions to keep */ |
14190 { | 14008 { |
14191 suggest_T *stp = &SUG(*gap, 0); | 14009 suggest_T *stp = &SUG(*gap, 0); |
14192 int i; | 14010 int i; |
14193 | 14011 |
14194 /* Sort the list. */ | 14012 /* Sort the list. */ |
14209 /* | 14027 /* |
14210 * Soundfold a string, for soundfold(). | 14028 * Soundfold a string, for soundfold(). |
14211 * Result is in allocated memory, NULL for an error. | 14029 * Result is in allocated memory, NULL for an error. |
14212 */ | 14030 */ |
14213 char_u * | 14031 char_u * |
14214 eval_soundfold(word) | 14032 eval_soundfold(char_u *word) |
14215 char_u *word; | |
14216 { | 14033 { |
14217 langp_T *lp; | 14034 langp_T *lp; |
14218 char_u sound[MAXWLEN]; | 14035 char_u sound[MAXWLEN]; |
14219 int lpi; | 14036 int lpi; |
14220 | 14037 |
14247 * We support two methods: | 14064 * We support two methods: |
14248 * 1. SOFOFROM/SOFOTO do a simple character mapping. | 14065 * 1. SOFOFROM/SOFOTO do a simple character mapping. |
14249 * 2. SAL items define a more advanced sound-folding (and much slower). | 14066 * 2. SAL items define a more advanced sound-folding (and much slower). |
14250 */ | 14067 */ |
14251 static void | 14068 static void |
14252 spell_soundfold(slang, inword, folded, res) | 14069 spell_soundfold( |
14253 slang_T *slang; | 14070 slang_T *slang, |
14254 char_u *inword; | 14071 char_u *inword, |
14255 int folded; /* "inword" is already case-folded */ | 14072 int folded, /* "inword" is already case-folded */ |
14256 char_u *res; | 14073 char_u *res) |
14257 { | 14074 { |
14258 char_u fword[MAXWLEN]; | 14075 char_u fword[MAXWLEN]; |
14259 char_u *word; | 14076 char_u *word; |
14260 | 14077 |
14261 if (slang->sl_sofo) | 14078 if (slang->sl_sofo) |
14284 /* | 14101 /* |
14285 * Perform sound folding of "inword" into "res" according to SOFOFROM and | 14102 * Perform sound folding of "inword" into "res" according to SOFOFROM and |
14286 * SOFOTO lines. | 14103 * SOFOTO lines. |
14287 */ | 14104 */ |
14288 static void | 14105 static void |
14289 spell_soundfold_sofo(slang, inword, res) | 14106 spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res) |
14290 slang_T *slang; | |
14291 char_u *inword; | |
14292 char_u *res; | |
14293 { | 14107 { |
14294 char_u *s; | 14108 char_u *s; |
14295 int ri = 0; | 14109 int ri = 0; |
14296 int c; | 14110 int c; |
14297 | 14111 |
14358 | 14172 |
14359 res[ri] = NUL; | 14173 res[ri] = NUL; |
14360 } | 14174 } |
14361 | 14175 |
14362 static void | 14176 static void |
14363 spell_soundfold_sal(slang, inword, res) | 14177 spell_soundfold_sal(slang_T *slang, char_u *inword, char_u *res) |
14364 slang_T *slang; | |
14365 char_u *inword; | |
14366 char_u *res; | |
14367 { | 14178 { |
14368 salitem_T *smp; | 14179 salitem_T *smp; |
14369 char_u word[MAXWLEN]; | 14180 char_u word[MAXWLEN]; |
14370 char_u *s = inword; | 14181 char_u *s = inword; |
14371 char_u *t; | 14182 char_u *t; |
14639 /* | 14450 /* |
14640 * Turn "inword" into its sound-a-like equivalent in "res[MAXWLEN]". | 14451 * Turn "inword" into its sound-a-like equivalent in "res[MAXWLEN]". |
14641 * Multi-byte version of spell_soundfold(). | 14452 * Multi-byte version of spell_soundfold(). |
14642 */ | 14453 */ |
14643 static void | 14454 static void |
14644 spell_soundfold_wsal(slang, inword, res) | 14455 spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) |
14645 slang_T *slang; | |
14646 char_u *inword; | |
14647 char_u *res; | |
14648 { | 14456 { |
14649 salitem_T *smp = (salitem_T *)slang->sl_sal.ga_data; | 14457 salitem_T *smp = (salitem_T *)slang->sl_sal.ga_data; |
14650 int word[MAXWLEN]; | 14458 int word[MAXWLEN]; |
14651 int wres[MAXWLEN]; | 14459 int wres[MAXWLEN]; |
14652 int l; | 14460 int l; |
14958 * This permits up to two inserts/deletes/swaps/etc. to keep things fast. | 14766 * This permits up to two inserts/deletes/swaps/etc. to keep things fast. |
14959 * Instead of a generic loop we write out the code. That keeps it fast by | 14767 * Instead of a generic loop we write out the code. That keeps it fast by |
14960 * avoiding checks that will not be possible. | 14768 * avoiding checks that will not be possible. |
14961 */ | 14769 */ |
14962 static int | 14770 static int |
14963 soundalike_score(goodstart, badstart) | 14771 soundalike_score( |
14964 char_u *goodstart; /* sound-folded good word */ | 14772 char_u *goodstart, /* sound-folded good word */ |
14965 char_u *badstart; /* sound-folded bad word */ | 14773 char_u *badstart) /* sound-folded bad word */ |
14966 { | 14774 { |
14967 char_u *goodsound = goodstart; | 14775 char_u *goodsound = goodstart; |
14968 char_u *badsound = badstart; | 14776 char_u *badsound = badstart; |
14969 int goodlen; | 14777 int goodlen; |
14970 int badlen; | 14778 int badlen; |
15193 * The implementation of the algorithm comes from Aspell editdist.cpp, | 15001 * The implementation of the algorithm comes from Aspell editdist.cpp, |
15194 * edit_distance(). It has been converted from C++ to C and modified to | 15002 * edit_distance(). It has been converted from C++ to C and modified to |
15195 * support multi-byte characters. | 15003 * support multi-byte characters. |
15196 */ | 15004 */ |
15197 static int | 15005 static int |
15198 spell_edit_score(slang, badword, goodword) | 15006 spell_edit_score( |
15199 slang_T *slang; | 15007 slang_T *slang, |
15200 char_u *badword; | 15008 char_u *badword, |
15201 char_u *goodword; | 15009 char_u *goodword) |
15202 { | 15010 { |
15203 int *cnt; | 15011 int *cnt; |
15204 int badlen, goodlen; /* lengths including NUL */ | 15012 int badlen, goodlen; /* lengths including NUL */ |
15205 int j, i; | 15013 int j, i; |
15206 int t; | 15014 int t; |
15325 * This uses a stack for the edits still to be tried. | 15133 * This uses a stack for the edits still to be tried. |
15326 * The idea comes from Aspell leditdist.cpp. Rewritten in C and added support | 15134 * The idea comes from Aspell leditdist.cpp. Rewritten in C and added support |
15327 * for multi-byte characters. | 15135 * for multi-byte characters. |
15328 */ | 15136 */ |
15329 static int | 15137 static int |
15330 spell_edit_score_limit(slang, badword, goodword, limit) | 15138 spell_edit_score_limit( |
15331 slang_T *slang; | 15139 slang_T *slang, |
15332 char_u *badword; | 15140 char_u *badword, |
15333 char_u *goodword; | 15141 char_u *goodword, |
15334 int limit; | 15142 int limit) |
15335 { | 15143 { |
15336 limitscore_T stack[10]; /* allow for over 3 * 2 edits */ | 15144 limitscore_T stack[10]; /* allow for over 3 * 2 edits */ |
15337 int stackidx; | 15145 int stackidx; |
15338 int bi, gi; | 15146 int bi, gi; |
15339 int bi2, gi2; | 15147 int bi2, gi2; |
15507 /* | 15315 /* |
15508 * Multi-byte version of spell_edit_score_limit(). | 15316 * Multi-byte version of spell_edit_score_limit(). |
15509 * Keep it in sync with the above! | 15317 * Keep it in sync with the above! |
15510 */ | 15318 */ |
15511 static int | 15319 static int |
15512 spell_edit_score_limit_w(slang, badword, goodword, limit) | 15320 spell_edit_score_limit_w( |
15513 slang_T *slang; | 15321 slang_T *slang, |
15514 char_u *badword; | 15322 char_u *badword, |
15515 char_u *goodword; | 15323 char_u *goodword, |
15516 int limit; | 15324 int limit) |
15517 { | 15325 { |
15518 limitscore_T stack[10]; /* allow for over 3 * 2 edits */ | 15326 limitscore_T stack[10]; /* allow for over 3 * 2 edits */ |
15519 int stackidx; | 15327 int stackidx; |
15520 int bi, gi; | 15328 int bi, gi; |
15521 int bi2, gi2; | 15329 int bi2, gi2; |
15696 | 15504 |
15697 /* | 15505 /* |
15698 * ":spellinfo" | 15506 * ":spellinfo" |
15699 */ | 15507 */ |
15700 void | 15508 void |
15701 ex_spellinfo(eap) | 15509 ex_spellinfo(exarg_T *eap UNUSED) |
15702 exarg_T *eap UNUSED; | |
15703 { | 15510 { |
15704 int lpi; | 15511 int lpi; |
15705 langp_T *lp; | 15512 langp_T *lp; |
15706 char_u *p; | 15513 char_u *p; |
15707 | 15514 |
15733 | 15540 |
15734 /* | 15541 /* |
15735 * ":spelldump" | 15542 * ":spelldump" |
15736 */ | 15543 */ |
15737 void | 15544 void |
15738 ex_spelldump(eap) | 15545 ex_spelldump(exarg_T *eap) |
15739 exarg_T *eap; | |
15740 { | 15546 { |
15741 char_u *spl; | 15547 char_u *spl; |
15742 long dummy; | 15548 long dummy; |
15743 | 15549 |
15744 if (no_spell_checking(curwin)) | 15550 if (no_spell_checking(curwin)) |
15770 * 1. When "pat" is NULL: dump a list of all words in the current buffer. | 15576 * 1. When "pat" is NULL: dump a list of all words in the current buffer. |
15771 * "ic" and "dir" are not used. | 15577 * "ic" and "dir" are not used. |
15772 * 2. When "pat" is not NULL: add matching words to insert mode completion. | 15578 * 2. When "pat" is not NULL: add matching words to insert mode completion. |
15773 */ | 15579 */ |
15774 void | 15580 void |
15775 spell_dump_compl(pat, ic, dir, dumpflags_arg) | 15581 spell_dump_compl( |
15776 char_u *pat; /* leading part of the word */ | 15582 char_u *pat, /* leading part of the word */ |
15777 int ic; /* ignore case */ | 15583 int ic, /* ignore case */ |
15778 int *dir; /* direction for adding matches */ | 15584 int *dir, /* direction for adding matches */ |
15779 int dumpflags_arg; /* DUMPFLAG_* */ | 15585 int dumpflags_arg) /* DUMPFLAG_* */ |
15780 { | 15586 { |
15781 langp_T *lp; | 15587 langp_T *lp; |
15782 slang_T *slang; | 15588 slang_T *slang; |
15783 idx_T arridx[MAXWLEN]; | 15589 idx_T arridx[MAXWLEN]; |
15784 int curi[MAXWLEN]; | 15590 int curi[MAXWLEN]; |
15971 /* | 15777 /* |
15972 * Dump one word: apply case modifications and append a line to the buffer. | 15778 * Dump one word: apply case modifications and append a line to the buffer. |
15973 * When "lnum" is zero add insert mode completion. | 15779 * When "lnum" is zero add insert mode completion. |
15974 */ | 15780 */ |
15975 static void | 15781 static void |
15976 dump_word(slang, word, pat, dir, dumpflags, wordflags, lnum) | 15782 dump_word( |
15977 slang_T *slang; | 15783 slang_T *slang, |
15978 char_u *word; | 15784 char_u *word, |
15979 char_u *pat; | 15785 char_u *pat, |
15980 int *dir; | 15786 int *dir, |
15981 int dumpflags; | 15787 int dumpflags, |
15982 int wordflags; | 15788 int wordflags, |
15983 linenr_T lnum; | 15789 linenr_T lnum) |
15984 { | 15790 { |
15985 int keepcap = FALSE; | 15791 int keepcap = FALSE; |
15986 char_u *p; | 15792 char_u *p; |
15987 char_u *tw; | 15793 char_u *tw; |
15988 char_u cword[MAXWLEN]; | 15794 char_u cword[MAXWLEN]; |
16061 * "word" and append a line to the buffer. | 15867 * "word" and append a line to the buffer. |
16062 * When "lnum" is zero add insert mode completion. | 15868 * When "lnum" is zero add insert mode completion. |
16063 * Return the updated line number. | 15869 * Return the updated line number. |
16064 */ | 15870 */ |
16065 static linenr_T | 15871 static linenr_T |
16066 dump_prefixes(slang, word, pat, dir, dumpflags, flags, startlnum) | 15872 dump_prefixes( |
16067 slang_T *slang; | 15873 slang_T *slang, |
16068 char_u *word; /* case-folded word */ | 15874 char_u *word, /* case-folded word */ |
16069 char_u *pat; | 15875 char_u *pat, |
16070 int *dir; | 15876 int *dir, |
16071 int dumpflags; | 15877 int dumpflags, |
16072 int flags; /* flags with prefix ID */ | 15878 int flags, /* flags with prefix ID */ |
16073 linenr_T startlnum; | 15879 linenr_T startlnum) |
16074 { | 15880 { |
16075 idx_T arridx[MAXWLEN]; | 15881 idx_T arridx[MAXWLEN]; |
16076 int curi[MAXWLEN]; | 15882 int curi[MAXWLEN]; |
16077 char_u prefix[MAXWLEN]; | 15883 char_u prefix[MAXWLEN]; |
16078 char_u word_up[MAXWLEN]; | 15884 char_u word_up[MAXWLEN]; |
16177 /* | 15983 /* |
16178 * Move "p" to the end of word "start". | 15984 * Move "p" to the end of word "start". |
16179 * Uses the spell-checking word characters. | 15985 * Uses the spell-checking word characters. |
16180 */ | 15986 */ |
16181 char_u * | 15987 char_u * |
16182 spell_to_word_end(start, win) | 15988 spell_to_word_end(char_u *start, win_T *win) |
16183 char_u *start; | |
16184 win_T *win; | |
16185 { | 15989 { |
16186 char_u *p = start; | 15990 char_u *p = start; |
16187 | 15991 |
16188 while (*p != NUL && spell_iswordp(p, win)) | 15992 while (*p != NUL && spell_iswordp(p, win)) |
16189 mb_ptr_adv(p); | 15993 mb_ptr_adv(p); |
16197 * We don't check if it is badly spelled, with completion we can only change | 16001 * We don't check if it is badly spelled, with completion we can only change |
16198 * the word in front of the cursor. | 16002 * the word in front of the cursor. |
16199 * Returns the column number of the word. | 16003 * Returns the column number of the word. |
16200 */ | 16004 */ |
16201 int | 16005 int |
16202 spell_word_start(startcol) | 16006 spell_word_start(int startcol) |
16203 int startcol; | |
16204 { | 16007 { |
16205 char_u *line; | 16008 char_u *line; |
16206 char_u *p; | 16009 char_u *p; |
16207 int col = 0; | 16010 int col = 0; |
16208 | 16011 |
16236 * expand_spelling() is called. Therefore the ugly global variable. | 16039 * expand_spelling() is called. Therefore the ugly global variable. |
16237 */ | 16040 */ |
16238 static int spell_expand_need_cap; | 16041 static int spell_expand_need_cap; |
16239 | 16042 |
16240 void | 16043 void |
16241 spell_expand_check_cap(col) | 16044 spell_expand_check_cap(colnr_T col) |
16242 colnr_T col; | |
16243 { | 16045 { |
16244 spell_expand_need_cap = check_need_cap(curwin->w_cursor.lnum, col); | 16046 spell_expand_need_cap = check_need_cap(curwin->w_cursor.lnum, col); |
16245 } | 16047 } |
16246 | 16048 |
16247 /* | 16049 /* |
16249 * Used for Insert mode completion CTRL-X ?. | 16051 * Used for Insert mode completion CTRL-X ?. |
16250 * Returns the number of matches. The matches are in "matchp[]", array of | 16052 * Returns the number of matches. The matches are in "matchp[]", array of |
16251 * allocated strings. | 16053 * allocated strings. |
16252 */ | 16054 */ |
16253 int | 16055 int |
16254 expand_spelling(lnum, pat, matchp) | 16056 expand_spelling( |
16255 linenr_T lnum UNUSED; | 16057 linenr_T lnum UNUSED, |
16256 char_u *pat; | 16058 char_u *pat, |
16257 char_u ***matchp; | 16059 char_u ***matchp) |
16258 { | 16060 { |
16259 garray_T ga; | 16061 garray_T ga; |
16260 | 16062 |
16261 spell_suggest_list(&ga, pat, 100, spell_expand_need_cap, TRUE); | 16063 spell_suggest_list(&ga, pat, 100, spell_expand_need_cap, TRUE); |
16262 *matchp = ga.ga_data; | 16064 *matchp = ga.ga_data; |