Update of /cvsroot/winbash/winbash
In directory usw-pr-cvs1:/tmp/cvs-serv7010
Modified Files:
bashline.c execute_cmd.c general.h nt_execute_cmd.c
Log Message:
improved file completion to include known executable extensions.
they default to {".exe", ".com", ".bat", ".sh", ".pl" } , but can
be overridden by using the NT_BASH_EXE_SUF and NT_BASH_EXE_ADD_SUF
Index: bashline.c
===================================================================
RCS file: /cvsroot/winbash/winbash/bashline.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- bashline.c 25 Mar 2002 11:22:00 -0000 1.6
+++ bashline.c 26 Mar 2002 03:34:34 -0000 1.7
@@ -1181,7 +1181,7 @@
}
/* If we have found a match, and it is an executable file, return it. */
- if (match && executable_file (val))
+ if (match && nt_executable_file_or_dir (val))
{
free (val);
val = ""; /* So it won't be NULL. */
Index: execute_cmd.c
===================================================================
RCS file: /cvsroot/winbash/winbash/execute_cmd.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- execute_cmd.c 20 Mar 2002 02:09:54 -0000 1.7
+++ execute_cmd.c 26 Mar 2002 03:34:34 -0000 1.8
@@ -3517,7 +3517,7 @@
/* If the file is a directory, then it is not "executable" in the
sense of the shell. */
if (S_ISDIR (finfo.st_mode))
- return (FS_EXISTS);
+ return (FS_EXISTS | FS_DIR);
#if defined (AFS)
/* We have to use access(2) to determine access because AFS does not
@@ -3580,6 +3580,7 @@
return (file_status (file) & FS_EXECABLE);
#endif /* !__NT_VC__ */
}
+
/* DOT_FOUND_IN_SEARCH becomes non-zero when find_user_command ()
encounters a `.' as the directory pathname while scanning the
Index: general.h
===================================================================
RCS file: /cvsroot/winbash/winbash/general.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- general.h 10 Mar 2002 23:25:31 -0000 1.3
+++ general.h 26 Mar 2002 03:34:34 -0000 1.4
@@ -154,6 +154,7 @@
#define FS_EXECABLE 0x2
#define FS_EXEC_PREFERRED 0x4
#define FS_EXEC_ONLY 0x8
+#define FS_DIR 0x10
/* Posix and USG systems do not guarantee to restart a read () that is
interrupted by a signal. */
Index: nt_execute_cmd.c
===================================================================
RCS file: /cvsroot/winbash/winbash/nt_execute_cmd.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- nt_execute_cmd.c 16 Mar 2002 02:46:59 -0000 1.4
+++ nt_execute_cmd.c 26 Mar 2002 03:34:34 -0000 1.5
@@ -1079,6 +1079,7 @@
return 0;
}
+
int
nt_file_exe_status (char **name)
{
@@ -1121,72 +1122,9 @@
return status;
}
}
- /* If the file is a directory, then it is not "executable" in the
- sense of the shell. */
- if(stat (*name, &finfo) >= 0 && S_ISDIR (finfo.st_mode))
- return orig_status;
return orig_status;
}
-/* Call repeatedly to get all names to try */
-/* base = 0 on all but first call */
-static const char *
-try_names (const char *base)
-{
- static const char *base_to_try[] =
- {"exe", "com", "sh", "pl", "bat", 0};
- static const char **to_try = 0;
- static const char **curr = 0;
- static const char *orig = 0;
-#define MAX_PATH_ALLOWED (_MAX_PATH + 128)
- static char buf[MAX_PATH_ALLOWED + 5];
- static const char *dest = 0;
-
- if (!to_try)
- {
-/**************
- * const char * nt_exe_suf = getenv("NT_BASH_EXE_SUF");
- * if (nt_exe_suf) to_try = nt_split(nt_exe_suf);
- * else if (nt_exe_suf = getenv("NT_BASH_EXE_ADD_SUF"))
- * to_try=nt_add_split(base_to_try, nt_exe_suf);
- * if (!to_try) to_try = base_to_try ;
- * curr = to_try ;
- ************/
- to_try = base_to_try;
- curr = to_try;
- }
- if (base)
- {
- int has_suffix = 0;
- int length = 0;
- char *pt;
- curr = to_try;
- orig = base;
- to_try = base_to_try;
- for (dest = buf, pt = orig; *pt && (length < MAX_PATH_ALLOWED);
- pt++, length++)
- {
- *dest++ = *pt;
- if (*pt == '.')
- has_suffix = 1;
- else if (*pt == '/' || *pt == '\\')
- has_suffix = 0;
- }
- if (has_suffix)
- {
- orig = 0;
- curr = 0;
- dest = 0;
- return 0;
- }
- *dest++ = '.';
- }
- if (!*curr)
- return 0;
- strcpy (dest, *curr++);
- return buf;
-}
-
const char **
nt_add_split (const char **base, const char *add)
{
@@ -1241,6 +1179,106 @@
}
ret[count] = 0;
return ret;
+}
+
+//these are used to do both file completion and to run an executable when invoked
+//without a file extension
+// (i.e. if you simply typed 'a' , it would look for .exe, .com etc.)
+
+#define MAX_PATH_ALLOWED (_MAX_PATH + 128)
+static const char *base_to_try[] = {".exe", ".com", ".bat", ".sh", ".pl", 0};
+static const char **to_try = 0;
+
+/* Call repeatedly to get all names to try */
+/* base = 0 on all but first call */
+static const char *
+try_names (const char *base)
+{
+ static const char **curr = 0;
+ static const char *orig = 0;
+ static char buf[MAX_PATH_ALLOWED + 5];
+ static const char *dest = 0;
+
+ if (!to_try)
+ {
+ const char * nt_exe_suf = getenv("NT_BASH_EXE_SUF");
+
+ if (nt_exe_suf)
+ to_try = nt_split(nt_exe_suf);
+ else if (nt_exe_suf = getenv("NT_BASH_EXE_ADD_SUF"))
+ to_try=nt_add_split(base_to_try, nt_exe_suf);
+ if (!to_try)
+ to_try = base_to_try ;
+ curr = to_try ;
+ }
+
+ if (base)
+ {
+ int has_suffix = 0;
+ int length = 0;
+ char *pt;
+ curr = to_try;
+ orig = base;
+ to_try = base_to_try;
+ for (dest = buf, pt = orig; *pt && (length < MAX_PATH_ALLOWED); pt++, length++)
+ {
+ *dest++ = *pt;
+ if (*pt == '.')
+ has_suffix = 1;
+ else if (*pt == '/' || *pt == '\\')
+ has_suffix = 0;
+ }
+ if (has_suffix)
+ {
+ orig = 0;
+ curr = 0;
+ dest = 0;
+ return 0;
+ }
+ }
+ if (!*curr)
+ return 0;
+ strcpy (dest, *curr++);
+ return buf;
+}
+
+/* Return non-zero if FILE exists and is executable or a directory.*/
+
+int
+nt_executable_file_or_dir (file)
+ char *file;
+{
+ int status = file_status (file);
+ if((status & FS_EXECABLE) || (status & FS_DIR))
+ return 1;
+ //try the different file extensions now
+ {
+ if (!to_try)
+ {
+ const char * nt_exe_suf = getenv("NT_BASH_EXE_SUF");
+
+ if (nt_exe_suf)
+ to_try = nt_split(nt_exe_suf);
+ else if (nt_exe_suf = getenv("NT_BASH_EXE_ADD_SUF"))
+ to_try=nt_add_split(base_to_try, nt_exe_suf);
+ if (!to_try)
+ to_try = base_to_try ;
+ }
+ if (file)
+ {
+ int i,len;
+ len = strlen(file);
+
+ for(i=0;to_try[i]!=0;i++) {
+ int cur_len = strlen(to_try[i]);
+ if(len>cur_len)
+ if( strnicmp(&file[len-cur_len],to_try[i],cur_len) == 0)
+ return 1;
+ continue;
+ }
+ }
+ }
+ return 0;
}
static char *
|