mirror of https://github.com/MidnightCommander/mc
* utilunix.c (canonicalize_pathname): Return void to make it
clear that the conversion is done in place. Adjust all callers.
This commit is contained in:
parent
c7c3073133
commit
4ced5086ac
|
@ -1,5 +1,8 @@
|
|||
2004-01-23 Pavel Roskin <proski@gnu.org>
|
||||
|
||||
* utilunix.c (canonicalize_pathname): Return void to make it
|
||||
clear that the conversion is done in place. Adjust all callers.
|
||||
|
||||
* filegui.c (init_replace): Don't show the "Reget" button when
|
||||
moving files. Reported by Arpad Biro <biro_arpad@yahoo.com>
|
||||
|
||||
|
|
151
src/complete.c
151
src/complete.c
|
@ -406,107 +406,110 @@ command_completion_function (char *text, int state)
|
|||
static int isabsolute;
|
||||
static int phase;
|
||||
static int text_len;
|
||||
static const char * const * words;
|
||||
static const char *const *words;
|
||||
static char *path;
|
||||
static char *cur_path;
|
||||
static char *cur_word;
|
||||
static int init_state;
|
||||
static const char * const bash_reserved [] = {
|
||||
"if", "then", "else", "elif", "fi", "case", "esac", "for", "select",
|
||||
"while", "until", "do", "done", "in", "function" , 0
|
||||
static const char *const bash_reserved[] = {
|
||||
"if", "then", "else", "elif", "fi", "case", "esac", "for",
|
||||
"select", "while", "until", "do", "done", "in", "function", 0
|
||||
};
|
||||
static const char * const bash_builtins [] = {
|
||||
"alias", "bg", "bind", "break", "builtin", "cd", "command", "continue",
|
||||
"declare", "dirs", "echo", "enable", "eval", "exec", "exit", "export",
|
||||
"fc", "fg", "getopts", "hash", "help", "history", "jobs", "kill", "let",
|
||||
"local", "logout", "popd", "pushd", "pwd", "read", "readonly", "return",
|
||||
"set", "shift", "source", "suspend", "test", "times", "trap", "type",
|
||||
"typeset", "ulimit", "umask", "unalias", "unset", "wait" , 0
|
||||
static const char *const bash_builtins[] = {
|
||||
"alias", "bg", "bind", "break", "builtin", "cd", "command",
|
||||
"continue", "declare", "dirs", "echo", "enable", "eval",
|
||||
"exec", "exit", "export", "fc", "fg", "getopts", "hash",
|
||||
"help", "history", "jobs", "kill", "let", "local", "logout",
|
||||
"popd", "pushd", "pwd", "read", "readonly", "return", "set",
|
||||
"shift", "source", "suspend", "test", "times", "trap", "type",
|
||||
"typeset", "ulimit", "umask", "unalias", "unset", "wait", 0
|
||||
};
|
||||
char *p, *found;
|
||||
|
||||
if (!state){ /* Initialize us a little bit */
|
||||
if (!state) { /* Initialize us a little bit */
|
||||
isabsolute = strchr (text, PATH_SEP) != 0;
|
||||
look_for_executables = isabsolute ? 1 : 2;
|
||||
if (!isabsolute){
|
||||
look_for_executables = isabsolute ? 1 : 2;
|
||||
if (!isabsolute) {
|
||||
words = bash_reserved;
|
||||
phase = 0;
|
||||
text_len = strlen (text);
|
||||
path = getenv ("PATH");
|
||||
if (path){
|
||||
if (path) {
|
||||
p = path = g_strdup (path);
|
||||
path_end = strchr (p, 0);
|
||||
while ((p = strchr (p, PATH_ENV_SEP))){
|
||||
while ((p = strchr (p, PATH_ENV_SEP))) {
|
||||
*p++ = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isabsolute){
|
||||
p = filename_completion_function (text, state);
|
||||
if (!p)
|
||||
look_for_executables = 0;
|
||||
return p;
|
||||
|
||||
if (isabsolute) {
|
||||
p = filename_completion_function (text, state);
|
||||
if (!p)
|
||||
look_for_executables = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
found = NULL;
|
||||
switch (phase){
|
||||
case 0: /* Reserved words */
|
||||
while (*words){
|
||||
if (!strncmp (*words, text, text_len))
|
||||
return g_strdup (*(words++));
|
||||
words++;
|
||||
found = NULL;
|
||||
switch (phase) {
|
||||
case 0: /* Reserved words */
|
||||
while (*words) {
|
||||
if (!strncmp (*words, text, text_len))
|
||||
return g_strdup (*(words++));
|
||||
words++;
|
||||
}
|
||||
phase++;
|
||||
words = bash_builtins;
|
||||
case 1: /* Builtin commands */
|
||||
while (*words) {
|
||||
if (!strncmp (*words, text, text_len))
|
||||
return g_strdup (*(words++));
|
||||
words++;
|
||||
}
|
||||
phase++;
|
||||
if (!path)
|
||||
break;
|
||||
cur_path = path;
|
||||
cur_word = NULL;
|
||||
case 2: /* And looking through the $PATH */
|
||||
while (!found) {
|
||||
if (!cur_word) {
|
||||
char *expanded;
|
||||
|
||||
if (cur_path >= path_end)
|
||||
break;
|
||||
expanded = tilde_expand (*cur_path ? cur_path : ".");
|
||||
cur_word = concat_dir_and_file (expanded, text);
|
||||
g_free (expanded);
|
||||
canonicalize_pathname (cur_word);
|
||||
cur_path = strchr (cur_path, 0) + 1;
|
||||
init_state = state;
|
||||
}
|
||||
phase++;
|
||||
words = bash_builtins;
|
||||
case 1: /* Builtin commands */
|
||||
while (*words){
|
||||
if (!strncmp (*words, text, text_len))
|
||||
return g_strdup (*(words++));
|
||||
words++;
|
||||
}
|
||||
phase++;
|
||||
if (!path)
|
||||
break;
|
||||
cur_path = path;
|
||||
cur_word = NULL;
|
||||
case 2: /* And looking through the $PATH */
|
||||
while (!found){
|
||||
if (!cur_word){
|
||||
char *expanded;
|
||||
|
||||
if (cur_path >= path_end)
|
||||
break;
|
||||
expanded = tilde_expand (*cur_path ? cur_path : ".");
|
||||
p = canonicalize_pathname (expanded);
|
||||
cur_word = concat_dir_and_file (p, text);
|
||||
g_free (p);
|
||||
cur_path = strchr (cur_path, 0) + 1;
|
||||
init_state = state;
|
||||
}
|
||||
found = filename_completion_function (cur_word, state - init_state);
|
||||
if (!found){
|
||||
g_free (cur_word);
|
||||
cur_word = NULL;
|
||||
}
|
||||
found =
|
||||
filename_completion_function (cur_word,
|
||||
state - init_state);
|
||||
if (!found) {
|
||||
g_free (cur_word);
|
||||
cur_word = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found){
|
||||
look_for_executables = 0;
|
||||
if (path)
|
||||
g_free (path);
|
||||
return NULL;
|
||||
|
||||
if (!found) {
|
||||
look_for_executables = 0;
|
||||
if (path)
|
||||
g_free (path);
|
||||
return NULL;
|
||||
}
|
||||
if ((p = strrchr (found, PATH_SEP)) != NULL){
|
||||
p++;
|
||||
p = g_strdup (p);
|
||||
g_free (found);
|
||||
return p;
|
||||
if ((p = strrchr (found, PATH_SEP)) != NULL) {
|
||||
p++;
|
||||
p = g_strdup (p);
|
||||
g_free (found);
|
||||
return p;
|
||||
}
|
||||
return found;
|
||||
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
@ -1684,7 +1684,8 @@ prepend_cwd_on_local (char *filename)
|
|||
l = strlen (d);
|
||||
d[l++] = PATH_SEP;
|
||||
strcpy (d + l, filename);
|
||||
return canonicalize_pathname (d);
|
||||
canonicalize_pathname (d);
|
||||
return d;
|
||||
} else
|
||||
return g_strdup (filename);
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ extern struct sigaction startup_handler;
|
|||
char *tilde_expand (const char *);
|
||||
|
||||
/* Pathname canonicalization */
|
||||
char *canonicalize_pathname (char *);
|
||||
void canonicalize_pathname (char *);
|
||||
|
||||
/* Misc Unix functions */
|
||||
char *get_current_wd (char *buffer, int size);
|
||||
|
|
|
@ -457,14 +457,14 @@ close_error_pipe (int error, char *text)
|
|||
Trailing `/'s are removed.
|
||||
Non-leading `../'s and trailing `..'s are handled by removing
|
||||
portions of the path. */
|
||||
char *
|
||||
void
|
||||
canonicalize_pathname (char *path)
|
||||
{
|
||||
char *p, *s;
|
||||
int len;
|
||||
|
||||
if (!path[0] || !path[1])
|
||||
return path;
|
||||
return;
|
||||
|
||||
/* Collapse multiple slashes */
|
||||
p = path;
|
||||
|
@ -495,7 +495,7 @@ canonicalize_pathname (char *path)
|
|||
if (path[0] == '.' && path[1] == PATH_SEP) {
|
||||
if (path[2] == 0) {
|
||||
path[1] = 0;
|
||||
return path;
|
||||
return;
|
||||
} else {
|
||||
strcpy (path, path + 2);
|
||||
}
|
||||
|
@ -504,14 +504,14 @@ canonicalize_pathname (char *path)
|
|||
/* Remove trailing "/" or "/." */
|
||||
len = strlen (path);
|
||||
if (len < 2)
|
||||
return path;
|
||||
return;
|
||||
if (path[len - 1] == PATH_SEP) {
|
||||
path[len - 1] = 0;
|
||||
} else {
|
||||
if (path[len - 1] == '.' && path[len - 2] == PATH_SEP) {
|
||||
if (len == 2) {
|
||||
path[1] = 0;
|
||||
return path;
|
||||
return;
|
||||
} else {
|
||||
path[len - 2] = 0;
|
||||
}
|
||||
|
@ -568,10 +568,8 @@ canonicalize_pathname (char *path)
|
|||
break;
|
||||
}
|
||||
|
||||
return path;
|
||||
break;
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
#ifdef HAVE_GET_PROCESS_STATS
|
||||
|
|
Loading…
Reference in New Issue