Fix style issues.

* Rename mch_full_name to mch_get_absolute_path.
* Rename mch_is_full_name to mch_is_absolute_path.
* Add a lot of missing parentheses.
* Remove yoda-conditions for consistency.
* Remove spaces in function declaration.
This commit is contained in:
Thomas Wienecke 2014-03-05 12:34:15 +01:00 committed by Thiago de Arruda
parent fdba1761f6
commit fc86866402
12 changed files with 52 additions and 45 deletions

View File

@ -2418,7 +2418,7 @@ void buflist_altfpos(win_T *win)
/*
* Return TRUE if 'ffname' is not the same file as current file.
* Fname must have a full path (expanded by mch_full_name()).
* Fname must have a full path (expanded by mch_get_absolute_path()).
*/
int otherfile(char_u *ffname)
{

View File

@ -12468,7 +12468,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv)
q[-1] = NUL;
q = gettail(p);
}
if (q > p && !mch_is_full_name(buf)) {
if (q > p && !mch_is_absolute_path(buf)) {
/* symlink is relative to directory of argument */
cpy = alloc((unsigned)(STRLEN(p) + STRLEN(buf) + 1));
if (cpy != NULL) {

View File

@ -3945,7 +3945,7 @@ expand_shellcmd (
flags |= EW_FILE | EW_EXEC;
/* For an absolute name we don't use $PATH. */
if (mch_is_full_name(pat))
if (mch_is_absolute_path(pat))
path = (char_u *)" ";
else if ((pat[0] == '.' && (vim_ispathsep(pat[1])
|| (pat[1] == '.' && vim_ispathsep(pat[2])))))

View File

@ -4770,7 +4770,7 @@ void shorten_fnames(int force)
&& !path_with_url(buf->b_fname)
&& (force
|| buf->b_sfname == NULL
|| mch_is_full_name(buf->b_sfname))) {
|| mch_is_absolute_path(buf->b_sfname))) {
vim_free(buf->b_sfname);
buf->b_sfname = NULL;
p = shorten_fname(buf->b_ffname, dirname);

View File

@ -3382,7 +3382,7 @@ int resolve_symlink(char_u *fname, char_u *buf)
* portion of the filename (if any) and the path the symlink
* points to.
*/
if (mch_is_full_name(buf))
if (mch_is_absolute_path(buf))
STRCPY(tmp, buf);
else {
char_u *tail;

View File

@ -7945,7 +7945,7 @@ static void expand_path_option(char_u *curdir, garray_T *gap)
else if (path_with_url(buf))
/* URL can't be used here */
continue;
else if (!mch_is_full_name(buf)) {
else if (!mch_is_absolute_path(buf)) {
/* Expand relative path to their full path equivalent */
len = (int)STRLEN(curdir);
if (len + (int)STRLEN(buf) + 3 > MAXPATHL)
@ -8086,7 +8086,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
break;
}
if (mch_is_full_name(path)) {
if (mch_is_absolute_path(path)) {
/*
* Last resort: shorten relative to curdir if possible.
* 'possible' means:
@ -8375,7 +8375,7 @@ gen_expand_wildcards (
*/
if (mch_has_exp_wildcard(p)) {
if ((flags & EW_PATH)
&& !mch_is_full_name(p)
&& !mch_is_absolute_path(p)
&& !(p[0] == '.'
&& (vim_ispathsep(p[1])
|| (p[1] == '.' && vim_ispathsep(p[2]))))

View File

@ -50,35 +50,38 @@ int mch_full_dir_name(char *directory, char *buffer, int len)
{
int retval = OK;
if(0 == STRLEN(directory)) {
if(STRLEN(directory) == 0) {
return mch_dirname((char_u *) buffer, len);
}
char old_dir[MAXPATHL];
/* Get current directory name. */
if (FAIL == mch_dirname((char_u *) old_dir, MAXPATHL)) {
if (mch_dirname((char_u *) old_dir, MAXPATHL) == FAIL) {
return FAIL;
}
/* We have to get back to the current dir at the end, check if that works. */
if (0 != mch_chdir(old_dir)) {
if (mch_chdir(old_dir) != 0) {
return FAIL;
}
if (0 != mch_chdir(directory)) {
if (mch_chdir(directory) != 0) {
/* Do not return immediatly since we may be in the wrong directory. */
retval = FAIL;
}
if ((FAIL == retval) || (FAIL == mch_dirname((char_u *) buffer, len))) {
if (retval == FAIL || mch_dirname((char_u *) buffer, len) == FAIL) {
/* Do not return immediatly since we are in the wrong directory. */
retval = FAIL;
}
if (0 != mch_chdir(old_dir)) {
if (mch_chdir(old_dir) != 0) {
/* That shouldn't happen, since we've tested if it works. */
retval = FAIL;
EMSG(_(e_prev_dir));
}
return retval;
}
@ -91,19 +94,23 @@ int append_path(char *path, char *to_append, int max_len)
int to_append_length = STRLEN(to_append);
/* Do not append empty strings. */
if (0 == to_append_length)
if (to_append_length == 0) {
return OK;
}
/* Do not append a dot. */
if (STRCMP(to_append, ".") == 0)
if (STRCMP(to_append, ".") == 0) {
return OK;
}
/* Glue both paths with a slash. */
if (current_length > 0 && path[current_length-1] != '/') {
current_length += 1; /* Count the trailing slash. */
if (current_length > max_len)
/* +1 for the NUL at the end. */
if (current_length +1 > max_len) {
return FAIL;
}
STRCAT(path, "/");
}
@ -125,7 +132,7 @@ int append_path(char *path, char *to_append, int max_len)
*
* return FAIL for failure, OK for success
*/
int mch_full_name(char_u *fname, char_u *buf, int len, int force)
int mch_get_absolute_path(char_u *fname, char_u *buf, int len, int force)
{
char_u *p;
*buf = NUL;
@ -134,7 +141,7 @@ int mch_full_name(char_u *fname, char_u *buf, int len, int force)
char *end_of_path = (char *) fname;
/* expand it if forced or not an absolute path */
if (force || !mch_is_full_name(fname)) {
if (force || !mch_is_absolute_path(fname)) {
if ((p = vim_strrchr(fname, '/')) != NULL) {
STRNCPY(relative_directory, fname, p-fname);
@ -155,7 +162,7 @@ int mch_full_name(char_u *fname, char_u *buf, int len, int force)
/*
* Return TRUE if "fname" does not depend on the current directory.
*/
int mch_is_full_name(char_u *fname)
int mch_is_absolute_path(char_u *fname)
{
return *fname == '/' || *fname == '~';
}

View File

@ -6,8 +6,8 @@
long_u mch_total_mem(int special);
int mch_chdir(char *path);
int mch_dirname(char_u *buf, int len);
int mch_full_name (char_u *fname, char_u *buf, int len, int force);
int mch_is_full_name (char_u *fname);
int mch_get_absolute_path(char_u *fname, char_u *buf, int len, int force);
int mch_is_absolute_path(char_u *fname);
int mch_isdir(char_u *name);
#endif

View File

@ -1344,7 +1344,7 @@ int mch_can_exe(char_u *name)
int retval;
/* If it's an absolute or relative path don't need to use $PATH. */
if (mch_is_full_name(name) || (name[0] == '.' && (name[1] == '/'
if (mch_is_absolute_path(name) || (name[0] == '.' && (name[1] == '/'
|| (name[1] == '.' &&
name[2] == '/'))))
return executable_file(name);

View File

@ -4188,7 +4188,7 @@ static void syn_cmd_include(exarg_T *eap, int syncing)
*/
eap->argt |= (XFILE | NOSPC);
separate_nextcmd(eap);
if (*eap->arg == '<' || *eap->arg == '$' || mch_is_full_name(eap->arg)) {
if (*eap->arg == '<' || *eap->arg == '$' || mch_is_absolute_path(eap->arg)) {
/* For an absolute path, "$VIM/..." or "<sfile>.." we ":source" the
* file. Need to expand the file name first. In other cases
* ":runtime!" is used. */

View File

@ -5065,7 +5065,7 @@ int path_with_url(char_u *fname)
*/
int vim_isAbsName(char_u *name)
{
return path_with_url(name) != 0 || mch_is_full_name(name);
return path_with_url(name) != 0 || mch_is_absolute_path(name);
}
/*
@ -5090,7 +5090,7 @@ vim_FullName (
url = path_with_url(fname);
if (!url)
retval = mch_full_name(fname, buf, len, force);
retval = mch_get_absolute_path(fname, buf, len, force);
if (url || retval == FAIL) {
/* something failed; use the file name (truncate when too long) */
vim_strncpy(buf, fname, len - 1);

View File

@ -70,12 +70,12 @@ describe 'fs function', ->
eq lfs.currentdir! .. '/empty-test-directory', (ffi.string buffer)
eq OK, result
describe 'mch_full_name', ->
ffi.cdef 'int mch_full_name(char *fname, char *buf, int len, int force);'
describe 'mch_get_absolute_path', ->
ffi.cdef 'int mch_get_absolute_path(char *fname, char *buf, int len, int force);'
mch_full_name = (filename, buffer, length, force) ->
mch_get_absolute_path = (filename, buffer, length, force) ->
filename = cstr (string.len filename) + 1, filename
fs.mch_full_name filename, buffer, length, force
fs.mch_get_absolute_path filename, buffer, length, force
before_each ->
-- Create empty string buffer which will contain the resulting path.
@ -92,12 +92,12 @@ describe 'fs function', ->
it 'fails if given filename contains non-existing directory', ->
force_expansion = 1
result = mch_full_name 'non_existing_dir/test.file', buffer, len, force_expansion
result = mch_get_absolute_path 'non_existing_dir/test.file', buffer, len, force_expansion
eq FAIL, result
it 'concatenates given filename if it does not contain a slash', ->
force_expansion = 1
result = mch_full_name 'test.file', buffer, len, force_expansion
result = mch_get_absolute_path 'test.file', buffer, len, force_expansion
expected = lfs.currentdir! .. '/test.file'
eq expected, (ffi.string buffer)
eq OK, result
@ -105,7 +105,7 @@ describe 'fs function', ->
it 'concatenates given filename if it is a directory but does not contain a
slash', ->
force_expansion = 1
result = mch_full_name '..', buffer, len, force_expansion
result = mch_get_absolute_path '..', buffer, len, force_expansion
expected = lfs.currentdir! .. '/..'
eq expected, (ffi.string buffer)
eq OK, result
@ -115,7 +115,7 @@ describe 'fs function', ->
it 'enters given directory (instead of just concatenating the strings) if
possible and if path contains a slash', ->
force_expansion = 1
result = mch_full_name '../test.file', buffer, len, force_expansion
result = mch_get_absolute_path '../test.file', buffer, len, force_expansion
old_dir = lfs.currentdir!
lfs.chdir '..'
expected = lfs.currentdir! .. '/test.file'
@ -126,26 +126,26 @@ describe 'fs function', ->
it 'just copies the path if it is already absolute and force=0', ->
force_expansion = 0
absolute_path = '/absolute/path'
result = mch_full_name absolute_path, buffer, len, force_expansion
result = mch_get_absolute_path absolute_path, buffer, len, force_expansion
eq absolute_path, (ffi.string buffer)
eq OK, result
it 'fails when the path is relative to HOME', ->
force_expansion = 1
absolute_path = '~/home.file'
result = mch_full_name absolute_path, buffer, len, force_expansion
result = mch_get_absolute_path absolute_path, buffer, len, force_expansion
eq FAIL, result
it 'works with some "normal" relative path with directories', ->
force_expansion = 1
result = mch_full_name 'empty-test-directory/empty.file', buffer, len, force_expansion
result = mch_get_absolute_path 'empty-test-directory/empty.file', buffer, len, force_expansion
eq OK, result
eq lfs.currentdir! .. '/empty-test-directory/empty.file', (ffi.string buffer)
it 'does not modify the given filename', ->
force_expansion = 1
filename = cstr 100, 'empty-test-directory/empty.file'
result = fs.mch_full_name filename, buffer, len, force_expansion
result = fs.mch_get_absolute_path filename, buffer, len, force_expansion
eq lfs.currentdir! .. '/empty-test-directory/empty.file', (ffi.string buffer)
eq 'empty-test-directory/empty.file', (ffi.string filename)
eq OK, result
@ -188,18 +188,18 @@ describe 'fs function', ->
eq OK, (fs.append_path path, to_append, 7)
eq '/path2', (ffi.string path)
describe 'mch_is_full_name', ->
ffi.cdef 'int mch_is_full_name(char *fname);'
describe 'mch_is_absolute_path', ->
ffi.cdef 'int mch_is_absolute_path(char *fname);'
mch_is_full_name = (filename) ->
mch_is_absolute_path = (filename) ->
filename = cstr (string.len filename) + 1, filename
fs.mch_is_full_name filename
fs.mch_is_absolute_path filename
it 'returns true if filename starts with a slash', ->
eq OK, mch_is_full_name '/some/directory/'
eq OK, mch_is_absolute_path '/some/directory/'
it 'returns true if filename starts with a tilde', ->
eq OK, mch_is_full_name '~/in/my/home~/directory'
eq OK, mch_is_absolute_path '~/in/my/home~/directory'
it 'returns false if filename starts not with slash nor tilde', ->
eq FAIL, mch_is_full_name 'not/in/my/home~/directory'
eq FAIL, mch_is_absolute_path 'not/in/my/home~/directory'