]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - menu/m_pattern.c
ncurses 5.7 - patch 20090221
[ncurses.git] / menu / m_pattern.c
index 34870012e0c7db83199e5b0c7ea1103d6923228f..1171390e214c8fae89aca191d12a0e315b42207c 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
+ * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -28,7 +28,6 @@
 
 /****************************************************************************
  *   Author:  Juergen Pfeifer, 1995,1997                                    *
 
 /****************************************************************************
  *   Author:  Juergen Pfeifer, 1995,1997                                    *
- *   Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en             *
  ****************************************************************************/
 
 /***************************************************************************
  ****************************************************************************/
 
 /***************************************************************************
@@ -38,7 +37,7 @@
 
 #include "menu.priv.h"
 
 
 #include "menu.priv.h"
 
-MODULE_ID("$Id: m_pattern.c,v 1.7 2002/07/06 15:22:16 juergen Exp $")
+MODULE_ID("$Id: m_pattern.c,v 1.15 2006/11/04 18:46:39 tom Exp $")
 
 /*---------------------------------------------------------------------------
 |   Facility      :  libnmenu  
 
 /*---------------------------------------------------------------------------
 |   Facility      :  libnmenu  
@@ -52,9 +51,12 @@ MODULE_ID("$Id: m_pattern.c,v 1.7 2002/07/06 15:22:16 juergen Exp $")
 |                    PatternString - as expected
 +--------------------------------------------------------------------------*/
 NCURSES_EXPORT(char *)
 |                    PatternString - as expected
 +--------------------------------------------------------------------------*/
 NCURSES_EXPORT(char *)
-menu_pattern (const MENU * menu)
+menu_pattern(const MENU * menu)
 {
 {
-  return (menu ? (menu->pattern ? menu->pattern : "") : (char *)0);
+  static char empty[] = "";
+
+  T((T_CALLED("menu_pattern(%p)"), menu));
+  returnPtr(menu ? (menu->pattern ? menu->pattern : empty) : 0);
 }
 
 /*---------------------------------------------------------------------------
 }
 
 /*---------------------------------------------------------------------------
@@ -66,54 +68,56 @@ menu_pattern (const MENU * menu)
 |
 |   Return Values :  E_OK              - success
 |                    E_BAD_ARGUMENT    - invalid menu or pattern pointer
 |
 |   Return Values :  E_OK              - success
 |                    E_BAD_ARGUMENT    - invalid menu or pattern pointer
-|                    E_NOT_CONNECTED   - no items connected to menu
 |                    E_BAD_STATE       - menu in user hook routine
 |                    E_BAD_STATE       - menu in user hook routine
+|                    E_NOT_CONNECTED   - no items connected to menu
 |                    E_NO_MATCH        - no item matches pattern
 +--------------------------------------------------------------------------*/
 NCURSES_EXPORT(int)
 |                    E_NO_MATCH        - no item matches pattern
 +--------------------------------------------------------------------------*/
 NCURSES_EXPORT(int)
-set_menu_pattern (MENU *menu, const char *p)
+set_menu_pattern(MENU * menu, const char *p)
 {
   ITEM *matchitem;
 {
   ITEM *matchitem;
-  int   matchpos;
-  
-  if (!menu || !p)     
+  int matchpos;
+
+  T((T_CALLED("set_menu_pattern(%p,%s)"), menu, _nc_visbuf(p)));
+
+  if (!menu || !p)
     RETURN(E_BAD_ARGUMENT);
     RETURN(E_BAD_ARGUMENT);
-  
+
   if (!(menu->items))
     RETURN(E_NOT_CONNECTED);
   if (!(menu->items))
     RETURN(E_NOT_CONNECTED);
-  
-  if ( menu->status & _IN_DRIVER )
+
+  if (menu->status & _IN_DRIVER)
     RETURN(E_BAD_STATE);
     RETURN(E_BAD_STATE);
-  
+
   Reset_Pattern(menu);
   Reset_Pattern(menu);
-  
+
   if (!(*p))
     {
       pos_menu_cursor(menu);
       RETURN(E_OK);
     }
   if (!(*p))
     {
       pos_menu_cursor(menu);
       RETURN(E_OK);
     }
-  
-  if (menu->status & _LINK_NEEDED) 
+
+  if (menu->status & _LINK_NEEDED)
     _nc_Link_Items(menu);
     _nc_Link_Items(menu);
-  
-  matchpos  = menu->toprow;
+
+  matchpos = menu->toprow;
   matchitem = menu->curitem;
   assert(matchitem);
   matchitem = menu->curitem;
   assert(matchitem);
-  
-  while(*p)
+
+  while (*p)
     {
     {
-      if ( !isprint((unsigned char)(*p)) || 
-         (_nc_Match_Next_Character_In_Item_Name(menu,*p,&matchitem) != E_OK) )
+      if (!isprint(UChar(*p)) ||
+         (_nc_Match_Next_Character_In_Item_Name(menu, *p, &matchitem) != E_OK))
        {
          Reset_Pattern(menu);
          pos_menu_cursor(menu);
          RETURN(E_NO_MATCH);
        }
       p++;
        {
          Reset_Pattern(menu);
          pos_menu_cursor(menu);
          RETURN(E_NO_MATCH);
        }
       p++;
-    }                  
-  
+    }
+
   /* This is reached if there was a match. So we position to the new item */
   /* This is reached if there was a match. So we position to the new item */
-  Adjust_Current_Item(menu,matchpos,matchitem);
+  Adjust_Current_Item(menu, matchpos, matchitem);
   RETURN(E_OK);
 }
 
   RETURN(E_OK);
 }