comparison src/spell.c @ 1753:5098908178cd v7.2.050

updated for version 7.2-050
author vimboss
date Fri, 28 Nov 2008 09:08:51 +0000
parents 5b43a3a9454a
children f10fe14748e2
comparison
equal deleted inserted replaced
1752:a8aae2e1d2ae 1753:5098908178cd
7924 garray_T *gap; 7924 garray_T *gap;
7925 fromto_T *ftp; 7925 fromto_T *ftp;
7926 char_u *p; 7926 char_u *p;
7927 int rr; 7927 int rr;
7928 int retval = OK; 7928 int retval = OK;
7929 int fwv = 1; /* collect return value of fwrite() to avoid
7930 warnings from picky compiler */
7929 7931
7930 fd = mch_fopen((char *)fname, "w"); 7932 fd = mch_fopen((char *)fname, "w");
7931 if (fd == NULL) 7933 if (fd == NULL)
7932 { 7934 {
7933 EMSG2(_(e_notopen), fname); 7935 EMSG2(_(e_notopen), fname);
7934 return FAIL; 7936 return FAIL;
7935 } 7937 }
7936 7938
7937 /* <HEADER>: <fileID> <versionnr> */ 7939 /* <HEADER>: <fileID> <versionnr> */
7938 /* <fileID> */ 7940 /* <fileID> */
7939 if (fwrite(VIMSPELLMAGIC, VIMSPELLMAGICL, (size_t)1, fd) != 1) 7941 fwv &= fwrite(VIMSPELLMAGIC, VIMSPELLMAGICL, (size_t)1, fd);
7940 {
7941 EMSG(_(e_write));
7942 retval = FAIL;
7943 }
7944 putc(VIMSPELLVERSION, fd); /* <versionnr> */ 7942 putc(VIMSPELLVERSION, fd); /* <versionnr> */
7945 7943
7946 /* 7944 /*
7947 * <SECTIONS>: <section> ... <sectionend> 7945 * <SECTIONS>: <section> ... <sectionend>
7948 */ 7946 */
7953 putc(SN_INFO, fd); /* <sectionID> */ 7951 putc(SN_INFO, fd); /* <sectionID> */
7954 putc(0, fd); /* <sectionflags> */ 7952 putc(0, fd); /* <sectionflags> */
7955 7953
7956 i = (int)STRLEN(spin->si_info); 7954 i = (int)STRLEN(spin->si_info);
7957 put_bytes(fd, (long_u)i, 4); /* <sectionlen> */ 7955 put_bytes(fd, (long_u)i, 4); /* <sectionlen> */
7958 fwrite(spin->si_info, (size_t)i, (size_t)1, fd); /* <infotext> */ 7956 fwv &= fwrite(spin->si_info, (size_t)i, (size_t)1, fd); /* <infotext> */
7959 } 7957 }
7960 7958
7961 /* SN_REGION: <regionname> ... 7959 /* SN_REGION: <regionname> ...
7962 * Write the region names only if there is more than one. */ 7960 * Write the region names only if there is more than one. */
7963 if (spin->si_region_count > 1) 7961 if (spin->si_region_count > 1)
7964 { 7962 {
7965 putc(SN_REGION, fd); /* <sectionID> */ 7963 putc(SN_REGION, fd); /* <sectionID> */
7966 putc(SNF_REQUIRED, fd); /* <sectionflags> */ 7964 putc(SNF_REQUIRED, fd); /* <sectionflags> */
7967 l = spin->si_region_count * 2; 7965 l = spin->si_region_count * 2;
7968 put_bytes(fd, (long_u)l, 4); /* <sectionlen> */ 7966 put_bytes(fd, (long_u)l, 4); /* <sectionlen> */
7969 fwrite(spin->si_region_name, (size_t)l, (size_t)1, fd); 7967 fwv &= fwrite(spin->si_region_name, (size_t)l, (size_t)1, fd);
7970 /* <regionname> ... */ 7968 /* <regionname> ... */
7971 regionmask = (1 << spin->si_region_count) - 1; 7969 regionmask = (1 << spin->si_region_count) - 1;
7972 } 7970 }
7973 else 7971 else
7974 regionmask = 0; 7972 regionmask = 0;
8014 flags |= CF_UPPER; 8012 flags |= CF_UPPER;
8015 fputc(flags, fd); /* <charflags> */ 8013 fputc(flags, fd); /* <charflags> */
8016 } 8014 }
8017 8015
8018 put_bytes(fd, (long_u)l, 2); /* <folcharslen> */ 8016 put_bytes(fd, (long_u)l, 2); /* <folcharslen> */
8019 fwrite(folchars, (size_t)l, (size_t)1, fd); /* <folchars> */ 8017 fwv &= fwrite(folchars, (size_t)l, (size_t)1, fd); /* <folchars> */
8020 } 8018 }
8021 8019
8022 /* SN_MIDWORD: <midword> */ 8020 /* SN_MIDWORD: <midword> */
8023 if (spin->si_midword != NULL) 8021 if (spin->si_midword != NULL)
8024 { 8022 {
8025 putc(SN_MIDWORD, fd); /* <sectionID> */ 8023 putc(SN_MIDWORD, fd); /* <sectionID> */
8026 putc(SNF_REQUIRED, fd); /* <sectionflags> */ 8024 putc(SNF_REQUIRED, fd); /* <sectionflags> */
8027 8025
8028 i = (int)STRLEN(spin->si_midword); 8026 i = (int)STRLEN(spin->si_midword);
8029 put_bytes(fd, (long_u)i, 4); /* <sectionlen> */ 8027 put_bytes(fd, (long_u)i, 4); /* <sectionlen> */
8030 fwrite(spin->si_midword, (size_t)i, (size_t)1, fd); /* <midword> */ 8028 fwv &= fwrite(spin->si_midword, (size_t)i, (size_t)1, fd);
8029 /* <midword> */
8031 } 8030 }
8032 8031
8033 /* SN_PREFCOND: <prefcondcnt> <prefcond> ... */ 8032 /* SN_PREFCOND: <prefcondcnt> <prefcond> ... */
8034 if (spin->si_prefcond.ga_len > 0) 8033 if (spin->si_prefcond.ga_len > 0)
8035 { 8034 {
8111 for (rr = 1; rr <= 2; ++rr) 8110 for (rr = 1; rr <= 2; ++rr)
8112 { 8111 {
8113 p = rr == 1 ? ftp->ft_from : ftp->ft_to; 8112 p = rr == 1 ? ftp->ft_from : ftp->ft_to;
8114 l = (int)STRLEN(p); 8113 l = (int)STRLEN(p);
8115 putc(l, fd); 8114 putc(l, fd);
8116 fwrite(p, l, (size_t)1, fd); 8115 fwv &= fwrite(p, l, (size_t)1, fd);
8117 } 8116 }
8118 } 8117 }
8119 8118
8120 } 8119 }
8121 8120
8129 l = (int)STRLEN(spin->si_sofofr); 8128 l = (int)STRLEN(spin->si_sofofr);
8130 put_bytes(fd, (long_u)(l + STRLEN(spin->si_sofoto) + 4), 4); 8129 put_bytes(fd, (long_u)(l + STRLEN(spin->si_sofoto) + 4), 4);
8131 /* <sectionlen> */ 8130 /* <sectionlen> */
8132 8131
8133 put_bytes(fd, (long_u)l, 2); /* <sofofromlen> */ 8132 put_bytes(fd, (long_u)l, 2); /* <sofofromlen> */
8134 fwrite(spin->si_sofofr, l, (size_t)1, fd); /* <sofofrom> */ 8133 fwv &= fwrite(spin->si_sofofr, l, (size_t)1, fd); /* <sofofrom> */
8135 8134
8136 l = (int)STRLEN(spin->si_sofoto); 8135 l = (int)STRLEN(spin->si_sofoto);
8137 put_bytes(fd, (long_u)l, 2); /* <sofotolen> */ 8136 put_bytes(fd, (long_u)l, 2); /* <sofotolen> */
8138 fwrite(spin->si_sofoto, l, (size_t)1, fd); /* <sofoto> */ 8137 fwv &= fwrite(spin->si_sofoto, l, (size_t)1, fd); /* <sofoto> */
8139 } 8138 }
8140 8139
8141 /* SN_WORDS: <word> ... 8140 /* SN_WORDS: <word> ...
8142 * This is for making suggestions, section is not required. */ 8141 * This is for making suggestions, section is not required. */
8143 if (spin->si_commonwords.ht_used > 0) 8142 if (spin->si_commonwords.ht_used > 0)
8158 if (!HASHITEM_EMPTY(hi)) 8157 if (!HASHITEM_EMPTY(hi))
8159 { 8158 {
8160 l = (int)STRLEN(hi->hi_key) + 1; 8159 l = (int)STRLEN(hi->hi_key) + 1;
8161 len += l; 8160 len += l;
8162 if (round == 2) /* <word> */ 8161 if (round == 2) /* <word> */
8163 fwrite(hi->hi_key, (size_t)l, (size_t)1, fd); 8162 fwv &= fwrite(hi->hi_key, (size_t)l, (size_t)1, fd);
8164 --todo; 8163 --todo;
8165 } 8164 }
8166 if (round == 1) 8165 if (round == 1)
8167 put_bytes(fd, (long_u)len, 4); /* <sectionlen> */ 8166 put_bytes(fd, (long_u)len, 4); /* <sectionlen> */
8168 } 8167 }
8174 { 8173 {
8175 putc(SN_MAP, fd); /* <sectionID> */ 8174 putc(SN_MAP, fd); /* <sectionID> */
8176 putc(0, fd); /* <sectionflags> */ 8175 putc(0, fd); /* <sectionflags> */
8177 l = spin->si_map.ga_len; 8176 l = spin->si_map.ga_len;
8178 put_bytes(fd, (long_u)l, 4); /* <sectionlen> */ 8177 put_bytes(fd, (long_u)l, 4); /* <sectionlen> */
8179 fwrite(spin->si_map.ga_data, (size_t)l, (size_t)1, fd); 8178 fwv &= fwrite(spin->si_map.ga_data, (size_t)l, (size_t)1, fd);
8180 /* <mapstr> */ 8179 /* <mapstr> */
8181 } 8180 }
8182 8181
8183 /* SN_SUGFILE: <timestamp> 8182 /* SN_SUGFILE: <timestamp>
8184 * This is used to notify that a .sug file may be available and at the 8183 * This is used to notify that a .sug file may be available and at the
8230 /* <comppatcount> */ 8229 /* <comppatcount> */
8231 for (i = 0; i < spin->si_comppat.ga_len; ++i) 8230 for (i = 0; i < spin->si_comppat.ga_len; ++i)
8232 { 8231 {
8233 p = ((char_u **)(spin->si_comppat.ga_data))[i]; 8232 p = ((char_u **)(spin->si_comppat.ga_data))[i];
8234 putc((int)STRLEN(p), fd); /* <comppatlen> */ 8233 putc((int)STRLEN(p), fd); /* <comppatlen> */
8235 fwrite(p, (size_t)STRLEN(p), (size_t)1, fd);/* <comppattext> */ 8234 fwv &= fwrite(p, (size_t)STRLEN(p), (size_t)1, fd);
8235 /* <comppattext> */
8236 } 8236 }
8237 /* <compflags> */ 8237 /* <compflags> */
8238 fwrite(spin->si_compflags, (size_t)STRLEN(spin->si_compflags), 8238 fwv &= fwrite(spin->si_compflags, (size_t)STRLEN(spin->si_compflags),
8239 (size_t)1, fd); 8239 (size_t)1, fd);
8240 } 8240 }
8241 8241
8242 /* SN_NOBREAK: NOBREAK flag */ 8242 /* SN_NOBREAK: NOBREAK flag */
8243 if (spin->si_nobreak) 8243 if (spin->si_nobreak)
8257 putc(SN_SYLLABLE, fd); /* <sectionID> */ 8257 putc(SN_SYLLABLE, fd); /* <sectionID> */
8258 putc(0, fd); /* <sectionflags> */ 8258 putc(0, fd); /* <sectionflags> */
8259 8259
8260 l = (int)STRLEN(spin->si_syllable); 8260 l = (int)STRLEN(spin->si_syllable);
8261 put_bytes(fd, (long_u)l, 4); /* <sectionlen> */ 8261 put_bytes(fd, (long_u)l, 4); /* <sectionlen> */
8262 fwrite(spin->si_syllable, (size_t)l, (size_t)1, fd); /* <syllable> */ 8262 fwv &= fwrite(spin->si_syllable, (size_t)l, (size_t)1, fd);
8263 /* <syllable> */
8263 } 8264 }
8264 8265
8265 /* end of <SECTIONS> */ 8266 /* end of <SECTIONS> */
8266 putc(SN_END, fd); /* <sectionend> */ 8267 putc(SN_END, fd); /* <sectionend> */
8267 8268
8293 8294
8294 /* Write the nodes. */ 8295 /* Write the nodes. */
8295 (void)put_node(fd, tree, 0, regionmask, round == 3); 8296 (void)put_node(fd, tree, 0, regionmask, round == 3);
8296 } 8297 }
8297 8298
8298 /* Write another byte to check for errors. */ 8299 /* Write another byte to check for errors (file system full). */
8299 if (putc(0, fd) == EOF) 8300 if (putc(0, fd) == EOF)
8300 retval = FAIL; 8301 retval = FAIL;
8301 8302
8302 if (fclose(fd) == EOF) 8303 if (fclose(fd) == EOF)
8303 retval = FAIL; 8304 retval = FAIL;
8305
8306 if (fwv != 1)
8307 retval = FAIL;
8308 if (retval == FAIL)
8309 EMSG(_(e_write));
8304 8310
8305 return retval; 8311 return retval;
8306 } 8312 }
8307 8313
8308 /* 8314 /*
9888 { 9894 {
9889 int i; 9895 int i;
9890 char_u *p; 9896 char_u *p;
9891 int len; 9897 int len;
9892 int totlen; 9898 int totlen;
9899 int x = 1; /* collect return value of fwrite() */
9893 9900
9894 if (fd != NULL) 9901 if (fd != NULL)
9895 put_bytes(fd, (long_u)gap->ga_len, 2); /* <prefcondcnt> */ 9902 put_bytes(fd, (long_u)gap->ga_len, 2); /* <prefcondcnt> */
9896 9903
9897 totlen = 2 + gap->ga_len; /* length of <prefcondcnt> and <condlen> bytes */ 9904 totlen = 2 + gap->ga_len; /* length of <prefcondcnt> and <condlen> bytes */
9904 { 9911 {
9905 len = (int)STRLEN(p); 9912 len = (int)STRLEN(p);
9906 if (fd != NULL) 9913 if (fd != NULL)
9907 { 9914 {
9908 fputc(len, fd); 9915 fputc(len, fd);
9909 fwrite(p, (size_t)len, (size_t)1, fd); 9916 x &= fwrite(p, (size_t)len, (size_t)1, fd);
9910 } 9917 }
9911 totlen += len; 9918 totlen += len;
9912 } 9919 }
9913 else if (fd != NULL) 9920 else if (fd != NULL)
9914 fputc(0, fd); 9921 fputc(0, fd);