linux-0.11调试教程,update_line()函数分析,和update_line()函数的数据模型

来源:互联网 发布:ios 淘宝详情页 编辑:程序博客网 时间:2024/05/18 01:16

如何由old变成new的?答案在最后!



例子一:

[/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;
{     ....

          else
        {
          /* At the end of a line the characters do not have to
             be "inserted".  They can just be placed on the screen. */
          output_some_chars (nfd, lendiff);
          last_c_pos += lendiff;
        }
          /* Copy (new) chars to screen from first diff to last match. */
          if (((nls - nfd) - lendiff) > 0)
        {
          output_some_chars (&nfd[lendiff], ((nls - nfd) - lendiff));
          last_c_pos += ((nls - nfd) - lendiff);
        }

     ....

}


output_some_chars (nfd, lendiff);时:

output_some_chars (&nfd[lendiff], ((nls - nfd) - lendiff));时:


可见nfd为0x59c15,lendiff为1,nls为0x59c17,ne0x59c17

(ofd为0x63415,ols和oe都为0x63416)


/* if (len (new) > len (old)) */
  lendiff = (nls - nfd) - (ols - ofd);
             /* lendiff = 2-1=1 





例子2:下面的对应下面的图,退格键时的6个位置

  else                /* Delete characters from line. */
    {
      /* If possible and inexpensive to use terminal deletion, then do so. */
      if (term_dc && (2 * (ne - nfd)) >= (-lendiff))
    {
      if (lendiff)
        delete_chars (-lendiff); /* delete (diff) characters     /*产生字符0x50315b1b*/

      /* Copy (new) chars to screen from first diff to last match   */
      if ((nls - nfd) > 0)
        {
          output_some_chars (nfd, (nls - nfd));  /*产生字符0x63*/
          last_c_pos += (nls - nfd);
        }
    }


[/root]# abc   -->      [/root]# ac  按下退格键,lengthb

delete_chars (-lendiff);时


output_some_chars()时


lendiff = (nls - nfd) - (ols - ofd);

lendiff = 10 - 15 = -5;

先删除5个字符,delete_chars (-lendiff);/*产生字符0x50355b1b*/,会调用内核的csi_P()函数。

然后再打印出10个字符buggy say,把le-buggy i覆盖掉!!!

既调用output_some_chars (nfd, (nls - nfd));




static void delete_char(int currcons)
{
    int i;
    unsigned short * p = (unsigned short *) pos;

    if (x>=video_num_columns)
        return;
    i = x;
    while (++i < video_num_columns) {
        *p = *(p+1);
        p++;
    }
    *p = video_erase_char;

}


static void csi_P(int currcons, unsigned int nr)
{
    if (nr > video_num_columns)
        nr = video_num_columns;
    else if (!nr)
        nr = 1;
    while (nr--)
        delete_char(currcons);
}

原创粉丝点击