sdiff.c (2c320002252043900833444d7dc8b88876a70e24) | sdiff.c (0ace12afe47711d31418305e3ebbdac8aa038164) |
---|---|
1/* $OpenBSD: sdiff.c,v 1.36 2015/12/29 19:04:46 gsoares Exp $ */ 2 3/* 4 * Written by Raymond Lai <ray@cyth.net>. 5 * Public domain. 6 */ 7 8#include <sys/cdefs.h> --- 604 unchanged lines hidden (view full) --- 613 * treated as empty columns. If the divider is the ` ' character, the 614 * second column is not printed (-l flag). In this case, the second 615 * string must be NULL. When the second column is NULL, the divider 616 * does not print the trailing space following the divider character. 617 * 618 * Takes into account that tabs can take multiple columns. 619 */ 620static void | 1/* $OpenBSD: sdiff.c,v 1.36 2015/12/29 19:04:46 gsoares Exp $ */ 2 3/* 4 * Written by Raymond Lai <ray@cyth.net>. 5 * Public domain. 6 */ 7 8#include <sys/cdefs.h> --- 604 unchanged lines hidden (view full) --- 613 * treated as empty columns. If the divider is the ` ' character, the 614 * second column is not printed (-l flag). In this case, the second 615 * string must be NULL. When the second column is NULL, the divider 616 * does not print the trailing space following the divider character. 617 * 618 * Takes into account that tabs can take multiple columns. 619 */ 620static void |
621println(const char *s1, const char div, const char *s2) | 621println(const char *s1, const char divider, const char *s2) |
622{ 623 size_t col; 624 625 /* Print first column. Skips if s1 == NULL. */ 626 col = 0; 627 if (s1) { 628 /* Skip angle bracket and space. */ 629 printcol(s1, &col, width); 630 631 } 632 633 /* Otherwise, we pad this column up to width. */ 634 for (; col < width; ++col) 635 putchar(' '); 636 637 /* Only print left column. */ | 622{ 623 size_t col; 624 625 /* Print first column. Skips if s1 == NULL. */ 626 col = 0; 627 if (s1) { 628 /* Skip angle bracket and space. */ 629 printcol(s1, &col, width); 630 631 } 632 633 /* Otherwise, we pad this column up to width. */ 634 for (; col < width; ++col) 635 putchar(' '); 636 637 /* Only print left column. */ |
638 if (div == ' ' && !s2) { | 638 if (divider == ' ' && !s2) { |
639 printf(" (\n"); 640 return; 641 } 642 643 /* 644 * Print column divider. If there is no second column, we don't 645 * need to add the space for padding. 646 */ 647 if (!s2) { | 639 printf(" (\n"); 640 return; 641 } 642 643 /* 644 * Print column divider. If there is no second column, we don't 645 * need to add the space for padding. 646 */ 647 if (!s2) { |
648 printf(" %c\n", div); | 648 printf(" %c\n", divider); |
649 return; 650 } | 649 return; 650 } |
651 printf(" %c ", div); | 651 printf(" %c ", divider); |
652 col += 3; 653 654 /* Skip angle bracket and space. */ 655 printcol(s2, &col, line_width); 656 657 putchar('\n'); 658} 659 --- 205 unchanged lines hidden (view full) --- 865 866 return (0); 867} 868 869/* 870 * Queues up a diff line. 871 */ 872static void | 652 col += 3; 653 654 /* Skip angle bracket and space. */ 655 printcol(s2, &col, line_width); 656 657 putchar('\n'); 658} 659 --- 205 unchanged lines hidden (view full) --- 865 866 return (0); 867} 868 869/* 870 * Queues up a diff line. 871 */ 872static void |
873enqueue(char *left, char div, char *right) | 873enqueue(char *left, char divider, char *right) |
874{ 875 struct diffline *diffp; 876 877 if (!(diffp = malloc(sizeof(struct diffline)))) 878 err(2, "enqueue"); 879 diffp->left = left; | 874{ 875 struct diffline *diffp; 876 877 if (!(diffp = malloc(sizeof(struct diffline)))) 878 err(2, "enqueue"); 879 diffp->left = left; |
880 diffp->div = div; | 880 diffp->div = divider; |
881 diffp->right = right; 882 STAILQ_INSERT_TAIL(&diffhead, diffp, diffentries); 883} 884 885/* 886 * Free a diffline structure and its elements. 887 */ 888static void --- 271 unchanged lines hidden --- | 881 diffp->right = right; 882 STAILQ_INSERT_TAIL(&diffhead, diffp, diffentries); 883} 884 885/* 886 * Free a diffline structure and its elements. 887 */ 888static void --- 271 unchanged lines hidden --- |