Update of /cvsroot/winbash/winbash
In directory usw-pr-cvs1:/tmp/cvs-serv22858
Modified Files:
.build bashline.c version.h
Log Message:
fixed readline completion so that quotes will properly be added/removed when file names have spaces
Index: .build
===================================================================
RCS file: /cvsroot/winbash/winbash/.build,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- .build 26 Mar 2002 17:22:21 -0000 1.18
+++ .build 27 Mar 2002 13:47:51 -0000 1.19
@@ -1 +1 @@
-40
+41
Index: bashline.c
===================================================================
RCS file: /cvsroot/winbash/winbash/bashline.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- bashline.c 26 Mar 2002 03:34:34 -0000 1.7
+++ bashline.c 27 Mar 2002 13:47:51 -0000 1.8
@@ -78,6 +78,9 @@
static void snarf_hosts_from_file (), add_host_name ();
static void sort_hostname_list ();
+static char *bash_dequote_filename (char *, int);
+static char *bash_quote_filename (char *, int, char *);
+
#define DYNAMIC_HISTORY_COMPLETION
#if defined (DYNAMIC_HISTORY_COMPLETION)
static void dynamic_complete_history ();
@@ -92,6 +95,9 @@
extern int rl_filename_completion_desired;
int rl_hostname_completion_desired =0;
+/* imported from subst.c */
+extern int char_is_quoted (char *, int);
+
/* SPECIFIC_COMPLETION_FUNCTIONS specifies that we have individual
completion functions which indicate what type of completion should be
done (at or before point) that can be bound to key sequences with
@@ -142,33 +148,6 @@
#endif
}
-rl_quote_func_t *orig_quote_filename;
-static char *
-bash_quote_filename (s, rtype, qcp)
- char *s;
- int rtype;
- char *qcp;
-{
- char *r;
-
- r = xmalloc (strlen (s) + 3);
- *r = *rl_completer_quote_characters;
- strcpy (r + 1, s);
- strcat(r, "\"");
- if (qcp)
- *qcp = *rl_completer_quote_characters;
- return r;
-}
-
-/* static char * */
-/* bash_dequote_filename(text, quote_char) */
-/* char *text; */
-/* int quote_char; */
-/* { */
-/* printf("bash_dequote_filename\n"); */
-/* return text; */
-/* } */
-
/* Called once from parse.y if we are going to use readline. */
void
initialize_readline ()
@@ -277,9 +256,10 @@
#endif
rl_completer_quote_characters = "\"'";
-/* orig_quote_filename = rl_filename_quoting_function; */
-/* rl_filename_quoting_function = bash_quote_filename; */
-/* rl_filename_dequoting_function = bash_dequote_filename; */
+
+ rl_filename_quoting_function = bash_quote_filename;
+ rl_filename_dequoting_function = bash_dequote_filename;
+ rl_char_is_quoted_p = char_is_quoted;
rl_filename_quote_characters = " ";
/* Need to modify this from the default; `$', `{', `\', and ``' are not
@@ -2112,3 +2092,92 @@
}
#endif /* SPECIFIC_COMPLETION_FUNCTIONS */
+
+/* Quote a filename using double quotes.
+ NOTE: this is a simplified version of bash_quote_filename
+ found in bash 2.05a.
+ */
+static char *
+bash_quote_filename (s, rtype, qcp)
+ char *s;
+ int rtype;
+ char *qcp;
+{
+ char *rtext, *mtext;
+ char quote_char;
+ int rlen, cs;
+
+ rtext = (char *)NULL;
+
+ /* If RTYPE == MULT_MATCH, it means that there is
+ more than one match. In this case, we do not add
+ the closing quote or attempt to perform tilde
+ expansion. If RTYPE == SINGLE_MATCH, we try
+ to perform tilde expansion, because single and double
+ quotes inhibit tilde expansion by the shell. */
+
+ mtext = s;
+ if (mtext[0] == '~' && rtype == SINGLE_MATCH)
+ mtext = tilde_expand (s);
+
+ /* Leave the opening quote intact. The readline completion code takes
+ care of avoiding doubled opening quotes. */
+
+ rtext = xmalloc(strlen(mtext) + 3);
+
+ rtext[0] = '"';
+ strcpy(rtext + 1, mtext);
+
+ /* If there are multiple matches, don't add the closing quote. */
+ if (rtype != MULT_MATCH)
+ strcat(rtext, "\"");
+
+ if (mtext != s)
+ free (mtext);
+
+ return rtext;
+}
+
+/* NOTE: copied from bash 2.05a, bashline.c */
+/* Filename quoting for completion. */
+/* A function to strip unquoted quote characters (single quotes, double
+ quotes, and backslashes). It allows single quotes to appear
+ within double quotes, and vice versa. It should be smarter. */
+static char *
+bash_dequote_filename (text, quote_char)
+ char *text;
+ int quote_char;
+{
+ char *ret, *p, *r;
+ int l, quoted;
+
+ l = strlen (text);
+ ret = (char *)xmalloc (l + 1);
+ for (quoted = quote_char, p = text, r = ret; p && *p; p++)
+ {
+ /* Allow backslash-quoted characters to pass through unscathed. */
+ if (*p == '\\')
+ {
+ *r++ = *++p;
+ if (*p == '\0')
+ break;
+ continue;
+ }
+ /* Close quote. */
+ if (quoted && *p == quoted)
+ {
+ quoted = 0;
+ continue;
+ }
+ /* Open quote. */
+ if (quoted == 0 && (*p == '\'' || *p == '"'))
+ {
+ quoted = *p;
+ continue;
+ }
+ *r++ = *p;
+ }
+ *r = '\0';
+ return ret;
+}
+
Index: version.h
===================================================================
RCS file: /cvsroot/winbash/winbash/version.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- version.h 26 Mar 2002 17:22:21 -0000 1.18
+++ version.h 27 Mar 2002 13:47:51 -0000 1.19
@@ -8,9 +8,9 @@
#define PATCHLEVEL 7
/* The last built version of this shell. */
-#define BUILDVERSION 40
+#define BUILDVERSION 41
/* A version string for use by sccs and the what command. */
-#define SCCSVERSION "@(#)Bash version 1.14.7(40) GNU"
+#define SCCSVERSION "@(#)Bash version 1.14.7(41) GNU"
|