🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sources.bugs
Article #2170

Fix for MIT Athena delete/undelete programs

#2170
From: Wayne Davison
Date: Tue, 04 Apr 1989 23:21
256 lines
8017 bytes
The following patch file fixes two bugs in the MIT Athena delete/undelete
posting in comp.sources.unix and makes one usability change to expunge.c.

The first bug is a problem in col.c when using an auto-wrap terminal.  If
the columns divide evenly into 80, the last one will be space-padded up to
the 80th character, causing a screen wrap and double-spaced output.  The
fix is to not space-pad the last column on a line.

The second bug is more serious.  When you specify a minimum time for expunge
and it skips a file because it is not old enough to expunge, it decreases
the number of found files.  This causes the loop to terminate before processing
all of the files, skipping the ones at the end of the list.  I fixed this by
adding a count of skipped files, and subtracting it off the found count for
the return value.

Finally, I changed the way purge is handled in expunge to enable the
processing of options such as `-t2' or a directory name.  The purge
functionality can now be accessed either with the `-p' option of expunge,
or through the `purge' file link created by the Makefile.

					..Wayne..
----------------------------------Cut Here----------------------------------
*** col.c.orig	Tue Apr  4 13:59:20 1989
--- col.c	Tue Apr  4 13:59:43 1989
***************
*** 64,81 ****
  	  height++;
       
       if (number_flag) for (updown = 0; updown < height; updown++) {
! 	  for (leftright = updown; leftright < num_to_print;
! 	       leftright += height) {
  	       (void) sprintf(buf, "%*d. %s", numwidth, leftright+1,
  			      strings[leftright]);
! 	       fprintf(outfile, "%*s", -column_width, buf);
  	  }
  	  fprintf(outfile, "\n");
       } else for (updown = 0; updown < height; updown++) {
! 	  for (leftright = updown; leftright < num_to_print;
! 	       leftright += height) {
  	       (void) sprintf(buf, "%s", strings[leftright]);
! 	       fprintf(outfile, "%*s", -column_width, buf);
  	  }
  	  fprintf(outfile, "\n");
       }
--- 64,85 ----
  	  height++;
       
       if (number_flag) for (updown = 0; updown < height; updown++) {
! 	  for (leftright = updown; leftright < num_to_print; ) {
  	       (void) sprintf(buf, "%*d. %s", numwidth, leftright+1,
  			      strings[leftright]);
! 	       if ((leftright += height) >= num_to_print)
! 		    fprintf(outfile, "%s", buf );
! 	       else
! 		    fprintf(outfile, "%*s", -column_width, buf);
  	  }
  	  fprintf(outfile, "\n");
       } else for (updown = 0; updown < height; updown++) {
! 	  for (leftright = updown; leftright < num_to_print; ) {
  	       (void) sprintf(buf, "%s", strings[leftright]);
! 	       if ((leftright += height) >= num_to_print)
! 		    fprintf(outfile, "%s", buf );
! 	       else
! 		    fprintf(outfile, "%*s", -column_width, buf);
  	  }
  	  fprintf(outfile, "\n");
       }
*** expunge.c.orig	Tue Apr  4 13:59:21 1989
--- expunge.c	Tue Apr  4 14:12:19 1989
***************
*** 47,53 ****
       verbose,		/* print a line as each file is deleted */
       force,		/* do not ask for any confirmation */
       listfiles,		/* list files at toplevel */
!      yield;		/* print yield of expunge at end */
  
  int blocks_removed = 0;
  
--- 47,54 ----
       verbose,		/* print a line as each file is deleted */
       force,		/* do not ask for any confirmation */
       listfiles,		/* list files at toplevel */
!      yield,		/* print yield of expunge at end */
!      purge;		/* alias for expunge -r -l -y $HOME */
  
  int blocks_removed = 0;
  
***************
*** 61,67 ****
       extern char *optarg;
       extern int optind;
       int arg;
!      int status = 0;
  
       whoami = lastpart(argv[0]);
       error_buf = malloc(strlen(whoami) + MAXPATHLEN + 3);
--- 62,68 ----
       extern char *optarg;
       extern int optind;
       int arg;
!      char *dir;
  
       whoami = lastpart(argv[0]);
       error_buf = malloc(strlen(whoami) + MAXPATHLEN + 3);
***************
*** 70,81 ****
  	  exit(1);
       }
       if (*whoami == 'p') { /* we're doing a purge */
! 	  exit (purge());
       }
       timev = 0;
       yield = interactive = recursive = noop = verbose = listfiles = force = 0;
!      while ((arg = getopt(argc, argv, "t:irfnvly")) != -1) {
  	  switch (arg) {
  	  case 't':
  	       timev = atoi(optarg);
  	       break;
--- 71,85 ----
  	  exit(1);
       }
       if (*whoami == 'p') { /* we're doing a purge */
! 	  purge++;
       }
       timev = 0;
       yield = interactive = recursive = noop = verbose = listfiles = force = 0;
!      while ((arg = getopt(argc, argv, "pt:irfnvly")) != -1) {
  	  switch (arg) {
+ 	  case 'p':
+ 	       purge++;
+ 	       break;
  	  case 't':
  	       timev = atoi(optarg);
  	       break;
***************
*** 105,144 ****
  	       exit(1);
  	  }
       }
!      if (optind == argc) {
! 	  char *dir;
! 	  dir = ".";
! 	  status = status | expunge(&dir, 1); /* current working directory */
       }
!      else
! 	  status = status | expunge(&argv[optind], argc - optind);
!      exit(status & ERROR_MASK);
! }
! 
! 
! 
! 
! 
! purge()
! {
!      char *home[1];
! 
!      home[0] = malloc(MAXPATHLEN);
!      if (! home[0]) {
! 	  perror(sprintf(error_buf, "%s: purge", whoami));
! 	  exit(1);
       }
!      timev = interactive = noop = verbose = force = 0;
!      yield = listfiles = recursive = 1;
!      get_home(home[0]);
!      if (! *home[0]) {
! 	  fprintf(stderr, "%s: purge: can't get home directory\n", whoami);
! 	  exit(1);
       }
! 
!      printf("Please be patient.... this may take a while.\n\n");
!      
!      return(expunge(home, 1));
  }
  
  
--- 109,139 ----
  	       exit(1);
  	  }
       }
!      if (purge) {
! 	  yield = listfiles = recursive = 1;
       }
!      if (optind == argc) {
! 	  if (purge) {
! 	       dir = malloc(MAXPATHLEN);
! 	       if (! dir) {
! 		  perror(whoami);
! 		  exit(1);
! 	       }
! 	       get_home(dir);
! 	       if (! *dir) {
! 		  fprintf(stderr, "%s: can't get home directory\n", whoami);
! 		  exit(1);
! 	       }
! 	  } else {
! 	       dir = ".";
! 	  }
! 	  argv[optind] = dir;
! 	  argc++;
       }
!      if (recursive) {
! 	  printf("Please be patient.... this may take a while.\n\n");
       }
!      exit(expunge(&argv[optind], argc - optind) & ERROR_MASK);
  }
  
  
***************
*** 270,276 ****
  char **files;
  int num;
  {
!      int i;
       filerec *leaf;
       
       for (i = 0; i < num; i++) {
--- 265,271 ----
  char **files;
  int num;
  {
!      int i, skipped = 0;
       filerec *leaf;
       
       for (i = 0; i < num; i++) {
***************
*** 283,293 ****
  	  free(files[i]);
  	  if (! timed_out(leaf, current_time, timev)) {
  	       free_leaf(leaf);
! 	       num--;
  	  }
       }
       free(files);
!      return(num);
  }
  
  
--- 278,288 ----
  	  free(files[i]);
  	  if (! timed_out(leaf, current_time, timev)) {
  	       free_leaf(leaf);
! 	       skipped++;
  	  }
       }
       free(files);
!      return(num-skipped);
  }
  
  
----------------------------------Cut Here----------------------------------
-- 
 Wayne Davison                                        ...amdahl!drivax!davison
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
   Lkung tku nrcd pdnm bknwrea xztmykazojb nrcd ypdbd?  Yzt "xztmyk", ypd
   xztmykazoj-nkwdz'b qzrdeg.  Oy o xkjm.bkuzxdb.aojdb ozxprwdz edoz tku.
Technical Details
Message-ID: <4479@drivax.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!apple!amdahl!drivax!davison

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!apple!amdahl!drivax!davison
From: davison@drivax.UUCP (Wayne Davison)
Newsgroups: comp.sources.bugs
Subject: Fix for MIT Athena delete/undelete programs
Message-ID: <4479@drivax.UUCP>
Date: 4 Apr 89 23:21:22 GMT
Reply-To: davison@drivax.UUCP (Wayne Davison)
Organization: Digital Research, Inc.
Lines: 256