diff3prog.c (b369f4b871a39ef94e220443957975f445f52eb6) | diff3prog.c (23a1ccea6aac035f084a7a4cdc968687d1b02daf) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 4 unchanged lines hidden (view full) --- 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 4 unchanged lines hidden (view full) --- 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ |
21/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 22/* All Rights Reserved */ | |
23 | 21 |
24 | |
25/* | 22/* |
26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 27 * Use is subject to license terms. | 23 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved. |
28 */ 29 | 24 */ 25 |
30#pragma ident "%Z%%M% %I% %E% SMI" | 26/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 27/* All Rights Reserved */ |
31 32#include <stdio.h> 33#include <stdlib.h> 34#include <unistd.h> 35#include <limits.h> 36#include <sys/param.h> 37#include <errno.h> 38# --- 61 unchanged lines hidden (view full) --- 100static char f1mark[8+MAXPATHLEN], f3mark[8+MAXPATHLEN]; 101 /* Need space for "<<<<<<< " or ">>>>>>> " plus filename */ 102static int save_err; /* saves errno */ 103 104static int readin(char *name, struct diff *dd); 105static int number(char **lc); 106static int digit(int c); 107static int getchange(FILE *b); | 28 29#include <stdio.h> 30#include <stdlib.h> 31#include <unistd.h> 32#include <limits.h> 33#include <sys/param.h> 34#include <errno.h> 35# --- 61 unchanged lines hidden (view full) --- 97static char f1mark[8+MAXPATHLEN], f3mark[8+MAXPATHLEN]; 98 /* Need space for "<<<<<<< " or ">>>>>>> " plus filename */ 99static int save_err; /* saves errno */ 100 101static int readin(char *name, struct diff *dd); 102static int number(char **lc); 103static int digit(int c); 104static int getchange(FILE *b); |
108static int getline(FILE *b); | 105static int getaline(FILE *b); |
109static void merge(int m1, int m2); 110static void separate(char *s); 111static void change(int i, struct range *rold, int dup); 112static void prange(struct range *rold); 113static void keep(int i, struct range *rnew); 114static int skip(int i, int from, char *pr); 115static int duplicate(struct range *r1, struct range *r2); 116static void repos(int nchar); --- 32 unchanged lines hidden (view full) --- 149 } 150 argv++; 151 argc--; 152 } 153 if (argc < 6) 154 usage(); 155 if (oflag) { 156 (void) snprintf(f1mark, sizeof (f1mark), "<<<<<<< %s", | 106static void merge(int m1, int m2); 107static void separate(char *s); 108static void change(int i, struct range *rold, int dup); 109static void prange(struct range *rold); 110static void keep(int i, struct range *rnew); 111static int skip(int i, int from, char *pr); 112static int duplicate(struct range *r1, struct range *r2); 113static void repos(int nchar); --- 32 unchanged lines hidden (view full) --- 146 } 147 argv++; 148 argc--; 149 } 150 if (argc < 6) 151 usage(); 152 if (oflag) { 153 (void) snprintf(f1mark, sizeof (f1mark), "<<<<<<< %s", |
157 argc >= 7 ? argv[6] : argv[3]); | 154 argc >= 7 ? argv[6] : argv[3]); |
158 (void) snprintf(f3mark, sizeof (f3mark), ">>>>>>> %s", | 155 (void) snprintf(f3mark, sizeof (f3mark), ">>>>>>> %s", |
159 argc >= 8 ? argv[7] : argv[5]); | 156 argc >= 8 ? argv[7] : argv[5]); |
160 } 161 162 m = readin(argv[1], d13); 163 n = readin(argv[2], d23); 164 for (i = 0; i <= 2; i++) 165 if ((fp[i] = fopen(argv[i+3], "r")) == NULL) { 166 save_err = errno; 167 (void) fprintf(stderr, "diff3: can't open %s: ", | 157 } 158 159 m = readin(argv[1], d13); 160 n = readin(argv[2], d23); 161 for (i = 0; i <= 2; i++) 162 if ((fp[i] = fopen(argv[i+3], "r")) == NULL) { 163 save_err = errno; 164 (void) fprintf(stderr, "diff3: can't open %s: ", |
168 argv[i+3]); | 165 argv[i+3]); |
169 errno = save_err; 170 perror(""); 171 exit(1); 172 } 173 merge(m, n); 174 return (0); 175} 176 --- 68 unchanged lines hidden (view full) --- 245digit(int c) 246{ 247 return (c >= '0' && c <= '9'); 248} 249 250static int 251getchange(FILE *b) 252{ | 166 errno = save_err; 167 perror(""); 168 exit(1); 169 } 170 merge(m, n); 171 return (0); 172} 173 --- 68 unchanged lines hidden (view full) --- 242digit(int c) 243{ 244 return (c >= '0' && c <= '9'); 245} 246 247static int 248getchange(FILE *b) 249{ |
253 while (getline(b)) | 250 while (getaline(b)) |
254 if (digit(line[0])) 255 return (1); 256 return (0); 257} 258 259static int | 251 if (digit(line[0])) 252 return (1); 253 return (0); 254} 255 256static int |
260getline(FILE *b) | 257getaline(FILE *b) |
261{ 262 int i, c; 263 for (i = 0; i < sizeof (line)-1; i++) { 264 c = getc(b); 265 if (c == EOF) { 266 line[i] = 0; 267 return (i); 268 } --- 14 unchanged lines hidden (view full) --- 283 int j; 284 int t1, t2; 285 d1 = d13; 286 d2 = d23; 287 j = 0; 288 for (; (t1 = d1 < d13+m1) | (t2 = d2 < d23+m2); ) { 289 if (debug) { 290 (void) printf("%d,%d=%d,%d %d,%d=%d,%d\n", | 258{ 259 int i, c; 260 for (i = 0; i < sizeof (line)-1; i++) { 261 c = getc(b); 262 if (c == EOF) { 263 line[i] = 0; 264 return (i); 265 } --- 14 unchanged lines hidden (view full) --- 280 int j; 281 int t1, t2; 282 d1 = d13; 283 d2 = d23; 284 j = 0; 285 for (; (t1 = d1 < d13+m1) | (t2 = d2 < d23+m2); ) { 286 if (debug) { 287 (void) printf("%d,%d=%d,%d %d,%d=%d,%d\n", |
291 d1->old.from, d1->old.to, 292 d1->new.from, d1->new.to, 293 d2->old.from, d2->old.to, 294 d2->new.from, d2->new.to); | 288 d1->old.from, d1->old.to, 289 d1->new.from, d1->new.to, 290 d2->old.from, d2->old.to, 291 d2->new.from, d2->new.to); |
295 } 296 297 /* first file is different from others */ 298 if (!t2 || t1 && d1->new.to < d2->new.from) { 299 /* stuff peculiar to 1st file */ 300 if (eflag == 0) { 301 separate("1"); 302 change(1, &d1->old, 0); --- 146 unchanged lines hidden (view full) --- 449 * if "pr" is nonzero, print all skipped stuff 450 * with string pr as a prefix 451 */ 452static int 453skip(int i, int from, char *pr) 454{ 455 int j, n; 456 for (n = 0; cline[i] < from-1; n += j) { | 292 } 293 294 /* first file is different from others */ 295 if (!t2 || t1 && d1->new.to < d2->new.from) { 296 /* stuff peculiar to 1st file */ 297 if (eflag == 0) { 298 separate("1"); 299 change(1, &d1->old, 0); --- 146 unchanged lines hidden (view full) --- 446 * if "pr" is nonzero, print all skipped stuff 447 * with string pr as a prefix 448 */ 449static int 450skip(int i, int from, char *pr) 451{ 452 int j, n; 453 for (n = 0; cline[i] < from-1; n += j) { |
457 if ((j = getline(fp[i])) == 0) | 454 if ((j = getaline(fp[i])) == 0) |
458 trouble(); 459 if (pr) 460 (void) printf("%s%s", pr, line); 461 cline[i]++; 462 } 463 return (n); 464} 465 --- 101 unchanged lines hidden --- | 455 trouble(); 456 if (pr) 457 (void) printf("%s%s", pr, line); 458 cline[i]++; 459 } 460 return (n); 461} 462 --- 101 unchanged lines hidden --- |