Imported from ../bash-3.1.tar.gz.
[platform/upstream/bash.git] / lib / readline / util.c
index bd08b38..e44ef64 100644 (file)
@@ -1,6 +1,6 @@
 /* util.c -- readline utility functions */
 
-/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
 
    This file is part of the GNU Readline Library, a library for
    reading lines of text with interactive input and history editing.
@@ -44,6 +44,7 @@
 
 /* System-specific feature definitions and include files. */
 #include "rldefs.h"
+#include "rlmbutil.h"
 
 #if defined (TIOCSTAT_IN_SYS_IOCTL)
 #  include <sys/ioctl.h>
@@ -55,8 +56,6 @@
 #include "rlprivate.h"
 #include "xmalloc.h"
 
-#define SWAP(s, e)  do { int t; t = s; s = e; e = t; } while (0)
-
 /* **************************************************************** */
 /*                                                                 */
 /*                     Utility Functions                           */
@@ -80,16 +79,32 @@ rl_alphabetic (c)
            strchr (pathname_alphabetic_chars, c) != NULL);
 }
 
+#if defined (HANDLE_MULTIBYTE)
+int
+_rl_walphabetic (wc)
+     wchar_t wc;
+{
+  int c;
+
+  if (iswalnum (wc))
+    return (1);     
+
+  c = wc & 0177;
+  return (_rl_allow_pathname_alphabetic_chars &&
+           strchr (pathname_alphabetic_chars, c) != NULL);
+}
+#endif
+
 /* How to abort things. */
 int
 _rl_abort_internal ()
 {
   rl_ding ();
   rl_clear_message ();
-  _rl_init_argument ();
+  _rl_reset_argument ();
   rl_clear_pending_input ();
 
-  _rl_defining_kbd_macro = 0;
+  RL_UNSETSTATE (RL_STATE_MACRODEF);
   while (rl_executing_macro)
     _rl_pop_executing_macro ();
 
@@ -233,6 +248,12 @@ _rl_strpbrk (string1, string2)
      const char *string1, *string2;
 {
   register const char *scan;
+#if defined (HANDLE_MULTIBYTE)
+  mbstate_t ps;
+  register int i, v;
+
+  memset (&ps, 0, sizeof (mbstate_t));
+#endif
 
   for (; *string1; string1++)
     {
@@ -241,6 +262,14 @@ _rl_strpbrk (string1, string2)
          if (*string1 == *scan)
            return ((char *)string1);
        }
+#if defined (HANDLE_MULTIBYTE)
+      if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
+       {
+         v = _rl_get_char_len (string1, &ps);
+         if (v > 1)
+           string1 += v - 1;   /* -1 to account for auto-increment in loop */
+       }
+#endif
     }
   return ((char *)NULL);
 }