%%s 0/0/0 %%d D 1.1 25-Mar-82 12:02:49 v1.1 1 0 %%c Version 1.1 is the Spring 1982 Distribution of the LBL/Hughes release %%c of the Software Tools Virtual Operating System software and documentation. %%T %%I 1 #-h- ccomm 314 asc 25-mar-82 07:27:34 v1.1 (sw-tools v1.1) ## ccomm - common block to hold flags for comm # Put on a file called 'ccomm' # Used only the comm tool common /ccomm/ one, two, three integer one #flag to print col1 (lines only in file 1) integer two #flag to print col2 (lines only in file 2) integer three #flag to print col3 (lines in both files) #-h- comm.r 3495 asc 25-mar-82 07:27:36 v1.1 (sw-tools v1.1) #-h- main 780 asc 25-mar-82 07:27:02 v1.1 (sw-tools v1.1) ## comm - print lines common to two files DRIVER(comm) character buf(MAXLINE) integer getarg, open, index integer i, file(2), j include ccomm string usestr "usage: comm [-123] file1 [file2]." call query(usestr) one = YES two = YES three = YES j = 0 for (i=1; getarg(i,buf,MAXLINE)!=EOF; i=i+1) { if (j == 2) break if (buf(1) == '-' & buf(2) != EOS) { if (index(buf, '1') == 0) one = NO if (index(buf, '2') == 0) two = NO if (index(buf, '3') == 0) three = NO } else if (buf(1) == '-') { j = j + 1 file(j) = STDIN } else { j = j + 1 file(j) = open(buf,READ) if (file(j) == ERR) call cant(buf) } } if (j == 0) call error(usestr) if (j == 1) file(2) = STDIN call common(file(1), file(2)) DRETURN end #-h- cmpar 272 asc 25-mar-82 07:27:05 v1.1 (sw-tools v1.1) ## cmpar - compare lin1 with lin2 integer function cmpar(lin1, lin2) character lin1(ARB), lin2(ARB) integer i for (i=1; lin1(i) == lin2(i); i=i+1) if (lin1(i) == EOS) { cmpar = 0 return } if (lin1(i) < lin2(i)) cmpar = -1 else cmpar = + 1 return end #-h- col1 282 asc 25-mar-82 07:27:06 v1.1 (sw-tools v1.1) ## col1 - print col1 (lines only in file1) for comm tool # (remove leading blanks) subroutine col1 (buf) character buf(ARB) include ccomm if (one == NO) #return if column not to be printed return i = 1 call skipbl (buf, i) call putlin(buf(i), STDOUT) return end #-h- col2 353 asc 25-mar-82 07:27:08 v1.1 (sw-tools v1.1) ## col2 - print col2 (lines only in file2) for comm tool # (remove leading blanks) subroutine col2 (buf) character buf(ARB) integer i include ccomm if (two == NO) #return if column not to be printed return if (one == YES) for (i=1; i<=15; i=i+1) call putc(' ') i = 1 call skipbl (buf, i) call putlin(buf(i), STDOUT) return end #-h- col3 411 asc 25-mar-82 07:27:08 v1.1 (sw-tools v1.1) ## col3 - print col3 (lines in both files) for comm tool # (remove leading blanks) subroutine col3(buf) character buf(ARB) integer i include ccomm if (three == NO) #return if column not to be printed return if (one == YES) for (i=1; i<=10; i=i+1) call putc(' ') if (two == YES) for (i=1; i<=15; i=i+1) call putc(' ') i = 1 call skipbl(buf, i) call putlin(buf(i), STDOUT) return end #-h- common 959 asc 25-mar-82 07:27:09 v1.1 (sw-tools v1.1) ## common - print lines common to file1 and file2 subroutine common(file1, file2) integer file1, file2, k, stat1, stat2 integer getlin character buf1(MAXLINE), buf2(MAXLINE) integer cmpar stat1 = getlin(buf1,file1) stat2 = getlin(buf2,file2) repeat { if (stat1 == EOF | stat2 == EOF) break k = cmpar(buf1, buf2) #compare lines if (k < 0) #line only in file1 { call col1(buf1) stat1 = getlin(buf1, file1) } else if (k > 0) #line only in file2 { call col2(buf2) stat2 = getlin(buf2, file2) } else #line in both files { call col3(buf1) stat1 = getlin(buf1, file1) stat2 = getlin(buf2, file2) } } if (stat1 == EOF & two == YES) #end of file1, print rest of file2 while(stat2 != EOF) { call col2(buf2) stat2 = getlin(buf2, file2) } else if (stat2 == EOF & one == YES) #end of file2, print rest of file1 while (stat1 != EOF) { call col1(buf1) stat1 = getlin(buf1, file1) } return end #-h- comm.fmt 1004 asc 25-mar-82 07:27:41 v1.1 (sw-tools v1.1) .so ~bin/manhdr .hd Comm (1) 11-Jan-79 print lines common to two files .sy comm [-123] file1 [file2] .ds comm reads file1 and file2, which should be sorted, and produces a three column output: lines only in file1, lines only in file2, and lines in both files. The filename '-' means the standard input. If there is only one file argument, file2 refers to the standard input. The optional arguments -1, -2, and -3 specify the printing of only the corresponding column. Thus "comm -3" prints only the lines common to both files, and "comm -12" prints lines which are in either file, but not in both. The default is -123. .fl none .sa cmp - compare two files .br the Unix tool "diff" .di A message is printed if an input file cannot be opened. .au Debbie Scherrer .bu The flags used by this tool are the reverse of those used by the Unix 'comm'. In Unix, the flags 1, 2, and 3 suppress printing of the corresponding column. Kernighan, on page 126 of 'Software Tools' suggests the version used above. %%E 1