linux-0.11调试教程,move_cursor_relative()函数和变量last_c_pos和变量c_pos的关系

来源:互联网 发布:怎样网络销售 编辑:程序博客网 时间:2024/06/05 14:51

move_cursor_relative()函数出现在update_line ()函数中和rl_redisplay ()函数中。

move_cursor_relative()函数last_c_pos的值和c_pos的值密切相关!!!


[/root]# c    -->    [/root]# ac        按下a键, length5   

具体过程为:[/root]# c    -->    [/root]# a    -->    [/root]# ac




static
update_line (old, new, current_line)
     register char *old, *new;
     int current_line;
{

...

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

...

}


move_cursor_relative()的时候

static void
move_cursor_relative (new, data)
     int new;
     char *data;
{

  register int i;

  /* It may be faster to output a CR, and then move forwards instead
     of moving backwards. */
  if (new + 1 < last_c_pos - new)
    {
      tputs (term_cr, 1, output_character_function);
      last_c_pos = 0;
    }

  if (last_c_pos == new) return;

...

new等于9,而last_c_pos也等于9,所以直接返回。

0x17:0x42374last_c_pos的地址


第二次调用move_cursor_relative()是在rl_redisplay ()函数中。

c_pos的值为0xa,而last_c_pos的值为0xb,所以需要把光标左移一格:既0x445b1b。


  for (in = 0; in < rl_end; in++)
    {
      c = (unsigned char)the_line[in];

...
      if (in == rl_point)
    c_pos = out;        //注意这里c_pos的值既是rl_point的值既是当前光标的绝对位置既out的值。


...
      else
    line[out++] = c;
    }


原创粉丝点击