Ejemplo n.º 1
0
static void
print_1sdiff_line (char const *const *left, char sep,
                   char const *const *right)
{
    FILE *out = outfile;
    size_t hw = sdiff_half_width;
    size_t c2o = sdiff_column2_offset;
    size_t col = 0;
    bool put_newline = false;
    bool color_to_reset = false;

    if (sep == '<')
    {
        set_color_context (DELETE_CONTEXT);
        color_to_reset = true;
    }
    else if (sep == '>')
    {
        set_color_context (ADD_CONTEXT);
        color_to_reset = true;
    }

    if (left)
    {
        put_newline |= left[1][-1] == '\n';
        col = print_half_line (left, 0, hw);
    }

    if (sep != ' ')
    {
        col = tab_from_to (col, (hw + c2o - 1) / 2) + 1;
        if (sep == '|' && put_newline != (right[1][-1] == '\n'))
            sep = put_newline ? '/' : '\\';
        putc (sep, out);
    }

    if (right)
    {
        put_newline |= right[1][-1] == '\n';
        if (**right != '\n')
        {
            col = tab_from_to (col, c2o);
            print_half_line (right, col, hw);
        }
    }

    if (put_newline)
        putc ('\n', out);

    if (color_to_reset)
        set_color_context (RESET_CONTEXT);
}
Ejemplo n.º 2
0
void
print_1overview_line (const char *left, int are_different,
		      const char *right)
{
  FILE *out = outfile;
  unsigned int hw = sdiff_half_width, c2o = sdiff_column2_offset;
  unsigned int col = 0;
  bool put_newline = 0; 
  register const char *end_of_left = left;
  register const char *end_of_right = right;
  const char *sep = ":!:";

  if (left)
    {
      for (; *end_of_left != '\0'; end_of_left++);
      if (end_of_left != left)
	end_of_left--;
      put_newline |= *end_of_left == '\n';
      col = display_half_line (left, 0, hw);
    }
  else
    sep = ":>:";

  if (!right)
    sep = ":<:";

  if ((are_different))
    {
      col = tab_from_to (col, (hw + c2o - 3) / 2) + 3;
      fputs (sep, out);
    }

  if (right)
    {
      for (; *end_of_right != '\0'; end_of_right++);
      if (end_of_right != right)
	end_of_right--;
      put_newline |= (*end_of_right == '\n');
      if (*right != '\n')
	{
	  col = tab_from_to (col, c2o);
	  display_half_line (right, col, hw);
	}
    }

  if (put_newline)
    putc ('\n', out);
}
Ejemplo n.º 3
0
Archivo: side.c Proyecto: Rekoz/CS35L
static void
print_1sdiff_line (char const *const *left, char sep,
		   char const *const *right)
{
  FILE *out = outfile;
  size_t hw = sdiff_half_width;
  size_t c2o = sdiff_column2_offset;
  size_t col = 0;
  bool put_newline = false;

  if (left)
    {
      put_newline |= left[1][-1] == '\n';
      col = print_half_line (left, 0, hw);
    }

  if (sep != ' ')
    {
      col = tab_from_to (col, (hw + c2o - 1) / 2) + 1;
      if (sep == '|' && put_newline != (right[1][-1] == '\n'))
	sep = put_newline ? '/' : '\\';
      putc (sep, out);
    }

  if (right)
    {
      put_newline |= right[1][-1] == '\n';
      if (**right != '\n')
	{
	  col = tab_from_to (col, c2o);
	  print_half_line (right, col, hw);
	}
    }

  if (put_newline)
    putc ('\n', out);
}
Ejemplo n.º 4
0
static size_t
print_half_line (char const *const *line, size_t indent, size_t out_bound)
{
    FILE *out = outfile;
    register size_t in_position = 0;
    register size_t out_position = 0;
    register char const *text_pointer = line[0];
    register char const *text_limit = line[1];
    mbstate_t mbstate = { 0 };

    while (text_pointer < text_limit)
    {
        char const *tp0 = text_pointer;
        register char c = *text_pointer++;

        switch (c)
        {
        case '\t':
        {
            size_t spaces = tabsize - in_position % tabsize;
            if (in_position == out_position)
            {
                size_t tabstop = out_position + spaces;
                if (expand_tabs)
                {
                    if (out_bound < tabstop)
                        tabstop = out_bound;
                    for (;  out_position < tabstop;  out_position++)
                        putc (' ', out);
                }
                else if (tabstop < out_bound)
                {
                    out_position = tabstop;
                    putc (c, out);
                }
            }
            in_position += spaces;
        }
        break;

        case '\r':
        {
            putc (c, out);
            tab_from_to (0, indent);
            in_position = out_position = 0;
        }
        break;

        case '\b':
            if (in_position != 0 && --in_position < out_bound)
            {
                if (out_position <= in_position)
                    /* Add spaces to make up for suppressed tab past out_bound.  */
                    for (;  out_position < in_position;  out_position++)
                        putc (' ', out);
                else
                {
                    out_position = in_position;
                    putc (c, out);
                }
            }
            break;

        default:
        {
            wchar_t wc;
            size_t bytes = mbrtowc (&wc, tp0, text_limit - tp0, &mbstate);

            if (0 < bytes && bytes < (size_t) -2)
            {
                int width = wcwidth (wc);
                if (0 < width)
                    in_position += width;
                if (in_position <= out_bound)
                {
                    out_position = in_position;
                    fwrite (tp0, 1, bytes, stdout);
                }
                text_pointer = tp0 + bytes;
                break;
            }
        }
        /* Fall through.  */
        case '\f':
        case '\v':
            if (in_position < out_bound)
                putc (c, out);
            break;

        case ' ':
        case '!':
        case '"':
        case '#':
        case '%':
        case '&':
        case '\'':
        case '(':
        case ')':
        case '*':
        case '+':
        case ',':
        case '-':
        case '.':
        case '/':
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
        case ':':
        case ';':
        case '<':
        case '=':
        case '>':
        case '?':
        case 'A':
        case 'B':
        case 'C':
        case 'D':
        case 'E':
        case 'F':
        case 'G':
        case 'H':
        case 'I':
        case 'J':
        case 'K':
        case 'L':
        case 'M':
        case 'N':
        case 'O':
        case 'P':
        case 'Q':
        case 'R':
        case 'S':
        case 'T':
        case 'U':
        case 'V':
        case 'W':
        case 'X':
        case 'Y':
        case 'Z':
        case '[':
        case '\\':
        case ']':
        case '^':
        case '_':
        case 'a':
        case 'b':
        case 'c':
        case 'd':
        case 'e':
        case 'f':
        case 'g':
        case 'h':
        case 'i':
        case 'j':
        case 'k':
        case 'l':
        case 'm':
        case 'n':
        case 'o':
        case 'p':
        case 'q':
        case 'r':
        case 's':
        case 't':
        case 'u':
        case 'v':
        case 'w':
        case 'x':
        case 'y':
        case 'z':
        case '{':
        case '|':
        case '}':
        case '~':
            /* These characters are printable ASCII characters.  */
            if (in_position++ < out_bound)
            {
                out_position = in_position;
                putc (c, out);
            }
            break;

        case '\n':
            return out_position;
        }
    }

    return out_position;
}
Ejemplo n.º 5
0
/*
 * Print the text for half an sdiff line.  This means truncate to width
 * observing tabs, and trim a trailing newline.  Returns the last column
 * written (not the number of chars).
 */
