🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.utils.bug
Article #164

Enhancements to gdiff-1.15

#164
From: john r. durand
Date: Mon, 20 Jul 1992 18:35
307 lines
8904 bytes
i enhanced diff-1.15 to allow the diffing of symbolic link text.  if, for
example, two links exist that point to different places, diff will report
the differences in link text itself.  this was added in the form of two
new options: -x, and -X.

-x will simply report link text differences:

   % ln -s /wow a
   % ln -s /wee b
   % diff -x a b
   Symbolic links a and b differ

-X will show the link text differences:

   % diff -X a b
   < /wow
   > /wee

these patches were made to diff-1.15; if they can not be applied to the most
current version of diff, simpley send it my way and i will product another
patch file that will patch the current version.  thanks!

john r. durand                Cadre Technologies Inc.

  O_o                         222 Richmond Street
=(  )=   Ack!                 Providence, Rhode Island
   U                          0  2  9  0  3

email: jrd@cadre.com          Phone: (401) 351-5950
			      FAX:   (401) 351-7380

--------------------------- patch file follows -----------------------------
*** /export/source/diff-1.15/ChangeLog	Thu Jun 18 06:53:43 1992
--- /export/source/gdiff/ChangeLog	Mon Jul 20 13:56:31 1992
***************
*** 1,3 ****
--- 1,9 ----
+ Thu Jun 18 09:44:47 1992  john r. durand  (jrd@cadre.com)
+ 
+         * Add -x and -X options to compare text of symbolic links.
+ 
+ 	* diff.h, diff.c add ln_p; handle -x, -X options
+ 
  Sun Jan  6 18:42:23 1991  Michael I Bushnell  (mib at geech.ai.mit.edu)
  
  	* Version 1.15 released.
*** /export/source/diff-1.15/diff.c	Thu Jun 18 06:53:43 1992
--- /export/source/gdiff/diff.c	Mon Jul 20 14:35:29 1992
***************
*** 101,106 ****
--- 101,108 ----
    {"report-identical-files", 0, 0, 's'},
    {"expand-tabs", 0, 0, 't'},
    {"ignore-all-space", 0, 0, 'w'},
+   {"compare-link-text", 0, 0, 'x'},
+   {"show-link-text", 0, 0, 'X'},
    {"unified", 2, 0, 130},
    {"version", 0, 0, 'v'},
    {0, 0, 0, 0}
***************
*** 137,142 ****
--- 139,146 ----
    tab_expand_flag = FALSE;
    recursive = FALSE;
    paginate_flag = FALSE;
+   compare_link_text = FALSE;
+   show_link_text = FALSE;
    ifdef_string = NULL;
    heuristic = FALSE;
    dir_start_file = NULL;
***************
*** 147,153 ****
    /* Decode the options.  */
  
    while ((c = getopt_long (argc, argv,
! 			   "0123456789abBcC:dD:efF:hHiI:lL:nNpqrsS:tTuvw",
  			   longopts, &longind)) != EOF)
      {
        if (c == 0)		/* Long option. */
--- 151,157 ----
    /* Decode the options.  */
  
    while ((c = getopt_long (argc, argv,
! 			   "0123456789abBcC:dD:efF:hHiI:lL:nNpqrsS:tTuvwxX",
  			   longopts, &longind)) != EOF)
      {
        if (c == 0)		/* Long option. */
***************
*** 350,355 ****
--- 354,370 ----
  	  length_varies = 1;
  	  break;
  
+ 	case 'x':
+ 	  /* Compare text of symbolic links instead of contents.  */
+ 	  compare_link_text = 1;
+ 	  break;
+ 
+ 	case 'X':
+ 	  /* Show differences in text of symbolic links.  */
+ 	  compare_link_text = 1;
+ 	  show_link_text = 1;
+ 	  break;
+ 
  	default:
  	  usage ();
  	}
***************
*** 402,408 ****
  usage ()
  {
    fprintf (stderr, "\
! Usage: diff [-#] [-abBcdefhHilnNprstTuvw] [-C lines] [-F regexp] [-I regexp]\n\
         [-L label [-L label]] [-S file] [-D symbol] [+ignore-blank-lines]\n\
         [+context[=lines]] [+unified[=lines]] [+ifdef=symbol]\n\
         [+show-function-line=regexp]\n");
--- 417,423 ----
  usage ()
  {
    fprintf (stderr, "\
! Usage: diff [-#] [-abBcdefhHilnNprstTuvwxX] [-C lines] [-F regexp] [-I regexp]\n\
         [-L label [-L label]] [-S file] [-D symbol] [+ignore-blank-lines]\n\
         [+context[=lines]] [+unified[=lines]] [+ifdef=symbol]\n\
         [+show-function-line=regexp]\n");
***************
*** 413,418 ****
--- 428,434 ----
    fprintf (stderr, "\
         [+print] [+rcs] [+show-c-function] [+binary] [+brief] [+recursive]\n\
         [+report-identical-files] [+expand-tabs] [+ignore-all-space]\n\
+        [+compare-link-text] [+show-link-text]\n\
         [+file-label=label [+file-label=label]] [+version] path1 path2\n");
    exit (2);
  } 
***************
*** 491,497 ****
  
  	  stat_result[i] = 
  	    strcmp (filename, "-")
! 	      ? stat (filename, &inf[i].stat)
  	      : fstat (0, &inf[i].stat);
  		  
  	  if (stat_result[i] < 0)
--- 507,515 ----
  
  	  stat_result[i] = 
  	    strcmp (filename, "-")
! 	      ? 
! 		(compare_link_text) ? lstat (filename, &inf[i].stat)
! 		    : stat (filename, &inf[i].stat)
  	      : fstat (0, &inf[i].stat);
  		  
  	  if (stat_result[i] < 0)
***************
*** 500,508 ****
  	      errorcount = 1;
  	    }
  	  else
! 	    inf[i].dir_p = 
! 	      S_IFDIR == (inf[i].stat.st_mode & S_IFMT)
! 	      && strcmp (filename, "-");
  	}
      }
  
