Subject: bin/6982: comm(1) should be able to fold case (ala sort)
To: None <gnats-bugs@gnats.netbsd.org>
From: Andrew Brown <twofsonet@graffiti.com>
List: netbsd-bugs
Date: 02/10/1999 19:01:53
>Number:         6982
>Category:       bin
>Synopsis:       comm(1) should be able to fold case (ala sort)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Feb 10 16:05:00 1999
>Last-Modified:
>Originator:     Andrew Brown
>Organization:
none
>Release:        -current
>Environment:
System: NetBSD noc 1.2 NetBSD 1.2 (null) #4: Fri Oct 24 01:27:28 EDT 1997 root@noc:/usr/src/sys/arch/i386/compile/null i386  :)


>Description:

try to join a few sort -f'ed files using comm and throw up hands in
frustration at the stupidity of the output.

>How-To-Repeat:

% cat list 
five
four
one
six
three
two
% cat remove 
four
one
seven
six
TWO
% comm list remove 
five
		four
		one
	seven
		six
	TWO
three
two
# (aargh!)

>Fix:

here's a patch to add -f functionality.  notice that comm tris to use
strcoll(3), but that just calls strcmp (for now) so this patch'll need
a little work when locales are implemented properly.

diff -cr comm.orig/comm.c comm/comm.c
*** comm.orig/comm.c	Sat Oct 18 16:29:31 1997
--- comm/comm.c	Wed Feb 10 18:49:37 1999
***************
*** 76,87 ****
  	FILE *fp1, *fp2;
  	char *col1, *col2, *col3;
  	char **p, line1[MAXLINELEN], line2[MAXLINELEN];
  
  	setlocale(LC_ALL, "");
  
  	file1done = file2done = 0;
  	flag1 = flag2 = flag3 = 1;
! 	while ((ch = getopt(argc, argv, "123")) != -1)
  		switch(ch) {
  		case '1':
  			flag1 = 0;
--- 76,89 ----
  	FILE *fp1, *fp2;
  	char *col1, *col2, *col3;
  	char **p, line1[MAXLINELEN], line2[MAXLINELEN];
+ 	int (*compare)(const char*,const char*);
  
  	setlocale(LC_ALL, "");
  
  	file1done = file2done = 0;
  	flag1 = flag2 = flag3 = 1;
! 	compare = strcoll;
! 	while ((ch = getopt(argc, argv, "123f")) != -1)
  		switch(ch) {
  		case '1':
  			flag1 = 0;
***************
*** 92,97 ****
--- 94,102 ----
  		case '3':
  			flag3 = 0;
  			break;
+ 		case 'f':
+ 			compare = strcasecmp;
+ 			break;
  		case '?':
  		default:
  			usage();
***************
*** 135,141 ****
  		}
  
  		/* lines are the same */
! 		if (!(comp = strcoll(line1, line2))) {
  			read1 = read2 = 1;
  			if (col3)
  				if (printf("%s%s", col3, line1) < 0)
--- 140,146 ----
  		}
  
  		/* lines are the same */
! 		if (!(comp = compare(line1, line2))) {
  			read1 = read2 = 1;
  			if (col3)
  				if (printf("%s%s", col3, line1) < 0)
diff -cr comm.orig/comm.1 comm/comm.1
*** comm.orig/comm.1	Sat Oct 18 16:29:30 1997
--- comm/comm.1	Wed Feb 10 18:49:22 1999
***************
*** 44,50 ****
  .Nd select or reject lines common to two files
  .Sh SYNOPSIS
  .Nm
! .Op Fl 123
  .Ar file1 file2
  .Sh DESCRIPTION
  The
--- 44,50 ----
  .Nd select or reject lines common to two files
  .Sh SYNOPSIS
  .Nm
! .Op Fl 123f
  .Ar file1 file2
  .Sh DESCRIPTION
  The
***************
*** 71,76 ****
--- 71,78 ----
  Suppress printing of column 2.
  .It Fl 3
  Suppress printing of column 3.
+ .It Fl f
+ Fold case in line comparisons.
  .El
  .Pp
  Each column will have a number of tab characters prepended to it
>Audit-Trail:
>Unformatted: