linux-0.11调试教程,readline()回显字符调用顺序

来源:互联网 发布:中国装束复原小组淘宝 编辑:程序博客网 时间:2024/05/19 19:33
readline_internal ()
{
...
...

      if (!rl_done)
    rl_redisplay ();

    }

因为rl_done为0,所以按下字符键后,会调用rl_redisplay()函数。



update_line()

{

...

  move_vert (current_line);
  move_cursor_relative (ofd - old, old);


          output_some_chars (nfd, lendiff);//这里会调用fwrite()函数!!!


...

}



下面是output_some_chars函数的定义:

/* Write COUNT characters from STRING to the output stream. */
static void
output_some_chars (string, count)
     char *string;
     int count;
{
  fwrite (string, 1, count, out_stream);
}



      /* Move the cursor where it should be. */
      move_vert (c_pos / screenwidth);              //move_vert()移动光标垂直方向位置。
      move_cursor_relative (c_pos % screenwidth,
                &invisible_line[(c_pos / screenwidth) * screenwidth]);  

//move_cursor_relative()函数移动光标位置。


这时光标的位置为0x1e既30

[/root]# cp bash /bin/basheee_

正好是这一行的第29个字符的位置。fflush()函数之后光标会在第30个字符位置显示。



最终fflush()函数之后会显示出字符来。





按下退格键删除一个字符的过程:

如果你按下了backspace退格键

 

第一步会调用readline_internal()函数中   rl_dispatch (c, keymap);

  { ISFUNC, rl_rubout }        /* RUBOUT */

因为这时返回的值是0x7f,对应函数rl_rubout()所以会执行rl_rubout()函数。


 switch (map[key].type)
    {
    case ISFUNC:
      {
    Function *func = map[key].function;

    if (func != (Function *)NULL)
      {
        /* Special case rl_do_lowercase_version (). */
        if (func == rl_do_lowercase_version)
          {
        rl_dispatch (to_lower (key), map);
        return;
          }

        (*map[key].function)(rl_numeric_arg * rl_arg_sign, key);


第二步会调用rl_rubout ()函数
/* Rubout the character behind point. */
rl_rubout (count)
     int count;
{
 
    else
    {
      int c = the_line[--rl_point];
      rl_delete_text (rl_point, rl_point + 1);

...

}


rl_delete_text()处下断点的情形:

第一块内容是堆栈,参数是0x11和0x12第二块是the_line变量的内容,

第三块是the_line[]数组的内容:cp bash /bin/bashe



下面可以看出rl_delete_text()函数的作用:修改the_line[]数组的内容


rl_rubout (count)
     int count;
{


....

      if (rl_point == rl_end && isprint (c) && last_c_pos)
    {
      backspace (1);
      putc (' ', out_stream);
      backspace (1);
      last_c_pos--;
      visible_line[last_c_pos] = '\0';
      rl_display_fixed++;
    }
  }
}

也会调用readline_internal()函数中的redisplay()函数,

      if (!rl_done)
    rl_redisplay ();

然后调用redisplay()函数中的fflush()函数。

但不会调用update_line()函数,move_vert ()move_cursor_relative ()函数。

readline_echoing_p不为0

原创粉丝点击