Path: utzoo!utgpu!watmath!iuvax!cica!tut.cis.ohio-state.edu!YIN.CPAC.WASHINGTON.EDU!tom From: tom@YIN.CPAC.WASHINGTON.EDU (Tom May) Newsgroups: gnu.utils.bug Subject: (none) Message-ID: <8908090552.AA04709@yin.cpac.washington.edu> Date: 9 Aug 89 05:52:13 GMT Distribution: gnu Organization: GNUs Not Usenet Lines: 274 GNU people, Imagine my dismay when the latest version of GNU diff I snarfed (version 1.7) didn't support the -D switch. Here are some diffs to add it. If you use them, I will once again be happy to have contributed to project GNU. Tom May tom@yin.cpac.washington.edu diff -N -c diff-old/Makefile diff-new/Makefile *** diff-old/Makefile Fri Feb 24 09:40:43 1989 --- diff-new/Makefile Tue Aug 8 12:16:30 1989 *************** *** 37,43 **** srcs=diff.c analyze.c io.c context.c ed.c normal.c util.c dir.c diff.h \ regex.c regex.h limits.h diff3.c # Object files for diff only. ! objs=diff.o analyze.o io.o context.o ed.o normal.o util.o dir.o regex.o tapefiles = $(srcs) README diagmeet.note Makefile COPYING all: diff diff3 --- 37,44 ---- srcs=diff.c analyze.c io.c context.c ed.c normal.c util.c dir.c diff.h \ regex.c regex.h limits.h diff3.c # Object files for diff only. ! objs=diff.o analyze.o io.o context.o ed.o normal.o util.o dir.o regex.o \ ! ifdef.o tapefiles = $(srcs) README diagmeet.note Makefile COPYING all: diff diff3 diff -N -c diff-old/analyze.c diff-new/analyze.c *** diff-old/analyze.c Fri Feb 24 09:42:16 1989 --- diff-new/analyze.c Tue Aug 8 12:07:24 1989 *************** *** 763,768 **** --- 763,772 ---- case OUTPUT_NORMAL: print_normal_script (script); break; + + case OUTPUT_IFDEF: + print_ifdef_script (script); + break; } finish_output (); diff -N -c diff-old/diff.c diff-new/diff.c *** diff-old/diff.c Wed Apr 26 12:38:27 1989 --- diff-new/diff.c Tue Aug 8 22:22:23 1989 *************** *** 97,102 **** --- 97,103 ---- tab_expand_flag = FALSE; recursive = FALSE; paginate_flag = FALSE; + ifdef_string = NULL; heuristic = FALSE; dir_start_file = NULL; msg_chain = NULL; *************** *** 105,111 **** /* Decode the options. */ ! while ((c = getopt (argc, argv, "0123456789abBcC:defF:hHiI:lnNprsS:tTw")) != EOF) { switch (c) --- 106,112 ---- /* Decode the options. */ ! while ((c = getopt (argc, argv, "0123456789abBcC:dD:efF:hHiI:lnNprsS:tTw")) != EOF) { switch (c) *************** *** 171,176 **** --- 172,183 ---- no_discards = 1; break; + case 'D': + /* Make merged #ifdef output. */ + specify_style (OUTPUT_IFDEF); + ifdef_string = optarg; + break; + case 'e': /* Make output that is a valid `ed' script. */ specify_style (OUTPUT_ED); *************** *** 457,462 **** --- 464,471 ---- } else if (inf[0].dir_p && inf[1].dir_p) { + if (output_style == OUTPUT_IFDEF) + fatal ("Can't specify -D with directories."); /* If both are directories, compare the files in them. */ diff -N -c diff-old/diff.h diff-new/diff.h *** diff-old/diff.h Fri Feb 24 09:42:05 1989 --- diff-new/diff.h Tue Aug 8 17:06:17 1989 *************** *** 99,105 **** /* Output the diff as a forward ed script (-f). */ OUTPUT_FORWARD_ED, /* Like -f, but output a count of changed lines in each "command" (-n). */ ! OUTPUT_RCS }; EXTERN enum output_style output_style; --- 99,107 ---- /* Output the diff as a forward ed script (-f). */ OUTPUT_FORWARD_ED, /* Like -f, but output a count of changed lines in each "command" (-n). */ ! OUTPUT_RCS, ! /* Output merged #ifdef'd file (-D). */ ! OUTPUT_IFDEF }; EXTERN enum output_style output_style; *************** *** 165,170 **** --- 167,175 ---- /* Pipe each file's output through pr (-l). */ EXTERN int paginate_flag; + + /* String to use for #ifdef (-D). */ + EXTERN char * ifdef_string; /* String containing all the command options diff received, with spaces between and at the beginning but none at the end. diff -N -c diff-old/ifdef.c diff-new/ifdef.c *** diff-old/ifdef.c Wed Dec 31 16:00:00 1969 --- diff-new/ifdef.c Tue Aug 8 22:09:17 1989 *************** *** 0 **** --- 1,82 ---- + /* #ifdef-format output routines for GNU DIFF. + Copyright (C) 1989 Free Software Foundation, Inc. + + This file is part of GNU DIFF. + + GNU DIFF is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY. No author or distributor + accepts responsibility to anyone for the consequences of using it + or for whether it serves any particular purpose or works at all, + unless he says so in writing. Refer to the GNU DIFF General Public + License for full details. + + Everyone is granted permission to copy, modify and redistribute + GNU DIFF, but only under the conditions described in the + GNU DIFF General Public License. A copy of this license is + supposed to have been given to you along with GNU DIFF so you + can know your rights and responsibilities. It should be in a + file named COPYING. Among other things, the copyright notice + and this notice must be preserved on all copies. */ + + + #include "diff.h" + + static void print_ifdef_hunk (); + struct change *find_change (); + + static int next_line; + + /* Print the edit-script SCRIPT as a merged #ifdef file. */ + + void + print_ifdef_script (script) + struct change *script; + { + next_line = 0; + print_script (script, find_change, print_ifdef_hunk); + while (next_line < files[0].buffered_lines) + print_1_line ("", &files[0].linbuf[next_line++]); + } + + /* Print a hunk of an ifdef diff. + This is a contiguous portion of a complete edit script, + describing changes in consecutive lines. */ + + static void + print_ifdef_hunk (hunk) + struct change *hunk; + { + int first0, last0, first1, last1, deletes, inserts; + register int i; + + /* Determine range of line numbers involved in each file. */ + analyze_hunk (hunk, &first0, &last0, &first1, &last1, &deletes, &inserts); + if (!deletes && !inserts) + return; + + /* Print out lines up to this change. */ + while (next_line < first0) + print_1_line ("", &files[0].linbuf[next_line++]); + + /* Print out stuff deleted from first file. */ + if (deletes) + { + fprintf (outfile, "#ifndef %s\n", ifdef_string); + for (i = first0; i <= last0; i++) + print_1_line ("", &files[0].linbuf[i]); + next_line = i; + } + + /* Print out stuff inserted from second file. */ + if (inserts) + { + if (deletes) + fprintf (outfile, "#else\n"); + else + fprintf (outfile, "#ifdef %s\n", ifdef_string); + for (i = first1; i <= last1; i++) + print_1_line ("", &files[1].linbuf[i]); + } + + fprintf (outfile, "#endif\n"); + } diff -N -c diff-old/io.c diff-new/io.c *** diff-old/io.c Tue Apr 11 22:06:17 1989 --- diff-new/io.c Tue Aug 8 22:16:24 1989 *************** *** 137,147 **** current->linbuf = (struct line_def *) xmalloc (current->linbufsize * sizeof (struct line_def)); ! if (function_regexp) { /* If the -C or -F option is used, we need to find the lines of the matching prefix. At least we will need to find the last few, ! but since we don't know how many, it's easiest to find them all. */ current->buffered_lines = 0; p = (unsigned char *) current->buffer; } --- 137,148 ---- current->linbuf = (struct line_def *) xmalloc (current->linbufsize * sizeof (struct line_def)); ! if (function_regexp || output_style == OUTPUT_IFDEF) { /* If the -C or -F option is used, we need to find the lines of the matching prefix. At least we will need to find the last few, ! but since we don't know how many, it's easiest to find them all. ! If -D is specified, we need all the lines of the first file. */ current->buffered_lines = 0; p = (unsigned char *) current->buffer; } *************** *** 265,271 **** } i = 0; ! while (i < context && (char *) p < current->buffer + current->buffered_chars) { ip = p; while (*p++ != '\n') --- 266,273 ---- } i = 0; ! while ((i < context || output_style == OUTPUT_IFDEF) ! && (char *) p < current->buffer + current->buffered_chars) { ip = p; while (*p++ != '\n') (That's all.)