--- 518,540 ----
  	      errorcount = 1;
  	    }
  	  else
! 	    {
! 	      inf[i].dir_p = 
! 	        S_IFDIR == (inf[i].stat.st_mode & S_IFMT)
! 	        && strcmp (filename, "-");
! 	      inf[i].ln_p = 
! 	        S_IFLNK == (inf[i].stat.st_mode & S_IFMT)
! 	        && strcmp (filename, "-");
! 
! 	      /*
! 	       *  If this is a link, mark it as non-existsnat files so
! 	       *  that it won't be opened.
! 	       */
! 	      if (inf[i].ln_p)
! 		{
! 		  inf[i].desc = -1;
! 		}
! 	    }
  	}
      }
  
***************
*** 557,562 ****
--- 589,642 ----
        val = 2;
  
      }
+   else if (inf[0].ln_p || inf[1].ln_p)
+     {
+       if (inf[0].ln_p && ! inf[1].ln_p)
+ 	{
+ 	  message ("%s is a symbolic link but %s is not\n",
+ 		 inf[0].name, inf[1].name);
+ 	  val = 1;
+ 	}
+       else if (! inf[0].ln_p && inf[1].ln_p)
+ 	{
+ 	  message ("%s is a symbolic link but %s is not\n",
+ 		 inf[1].name, inf[0].name);
+ 	  val = 1;
+ 	}
+       else if (inf[0].ln_p && inf[1].ln_p)
+       {
+ 	char linktext1[MAXPATHLEN];
+ 	char linktext2[MAXPATHLEN];
+ 
+ 	if (readlink(inf[0].name, linktext1, sizeof(linktext1)) < 0)
+ 	  {
+ 	    message ("Can't read link text for %s\n", inf[0].name);
+ 	    val = 1;
+ 	  }
+ 	else if (readlink(inf[1].name, linktext2, sizeof(linktext2)) < 0)
+ 	  {
+ 	    message ("Can't read link text for %s\n", inf[1].name);
+ 	    val = 1;
+ 	  }
+ 	else
+ 	  {
+ 	    if (strcmp(linktext1, linktext2))
+ 	      {
+ 		if (show_link_text)
+ 		  {
+ 		    setup_output (inf[0].name, inf[1].name, depth);
+ 		    message ("< %s\n", linktext1);
+ 		    message ("> %s\n", linktext2);
+ 		  }
+ 		else
+ 		  {
+ 		    message ("Symbolic links %s and %s differ\n", inf[0].name, inf[1].name);
+ 		  }
+ 		val = 1;
+ 	      }
+ 	  }
+       }
+     }
    else if (inf[0].dir_p && inf[1].dir_p)
      {
        if (output_style == OUTPUT_IFDEF)
***************
*** 677,684 ****
    if (val == 0 && !inf[0].dir_p)
      {
        if (print_file_same_flag)
! 	message ("Files %s and %s are identical\n",
! 		 inf[0].name, inf[1].name);
      }
    else
      fflush (stdout);
--- 757,770 ----
    if (val == 0 && !inf[0].dir_p)
      {
        if (print_file_same_flag)
! 	{
!           if (inf[0].ln_p)
! 	    message ("Symbolic links %s and %s are identical\n",
! 		     inf[0].name, inf[1].name);
!           else
! 	    message ("Files %s and %s are identical\n",
! 		     inf[0].name, inf[1].name);
! 	}
      }
    else
      fflush (stdout);
*** /export/source/diff-1.15/diff.h	Thu Jun 18 06:53:43 1992
--- /export/source/gdiff/diff.h	Thu Jun 18 08:21:45 1992
***************
*** 20,25 ****
--- 20,26 ----
  
  #include <ctype.h>
  #include <stdio.h>
+ #include <sys/param.h>
  #include <sys/types.h>
  #include <sys/stat.h>
  
***************
*** 199,204 ****
--- 200,211 ----
  /* Pipe each file's output through pr (-l).  */
  EXTERN int	paginate_flag;
  
+ /* Compare link text (-x).  */
+ EXTERN int	compare_link_text;
+ 
+ /* Show link text (-X).  */
+ EXTERN int	show_link_text;
+ 
  /* String to use for #ifdef (-D).  */
  EXTERN char *	ifdef_string;
  
***************
*** 250,255 ****
--- 257,263 ----
      int             desc;	/* File descriptor  */
      char           *name;	/* File name  */
      struct stat     stat;	/* File status from fstat()  */
+     int             ln_p;	/* 1 if file is a link  */
      int             dir_p;	/* 1 if file is a directory  */
  
      /* Buffer in which text of file is read.  */
Technical Details
Message-ID: <m0mA2mi-000uO4C@cadre.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cadre.COM!jrd

Show Full Headers
Complete Article Headers
Newsgroups: gnu.utils.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cadre.COM!jrd
From: jrd@cadre.COM (john r. durand)
Subject: Enhancements to gdiff-1.15
Message-ID: <m0mA2mi-000uO4C@cadre.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Mon, 20 Jul 1992 18:35:36 GMT
Approved: bug-gnu-utils@prep.ai.mit.edu
Lines: 308