int
invert_case_line (int count, int key)
{
  int start, end;
  int direction;

  start = rl_point;

  /* Find the end of the range to modify. */
  end = start + count;

  /* Force it to be within range. */
  if (end > rl_end)
    end = rl_end;
  else if (end < 0)
    end = 0;

  if (start == end)
    return 0;

  /* For positive arguments, moves the point to the right of the last changed
     character. For negative arguments, moves the point above the last changed
     character. */
  rl_point = end;

  if (start > end)
    {
      int temp = start;
      start = end;
      end = temp;
    }

  /* Tell readline that we are modifying the line, so save the undo
     information. */
  rl_modifying (start, end);

  for (; start < end; start ++)
    {
      if (_rl_uppercase_p (rl_line_buffer[start]))
        rl_line_buffer[start] = _rl_to_lower (rl_line_buffer[start]);
      else if (_rl_lowercase_p (rl_line_buffer[start]))
        rl_line_buffer[start] = _rl_to_upper (rl_line_buffer[start]);
    }

  return 0;
}
