mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-27 19:53:36 +08:00
lint: Use early exit/continue
This commit is contained in:
parent
2a5ad198bf
commit
49ed20c8cb
|
@ -381,59 +381,62 @@ int wgetopter_t::_wgetopt_internal(int argc, wchar_t **argv, const wchar_t *opts
|
|||
}
|
||||
|
||||
// Look at and handle the next short option-character.
|
||||
{
|
||||
wchar_t c = *nextchar++;
|
||||
wchar_t *temp = const_cast<wchar_t *>(my_index(optstring, c));
|
||||
wchar_t c = *nextchar++;
|
||||
wchar_t *temp = const_cast<wchar_t *>(my_index(optstring, c));
|
||||
|
||||
// Increment `woptind' when we start to process its last character.
|
||||
if (*nextchar == '\0') ++woptind;
|
||||
// Increment `woptind' when we start to process its last character.
|
||||
if (*nextchar == '\0') ++woptind;
|
||||
|
||||
if (temp == NULL || c == ':') {
|
||||
if (wopterr) {
|
||||
fwprintf(stderr, _(L"%ls: Invalid option -- %lc\n"), argv[0], (wint_t)c);
|
||||
}
|
||||
woptopt = c;
|
||||
|
||||
if (*nextchar != '\0') woptind++;
|
||||
|
||||
return '?';
|
||||
}
|
||||
if (temp[1] == ':') {
|
||||
if (temp[2] == ':') {
|
||||
// This is an option that accepts an argument optionally.
|
||||
if (*nextchar != '\0') {
|
||||
woptarg = nextchar;
|
||||
woptind++;
|
||||
} else
|
||||
woptarg = NULL;
|
||||
nextchar = NULL;
|
||||
} else {
|
||||
// This is an option that requires an argument.
|
||||
if (*nextchar != '\0') {
|
||||
woptarg = nextchar;
|
||||
// If we end this ARGV-element by taking the rest as an arg, we must advance to
|
||||
// the next element now.
|
||||
woptind++;
|
||||
} else if (woptind == argc) {
|
||||
if (wopterr) {
|
||||
// 1003.2 specifies the format of this message.
|
||||
fwprintf(stderr, _(L"%ls: Option requires an argument -- %lc\n"), argv[0],
|
||||
(wint_t)c);
|
||||
}
|
||||
woptopt = c;
|
||||
if (optstring[0] == ':')
|
||||
c = ':';
|
||||
else
|
||||
c = '?';
|
||||
} else
|
||||
// We already incremented `woptind' once; increment it again when taking next
|
||||
// ARGV-elt as argument.
|
||||
woptarg = argv[woptind++];
|
||||
nextchar = NULL;
|
||||
}
|
||||
if (temp == NULL || c == ':') {
|
||||
if (wopterr) {
|
||||
fwprintf(stderr, _(L"%ls: Invalid option -- %lc\n"), argv[0], (wint_t)c);
|
||||
}
|
||||
woptopt = c;
|
||||
|
||||
if (*nextchar != '\0') woptind++;
|
||||
return '?';
|
||||
}
|
||||
|
||||
if (temp[1] != ':') {
|
||||
return c;
|
||||
}
|
||||
|
||||
if (temp[2] == ':') {
|
||||
// This is an option that accepts an argument optionally.
|
||||
if (*nextchar != '\0') {
|
||||
woptarg = nextchar;
|
||||
woptind++;
|
||||
} else {
|
||||
woptarg = NULL;
|
||||
}
|
||||
nextchar = NULL;
|
||||
} else {
|
||||
// This is an option that requires an argument.
|
||||
if (*nextchar != '\0') {
|
||||
woptarg = nextchar;
|
||||
// If we end this ARGV-element by taking the rest as an arg, we must advance to
|
||||
// the next element now.
|
||||
woptind++;
|
||||
} else if (woptind == argc) {
|
||||
if (wopterr) {
|
||||
// 1003.2 specifies the format of this message.
|
||||
fwprintf(stderr, _(L"%ls: Option requires an argument -- %lc\n"), argv[0],
|
||||
(wint_t)c);
|
||||
}
|
||||
woptopt = c;
|
||||
if (optstring[0] == ':') {
|
||||
c = ':';
|
||||
} else {
|
||||
c = '?';
|
||||
}
|
||||
} else {
|
||||
// We already incremented `woptind' once; increment it again when taking next
|
||||
// ARGV-elt as argument.
|
||||
woptarg = argv[woptind++];
|
||||
}
|
||||
nextchar = NULL;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int wgetopter_t::wgetopt_long(int argc, wchar_t **argv, const wchar_t *options,
|
||||
|
|
|
@ -50,40 +50,39 @@ bool wreaddir_resolving(DIR *dir, const std::wstring &dir_path, std::wstring &ou
|
|||
if (!d) return false;
|
||||
|
||||
out_name = str2wcstring(d->d_name);
|
||||
if (out_is_dir) {
|
||||
// The caller cares if this is a directory, so check.
|
||||
bool is_dir = false;
|
||||
if (!out_is_dir) return true;
|
||||
|
||||
// We may be able to skip stat, if the readdir can tell us the file type directly.
|
||||
bool check_with_stat = true;
|
||||
// The caller cares if this is a directory, so check.
|
||||
bool is_dir = false;
|
||||
// We may be able to skip stat, if the readdir can tell us the file type directly.
|
||||
bool check_with_stat = true;
|
||||
#ifdef HAVE_STRUCT_DIRENT_D_TYPE
|
||||
if (d->d_type == DT_DIR) {
|
||||
// Known directory.
|
||||
is_dir = true;
|
||||
check_with_stat = false;
|
||||
} else if (d->d_type == DT_LNK || d->d_type == DT_UNKNOWN) {
|
||||
// We want to treat symlinks to directories as directories. Use stat to resolve it.
|
||||
check_with_stat = true;
|
||||
} else {
|
||||
// Regular file.
|
||||
is_dir = false;
|
||||
check_with_stat = false;
|
||||
}
|
||||
#endif // HAVE_STRUCT_DIRENT_D_TYPE
|
||||
if (check_with_stat) {
|
||||
// We couldn't determine the file type from the dirent; check by stat'ing it.
|
||||
cstring fullpath = wcs2string(dir_path);
|
||||
fullpath.push_back('/');
|
||||
fullpath.append(d->d_name);
|
||||
struct stat buf;
|
||||
if (stat(fullpath.c_str(), &buf) != 0) {
|
||||
is_dir = false;
|
||||
} else {
|
||||
is_dir = static_cast<bool>(S_ISDIR(buf.st_mode));
|
||||
}
|
||||
}
|
||||
*out_is_dir = is_dir;
|
||||
if (d->d_type == DT_DIR) {
|
||||
// Known directory.
|
||||
is_dir = true;
|
||||
check_with_stat = false;
|
||||
} else if (d->d_type == DT_LNK || d->d_type == DT_UNKNOWN) {
|
||||
// We want to treat symlinks to directories as directories. Use stat to resolve it.
|
||||
check_with_stat = true;
|
||||
} else {
|
||||
// Regular file.
|
||||
is_dir = false;
|
||||
check_with_stat = false;
|
||||
}
|
||||
#endif // HAVE_STRUCT_DIRENT_D_TYPE
|
||||
if (check_with_stat) {
|
||||
// We couldn't determine the file type from the dirent; check by stat'ing it.
|
||||
cstring fullpath = wcs2string(dir_path);
|
||||
fullpath.push_back('/');
|
||||
fullpath.append(d->d_name);
|
||||
struct stat buf;
|
||||
if (stat(fullpath.c_str(), &buf) != 0) {
|
||||
is_dir = false;
|
||||
} else {
|
||||
is_dir = static_cast<bool>(S_ISDIR(buf.st_mode));
|
||||
}
|
||||
}
|
||||
*out_is_dir = is_dir;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user