|
|
1.1 root 1: static char sccsid[] = "@(#)diff.c 4.1 10/9/80";
2:
3: #include "diff.h"
4: /*
5: * diff - driver and subroutines
6: */
7:
8: char diff[] = DIFF;
9: char diffh[] = DIFFH;
10: char pr[] = PR;
11:
12: main(argc, argv)
13: int argc;
14: char **argv;
15: {
16: register char *argp;
17:
18: dummy = malloc(0);
19: ifdef1 = "FILE1"; ifdef2 = "FILE2";
20: status = 2;
21: diffargv = argv;
22: argc--, argv++;
23: while (argc > 2 && argv[0][0] == '-') {
24: argp = &argv[0][1];
25: argv++, argc--;
26: while (*argp) switch(*argp++) {
27:
28: #ifdef notdef
29: case 'I':
30: opt = D_IFDEF;
31: wantelses = 0;
32: continue;
33: case 'E':
34: opt = D_IFDEF;
35: wantelses = 1;
36: continue;
37: case '1':
38: opt = D_IFDEF;
39: ifdef1 = argp;
40: *--argp = 0;
41: continue;
42: #endif
43: case 'D':
44: /* -Dfoo = -E -1 -2foo */
45: wantelses = 1;
46: ifdef1 = "";
47: /* fall through */
48: #ifdef notdef
49: case '2':
50: #endif
51: opt = D_IFDEF;
52: ifdef2 = argp;
53: *--argp = 0;
54: continue;
55: case 'e':
56: opt = D_EDIT;
57: continue;
58: case 'f':
59: opt = D_REVERSE;
60: continue;
61: case 'b':
62: bflag = 1;
63: continue;
64: case 'c':
65: opt = D_CONTEXT;
66: if (isdigit(*argp)) {
67: context = atoi(argp);
68: while (isdigit(*argp))
69: argp++;
70: if (*argp) {
71: fprintf(stderr,
72: "diff: -c: bad count\n");
73: done();
74: }
75: argp = "";
76: } else
77: context = 3;
78: continue;
79: case 'h':
80: hflag++;
81: continue;
82: case 'S':
83: if (*argp == 0) {
84: fprintf(stderr, "diff: use -Sstart\n");
85: done();
86: }
87: start = argp;
88: *--argp = 0; /* don't pass it on */
89: continue;
90: case 'r':
91: rflag++;
92: continue;
93: case 's':
94: sflag++;
95: continue;
96: case 'l':
97: lflag++;
98: continue;
99: default:
100: fprintf(stderr, "diff: -%s: unknown option\n",
101: --argp);
102: done();
103: }
104: }
105: if (argc != 2) {
106: fprintf(stderr, "diff: two filename arguments required\n");
107: done();
108: }
109: file1 = argv[0];
110: file2 = argv[1];
111: if (hflag && opt) {
112: fprintf(stderr,
113: "diff: -h doesn't support -e, -f, -c, or -I\n");
114: done();
115: }
116: if (!strcmp(file1, "-"))
117: stb1.st_mode = S_IFREG;
118: else if (stat(file1, &stb1) < 0) {
119: fprintf(stderr, "diff: ");
120: perror(file1);
121: done();
122: }
123: if (!strcmp(file2, "-"))
124: stb2.st_mode = S_IFREG;
125: else if (stat(file2, &stb2) < 0) {
126: fprintf(stderr, "diff: ");
127: perror(file2);
128: done();
129: }
130: if ((stb1.st_mode & S_IFMT) == S_IFDIR &&
131: (stb2.st_mode & S_IFMT) == S_IFDIR) {
132: diffdir(argv);
133: } else
134: diffreg();
135: done();
136: }
137:
138: char *
139: savestr(cp)
140: register char *cp;
141: {
142: register char *dp = malloc(strlen(cp)+1);
143:
144: if (dp == 0) {
145: fprintf(stderr, "diff: ran out of memory\n");
146: done();
147: }
148: strcpy(dp, cp);
149: return (dp);
150: }
151:
152: min(a,b)
153: int a,b;
154: {
155:
156: return (a < b ? a : b);
157: }
158:
159: max(a,b)
160: int a,b;
161: {
162:
163: return (a > b ? a : b);
164: }
165:
166: done()
167: {
168: unlink(tempfile);
169: exit(status);
170: }
171:
172: char *
173: talloc(n)
174: {
175: register char *p;
176: p = malloc((unsigned)n);
177: if(p!=NULL)
178: return(p);
179: noroom();
180: }
181:
182: char *
183: ralloc(p,n) /*compacting reallocation */
184: char *p;
185: {
186: register char *q;
187: char *realloc();
188: free(p);
189: free(dummy);
190: dummy = malloc(1);
191: q = realloc(p, (unsigned)n);
192: if(q==NULL)
193: noroom();
194: return(q);
195: }
196:
197: noroom()
198: {
199: fprintf(stderr, "diff: files too big, try -h\n");
200: done();
201: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.