comparison src/spell.c @ 2770:25672ad7f377 v7.3.161

updated for version 7.3.161 Problem: Items on the stack may be too big. Solution: Make items static or allocate them.
author Bram Moolenaar <bram@vim.org>
date Mon, 11 Apr 2011 21:35:11 +0200
parents c5e47b752f07
children 6cd0d6413a2e
comparison
equal deleted inserted replaced
2769:ccce1db172b3 2770:25672ad7f377
8588 static void 8588 static void
8589 spell_make_sugfile(spin, wfname) 8589 spell_make_sugfile(spin, wfname)
8590 spellinfo_T *spin; 8590 spellinfo_T *spin;
8591 char_u *wfname; 8591 char_u *wfname;
8592 { 8592 {
8593 char_u fname[MAXPATHL]; 8593 char_u *fname = NULL;
8594 int len; 8594 int len;
8595 slang_T *slang; 8595 slang_T *slang;
8596 int free_slang = FALSE; 8596 int free_slang = FALSE;
8597 8597
8598 /* 8598 /*
8652 8652
8653 /* 8653 /*
8654 * Write the .sug file. 8654 * Write the .sug file.
8655 * Make the file name by changing ".spl" to ".sug". 8655 * Make the file name by changing ".spl" to ".sug".
8656 */ 8656 */
8657 fname = alloc(MAXPATHL);
8658 if (fname == NULL)
8659 goto theend;
8657 vim_strncpy(fname, wfname, MAXPATHL - 1); 8660 vim_strncpy(fname, wfname, MAXPATHL - 1);
8658 len = (int)STRLEN(fname); 8661 len = (int)STRLEN(fname);
8659 fname[len - 2] = 'u'; 8662 fname[len - 2] = 'u';
8660 fname[len - 1] = 'g'; 8663 fname[len - 1] = 'g';
8661 sug_write(spin, fname); 8664 sug_write(spin, fname);
8662 8665
8663 theend: 8666 theend:
8667 vim_free(fname);
8664 if (free_slang) 8668 if (free_slang)
8665 slang_free(slang); 8669 slang_free(slang);
8666 free_blocks(spin->si_blocks); 8670 free_blocks(spin->si_blocks);
8667 close_spellbuf(spin->si_spellbuf); 8671 close_spellbuf(spin->si_spellbuf);
8668 } 8672 }
9104 char_u **fnames; 9108 char_u **fnames;
9105 int ascii; /* -ascii argument given */ 9109 int ascii; /* -ascii argument given */
9106 int overwrite; /* overwrite existing output file */ 9110 int overwrite; /* overwrite existing output file */
9107 int added_word; /* invoked through "zg" */ 9111 int added_word; /* invoked through "zg" */
9108 { 9112 {
9109 char_u fname[MAXPATHL]; 9113 char_u *fname = NULL;
9110 char_u wfname[MAXPATHL]; 9114 char_u *wfname;
9111 char_u **innames; 9115 char_u **innames;
9112 int incount; 9116 int incount;
9113 afffile_T *(afile[8]); 9117 afffile_T *(afile[8]);
9114 int i; 9118 int i;
9115 int len; 9119 int len;
9133 9137
9134 /* default: fnames[0] is output file, following are input files */ 9138 /* default: fnames[0] is output file, following are input files */
9135 innames = &fnames[1]; 9139 innames = &fnames[1];
9136 incount = fcount - 1; 9140 incount = fcount - 1;
9137 9141
9142 wfname = alloc(MAXPATHL);
9143 if (wfname == NULL)
9144 return;
9145
9138 if (fcount >= 1) 9146 if (fcount >= 1)
9139 { 9147 {
9140 len = (int)STRLEN(fnames[0]); 9148 len = (int)STRLEN(fnames[0]);
9141 if (fcount == 1 && len > 4 && STRCMP(fnames[0] + len - 4, ".add") == 0) 9149 if (fcount == 1 && len > 4 && STRCMP(fnames[0] + len - 4, ".add") == 0)
9142 { 9150 {
9143 /* For ":mkspell path/en.latin1.add" output file is 9151 /* For ":mkspell path/en.latin1.add" output file is
9144 * "path/en.latin1.add.spl". */ 9152 * "path/en.latin1.add.spl". */
9145 innames = &fnames[0]; 9153 innames = &fnames[0];
9146 incount = 1; 9154 incount = 1;
9147 vim_snprintf((char *)wfname, sizeof(wfname), "%s.spl", fnames[0]); 9155 vim_snprintf((char *)wfname, MAXPATHL, "%s.spl", fnames[0]);
9148 } 9156 }
9149 else if (fcount == 1) 9157 else if (fcount == 1)
9150 { 9158 {
9151 /* For ":mkspell path/vim" output file is "path/vim.latin1.spl". */ 9159 /* For ":mkspell path/vim" output file is "path/vim.latin1.spl". */
9152 innames = &fnames[0]; 9160 innames = &fnames[0];
9153 incount = 1; 9161 incount = 1;
9154 vim_snprintf((char *)wfname, sizeof(wfname), SPL_FNAME_TMPL, 9162 vim_snprintf((char *)wfname, MAXPATHL, SPL_FNAME_TMPL,
9155 fnames[0], spin.si_ascii ? (char_u *)"ascii" : spell_enc()); 9163 fnames[0], spin.si_ascii ? (char_u *)"ascii" : spell_enc());
9156 } 9164 }
9157 else if (len > 4 && STRCMP(fnames[0] + len - 4, ".spl") == 0) 9165 else if (len > 4 && STRCMP(fnames[0] + len - 4, ".spl") == 0)
9158 { 9166 {
9159 /* Name ends in ".spl", use as the file name. */ 9167 /* Name ends in ".spl", use as the file name. */
9160 vim_strncpy(wfname, fnames[0], sizeof(wfname) - 1); 9168 vim_strncpy(wfname, fnames[0], MAXPATHL - 1);
9161 } 9169 }
9162 else 9170 else
9163 /* Name should be language, make the file name from it. */ 9171 /* Name should be language, make the file name from it. */
9164 vim_snprintf((char *)wfname, sizeof(wfname), SPL_FNAME_TMPL, 9172 vim_snprintf((char *)wfname, MAXPATHL, SPL_FNAME_TMPL,
9165 fnames[0], spin.si_ascii ? (char_u *)"ascii" : spell_enc()); 9173 fnames[0], spin.si_ascii ? (char_u *)"ascii" : spell_enc());
9166 9174
9167 /* Check for .ascii.spl. */ 9175 /* Check for .ascii.spl. */
9168 if (strstr((char *)gettail(wfname), SPL_FNAME_ASCII) != NULL) 9176 if (strstr((char *)gettail(wfname), SPL_FNAME_ASCII) != NULL)
9169 spin.si_ascii = TRUE; 9177 spin.si_ascii = TRUE;
9184 /* Check for overwriting before doing things that may take a lot of 9192 /* Check for overwriting before doing things that may take a lot of
9185 * time. */ 9193 * time. */
9186 if (!overwrite && mch_stat((char *)wfname, &st) >= 0) 9194 if (!overwrite && mch_stat((char *)wfname, &st) >= 0)
9187 { 9195 {
9188 EMSG(_(e_exists)); 9196 EMSG(_(e_exists));
9189 return; 9197 goto theend;
9190 } 9198 }
9191 if (mch_isdir(wfname)) 9199 if (mch_isdir(wfname))
9192 { 9200 {
9193 EMSG2(_(e_isadir2), wfname); 9201 EMSG2(_(e_isadir2), wfname);
9194 return; 9202 goto theend;
9195 } 9203 }
9204
9205 fname = alloc(MAXPATHL);
9206 if (fname == NULL)
9207 goto theend;
9196 9208
9197 /* 9209 /*
9198 * Init the aff and dic pointers. 9210 * Init the aff and dic pointers.
9199 * Get the region names if there are more than 2 arguments. 9211 * Get the region names if there are more than 2 arguments.
9200 */ 9212 */
9207 len = (int)STRLEN(innames[i]); 9219 len = (int)STRLEN(innames[i]);
9208 if (STRLEN(gettail(innames[i])) < 5 9220 if (STRLEN(gettail(innames[i])) < 5
9209 || innames[i][len - 3] != '_') 9221 || innames[i][len - 3] != '_')
9210 { 9222 {
9211 EMSG2(_("E755: Invalid region in %s"), innames[i]); 9223 EMSG2(_("E755: Invalid region in %s"), innames[i]);
9212 return; 9224 goto theend;
9213 } 9225 }
9214 spin.si_region_name[i * 2] = TOLOWER_ASC(innames[i][len - 2]); 9226 spin.si_region_name[i * 2] = TOLOWER_ASC(innames[i][len - 2]);
9215 spin.si_region_name[i * 2 + 1] = 9227 spin.si_region_name[i * 2 + 1] =
9216 TOLOWER_ASC(innames[i][len - 1]); 9228 TOLOWER_ASC(innames[i][len - 1]);
9217 } 9229 }
9224 if (spin.si_foldroot == NULL 9236 if (spin.si_foldroot == NULL
9225 || spin.si_keeproot == NULL 9237 || spin.si_keeproot == NULL
9226 || spin.si_prefroot == NULL) 9238 || spin.si_prefroot == NULL)
9227 { 9239 {
9228 free_blocks(spin.si_blocks); 9240 free_blocks(spin.si_blocks);
9229 return; 9241 goto theend;
9230 } 9242 }
9231 9243
9232 /* When not producing a .add.spl file clear the character table when 9244 /* When not producing a .add.spl file clear the character table when
9233 * we encounter one in the .aff file. This means we dump the current 9245 * we encounter one in the .aff file. This means we dump the current
9234 * one in the .spl file if the .aff file doesn't define one. That's 9246 * one in the .spl file if the .aff file doesn't define one. That's
9245 for (i = 0; i < incount && !error; ++i) 9257 for (i = 0; i < incount && !error; ++i)
9246 { 9258 {
9247 spin.si_conv.vc_type = CONV_NONE; 9259 spin.si_conv.vc_type = CONV_NONE;
9248 spin.si_region = 1 << i; 9260 spin.si_region = 1 << i;
9249 9261
9250 vim_snprintf((char *)fname, sizeof(fname), "%s.aff", innames[i]); 9262 vim_snprintf((char *)fname, MAXPATHL, "%s.aff", innames[i]);
9251 if (mch_stat((char *)fname, &st) >= 0) 9263 if (mch_stat((char *)fname, &st) >= 0)
9252 { 9264 {
9253 /* Read the .aff file. Will init "spin->si_conv" based on the 9265 /* Read the .aff file. Will init "spin->si_conv" based on the
9254 * "SET" line. */ 9266 * "SET" line. */
9255 afile[i] = spell_read_aff(&spin, fname); 9267 afile[i] = spell_read_aff(&spin, fname);
9256 if (afile[i] == NULL) 9268 if (afile[i] == NULL)
9257 error = TRUE; 9269 error = TRUE;
9258 else 9270 else
9259 { 9271 {
9260 /* Read the .dic file and store the words in the trees. */ 9272 /* Read the .dic file and store the words in the trees. */
9261 vim_snprintf((char *)fname, sizeof(fname), "%s.dic", 9273 vim_snprintf((char *)fname, MAXPATHL, "%s.dic",
9262 innames[i]); 9274 innames[i]);
9263 if (spell_read_dic(&spin, fname, afile[i]) == FAIL) 9275 if (spell_read_dic(&spin, fname, afile[i]) == FAIL)
9264 error = TRUE; 9276 error = TRUE;
9265 } 9277 }
9266 } 9278 }
9338 */ 9350 */
9339 if (spin.si_sugtime != 0 && !error && !got_int) 9351 if (spin.si_sugtime != 0 && !error && !got_int)
9340 spell_make_sugfile(&spin, wfname); 9352 spell_make_sugfile(&spin, wfname);
9341 9353
9342 } 9354 }
9355
9356 theend:
9357 vim_free(fname);
9358 vim_free(wfname);
9343 } 9359 }
9344 9360
9345 /* 9361 /*
9346 * Display a message for spell file processing when 'verbose' is set or using 9362 * Display a message for spell file processing when 'verbose' is set or using
9347 * ":mkspell". "str" can be IObuff. 9363 * ":mkspell". "str" can be IObuff.
9390 { 9406 {
9391 FILE *fd = NULL; 9407 FILE *fd = NULL;
9392 buf_T *buf = NULL; 9408 buf_T *buf = NULL;
9393 int new_spf = FALSE; 9409 int new_spf = FALSE;
9394 char_u *fname; 9410 char_u *fname;
9395 char_u fnamebuf[MAXPATHL]; 9411 char_u *fnamebuf = NULL;
9396 char_u line[MAXWLEN * 2]; 9412 char_u line[MAXWLEN * 2];
9397 long fpos, fpos_next = 0; 9413 long fpos, fpos_next = 0;
9398 int i; 9414 int i;
9399 char_u *spf; 9415 char_u *spf;
9400 9416
9420 if (*curwin->w_s->b_p_spf == NUL) 9436 if (*curwin->w_s->b_p_spf == NUL)
9421 { 9437 {
9422 EMSG2(_(e_notset), "spellfile"); 9438 EMSG2(_(e_notset), "spellfile");
9423 return; 9439 return;
9424 } 9440 }
9441 fnamebuf = alloc(MAXPATHL);
9442 if (fnamebuf == NULL)
9443 return;
9425 9444
9426 for (spf = curwin->w_s->b_p_spf, i = 1; *spf != NUL; ++i) 9445 for (spf = curwin->w_s->b_p_spf, i = 1; *spf != NUL; ++i)
9427 { 9446 {
9428 copy_option_part(&spf, fnamebuf, MAXPATHL, ","); 9447 copy_option_part(&spf, fnamebuf, MAXPATHL, ",");
9429 if (i == idx) 9448 if (i == idx)
9430 break; 9449 break;
9431 if (*spf == NUL) 9450 if (*spf == NUL)
9432 { 9451 {
9433 EMSGN(_("E765: 'spellfile' does not have %ld entries"), idx); 9452 EMSGN(_("E765: 'spellfile' does not have %ld entries"), idx);
9453 vim_free(fnamebuf);
9434 return; 9454 return;
9435 } 9455 }
9436 } 9456 }
9437 9457
9438 /* Check that the user isn't editing the .add file somewhere. */ 9458 /* Check that the user isn't editing the .add file somewhere. */
9440 if (buf != NULL && buf->b_ml.ml_mfp == NULL) 9460 if (buf != NULL && buf->b_ml.ml_mfp == NULL)
9441 buf = NULL; 9461 buf = NULL;
9442 if (buf != NULL && bufIsChanged(buf)) 9462 if (buf != NULL && bufIsChanged(buf))
9443 { 9463 {
9444 EMSG(_(e_bufloaded)); 9464 EMSG(_(e_bufloaded));
9465 vim_free(fnamebuf);
9445 return; 9466 return;
9446 } 9467 }
9447 9468
9448 fname = fnamebuf; 9469 fname = fnamebuf;
9449 } 9470 }
9534 if (buf != NULL) 9555 if (buf != NULL)
9535 buf_reload(buf, buf->b_orig_mode); 9556 buf_reload(buf, buf->b_orig_mode);
9536 9557
9537 redraw_all_later(SOME_VALID); 9558 redraw_all_later(SOME_VALID);
9538 } 9559 }
9560 vim_free(fnamebuf);
9539 } 9561 }
9540 9562
9541 /* 9563 /*
9542 * Initialize 'spellfile' for the current buffer. 9564 * Initialize 'spellfile' for the current buffer.
9543 */ 9565 */
9544 static void 9566 static void
9545 init_spellfile() 9567 init_spellfile()
9546 { 9568 {
9547 char_u buf[MAXPATHL]; 9569 char_u *buf;
9548 int l; 9570 int l;
9549 char_u *fname; 9571 char_u *fname;
9550 char_u *rtp; 9572 char_u *rtp;
9551 char_u *lend; 9573 char_u *lend;
9552 int aspath = FALSE; 9574 int aspath = FALSE;
9553 char_u *lstart = curbuf->b_s.b_p_spl; 9575 char_u *lstart = curbuf->b_s.b_p_spl;
9554 9576
9555 if (*curwin->w_s->b_p_spl != NUL && curwin->w_s->b_langp.ga_len > 0) 9577 if (*curwin->w_s->b_p_spl != NUL && curwin->w_s->b_langp.ga_len > 0)
9556 { 9578 {
9579 buf = alloc(MAXPATHL);
9580 if (buf == NULL)
9581 return;
9582
9557 /* Find the end of the language name. Exclude the region. If there 9583 /* Find the end of the language name. Exclude the region. If there
9558 * is a path separator remember the start of the tail. */ 9584 * is a path separator remember the start of the tail. */
9559 for (lend = curwin->w_s->b_p_spl; *lend != NUL 9585 for (lend = curwin->w_s->b_p_spl; *lend != NUL
9560 && vim_strchr((char_u *)",._", *lend) == NULL; ++lend) 9586 && vim_strchr((char_u *)",._", *lend) == NULL; ++lend)
9561 if (vim_ispathsep(*lend)) 9587 if (vim_ispathsep(*lend))
9595 l = (int)STRLEN(buf); 9621 l = (int)STRLEN(buf);
9596 vim_snprintf((char *)buf + l, MAXPATHL - l, 9622 vim_snprintf((char *)buf + l, MAXPATHL - l,
9597 "/%.*s", (int)(lend - lstart), lstart); 9623 "/%.*s", (int)(lend - lstart), lstart);
9598 } 9624 }
9599 l = (int)STRLEN(buf); 9625 l = (int)STRLEN(buf);
9600 fname = LANGP_ENTRY(curwin->w_s->b_langp, 0)->lp_slang->sl_fname; 9626 fname = LANGP_ENTRY(curwin->w_s->b_langp, 0)
9627 ->lp_slang->sl_fname;
9601 vim_snprintf((char *)buf + l, MAXPATHL - l, ".%s.add", 9628 vim_snprintf((char *)buf + l, MAXPATHL - l, ".%s.add",
9602 fname != NULL 9629 fname != NULL
9603 && strstr((char *)gettail(fname), ".ascii.") != NULL 9630 && strstr((char *)gettail(fname), ".ascii.") != NULL
9604 ? (char_u *)"ascii" : spell_enc()); 9631 ? (char_u *)"ascii" : spell_enc());
9605 set_option_value((char_u *)"spellfile", 0L, buf, OPT_LOCAL); 9632 set_option_value((char_u *)"spellfile", 0L, buf, OPT_LOCAL);
9606 break; 9633 break;
9607 } 9634 }
9608 aspath = FALSE; 9635 aspath = FALSE;
9609 } 9636 }
9637
9638 vim_free(buf);
9610 } 9639 }
9611 } 9640 }
9612 9641
9613 9642
9614 /* 9643 /*