⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bind.c

📁 Linux下的MUD客户端程序
💻 C
📖 第 1 页 / 共 3 页
字号:
	}    }  /* Not a boolean variable, so check for specials. */  /* Editing mode change? */  if (stricmp (name, "editing-mode") == 0)    {      if (strnicmp (value, "vi", 2) == 0)	{#if defined (VI_MODE)	  _rl_keymap = vi_insertion_keymap;	  rl_editing_mode = vi_mode;#endif /* VI_MODE */	}      else if (strnicmp (value, "emacs", 5) == 0)	{	  _rl_keymap = emacs_standard_keymap;	  rl_editing_mode = emacs_mode;	}    }  /* Comment string change? */  else if (stricmp (name, "comment-begin") == 0)    {#if defined (VI_MODE)      if (*value)	{	  if (rl_vi_comment_begin)	    free (rl_vi_comment_begin);	  rl_vi_comment_begin = savestring (value);	}#endif /* VI_MODE */    }  else if (stricmp (name, "completion-query-items") == 0)    {      int nval = 100;      if (*value)	{	  nval = atoi (value);	  if (nval < 0)	    nval = 0;	}      rl_completion_query_items = nval;    }  else if (stricmp (name, "keymap") == 0)    {      Keymap kmap;      kmap = rl_get_keymap_by_name (value);      if (kmap)        rl_set_keymap (kmap);    }  else if (stricmp (name, "bell-style") == 0)    {      if (!*value)        _rl_bell_preference = AUDIBLE_BELL;      else        {          if (stricmp (value, "none") == 0 || stricmp (value, "off") == 0)            _rl_bell_preference = NO_BELL;          else if (stricmp (value, "audible") == 0 || stricmp (value, "on") == 0)            _rl_bell_preference = AUDIBLE_BELL;          else if (stricmp (value, "visible") == 0)            _rl_bell_preference = VISIBLE_BELL;        }    }  else if (stricmp (name, "prefer-visible-bell") == 0)    {      /* Backwards compatibility. */      if (*value && (stricmp (value, "on") == 0 ||		     (*value == '1' && !value[1])))        _rl_bell_preference = VISIBLE_BELL;      else        _rl_bell_preference = AUDIBLE_BELL;    }  return 0;}/* Return the character which matches NAME.   For example, `Space' returns ' '. */typedef struct {  char *name;  int value;} assoc_list;static assoc_list name_key_alist[] = {  { "DEL", 0x7f },  { "ESC", '\033' },  { "Escape", '\033' },  { "LFD", '\n' },  { "Newline", '\n' },  { "RET", '\r' },  { "Return", '\r' },  { "Rubout", 0x7f },  { "SPC", ' ' },  { "Space", ' ' },  { "Tab", 0x09 },  { (char *)0x0, 0 }};static intglean_key_from_name (name)     char *name;{  register int i;  for (i = 0; name_key_alist[i].name; i++)    if (stricmp (name, name_key_alist[i].name) == 0)      return (name_key_alist[i].value);  return (*(unsigned char *)name);	/* XXX was return (*name) */}/* Auxiliary functions to manage keymaps. */static struct {  char *name;  Keymap map;} keymap_names[] = {  { "emacs", emacs_standard_keymap },  { "emacs-standard", emacs_standard_keymap },  { "emacs-meta", emacs_meta_keymap },  { "emacs-ctlx", emacs_ctlx_keymap },#if defined (VI_MODE)  { "vi", vi_movement_keymap },  { "vi-move", vi_movement_keymap },  { "vi-command", vi_movement_keymap },  { "vi-insert", vi_insertion_keymap },#endif /* VI_MODE */  { (char *)0x0, (Keymap)0x0 }};Keymaprl_get_keymap_by_name (name)     char *name;{  register int i;  for (i = 0; keymap_names[i].name; i++)    if (strcmp (name, keymap_names[i].name) == 0)      return (keymap_names[i].map);  return ((Keymap) NULL);}voidrl_set_keymap (map)     Keymap map;{  if (map)    _rl_keymap = map;}Keymaprl_get_keymap (){  return (_rl_keymap);}voidrl_set_keymap_from_edit_mode (){  if (rl_editing_mode == emacs_mode)    _rl_keymap = emacs_standard_keymap;#if defined (VI_MODE)  else if (rl_editing_mode == vi_mode)    _rl_keymap = vi_insertion_keymap;#endif /* VI_MODE */}/* **************************************************************** *//*								    *//*		  Key Binding and Function Information		    *//*								    *//* **************************************************************** *//* Each of the following functions produces information about the   state of keybindings and functions known to Readline.  The info   is always printed to rl_outstream, and in such a way that it can   be read back in (i.e., passed to rl_parse_and_bind (). *//* Print the names of functions known to Readline. */voidrl_list_funmap_names (count, ignore)     int count, ignore;{  register int i;  char **funmap_names;  funmap_names = rl_funmap_names ();  if (!funmap_names)    return;  for (i = 0; funmap_names[i]; i++)    fprintf (rl_outstream, "%s\n", funmap_names[i]);  free (funmap_names);}/* Return a NULL terminated array of strings which represent the key   sequences that are used to invoke FUNCTION in MAP. */char **rl_invoking_keyseqs_in_map (function, map)     Function *function;     Keymap map;{  register int key;  char **result;  int result_index, result_size;  result = (char **)NULL;  result_index = result_size = 0;  for (key = 0; key < 128; key++)    {      switch (map[key].type)	{	case ISMACR:	  /* Macros match, if, and only if, the pointers are identical.	     Thus, they are treated exactly like functions in here. */	case ISFUNC:	  /* If the function in the keymap is the one we are looking for,	     then add the current KEY to the list of invoking keys. */	  if (map[key].function == function)	    {	      char *keyname = (char *)xmalloc (5);	      if (CTRL_CHAR (key))		sprintf (keyname, "\\C-%c", to_lower (UNCTRL (key)));	      else if (key == RUBOUT)		sprintf (keyname, "\\C-?");	      else if (key == '\\' || key == '"')		{		  keyname[0] = '\\';		  keyname[1] = (char) key;		  keyname[2] = '\0';		}	      else		{		  keyname[0] = (char) key;		  keyname[1] = '\0';		}	      if (result_index + 2 > result_size)		result = (char **) xrealloc		  (result, (result_size += 10) * sizeof (char *));	      result[result_index++] = keyname;	      result[result_index] = (char *)NULL;	    }	  break;	case ISKMAP:	  {	    char **seqs = (char **)NULL;	    /* Find the list of keyseqs in this map which have FUNCTION as	       their target.  Add the key sequences found to RESULT. */	    if (map[key].function)	      seqs =	        rl_invoking_keyseqs_in_map (function, FUNCTION_TO_KEYMAP (map, key));	    if (seqs)	      {		register int i;		for (i = 0; seqs[i]; i++)		  {		    char *keyname = (char *)xmalloc (6 + strlen (seqs[i]));		    if (key == ESC)		      sprintf (keyname, "\\e");		    else if (CTRL_CHAR (key))		      sprintf (keyname, "\\C-%c", to_lower (UNCTRL (key)));		    else if (key == RUBOUT)		      sprintf (keyname, "\\C-?");		    else if (key == '\\' || key == '"')		      {			keyname[0] = '\\';			keyname[1] = (char) key;			keyname[2] = '\0';		      }		    else		      {			keyname[0] = (char) key;			keyname[1] = '\0';		      }		    strcat (keyname, seqs[i]);		    free (seqs[i]);		    if (result_index + 2 > result_size)		      result = (char **) xrealloc			(result, (result_size += 10) * sizeof (char *));		    result[result_index++] = keyname;		    result[result_index] = (char *)NULL;		  }		free (seqs);	      }	  }	  break;	}    }  return (result);}/* Return a NULL terminated array of strings which represent the key   sequences that can be used to invoke FUNCTION using the current keymap. */char **rl_invoking_keyseqs (function)     Function *function;{  return (rl_invoking_keyseqs_in_map (function, _rl_keymap));}/* Print all of the current functions and their bindings to   rl_outstream.  If an explicit argument is given, then print   the output in such a way that it can be read back in. */intrl_dump_functions (count, key)     int count, key;{  rl_function_dumper (rl_explicit_arg);  rl_on_new_line ();  return (0);}/* Print all of the functions and their bindings to rl_outstream.  If   PRINT_READABLY is non-zero, then print the output in such a way   that it can be read back in. */voidrl_function_dumper (print_readably)     int print_readably;{  register int i;  char **names;  char *name;  names = rl_funmap_names ();  fprintf (rl_outstream, "\n");  for (i = 0; name = names[i]; i++)    {      Function *function;      char **invokers;      function = rl_named_function (name);      invokers = rl_invoking_keyseqs_in_map (function, _rl_keymap);      if (print_readably)	{	  if (!invokers)	    fprintf (rl_outstream, "# %s (not bound)\n", name);	  else	    {	      register int j;	      for (j = 0; invokers[j]; j++)		{		  fprintf (rl_outstream, "\"%s\": %s\n",			   invokers[j], name);		  free (invokers[j]);		}	      free (invokers);	    }	}      else	{	  if (!invokers)	    fprintf (rl_outstream, "%s is not bound to any keys\n",		     name);	  else	    {	      register int j;	      fprintf (rl_outstream, "%s can be found on ", name);	      for (j = 0; invokers[j] && j < 5; j++)		{		  fprintf (rl_outstream, "\"%s\"%s", invokers[j],			   invokers[j + 1] ? ", " : ".\n");		}	      if (j == 5 && invokers[j])		fprintf (rl_outstream, "...\n");	      for (j = 0; invokers[j]; j++)		free (invokers[j]);	      free (invokers);	    }	}    }}/* Bind key sequence KEYSEQ to DEFAULT_FUNC if KEYSEQ is unbound. */void_rl_bind_if_unbound (keyseq, default_func)     char *keyseq;     Function *default_func;{  Function *func;  if (keyseq)    {      func = rl_function_of_keyseq (keyseq, _rl_keymap, (int *)NULL);      if (!func || func == rl_do_lowercase_version)	rl_set_key (keyseq, default_func, _rl_keymap);    }}/* **************************************************************** *//*								    *//*			String Utility Functions		    *//*								    *//* **************************************************************** */static char *strindex ();/* Return non-zero if any members of ARRAY are a substring in STRING. */static intsubstring_member_of_array (string, array)     char *string, **array;{  while (*array)    {      if (strindex (string, *array))	return (1);      array++;    }  return (0);}#if !defined (HAVE_STRCASECMP)/* Whoops, Unix doesn't have strnicmp. *//* Compare at most COUNT characters from string1 to string2.  Case   doesn't matter. */static intstrnicmp (string1, string2, count)     char *string1, *string2;     int count;{  register char ch1, ch2;  while (count)    {      ch1 = *string1++;      ch2 = *string2++;      if (to_upper(ch1) == to_upper(ch2))	count--;      else        break;    }  return (count);}/* strcmp (), but caseless. */static intstricmp (string1, string2)     char *string1, *string2;{  register char ch1, ch2;  while (*string1 && *string2)    {      ch1 = *string1++;      ch2 = *string2++;      if (to_upper(ch1) != to_upper(ch2))	return (1);    }  return (*string1 - *string2);}#endif /* !HAVE_STRCASECMP *//* Determine if s2 occurs in s1.  If so, return a pointer to the   match in s1.  The compare is case insensitive. */static char *strindex (s1, s2)     register char *s1, *s2;{  register int i, l = strlen (s2);  register int len = strlen (s1);  for (i = 0; (len - i) >= l; i++)    if (strnicmp (s1 + i, s2, l) == 0)      return (s1 + i);  return ((char *)NULL);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -