=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/diff/diffreg.c,v retrieving revision 1.38 retrieving revision 1.39 diff -c -r1.38 -r1.39 *** src/usr.bin/diff/diffreg.c 2003/07/21 21:59:58 1.38 --- src/usr.bin/diff/diffreg.c 2003/07/22 00:15:55 1.39 *************** *** 1,4 **** ! /* $OpenBSD: diffreg.c,v 1.38 2003/07/21 21:59:58 henning Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. --- 1,4 ---- ! /* $OpenBSD: diffreg.c,v 1.39 2003/07/22 00:15:55 millert Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. *************** *** 65,71 **** */ #ifndef lint ! static const char rcsid[] = "$OpenBSD: diffreg.c,v 1.38 2003/07/21 21:59:58 henning Exp $"; #endif /* not lint */ #include --- 65,71 ---- */ #ifndef lint ! static const char rcsid[] = "$OpenBSD: diffreg.c,v 1.39 2003/07/22 00:15:55 millert Exp $"; #endif /* not lint */ #include *************** *** 196,202 **** static struct context_vec *context_vec_ptr; static FILE *opentemp(const char *); - static void fetch(long *, int, int, FILE *, char *, int); static void output(char *, FILE *, char *, FILE *); static void check(char *, FILE *, char *, FILE *); static void range(int, int, char *); --- 196,201 ---- *************** *** 211,216 **** --- 210,216 ---- static void change(char *, FILE *, char *, FILE *, int, int, int, int); static void sort(struct line *, int); static int asciifile(FILE *); + static int fetch(long *, int, int, FILE *, char *, int); static int newcand(int, int, int); static int search(int *, int, int); static int skipline(FILE *); *************** *** 935,941 **** --- 935,943 ---- change(char *file1, FILE *f1, char *file2, FILE *f2, int a, int b, int c, int d) { static size_t max_context = 64; + int i; + restart: if (format != D_IFDEF && a > b && c > d) return; if (format == D_CONTEXT || format == D_UNIFIED) { *************** *** 1010,1016 **** if (a <= b && c <= d && format == D_NORMAL) puts("---"); } ! fetch(ixnew, c, d, f2, format == D_NORMAL ? "> " : "", 0); if ((format == D_EDIT || format == D_REVERSE) && c <= d) puts("."); if (inifdef) { --- 1012,1032 ---- if (a <= b && c <= d && format == D_NORMAL) puts("---"); } ! i = fetch(ixnew, c, d, f2, format == D_NORMAL ? "> " : "", 0); ! if (i != 0 && format == D_EDIT) { ! /* ! * A non-zero return value for D_EDIT indicates that the ! * last line printed was a bare dot (".") that has been ! * escaped as ".." to prevent ed(1) from misinterpreting ! * it. We have to add a substitute command to change this ! * back and restart where we left off. ! */ ! puts("."); ! printf("%ds/^\\.\\././\n", a); ! a += i; ! c += i; ! goto restart; ! } if ((format == D_EDIT || format == D_REVERSE) && c <= d) puts("."); if (inifdef) { *************** *** 1019,1028 **** } } ! static void fetch(long *f, int a, int b, FILE *lb, char *s, int oldfile) { ! int i, j, c, col, nc; /* * When doing #ifdef's, copy down to current line --- 1035,1044 ---- } } ! static int fetch(long *f, int a, int b, FILE *lb, char *s, int oldfile) { ! int i, j, c, lastc, col, nc; /* * When doing #ifdef's, copy down to current line *************** *** 1036,1042 **** putchar(getc(lb)); } if (a > b) ! return; if (format == D_IFDEF) { if (inifdef) { printf("#else /* %s%s */\n", --- 1052,1058 ---- putchar(getc(lb)); } if (a > b) ! return (0); if (format == D_IFDEF) { if (inifdef) { printf("#else /* %s%s */\n", *************** *** 1055,1075 **** if (format != D_IFDEF) fputs(s, stdout); col = 0; ! for (j = 0; j < nc; j++) { if ((c = getc(lb)) == EOF) { puts("\n\\ No newline at end of file"); ! return; } if (c == '\t' && tflag) { do { putchar(' '); } while (++col & 7); } else { putchar(c); col++; } } } } #define HASHMASK (16 - 1) /* for masking out 16 bytes */ --- 1071,1104 ---- if (format != D_IFDEF) fputs(s, stdout); col = 0; ! for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) { if ((c = getc(lb)) == EOF) { puts("\n\\ No newline at end of file"); ! return (0);; } if (c == '\t' && tflag) { do { putchar(' '); } while (++col & 7); } else { + if (format == D_EDIT && j == 1 && c == '\n' + && lastc == '.') { + /* + * Don't print a bare "." line + * since that will confuse ed(1). + * Print ".." instead and return, + * giving the caller an offset + * from which to restart. + */ + puts("."); + return (i - a + 1); + } putchar(c); col++; } } } + return (0); } #define HASHMASK (16 - 1) /* for masking out 16 bytes */