From owner-freebsd-bugs@FreeBSD.ORG Tue Aug 31 19:40:24 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BBC6916A4D1 for ; Tue, 31 Aug 2004 19:40:24 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 917B743D46 for ; Tue, 31 Aug 2004 19:40:24 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.11/8.12.11) with ESMTP id i7VJeOS4005538 for ; Tue, 31 Aug 2004 19:40:24 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i7VJeOX0005537; Tue, 31 Aug 2004 19:40:24 GMT (envelope-from gnats) Resent-Date: Tue, 31 Aug 2004 19:40:24 GMT Resent-Message-Id: <200408311940.i7VJeOX0005537@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Chuck Swiger Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9B7E316A58B for ; Tue, 31 Aug 2004 19:36:34 +0000 (GMT) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id C04F643D39 for ; Tue, 31 Aug 2004 19:36:34 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.12.11/8.12.11) with ESMTP id i7VJaYiJ053892 for ; Tue, 31 Aug 2004 19:36:34 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.12.11/8.12.11/Submit) id i7VJaYwj053891; Tue, 31 Aug 2004 19:36:34 GMT (envelope-from nobody) Message-Id: <200408311936.i7VJaYwj053891@www.freebsd.org> Date: Tue, 31 Aug 2004 19:36:34 GMT From: Chuck Swiger To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Subject: gnu/71210: Update to GNU sdiff: add user-preference for merge keys X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Aug 2004 19:40:24 -0000 >Number: 71210 >Category: gnu >Synopsis: Update to GNU sdiff: add user-preference for merge keys >Confidential: no >Severity: serious >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Aug 31 19:40:24 GMT 2004 >Closed-Date: >Last-Modified: >Originator: Chuck Swiger >Release: 4.10, 5.3 >Organization: PKIx >Environment: FreeBSD ns1.pkix.net 4.10-STABLE FreeBSD 4.10-STABLE #18: Sat Jul 10 17:29:36 EDT 2004 root@ns1.pkix.net:/usr/obj/usr/src/sys/NORMAL i386 >Description: A recent discussion on -current about the default keys for mergemaster suggests that people find using 'l' and 'r' inconvenient. I think '1' and '2' are likely to be more reasonable even on foreign keyboard layouts, and have updated the default behavior to reflect this. The following patch also lets one define an SDIFF_MERGE_KEYS environment variable to pick any pair of keys they prefer. >How-To-Repeat: N/A--see mailing lists for prior discussion. [ Note that my PR mail bounced, so I'm posting this via WWW form. Sorry if this mangles tabs and spaces in the diff in the next section, original copy is at: http://www.pkix.net/~chuck/sdiff.diff ] >Fix: --- sdiff.c_orig Tue Aug 31 13:02:14 2004 +++ sdiff.c Tue Aug 31 14:55:06 2004 @@ -40,6 +40,12 @@ #define DEFAULT_EDITOR_PROGRAM "ed" #endif +/* Default sdiff keys for merging */ +#ifndef DEFAULT_MERGE_KEYS +/* #define DEFAULT_MERGE_KEYS "lr" -- old behavior */ +#define DEFAULT_MERGE_KEYS "12" +#endif + extern char version_string[]; static char const *program_name; static char const *diffbin = DIFF_PROGRAM; @@ -48,6 +54,8 @@ static char *tmpname; static int volatile tmpmade; +static char leftkey; +static char rightkey; #if HAVE_FORK static pid_t volatile diffpid; @@ -401,7 +409,8 @@ int opt; char *editor; char *differ; - + char *keys; + initialize_main (&argc, &argv); program_name = argv[0]; @@ -414,6 +423,15 @@ diffarg ("diff"); + keys = getenv("SDIFF_MERGE_KEYS"); + if (keys && strlen(keys) == 2) { + leftkey = keys[0]; + rightkey = keys[1]; + } else { + leftkey = DEFAULT_MERGE_KEYS[0]; + rightkey = DEFAULT_MERGE_KEYS[1]; + } + /* parse command line args */ while ((opt = getopt_long (argc, argv, "abBdHiI:lo:stvw:W", longopts, 0)) != EOF) @@ -794,10 +812,10 @@ static void give_help () { - fprintf (stderr,"l:\tuse the left version\n"); - fprintf (stderr,"r:\tuse the right version\n"); - fprintf (stderr,"e l:\tedit then use the left version\n"); - fprintf (stderr,"e r:\tedit then use the right version\n"); + fprintf (stderr,"%c:\tuse the left version\n", leftkey); + fprintf (stderr,"%c:\tuse the right version\n", rightkey); + fprintf (stderr,"e %c:\tedit then use the left version\n", leftkey); + fprintf (stderr,"e %c:\tedit then use the right version\n", rightkey); fprintf (stderr,"e b:\tedit then use the left and right versions concatenated\n"); fprintf (stderr,"e:\tedit a new version\n"); fprintf (stderr,"s:\tsilently include common lines\n"); @@ -841,195 +859,146 @@ int lenr; FILE *outfile; { - for (;;) - { - int cmd0, cmd1; - int gotcmd = 0; - - cmd1 = 0; /* Pacify `gcc -W'. */ - - while (!gotcmd) - { - if (putchar ('%') != '%') - perror_fatal ("output error"); - ck_fflush (stdout); - - cmd0 = skip_white (); - switch (cmd0) - { - case 'l': case 'r': case 's': case 'v': case 'q': - if (skip_white () != '\n') - { - give_help (); - flush_line (); - continue; - } - gotcmd = 1; - break; - - case 'e': - cmd1 = skip_white (); - switch (cmd1) - { - case 'l': case 'r': case 'b': - if (skip_white () != '\n') - { - give_help (); - flush_line (); - continue; - } - gotcmd = 1; - break; - case '\n': - gotcmd = 1; - break; - default: - give_help (); - flush_line (); - continue; - } - break; - case EOF: - if (feof (stdin)) - { - gotcmd = 1; - cmd0 = 'q'; - break; - } - /* falls through */ - default: - flush_line (); - /* falls through */ - case '\n': - give_help (); - continue; - } - } - - switch (cmd0) - { - case 'l': - lf_copy (left, lenl, outfile); - lf_skip (right, lenr); - return 1; - case 'r': - lf_copy (right, lenr, outfile); - lf_skip (left, lenl); - return 1; - case 's': - suppress_common_flag = 1; - break; - case 'v': - suppress_common_flag = 0; - break; - case 'q': - return 0; - case 'e': - { - int tfd; - FILE *tmp; - - if (tmpmade) - { - unlink (tmpname); - tmpmade = 0; - free (tmpname); - } - - asprintf (&tmpname, "%s/sdiff.XXXXXX", - getenv("TMPDIR") ?: P_tmpdir); - if (tmpname == NULL) - perror_fatal ("temporary file name"); - tfd = mkstemp(tmpname); - if (tfd == -1) - perror_fatal ("temporary file name"); - tmp = fdopen (tfd, "w+"); - if (tmp == NULL) - perror_fatal ("temporary file name"); - - tmpmade = 1; + int cmd0, cmd1 = 0; - if (cmd1 == 'l' || cmd1 == 'b') - lf_copy (left, lenl, tmp); - else - lf_skip (left, lenl); + for (;;) { + if (putchar ('%') != '%') + perror_fatal ("output error"); + ck_fflush (stdout); + + cmd0 = skip_white(); + if ((cmd0 == EOF) || (feof (stdin))) return 0; + + if (cmd0 == leftkey) { + lf_copy (left, lenl, outfile); + lf_skip (right, lenr); + return 1; + } else if (cmd0 == rightkey) { + lf_copy (right, lenr, outfile); + lf_skip (left, lenl); + return 1; + } else if (cmd0 == 's') { + suppress_common_flag = 1; + } else if (cmd0 == 'v') { + suppress_common_flag = 0; + } else if (cmd0 == 'q') { + return 0; + } else if (cmd0 == 'e') { + cmd1 = skip_white(); + if ((cmd1 == leftkey) || (cmd1 == rightkey) || + (cmd1 == 'b') || (cmd1 == '\n')) { + return calleditor(cmd1, left, lenl, right, lenr, outfile); + } + } else if (cmd0 == '\n') { + continue; + } else { + give_help(); + } + flush_line(); + } +} - if (cmd1 == 'r' || cmd1 == 'b') - lf_copy (right, lenr, tmp); - else - lf_skip (right, lenr); +int calleditor(cmd1, left, lenl, right, lenr, outfile) + int cmd1; + struct line_filter *left; + int lenl; + struct line_filter *right; + int lenr; + FILE *outfile; +{ + int tfd; + FILE *tmp; - ck_fflush (tmp); + if (tmpmade) { + unlink (tmpname); + tmpmade = 0; + free (tmpname); + } + + asprintf(&tmpname, "%s/sdiff.XXXXXX", getenv("TMPDIR") ?: P_tmpdir); + if (tmpname == NULL) + perror_fatal ("temporary file name"); + tfd = mkstemp(tmpname); + if (tfd == -1) + perror_fatal ("temporary file name"); + tmp = fdopen (tfd, "w+"); + if (tmp == NULL) + perror_fatal ("temporary file name"); + tmpmade = 1; + + if (cmd1 == leftkey || cmd1 == 'b') + lf_copy (left, lenl, tmp); + else + lf_skip (left, lenl); + + if (cmd1 == rightkey || cmd1 == 'b') + lf_copy (right, lenr, tmp); + else + lf_skip (right, lenr); + + ck_fflush (tmp); - { - int wstatus; + { + int wstatus; #if ! HAVE_FORK - char *command = xmalloc (strlen (edbin) + strlen (tmpname) + 2); - sprintf (command, "%s %s", edbin, tmpname); - wstatus = system (command); - free (command); + char *command = xmalloc (strlen (edbin) + strlen (tmpname) + 2); + sprintf (command, "%s %s", edbin, tmpname); + wstatus = system (command); + free (command); #else /* HAVE_FORK */ - pid_t pid; - - ignore_SIGINT = 1; - checksigs (); - - pid = vfork (); - if (pid == 0) - { - char const *argv[3]; - int i = 0; - - argv[i++] = edbin; - argv[i++] = tmpname; - argv[i++] = 0; - - execvp (edbin, (char **) argv); - write (STDERR_FILENO, edbin, strlen (edbin)); - write (STDERR_FILENO, ": not found\n", 12); - _exit (1); - } - - if (pid < 0) - perror_fatal ("fork failed"); - - while (waitpid (pid, &wstatus, 0) < 0) - if (errno == EINTR) - checksigs (); - else - perror_fatal ("wait failed"); - - ignore_SIGINT = 0; + pid_t pid; + + ignore_SIGINT = 1; + checksigs (); + + pid = vfork (); + if (pid == 0) { + char const *argv[3]; + int i = 0; + + argv[i++] = edbin; + argv[i++] = tmpname; + argv[i++] = 0; + + execvp (edbin, (char **) argv); + write (STDERR_FILENO, edbin, strlen (edbin)); + write (STDERR_FILENO, ": not found\n", 12); + _exit (1); + } + + if (pid < 0) + perror_fatal ("fork failed"); + + while (waitpid (pid, &wstatus, 0) < 0) + if (errno == EINTR) + checksigs (); + else + perror_fatal ("wait failed"); + + ignore_SIGINT = 0; #endif /* HAVE_FORK */ + + if (wstatus != 0) + fatal ("Subsidiary editor failed"); + } - if (wstatus != 0) - fatal ("Subsidiary editor failed"); - } - - if (fseek (tmp, 0L, SEEK_SET) != 0) - perror_fatal ("fseek"); - { - /* SDIFF_BUFSIZE is too big for a local var - in some compilers, so we allocate it dynamically. */ - char *buf = xmalloc (SDIFF_BUFSIZE); - size_t size; - - while ((size = ck_fread (buf, SDIFF_BUFSIZE, tmp)) != 0) - { - checksigs (); - ck_fwrite (buf, size, outfile); - } - ck_fclose (tmp); - - free (buf); - } - return 1; - } - default: - give_help (); - break; - } + if (fseek (tmp, 0L, SEEK_SET) != 0) + perror_fatal ("fseek"); + { + /* SDIFF_BUFSIZE is too big for a local var + in some compilers, so we allocate it dynamically. */ + char *buf = xmalloc (SDIFF_BUFSIZE); + size_t size; + + while ((size = ck_fread (buf, SDIFF_BUFSIZE, tmp)) != 0) { + checksigs (); + ck_fwrite (buf, size, outfile); + } + ck_fclose (tmp); + + free (buf); } + return 1; } >Release-Note: >Audit-Trail: >Unformatted: