diff options
author | Eliseo Martínez <eliseomarmol@gmail.com> | 2015-05-07 08:08:31 +0200 |
---|---|---|
committer | Eliseo Martínez <eliseomarmol@gmail.com> | 2015-05-07 08:08:31 +0200 |
commit | f88cec802169d94ad0a19d45746feac5fe2ea0fa (patch) | |
tree | c87107941de9eab120e21df65e46432921c7aebe /src/nvim/fileio.c | |
parent | a2cf628603bf5948f96ceb90b653d2879a9d2f9e (diff) | |
parent | 2f60a69bafc4b5130fb213df206179701ec0d74a (diff) | |
download | rneovim-f88cec802169d94ad0a19d45746feac5fe2ea0fa.tar.gz rneovim-f88cec802169d94ad0a19d45746feac5fe2ea0fa.tar.bz2 rneovim-f88cec802169d94ad0a19d45746feac5fe2ea0fa.zip |
Merge #2470: Remove char_u (5)
Reviewed-by: Scott Prager <splinterofchaos@gmail.com>
Reviewed-by: Michael Reed <m.reed@mykolab.com>
Reviewed-by: Eliseo Martínez <eliseomarmol@gmail.com>
Diffstat (limited to 'src/nvim/fileio.c')
-rw-r--r-- | src/nvim/fileio.c | 146 |
1 files changed, 73 insertions, 73 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 98a2cb4076..f5cf226da4 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -2814,7 +2814,7 @@ buf_write ( /* * Make backup file name. */ - backup = modname(rootname, backup_ext, FALSE); + backup = (char_u *)modname((char *)rootname, (char *)backup_ext, FALSE); if (backup == NULL) { xfree(rootname); some_error = TRUE; /* out of memory */ @@ -2985,7 +2985,7 @@ nobackup: if (rootname == NULL) backup = NULL; else { - backup = modname(rootname, backup_ext, FALSE); + backup = (char_u *)modname((char *)rootname, (char *)backup_ext, FALSE); xfree(rootname); } @@ -3595,7 +3595,7 @@ restore_backup: * the backup file our 'original' file. */ if (*p_pm && dobackup) { - char *org = (char *)modname(fname, p_pm, FALSE); + char *org = modname((char *)fname, (char *)p_pm, FALSE); if (backup != NULL) { /* @@ -4310,7 +4310,7 @@ void shorten_fnames(int force) FOR_ALL_BUFFERS(buf) { if (buf->b_fname != NULL && !bt_nofile(buf) - && !path_with_url(buf->b_fname) + && !path_with_url((char *)buf->b_fname) && (force || buf->b_sfname == NULL || path_is_absolute_path(buf->b_sfname))) { @@ -4333,108 +4333,108 @@ void shorten_fnames(int force) redraw_tabline = TRUE; } -/* - * add extension to file name - change path/fo.o.h to path/fo.o.h.ext - * - * Assumed that fname is a valid name found in the filesystem we assure that - * the return value is a different name and ends in 'ext'. - * "ext" MUST be at most 4 characters long if it starts with a dot, 3 - * characters otherwise. - * Space for the returned name is allocated, must be freed later. - * Returns NULL when out of memory. - */ -char_u * -modname ( - char_u *fname, - char_u *ext, - int prepend_dot /* may prepend a '.' to file name */ -) +/// Get new filename ended by given extension. +/// +/// @param fname The original filename. +/// If NULL, use current directory name and ext to +/// compute new filename. +/// @param ext The extension to add to the filename. +/// 4 chars max if prefixed with a dot, 3 otherwise. +/// @param prepend_dot If true, prefix ext with a dot. +/// Does nothing if ext already starts with a dot, or +/// if fname is NULL. +/// +/// @return [allocated] - A new filename, made up from: +/// * fname + ext, if fname not NULL. +/// * current dir + ext, if fname is NULL. +/// On Windows, and if ext starts with ".", a "_" is +/// preprended to ext (for filename to be valid). +/// Result is guaranteed to: +/// * be ended by <ext>. +/// * have a basename with at most BASENAMELEN chars: +/// original basename is truncated if necessary. +/// * be different than original: basename chars are +/// replaced by "_" if necessary. If that can't be done +/// because truncated value of original filename was +/// made of all underscores, replace first "_" by "v". +/// - NULL, if fname is NULL and there was a problem trying +/// to get current directory. +char *modname(const char *fname, const char *ext, bool prepend_dot) + FUNC_ATTR_NONNULL_ARG(2) { - char_u *retval; - char_u *s; - char_u *e; - char_u *ptr; - int fnamelen, extlen; - - extlen = (int)STRLEN(ext); + char *retval; + size_t fnamelen; + size_t extlen = strlen(ext); - /* - * If there is no file name we must get the name of the current directory - * (we need the full path in case :cd is used). - */ + // If there is no file name we must get the name of the current directory + // (we need the full path in case :cd is used). if (fname == NULL || *fname == NUL) { - retval = xmalloc(MAXPATHL + extlen + 3); - if (os_dirname(retval, MAXPATHL) == FAIL || - (fnamelen = (int)STRLEN(retval)) == 0) { + retval = xmalloc(MAXPATHL + extlen + 3); // +3 for PATHSEP, "_" (Win), NUL + if (os_dirname((char_u *)retval, MAXPATHL) == FAIL || + (fnamelen = strlen(retval)) == 0) { xfree(retval); return NULL; } - if (!after_pathsep((char *)retval, (char *)retval + fnamelen)) { - retval[fnamelen++] = PATHSEP; - retval[fnamelen] = NUL; - } - prepend_dot = FALSE; /* nothing to prepend a dot to */ + add_pathsep(retval); + fnamelen = strlen(retval); + prepend_dot = FALSE; // nothing to prepend a dot to } else { - fnamelen = (int)STRLEN(fname); + fnamelen = strlen(fname); retval = xmalloc(fnamelen + extlen + 3); - STRCPY(retval, fname); + strcpy(retval, fname); } - /* - * search backwards until we hit a '/', '\' or ':'. - * Then truncate what is after the '/', '\' or ':' to BASENAMELEN characters. - */ + // Search backwards until we hit a '/', '\' or ':'. + // Then truncate what is after the '/', '\' or ':' to BASENAMELEN characters. + char *ptr = NULL; for (ptr = retval + fnamelen; ptr > retval; mb_ptr_back(retval, ptr)) { if (vim_ispathsep(*ptr)) { - ++ptr; + ptr++; break; } } - /* the file name has at most BASENAMELEN characters. */ - if (STRLEN(ptr) > BASENAMELEN) + // the file name has at most BASENAMELEN characters. + if (strlen(ptr) > BASENAMELEN) { ptr[BASENAMELEN] = '\0'; + } - s = ptr + STRLEN(ptr); + char *s; + s = ptr + strlen(ptr); #if defined(WIN3264) - /* - * If there is no file name, and the extension starts with '.', put a - * '_' before the dot, because just ".ext" may be invalid if it's on a - * FAT partition, and on HPFS it doesn't matter. - */ - else if ((fname == NULL || *fname == NUL) && *ext == '.') + // If there is no file name, and the extension starts with '.', put a + // '_' before the dot, because just ".ext" may be invalid if it's on a + // FAT partition, and on HPFS it doesn't matter. + else if ((fname == NULL || *fname == NUL) && *ext == '.') { *s++ = '_'; + } #endif - /* - * Append the extension. - * ext can start with '.' and cannot exceed 3 more characters. - */ - STRCPY(s, ext); + // Append the extension. + // ext can start with '.' and cannot exceed 3 more characters. + strcpy(s, ext); - /* - * Prepend the dot. - */ - if (prepend_dot && *(e = path_tail(retval)) != '.') { + char *e; + // Prepend the dot if needed. + if (prepend_dot && *(e = (char *)path_tail((char_u *)retval)) != '.') { STRMOVE(e + 1, e); *e = '.'; } - /* - * Check that, after appending the extension, the file name is really - * different. - */ - if (fname != NULL && STRCMP(fname, retval) == 0) { - /* we search for a character that can be replaced by '_' */ + // Check that, after appending the extension, the file name is really + // different. + if (fname != NULL && strcmp(fname, retval) == 0) { + // we search for a character that can be replaced by '_' while (--s >= ptr) { if (*s != '_') { *s = '_'; break; } } - if (s < ptr) /* fname was "________.<ext>", how tricky! */ + if (s < ptr) { // fname was "________.<ext>", how tricky! *ptr = 'v'; + } } return retval; } @@ -6597,7 +6597,7 @@ apply_autocmds_group ( || event == EVENT_TABCLOSED) fname = vim_strsave(fname); else - fname = FullName_save(fname, FALSE); + fname = (char_u *)FullName_save((char *)fname, FALSE); } if (fname == NULL) { /* out of memory */ xfree(sfname); @@ -6923,7 +6923,7 @@ int has_autocmd(event_T event, char_u *sfname, buf_T *buf) char_u *tail = path_tail(sfname); int retval = FALSE; - fname = FullName_save(sfname, FALSE); + fname = (char_u *)FullName_save((char *)sfname, FALSE); if (fname == NULL) return FALSE; |