=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/diff3/diff3prog.c,v retrieving revision 1.5 retrieving revision 1.6 diff -c -r1.5 -r1.6 *** src/usr.bin/diff3/diff3prog.c 2004/01/07 18:16:42 1.5 --- src/usr.bin/diff3/diff3prog.c 2005/03/30 04:44:52 1.6 *************** *** 1,4 **** ! /* $OpenBSD: diff3prog.c,v 1.5 2004/01/07 18:16:42 canacar Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. --- 1,4 ---- ! /* $OpenBSD: diff3prog.c,v 1.6 2005/03/30 04:44:52 millert Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. *************** *** 71,81 **** #endif /* not lint */ #ifndef lint ! static const char rcsid[] = "$OpenBSD: diff3prog.c,v 1.5 2004/01/07 18:16:42 canacar Exp $"; #endif /* not lint */ #include #include #include #include --- 71,82 ---- #endif /* not lint */ #ifndef lint ! static const char rcsid[] = "$OpenBSD: diff3prog.c,v 1.6 2005/03/30 04:44:52 millert Exp $"; #endif /* not lint */ #include #include + #include #include #include *************** *** 117,123 **** struct diff de[NC]; char overlap[NC]; int overlapcnt; - char line[256]; FILE *fp[3]; int cline[3]; /* # of the last-read line in each file (0-2) */ /* --- 118,123 ---- *************** *** 132,139 **** int duplicate(struct range *, struct range *); int edit(struct diff *, int, int); ! int getchange(FILE *); ! int getline(FILE *); int number(char **); int readin(char *, struct diff *); int skip(int, int, char *); --- 132,139 ---- int duplicate(struct range *, struct range *); int edit(struct diff *, int, int); ! char *getchange(FILE *); ! char *getline(FILE *, size_t *); int number(char **); int readin(char *, struct diff *); int skip(int, int, char *); *************** *** 208,222 **** int readin(char *name, struct diff *dd) { ! int i; ! int a,b,c,d; ! char kind; ! char *p; fp[0] = fopen(name, "r"); ! for (i=0; getchange(fp[0]); i++) { if (i >= NC) err(EXIT_FAILURE, "too many changes"); - p = line; a = b = number(&p); if (*p == ',') { p++; --- 208,220 ---- int readin(char *name, struct diff *dd) { ! int a, b, c, d, i; ! char kind, *p; ! fp[0] = fopen(name, "r"); ! for (i=0; (p = getchange(fp[0])); i++) { if (i >= NC) err(EXIT_FAILURE, "too many changes"); a = b = number(&p); if (*p == ',') { p++; *************** *** 255,286 **** return (nn); } ! int getchange(FILE *b) { ! while (getline(b)) { if (isdigit((unsigned char)line[0])) ! return (1); } ! return (0); } ! int ! getline(FILE *b) { ! int i, c; ! for (i = 0; i < sizeof(line) - 1; i++) { ! c = getc(b); ! if (c == EOF) ! break; ! line[i] = c; ! if (c == '\n') { ! line[++i] = 0; ! return (i); ! } } ! return (0); } void --- 253,296 ---- return (nn); } ! char * getchange(FILE *b) { ! char *line; ! ! while ((line = getline(b, NULL))) { if (isdigit((unsigned char)line[0])) ! return (line); } ! return (NULL); } ! char * ! getline(FILE *b, size_t *n) { ! char *cp; ! size_t len; ! static char *buf; ! static size_t bufsize; ! if ((cp = fgetln(b, &len)) == NULL) ! return (NULL); ! ! if (cp[len - 1] != '\n') ! len++; ! if (len + 1 > bufsize) { ! do { ! bufsize += 1024; ! } while (len + 1 > bufsize); ! if ((buf = realloc(buf, bufsize)) == NULL) ! err(EXIT_FAILURE, NULL); } ! memcpy(buf, cp, len - 1); ! buf[len - 1] = '\n'; ! buf[len] = '\0'; ! if (n != NULL) ! *n = len; ! return (buf); } void *************** *** 447,462 **** int skip(int i, int from, char *pr) { ! int j, n; for (n = 0; cline[i] < from - 1; n += j) { ! if ((j = getline(fp[i])) == 0) trouble(); if (pr != NULL) printf("%s%s", pr, line); cline[i]++; } ! return (n); } /* --- 457,473 ---- int skip(int i, int from, char *pr) { ! size_t j, n; ! char *line; for (n = 0; cline[i] < from - 1; n += j) { ! if ((line = getline(fp[i], &j)) == NULL) trouble(); if (pr != NULL) printf("%s%s", pr, line); cline[i]++; } ! return ((int) n); } /*