Mercurial > vim
comparison src/spell.c @ 695:653eeb31bad6
updated for version 7.0210
author | vimboss |
---|---|
date | Tue, 28 Feb 2006 23:50:17 +0000 |
parents | 0e922220d322 |
children | e402b0af6083 |
comparison
equal
deleted
inserted
replaced
694:07d199fe02ed | 695:653eeb31bad6 |
---|---|
811 static void spell_load_lang __ARGS((char_u *lang)); | 811 static void spell_load_lang __ARGS((char_u *lang)); |
812 static char_u *spell_enc __ARGS((void)); | 812 static char_u *spell_enc __ARGS((void)); |
813 static void int_wordlist_spl __ARGS((char_u *fname)); | 813 static void int_wordlist_spl __ARGS((char_u *fname)); |
814 static void spell_load_cb __ARGS((char_u *fname, void *cookie)); | 814 static void spell_load_cb __ARGS((char_u *fname, void *cookie)); |
815 static slang_T *spell_load_file __ARGS((char_u *fname, char_u *lang, slang_T *old_lp, int silent)); | 815 static slang_T *spell_load_file __ARGS((char_u *fname, char_u *lang, slang_T *old_lp, int silent)); |
816 static int get2c __ARGS((FILE *fd)); | |
817 static int get3c __ARGS((FILE *fd)); | |
818 static int get4c __ARGS((FILE *fd)); | |
819 static time_t get8c __ARGS((FILE *fd)); | |
816 static char_u *read_cnt_string __ARGS((FILE *fd, int cnt_bytes, int *lenp)); | 820 static char_u *read_cnt_string __ARGS((FILE *fd, int cnt_bytes, int *lenp)); |
817 static char_u *read_string __ARGS((FILE *fd, int cnt)); | 821 static char_u *read_string __ARGS((FILE *fd, int cnt)); |
818 static int read_region_section __ARGS((FILE *fd, slang_T *slang, int len)); | 822 static int read_region_section __ARGS((FILE *fd, slang_T *slang, int len)); |
819 static int read_charflags_section __ARGS((FILE *fd)); | 823 static int read_charflags_section __ARGS((FILE *fd)); |
820 static int read_prefcond_section __ARGS((FILE *fd, slang_T *lp)); | 824 static int read_prefcond_section __ARGS((FILE *fd, slang_T *lp)); |
2600 { | 2604 { |
2601 n = getc(fd); /* <sectionID> or <sectionend> */ | 2605 n = getc(fd); /* <sectionID> or <sectionend> */ |
2602 if (n == SN_END) | 2606 if (n == SN_END) |
2603 break; | 2607 break; |
2604 c = getc(fd); /* <sectionflags> */ | 2608 c = getc(fd); /* <sectionflags> */ |
2605 len = (getc(fd) << 24) + (getc(fd) << 16) + (getc(fd) << 8) + getc(fd); | 2609 len = get4c(fd); /* <sectionlen> */ |
2606 /* <sectionlen> */ | |
2607 if (len < 0) | 2610 if (len < 0) |
2608 goto truncerr; | 2611 goto truncerr; |
2609 | 2612 |
2610 res = 0; | 2613 res = 0; |
2611 switch (n) | 2614 switch (n) |
2655 case SN_WORDS: | 2658 case SN_WORDS: |
2656 res = read_words_section(fd, lp, len); | 2659 res = read_words_section(fd, lp, len); |
2657 break; | 2660 break; |
2658 | 2661 |
2659 case SN_SUGFILE: | 2662 case SN_SUGFILE: |
2660 for (i = 7; i >= 0; --i) /* <timestamp> */ | 2663 lp->sl_sugtime = get8c(fd); /* <timestamp> */ |
2661 lp->sl_sugtime += getc(fd) << (i * 8); | |
2662 break; | 2664 break; |
2663 | 2665 |
2664 case SN_COMPOUND: | 2666 case SN_COMPOUND: |
2665 res = read_compound(fd, lp, len); | 2667 res = read_compound(fd, lp, len); |
2666 break; | 2668 break; |
2747 | 2749 |
2748 return lp; | 2750 return lp; |
2749 } | 2751 } |
2750 | 2752 |
2751 /* | 2753 /* |
2754 * Read 2 bytes from "fd" and turn them into an int, MSB first. | |
2755 */ | |
2756 static int | |
2757 get2c(fd) | |
2758 FILE *fd; | |
2759 { | |
2760 long n; | |
2761 | |
2762 n = getc(fd); | |
2763 n = (n << 8) + getc(fd); | |
2764 return n; | |
2765 } | |
2766 | |
2767 /* | |
2768 * Read 3 bytes from "fd" and turn them into an int, MSB first. | |
2769 */ | |
2770 static int | |
2771 get3c(fd) | |
2772 FILE *fd; | |
2773 { | |
2774 long n; | |
2775 | |
2776 n = getc(fd); | |
2777 n = (n << 8) + getc(fd); | |
2778 n = (n << 8) + getc(fd); | |
2779 return n; | |
2780 } | |
2781 | |
2782 /* | |
2783 * Read 4 bytes from "fd" and turn them into an int, MSB first. | |
2784 */ | |
2785 static int | |
2786 get4c(fd) | |
2787 FILE *fd; | |
2788 { | |
2789 long n; | |
2790 | |
2791 n = getc(fd); | |
2792 n = (n << 8) + getc(fd); | |
2793 n = (n << 8) + getc(fd); | |
2794 n = (n << 8) + getc(fd); | |
2795 return n; | |
2796 } | |
2797 | |
2798 /* | |
2799 * Read 8 bytes from "fd" and turn them into a time_t, MSB first. | |
2800 */ | |
2801 static time_t | |
2802 get8c(fd) | |
2803 FILE *fd; | |
2804 { | |
2805 time_t n = 0; | |
2806 int i; | |
2807 | |
2808 for (i = 0; i < 8; ++i) | |
2809 n = (n << 8) + getc(fd); | |
2810 return n; | |
2811 } | |
2812 | |
2813 /* | |
2752 * Read a length field from "fd" in "cnt_bytes" bytes. | 2814 * Read a length field from "fd" in "cnt_bytes" bytes. |
2753 * Allocate memory, read the string into it and add a NUL at the end. | 2815 * Allocate memory, read the string into it and add a NUL at the end. |
2754 * Returns NULL when the count is zero. | 2816 * Returns NULL when the count is zero. |
2755 * Sets "*cntp" to SP_*ERROR when there is an error, length of the result | 2817 * Sets "*cntp" to SP_*ERROR when there is an error, length of the result |
2756 * otherwise. | 2818 * otherwise. |
2880 int n; | 2942 int n; |
2881 char_u *p; | 2943 char_u *p; |
2882 char_u buf[MAXWLEN + 1]; | 2944 char_u buf[MAXWLEN + 1]; |
2883 | 2945 |
2884 /* <prefcondcnt> <prefcond> ... */ | 2946 /* <prefcondcnt> <prefcond> ... */ |
2885 cnt = (getc(fd) << 8) + getc(fd); /* <prefcondcnt> */ | 2947 cnt = get2c(fd); /* <prefcondcnt> */ |
2886 if (cnt <= 0) | 2948 if (cnt <= 0) |
2887 return SP_FORMERROR; | 2949 return SP_FORMERROR; |
2888 | 2950 |
2889 lp->sl_prefprog = (regprog_T **)alloc_clear( | 2951 lp->sl_prefprog = (regprog_T **)alloc_clear( |
2890 (unsigned)sizeof(regprog_T *) * cnt); | 2952 (unsigned)sizeof(regprog_T *) * cnt); |
2926 { | 2988 { |
2927 int cnt; | 2989 int cnt; |
2928 fromto_T *ftp; | 2990 fromto_T *ftp; |
2929 int i; | 2991 int i; |
2930 | 2992 |
2931 cnt = (getc(fd) << 8) + getc(fd); /* <repcount> */ | 2993 cnt = get2c(fd); /* <repcount> */ |
2932 if (cnt < 0) | 2994 if (cnt < 0) |
2933 return SP_TRUNCERROR; | 2995 return SP_TRUNCERROR; |
2934 | 2996 |
2935 if (ga_grow(gap, cnt) == FAIL) | 2997 if (ga_grow(gap, cnt) == FAIL) |
2936 return SP_OTHERERROR; | 2998 return SP_OTHERERROR; |
2991 if (i & SAL_COLLAPSE) | 3053 if (i & SAL_COLLAPSE) |
2992 slang->sl_collapse = TRUE; | 3054 slang->sl_collapse = TRUE; |
2993 if (i & SAL_REM_ACCENTS) | 3055 if (i & SAL_REM_ACCENTS) |
2994 slang->sl_rem_accents = TRUE; | 3056 slang->sl_rem_accents = TRUE; |
2995 | 3057 |
2996 cnt = (getc(fd) << 8) + getc(fd); /* <salcount> */ | 3058 cnt = get2c(fd); /* <salcount> */ |
2997 if (cnt < 0) | 3059 if (cnt < 0) |
2998 return SP_TRUNCERROR; | 3060 return SP_TRUNCERROR; |
2999 | 3061 |
3000 gap = &slang->sl_sal; | 3062 gap = &slang->sl_sal; |
3001 ga_init2(gap, sizeof(salitem_T), 10); | 3063 ga_init2(gap, sizeof(salitem_T), 10); |
3744 char_u *bp; | 3806 char_u *bp; |
3745 idx_T *ip; | 3807 idx_T *ip; |
3746 | 3808 |
3747 /* The tree size was computed when writing the file, so that we can | 3809 /* The tree size was computed when writing the file, so that we can |
3748 * allocate it as one long block. <nodecount> */ | 3810 * allocate it as one long block. <nodecount> */ |
3749 len = (getc(fd) << 24) + (getc(fd) << 16) + (getc(fd) << 8) + getc(fd); | 3811 len = get4c(fd); |
3750 if (len < 0) | 3812 if (len < 0) |
3751 return SP_TRUNCERROR; | 3813 return SP_TRUNCERROR; |
3752 if (len > 0) | 3814 if (len > 0) |
3753 { | 3815 { |
3754 /* Allocate the byte array. */ | 3816 /* Allocate the byte array. */ |
3834 else | 3896 else |
3835 c = 0; | 3897 c = 0; |
3836 | 3898 |
3837 c |= getc(fd); /* <affixID> */ | 3899 c |= getc(fd); /* <affixID> */ |
3838 | 3900 |
3839 n = (getc(fd) << 8) + getc(fd); /* <prefcondnr> */ | 3901 n = get2c(fd); /* <prefcondnr> */ |
3840 if (n >= maxprefcondnr) | 3902 if (n >= maxprefcondnr) |
3841 return SP_FORMERROR; | 3903 return SP_FORMERROR; |
3842 c |= (n << 8); | 3904 c |= (n << 8); |
3843 } | 3905 } |
3844 else /* c must be BY_FLAGS or BY_FLAGS2 */ | 3906 else /* c must be BY_FLAGS or BY_FLAGS2 */ |
3860 c = 0; | 3922 c = 0; |
3861 } | 3923 } |
3862 else /* c == BY_INDEX */ | 3924 else /* c == BY_INDEX */ |
3863 { | 3925 { |
3864 /* <nodeidx> */ | 3926 /* <nodeidx> */ |
3865 n = (getc(fd) << 16) + (getc(fd) << 8) + getc(fd); | 3927 n = get3c(fd); |
3866 if (n < 0 || n >= maxidx) | 3928 if (n < 0 || n >= maxidx) |
3867 return SP_FORMERROR; | 3929 return SP_FORMERROR; |
3868 idxs[idx] = n + SHARED_MASK; | 3930 idxs[idx] = n + SHARED_MASK; |
3869 c = getc(fd); /* <xbyte> */ | 3931 c = getc(fd); /* <xbyte> */ |
3870 } | 3932 } |
10183 goto nextone; | 10245 goto nextone; |
10184 } | 10246 } |
10185 | 10247 |
10186 /* Check the timestamp, it must be exactly the same as the one in | 10248 /* Check the timestamp, it must be exactly the same as the one in |
10187 * the .spl file. Otherwise the word numbers won't match. */ | 10249 * the .spl file. Otherwise the word numbers won't match. */ |
10188 timestamp = 0; | 10250 timestamp = get8c(fd); /* <timestamp> */ |
10189 for (i = 7; i >= 0; --i) /* <timestamp> */ | |
10190 timestamp += getc(fd) << (i * 8); | |
10191 if (timestamp != slang->sl_sugtime) | 10251 if (timestamp != slang->sl_sugtime) |
10192 { | 10252 { |
10193 EMSG2(_("E781: .sug file doesn't match .spl file: %s"), | 10253 EMSG2(_("E781: .sug file doesn't match .spl file: %s"), |
10194 slang->sl_fname); | 10254 slang->sl_fname); |
10195 goto nextone; | 10255 goto nextone; |
10218 */ | 10278 */ |
10219 slang->sl_sugbuf = open_spellbuf(); | 10279 slang->sl_sugbuf = open_spellbuf(); |
10220 if (slang->sl_sugbuf == NULL) | 10280 if (slang->sl_sugbuf == NULL) |
10221 goto someerror; | 10281 goto someerror; |
10222 /* <sugwcount> */ | 10282 /* <sugwcount> */ |
10223 wcount = (getc(fd) << 24) + (getc(fd) << 16) + (getc(fd) << 8) | 10283 wcount = get4c(fd); |
10224 + getc(fd); | |
10225 if (wcount < 0) | 10284 if (wcount < 0) |
10226 goto someerror; | 10285 goto someerror; |
10227 | 10286 |
10228 /* Read all the wordnr lists into the buffer, one NUL terminated | 10287 /* Read all the wordnr lists into the buffer, one NUL terminated |
10229 * list per line. */ | 10288 * list per line. */ |