static unsigned int
print_half_line (char const *const *line, unsigned int indent,
		 unsigned int out_bound)
{
  FILE *out = outfile;
  register unsigned int in_position = 0;
  register unsigned int out_position = 0;
  register char const *text_pointer = line[0];
  register char const *text_limit = line[1];

  while (text_pointer < text_limit)
    {
      register unsigned char c = *text_pointer++;

      switch (c)
	{
	case '\t':
	  {
	    unsigned int spaces = TAB_WIDTH - in_position % TAB_WIDTH;
	    if (in_position == out_position)
	      {
		unsigned int tabstop = out_position + spaces;
		if ((expand_tabs))
		  {
		    if (out_bound < tabstop)
		      tabstop = out_bound;
		    for (;  out_position < tabstop;  out_position++)
		      putc (' ', out);
		  }
		else
		  if (tabstop < out_bound)
		    {
		      out_position = tabstop;
		      putc (c, out);
		    }
	      }
	    in_position += spaces;
	  }
	  break;

	case '\r':
	  {
	    putc (c, out);
	    tab_from_to (0, indent);
	    in_position = out_position = 0;
	  }
	  break;

	case '\b':
	  if (in_position != 0 && --in_position < out_bound)
	    {
	      if (out_position <= in_position)
		/* Add spaces to make up for suppressed tab past out_bound.  */
		for (;  out_position < in_position;  out_position++)
		  putc (' ', out);
	      else
		{
		  out_position = in_position;
		  putc (c, out);
		}
	    }
	  break;

	case '\f':
	case '\v':
	control_char:
	  if (in_position < out_bound)
	    putc (c, out);
	  break;

	default:
	  if (! ISPRINT (c))
	    goto control_char;
	  /* falls through */
	case ' ':
	  if (in_position++ < out_bound)
	    {
	      out_position = in_position;
	      putc (c, out);
	    }
	  break;

	case '\n':
	  return out_position;
	}
    }

  return out_position;
}