&& (fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0)) >= 0)
{
int bfd;
- char_u *copybuf, *wp;
+ char_u *copybuf;
int some_error = FALSE;
stat_T st_new;
char_u *dirp;
char_u *rootname;
-#if defined(UNIX) || defined(MSWIN)
- char_u *p;
-#endif
#if defined(UNIX)
int did_set_shortname;
mode_t umask_save;
dirp = p_bdir;
while (*dirp)
{
+ char_u *p UNUSED;
+ int copybuf_len UNUSED;
+
#ifdef UNIX
st_new.st_ino = 0;
st_new.st_dev = 0;
#endif
// Isolate one directory name, using an entry in 'bdir'.
- (void)copy_option_part(&dirp, copybuf, WRITEBUFSIZE, ",");
+ copybuf_len = copy_option_part(&dirp, copybuf, WRITEBUFSIZE, ",");
#if defined(UNIX) || defined(MSWIN)
- p = copybuf + STRLEN(copybuf);
+ p = copybuf + copybuf_len;
if (after_pathsep(copybuf, p) && p[-1] == p[-2])
// Ends with '//', use full path
if ((p = make_percent_swname(copybuf, p, fname)) != NULL)
// Change one character, just before the extension.
if (!p_bk)
{
+ char_u *wp;
+
wp = backup + STRLEN(backup) - 1
- STRLEN(backup_ext);
if (wp < backup) // empty file name ???
dirp = p_bdir;
while (*dirp)
{
+ int IObufflen UNUSED;
+
// Isolate one directory name and make the backup file name.
- (void)copy_option_part(&dirp, IObuff, IOSIZE, ",");
+ IObufflen = copy_option_part(&dirp, IObuff, IOSIZE, ",");
#if defined(UNIX) || defined(MSWIN)
- p = IObuff + STRLEN(IObuff);
+ p = IObuff + IObufflen;
if (after_pathsep(IObuff, p) && p[-1] == p[-2])
// path ends with '//', use full path
if ((p = make_percent_swname(IObuff, p, fname)) != NULL)
char_u *lead_repl = NULL; // replaces comment leader
int lead_repl_len = 0; // length of *lead_repl
char_u lead_middle[COM_MAX_LEN]; // middle-comment string
+ int lead_middle_len; // length of the lead_middle
char_u lead_end[COM_MAX_LEN]; // end-comment string
char_u *comment_end = NULL; // where lead_end has been found
int extra_space = FALSE; // append extra space
require_blank = TRUE;
++p;
}
- (void)copy_option_part(&p, lead_middle, COM_MAX_LEN, ",");
+ lead_middle_len = copy_option_part(&p, lead_middle, COM_MAX_LEN, ",");
while (*p && p[-1] != ':') // find end of end flags
{
if (current_flag == COM_START)
{
lead_repl = lead_middle;
- lead_repl_len = (int)STRLEN(lead_middle);
+ lead_repl_len = lead_middle_len;
}
// If we have hit RETURN immediately after the start
char_u lead_start[COM_MAX_LEN]; // start-comment string
char_u lead_middle[COM_MAX_LEN]; // middle-comment string
char_u lead_end[COM_MAX_LEN]; // end-comment string
+ int lead_end_len;
char_u *p;
int start_align = 0;
int start_off = 0;
if (*p == ':')
++p;
- (void)copy_option_part(&p, lead_end, COM_MAX_LEN, ",");
+ lead_end_len = copy_option_part(&p, lead_end, COM_MAX_LEN, ",");
if (what == COM_START)
{
STRCPY(lead_start, lead_end);
- lead_start_len = (int)STRLEN(lead_start);
+ lead_start_len = lead_end_len;
start_off = off;
start_align = align;
}
else if (what == COM_MIDDLE)
{
STRCPY(lead_middle, lead_end);
- lead_middle_len = (int)STRLEN(lead_middle);
+ lead_middle_len = lead_end_len;
}
else if (what == COM_END)
{
// If our line starts with the middle comment string, line it
// up with the comment opener per the 'comments' option.
if (STRNCMP(theline, lead_middle, lead_middle_len) == 0
- && STRNCMP(theline, lead_end, STRLEN(lead_end)) != 0)
+ && STRNCMP(theline, lead_end, lead_end_len) != 0)
{
done = TRUE;
if (curwin->w_cursor.lnum > 1)
// If our line starts with the end comment string, line it up
// with the middle comment
if (STRNCMP(theline, lead_middle, lead_middle_len) != 0
- && STRNCMP(theline, lead_end, STRLEN(lead_end)) == 0)
+ && STRNCMP(theline, lead_end, lead_end_len) == 0)
{
amount = get_indent_lnum(curwin->w_cursor.lnum - 1);
// XXX
p = p_rtp;
while (*p != NUL)
{
- copy_option_part(&p, NameBuff, MAXPATHL, ",");
+ int NameBufflen;
+
+ NameBufflen = copy_option_part(&p, NameBuff, MAXPATHL, ",");
mustfree = FALSE;
rt = vim_getenv((char_u *)"VIMRUNTIME", &mustfree);
if (rt != NULL &&
char_u *cp;
// Find all "doc/ *.txt" files in this directory.
- add_pathsep(NameBuff);
+ if (*NameBuff != NUL && !after_pathsep(NameBuff, NameBuff + NameBufflen))
+ {
+ STRCPY(NameBuff + NameBufflen, PATHSEPSTR);
+ NameBufflen += STRLEN_LITERAL(PATHSEPSTR);
+ }
#ifdef FEAT_MULTI_LANG
- STRCAT(NameBuff, "doc/*.??[tx]");
+ STRCPY(NameBuff + NameBufflen, "doc/*.??[tx]");
#else
- STRCAT(NameBuff, "doc/*.txt");
+ STRCPY(NameBuff + NameBufflen, "doc/*.txt");
#endif
if (gen_expand_wildcards(1, &NameBuff, &fcount,
&fnames, EW_FILE|EW_SILENT) == OK
int file_count = 0;
char_u **files;
char_u *dirp;
- char_u *dir_name;
+ string_T dir_name;
char_u *fname_res = NULL;
#ifdef HAVE_READLINK
char_u fname_buf[MAXPATHL];
* Do the loop for every directory in 'directory'.
* First allocate some memory to put the directory name in.
*/
- dir_name = alloc(STRLEN(p_dir) + 1);
+ dir_name.string = alloc(STRLEN(p_dir) + 1);
dirp = p_dir;
- while (dir_name != NULL && *dirp)
+ while (dir_name.string != NULL && *dirp)
{
/*
* Isolate a directory name from *dirp and put it in dir_name (we know
* it is large enough, so use 31000 for length).
* Advance dirp to next directory name.
*/
- (void)copy_option_part(&dirp, dir_name, 31000, ",");
+ dir_name.length = (size_t)copy_option_part(&dirp, dir_name.string, 31000, ",");
- if (dir_name[0] == '.' && dir_name[1] == NUL) // check current dir
+ if (dir_name.string[0] == '.' && dir_name.string[1] == NUL) // check current dir
{
if (fname == NULL)
{
#ifdef VMS
- names[0] = vim_strsave((char_u *)"*_sw%");
+ names[0] = vim_strnsave((char_u *)"*_sw%", STRLEN_LITERAL("*_sw%"));
#else
- names[0] = vim_strsave((char_u *)"*.sw?");
+ names[0] = vim_strnsave((char_u *)"*.sw?", STRLEN_LITERAL("*.sw?"));
#endif
#if defined(UNIX) || defined(MSWIN)
// For Unix names starting with a dot are special. MS-Windows
// supports this too, on some file systems.
- names[1] = vim_strsave((char_u *)".*.sw?");
- names[2] = vim_strsave((char_u *)".sw?");
+ names[1] = vim_strnsave((char_u *)".*.sw?", STRLEN_LITERAL(".*.sw?"));
+ names[2] = vim_strnsave((char_u *)".sw?", STRLEN_LITERAL(".sw?"));
num_names = 3;
#else
# ifdef VMS
- names[1] = vim_strsave((char_u *)".*_sw%");
+ names[1] = vim_strnsave((char_u *)".*_sw%", STRLEN_LITERAL(".*_sw%"));
num_names = 2;
# else
num_names = 1;
if (fname == NULL)
{
#ifdef VMS
- names[0] = concat_fnames(dir_name, (char_u *)"*_sw%", TRUE);
+ names[0] = concat_fnames(dir_name.string, (char_u *)"*_sw%", TRUE);
#else
- names[0] = concat_fnames(dir_name, (char_u *)"*.sw?", TRUE);
+ names[0] = concat_fnames(dir_name.string, (char_u *)"*.sw?", TRUE);
#endif
#if defined(UNIX) || defined(MSWIN)
// For Unix names starting with a dot are special. MS-Windows
// supports this too, on some file systems.
- names[1] = concat_fnames(dir_name, (char_u *)".*.sw?", TRUE);
- names[2] = concat_fnames(dir_name, (char_u *)".sw?", TRUE);
+ names[1] = concat_fnames(dir_name.string, (char_u *)".*.sw?", TRUE);
+ names[2] = concat_fnames(dir_name.string, (char_u *)".sw?", TRUE);
num_names = 3;
#else
# ifdef VMS
- names[1] = concat_fnames(dir_name, (char_u *)".*_sw%", TRUE);
+ names[1] = concat_fnames(dir_name.string, (char_u *)".*_sw%", TRUE);
num_names = 2;
# else
num_names = 1;
else
{
#if defined(UNIX) || defined(MSWIN)
- int len = (int)STRLEN(dir_name);
-
- p = dir_name + len;
- if (after_pathsep(dir_name, p) && len > 1 && p[-1] == p[-2])
+ p = dir_name.string + dir_name.length;
+ if (after_pathsep(dir_name.string, p) && dir_name.length > 1 && p[-1] == p[-2])
{
// Ends with '//', Use Full path for swap name
- tail = make_percent_swname(dir_name, p, fname_res);
+ tail = make_percent_swname(dir_name.string, p, fname_res);
}
else
#endif
{
tail = gettail(fname_res);
- tail = concat_fnames(dir_name, tail, TRUE);
+ tail = concat_fnames(dir_name.string, tail, TRUE);
}
if (tail == NULL)
num_names = 0;
}
else if (do_list)
{
- if (dir_name[0] == '.' && dir_name[1] == NUL)
+ if (dir_name.string[0] == '.' && dir_name.string[1] == NUL)
{
if (fname == NULL)
msg_puts(_(" In current directory:\n"));
else
{
msg_puts(_(" In directory "));
- msg_home_replace(dir_name);
+ msg_home_replace(dir_name.string);
msg_puts(":\n");
}
{
for (int i = 0; i < num_files; ++i)
{
- char_u *name = concat_fnames(dir_name, files[i], TRUE);
+ char_u *name = concat_fnames(dir_name.string, files[i], TRUE);
if (name != NULL)
{
list_append_string(ret_list, name, -1);
if (num_files > 0)
FreeWild(num_files, files);
}
- vim_free(dir_name);
+ vim_free(dir_name.string);
return file_count;
}
int dofree = FALSE;
char_u *p;
char_u *q = p_rtp;
- char_u *buf = alloc(MAXPATHL);
+ string_T buf;
- if (buf == NULL)
+ buf.string = alloc(MAXPATHL);
+ if (buf.string == NULL)
return;
- (void)copy_option_part(&q, buf, MAXPATHL, ",");
+ buf.length = (size_t)copy_option_part(&q, buf.string, MAXPATHL, ",");
p = vim_getenv((char_u *)"MYVIMDIR", &dofree);
- if (p == NULL || STRCMP(p, buf) != 0)
+ if (p == NULL || STRCMP(p, buf.string) != 0)
{
- add_pathsep(buf);
+ if (*buf.string != NUL && !after_pathsep(buf.string, buf.string + buf.length))
+ STRCPY(buf.string + buf.length, PATHSEPSTR);
#ifdef MSWIN
// normalize path separators
- for (q = buf; *q != NUL; q++)
+ for (q = buf.string; *q != NUL; q++)
if (*q == '/')
*q = '\\';
#endif
- vim_setenv((char_u *)"MYVIMDIR", buf);
+ vim_setenv((char_u *)"MYVIMDIR", buf.string);
}
if (dofree)
vim_free(p);
- vim_free(buf);
+ vim_free(buf.string);
}
void *cookie)
{
char_u *rtp;
- char_u *np;
- char_u *buf;
+ string_T buf;
char_u *rtp_copy;
- char_u *tail;
int num_files;
char_u **files;
int i;
// Make a copy of 'runtimepath'. Invoking the callback may change the
// value.
rtp_copy = vim_strsave(path);
- buf = alloc(MAXPATHL);
- if (buf != NULL && rtp_copy != NULL)
+ buf.string = alloc(MAXPATHL);
+ if (buf.string != NULL && rtp_copy != NULL)
{
- if (p_verbose > 10 && name != NULL)
+ size_t prefixlen = 0;
+ size_t namelen = 0;
+
+ if (name != NULL)
{
- verbose_enter();
- if (*prefix != NUL)
- smsg(_("Searching for \"%s\" under \"%s\" in \"%s\""),
- (char *)name, prefix, (char *)path);
- else
- smsg(_("Searching for \"%s\" in \"%s\""),
- (char *)name, (char *)path);
- verbose_leave();
+ prefixlen = STRLEN(prefix);
+ namelen = STRLEN(name);
+
+ if (p_verbose > 10)
+ {
+ verbose_enter();
+ if (*prefix != NUL)
+ smsg(_("Searching for \"%s\" under \"%s\" in \"%s\""),
+ (char *)name, prefix, (char *)path);
+ else
+ smsg(_("Searching for \"%s\" in \"%s\""),
+ (char *)name, (char *)path);
+ verbose_leave();
+ }
}
// Loop over all entries in 'runtimepath'.
rtp = rtp_copy;
while (*rtp != NUL && ((flags & DIP_ALL) || !did_one))
{
- size_t buflen;
-
// Copy the path from 'runtimepath' to buf[].
- copy_option_part(&rtp, buf, MAXPATHL, ",");
- buflen = STRLEN(buf);
+ buf.length = (size_t)copy_option_part(&rtp, buf.string, MAXPATHL, ",");
// Skip after or non-after directories.
if (flags & (DIP_NOAFTER | DIP_AFTER))
{
- int is_after = buflen >= 5
- && STRCMP(buf + buflen - 5, "after") == 0;
+ int is_after = buf.length >= 5
+ && STRCMP(buf.string + buf.length - 5, "after") == 0;
if ((is_after && (flags & DIP_NOAFTER))
|| (!is_after && (flags & DIP_AFTER)))
if (name == NULL)
{
- (*callback)(buf, (void *) &cookie);
+ (*callback)(buf.string, (void *)&cookie);
if (!did_one)
did_one = (cookie == NULL);
}
- else if (buflen + 2 + STRLEN(prefix) + STRLEN(name) < MAXPATHL)
+ else if (buf.length + 2 + prefixlen + namelen < MAXPATHL)
{
- add_pathsep(buf);
- STRCAT(buf, prefix);
- tail = buf + STRLEN(buf);
+ char_u *np;
+ char_u *tail;
+
+ if (*buf.string != NUL
+ && !after_pathsep(buf.string, buf.string + buf.length))
+ {
+ STRCPY(buf.string + buf.length, PATHSEPSTR);
+ buf.length += STRLEN_LITERAL(PATHSEPSTR);
+ }
+ STRCPY(buf.string + buf.length, prefix);
+ buf.length += prefixlen;
+ tail = buf.string + buf.length;
// Loop over all patterns in "name"
np = name;
while (*np != NUL && ((flags & DIP_ALL) || !did_one))
{
// Append the pattern from "name" to buf[].
- copy_option_part(&np, tail, (int)(MAXPATHL - (tail - buf)),
+ copy_option_part(&np, tail, (int)(MAXPATHL - (tail - buf.string)),
"\t ");
if (p_verbose > 10)
{
verbose_enter();
- smsg(_("Searching for \"%s\""), buf);
+ smsg(_("Searching for \"%s\""), buf.string);
verbose_leave();
}
// Expand wildcards, invoke the callback for each match.
- if (gen_expand_wildcards(1, &buf, &num_files, &files,
+ if (gen_expand_wildcards(1, &buf.string, &num_files, &files,
(flags & DIP_DIR) ? EW_DIR : EW_FILE) == OK)
{
for (i = 0; i < num_files; ++i)
}
}
}
- vim_free(buf);
+ vim_free(buf.string);
vim_free(rtp_copy);
if (!did_one && name != NULL)
{
char_u *after_insp = NULL;
char_u *ffname = NULL;
size_t fname_len;
- char_u *buf = NULL;
+ string_T buf = {NULL, 0};
char_u *rtp_ffname;
int match;
int retval = FAIL;
// Find "ffname" in "p_rtp", ignoring '/' vs '\' differences.
// Also stop at the first "after" directory.
fname_len = STRLEN(ffname);
- buf = alloc(MAXPATHL);
- if (buf == NULL)
+ buf.string = alloc(MAXPATHL);
+ if (buf.string == NULL)
goto theend;
for (entry = p_rtp; *entry != NUL; )
{
char_u *cur_entry = entry;
- copy_option_part(&entry, buf, MAXPATHL, ",");
+ buf.length = (size_t)copy_option_part(&entry, buf.string, MAXPATHL, ",");
- if ((p = (char_u *)strstr((char *)buf, "after")) != NULL
- && p > buf
+ if ((p = (char_u *)strstr((char *)buf.string, "after")) != NULL
+ && p > buf.string
&& vim_ispathsep(p[-1])
&& (vim_ispathsep(p[5]) || p[5] == NUL || p[5] == ','))
{
if (insp == NULL)
{
- add_pathsep(buf);
- rtp_ffname = fix_fname(buf);
+ if (*buf.string != NUL && !after_pathsep(buf.string, buf.string + buf.length))
+ STRCPY(buf.string + buf.length, PATHSEPSTR);
+ rtp_ffname = fix_fname(buf.string);
if (rtp_ffname == NULL)
goto theend;
match = vim_fnamencmp(rtp_ffname, ffname, fname_len) == 0;
retval = OK;
theend:
- vim_free(buf);
+ vim_free(buf.string);
vim_free(ffname);
vim_free(afterdir);
return retval;
for (splp = spl_copy; *splp != NUL; )
{
// Get one language name.
- copy_option_part(&splp, lang, MAXWLEN, ",");
+ len = copy_option_part(&splp, lang, MAXWLEN, ",");
region = NULL;
- len = (int)STRLEN(lang);
if (!valid_spelllang(lang))
continue;
else
{
// One entry in 'spellfile'.
- copy_option_part(&spf, spf_name, MAXPATHL - 4, ",");
- STRCAT(spf_name, ".spl");
+ len = copy_option_part(&spf, spf_name, MAXPATHL - 4, ",");
+ STRCPY(spf_name + len, ".spl");
// If it was already found above then skip it.
for (c = 0; c < ga.ga_len; ++c)
static void
init_spellfile(void)
{
- char_u *buf;
- int l;
+ string_T buf;
char_u *fname;
char_u *rtp;
char_u *lend;
if (*curwin->w_s->b_p_spl == NUL || curwin->w_s->b_langp.ga_len <= 0)
return;
- buf = alloc(MAXPATHL);
- if (buf == NULL)
+ buf.string = alloc(MAXPATHL);
+ if (buf.string == NULL)
return;
+ buf.length = 0;
+
// Find the end of the language name. Exclude the region. If there
// is a path separator remember the start of the tail.
for (lend = curwin->w_s->b_p_spl; *lend != NUL
if (aspath)
// Use directory of an entry with path, e.g., for
// "/dir/lg.utf-8.spl" use "/dir".
- vim_strncpy(buf, curbuf->b_s.b_p_spl,
+ vim_strncpy(buf.string, curbuf->b_s.b_p_spl,
lstart - curbuf->b_s.b_p_spl - 1);
else
// Copy the path from 'runtimepath' to buf[].
- copy_option_part(&rtp, buf, MAXPATHL, ",");
- if (filewritable(buf) == 2)
+ buf.length = (size_t)copy_option_part(&rtp, buf.string, MAXPATHL, ",");
+ if (filewritable(buf.string) == 2)
{
// Use the first language name from 'spelllang' and the
// encoding used in the first loaded .spl file.
if (aspath)
- vim_strncpy(buf, curbuf->b_s.b_p_spl,
- lend - curbuf->b_s.b_p_spl);
+ {
+ buf.length = (size_t)(lend - curbuf->b_s.b_p_spl);
+ vim_strncpy(buf.string, curbuf->b_s.b_p_spl, buf.length);
+ }
else
{
// Create the "spell" directory if it doesn't exist yet.
- l = (int)STRLEN(buf);
- vim_snprintf((char *)buf + l, MAXPATHL - l, "/spell");
- if (filewritable(buf) != 2)
+ buf.length += vim_snprintf_safelen((char *)buf.string + buf.length,
+ MAXPATHL - buf.length, "/spell");
+ if (filewritable(buf.string) != 2)
{
- if (vim_mkdir(buf, 0755) != 0)
+ if (vim_mkdir(buf.string, 0755) != 0)
{
- vim_free(buf);
+ vim_free(buf.string);
return;
}
}
- l = (int)STRLEN(buf);
- vim_snprintf((char *)buf + l, MAXPATHL - l,
- "/%.*s", (int)(lend - lstart), lstart);
+ buf.length += vim_snprintf_safelen((char *)buf.string + buf.length,
+ MAXPATHL - buf.length, "/%.*s", (int)(lend - lstart), lstart);
}
- l = (int)STRLEN(buf);
fname = LANGP_ENTRY(curwin->w_s->b_langp, 0)
->lp_slang->sl_fname;
- vim_snprintf((char *)buf + l, MAXPATHL - l, ".%s.add",
- fname != NULL
- && strstr((char *)gettail(fname), ".ascii.") != NULL
+ vim_snprintf((char *)buf.string + buf.length, MAXPATHL - buf.length,
+ ".%s.add",
+ fname != NULL && strstr((char *)gettail(fname), ".ascii.") != NULL
? (char_u *)"ascii" : spell_enc());
set_option_value_give_err((char_u *)"spellfile",
- 0L, buf, OPT_LOCAL);
+ 0L, buf.string, OPT_LOCAL);
break;
}
aspath = FALSE;
}
- vim_free(buf);
+ vim_free(buf.string);
}
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 193,
/**/
192,
/**/
{
char_u *p;
char_u part[51];
+ int part_len;
int retval = FALSE;
- size_t n;
name = home_replace_save(NULL, name);
if (name == NULL)
return FALSE;
for (p = p_viminfo; *p; )
{
- copy_option_part(&p, part, 51, ", ");
+ part_len = copy_option_part(&p, part, sizeof(part), ", ");
if (part[0] == 'r')
{
- n = STRLEN(part + 1);
- if (MB_STRNICMP(part + 1, name, n) == 0)
+ if (MB_STRNICMP(part + 1, name, part_len - 1) == 0)
{
retval = TRUE;
break;