1: #include <stdio.h>
2: #include <ctype.h>
3:
4: FILE *file1,*file2;
5: int eflg;
6: int lflg = 1;
7: long line = 1;
8: long chr = 0;
9: long skip1;
10: long skip2;
11:
12: long otoi();
13:
14: main(argc, argv)
15: char **argv;
16: {
17: register c1, c2;
18: char *arg;
19:
20: if(argc < 3)
21: goto narg;
22: arg = argv[1];
23: if(arg[0] == '-' && arg[1] == 's') {
24: lflg--;
25: argv++;
26: argc--;
27: }
28: arg = argv[1];
29: if(arg[0] == '-' && arg[1] == 'l') {
30: lflg++;
31: argv++;
32: argc--;
33: }
34: if(argc < 3)
35: goto narg;
36: arg = argv[1];
37: if( arg[0]=='-' && arg[1]==0 )
38: file1 = stdin;
39: else if((file1 = fopen(arg, "r")) == NULL)
40: goto barg;
41: arg = argv[2];
42: if((file2 = fopen(arg, "r")) == NULL)
43: goto barg;
44: if (argc>3)
45: skip1 = otoi(argv[3]);
46: if (argc>4)
47: skip2 = otoi(argv[4]);
48: while (skip1) {
49: if ((c1 = getc(file1)) == EOF) {
50: arg = argv[1];
51: goto earg;
52: }
53: skip1--;
54: }
55: while (skip2) {
56: if ((c2 = getc(file2)) == EOF) {
57: arg = argv[2];
58: goto earg;
59: }
60: skip2--;
61: }
62:
63: loop:
64: chr++;
65: c1 = getc(file1);
66: c2 = getc(file2);
67: if(c1 == c2) {
68: if (c1 == '\n')
69: line++;
70: if(c1 == EOF) {
71: if(eflg)
72: exit(1);
73: exit(0);
74: }
75: goto loop;
76: }
77: if(lflg == 0)
78: exit(1);
79: if(c1 == EOF) {
80: arg = argv[1];
81: goto earg;
82: }
83: if(c2 == EOF)
84: goto earg;
85: if(lflg == 1) {
86: printf("%s %s differ: char %ld, line %ld\n", argv[1], arg,
87: chr, line);
88: exit(1);
89: }
90: eflg = 1;
91: printf("%6ld %3o %3o\n", chr, c1, c2);
92: goto loop;
93:
94: narg:
95: printf("cmp: arg count\n");
96: exit(2);
97:
98: barg:
99: if (lflg)
100: printf("cmp: cannot open %s\n", arg);
101: exit(2);
102:
103: earg:
104: printf("cmp: EOF on %s\n", arg);
105: exit(1);
106: }
107:
108: long otoi(s)
109: char *s;
110: {
111: long v;
112: int base;
113:
114: v = 0;
115: base = 10;
116: if (*s == '0')
117: base = 8;
118: while(isdigit(*s))
119: v = v*base + *s++ - '0';
120: return(v);
121: }
Defined functions
main
defined in line
14;
never used
otoi
defined in line
108; used 3 times
Defined variables
chr
defined in line
8; used 3 times
eflg
defined in line
5; used 2 times
lflg
defined in line
6; used 5 times
line
defined in line
7; used 2 times
skip1
defined in line
9; used 3 times
skip2
defined in line
10; used 3 times