[comp.sources.bugs] Official Patch #1 for Mush 6.5

schaefer@ogccse.ogc.edu (Barton E. Schaefer) (05/06/89)

This patch fixes a reported bug with "mushtool -Wi" that could actually
crash some suns (SunOS earlier than 4.0.1).  Also repaired are some minor
bugs with the curses header display.

A new feature added by this patch is an option to the "sort" command to
sort by message length (sort -l).  Dan is responsible for this, don't
blame me.  Thanks to Bill Petro for bribing Dan with a Sun T-shirt.

Dan is away from Island for the next several days, and doesn't have copies
of the patch kit there anyway.  Please send requests for lost or damaged
patch kit parts to me (schaefer@cse.ogc.edu).  [Did I really just let
myself in for that?]
--
Bart Schaefer       "And if you believe that, you'll believe anything."
							-- DangerMouse
CSNET / Internet                schaefer@cse.ogc.edu
UUCP                            ...{sun,tektronix,verdix}!ogccse!schaefer

*** /tmp/,RCSt1010587	Fri May  5 12:34:30 1989
--- cmd_help	Thu May  4 10:50:25 1989
***************
*** 206,214 ****
  %%
  
  %sort%
!       sort [-] [a|d|R|s|S]
    a         by author (alphabetical)
    d         according to date
    R         by subject including Re: (alphabetical)
    s         by subject ignoring Re: (alphabetical)
    S         by status
--- 206,215 ----
  %%
  
  %sort%
!       sort [-] [a|d|l|R|s|S]
    a         by author (alphabetical)
    d         according to date
+   l         by length (size)
    R         by subject including Re: (alphabetical)
    s         by subject ignoring Re: (alphabetical)
    S         by status
*** /tmp/,RCSt1010587	Fri May  5 12:34:35 1989
--- curses.c	Fri May  5 12:30:41 1989
***************
*** 230,235 ****
--- 230,240 ----
  	    }
  
  	when C_FIRST_MSG : case C_LAST_MSG :
+ 	    if (!msg_cnt) {
+ 		mac_flush();
+ 		bell();
+ 		break;
+ 	    }
  	    n = current_msg;
  	    move(LINES-1, 0), refresh();
  	    if (c == C_FIRST_MSG && (current_msg = 0) < n_array[0] ||
***************
*** 244,250 ****
  
  	/* top and bottom of headers screen */
  	when C_TOP_PAGE : case C_BOTTOM_PAGE :
! 	    if (isoff(glob_flags, CNTD_CMD))
  		if (c == C_TOP_PAGE)
  		    current_msg = n_array[0];
  		else
--- 249,255 ----
  
  	/* top and bottom of headers screen */
  	when C_TOP_PAGE : case C_BOTTOM_PAGE :
! 	    if (msg_cnt && isoff(glob_flags, CNTD_CMD))
  		if (c == C_TOP_PAGE)
  		    current_msg = n_array[0];
  		else
*** /tmp/,RCSt1010587	Fri May  5 12:34:38 1989
--- execute.c	Thu May  4 16:21:02 1989
***************
*** 99,114 ****
      int	   pid;
  
  #ifdef BSD
-     /* The following SHOULDN'T be necessary, but it is!!! ttysw_fork()
-      * returns the pid of the thing that it executes, but that's not the
-      * pid that dies!  There are many procs that might die from ttysw_fork
-      * one of them is the process, another is the tty, etc... other
-      * procs that might die are sendmail, fortune, etc... tool_sigchld()
-      * handles these, but we can't let it have control unless we KNOW the
-      * editor is done.
-      * so if what we catch is not the exec_pid from ttysw_fork(), then
-      * send ourselves a sigchld to go thru this routine again.  mush -d
-      */
      while ((pid = wait3(&status, WNOHANG, (struct rusage *)0)) > 0) {
  	Debug("%d died...\n", pid);
  	if (pid == exec_pid)
--- 99,104 ----
***************
*** 126,131 ****
--- 116,131 ----
  #ifndef SUNTOOL
      }
  #else /* SUNTOOL */
+     /* The following SHOULDN'T be necessary, but it is!!! ttysw_fork()
+      * returns the pid of the thing that it executes, but that's not the
+      * pid that dies!  There are many procs that might die from ttysw_fork
+      * one of them is the process, another is the tty, etc... other
+      * procs that might die are sendmail, fortune, etc... tool_sigchld()
+      * handles these, but we can't let it have control unless we KNOW the
+      * editor is done.
+      * so if what we catch is not the exec_pid from ttysw_fork(), then
+      * send ourselves a sigchld to go thru this routine again.  mush -d
+      */
      if (pid != exec_pid || exec_pid <= 0) /* if the editor didn't die, return */
  	return;
      /* editor died -- reset exec_pid so no one thinks we're running */
*** /tmp/,RCSt1010587	Fri May  5 12:34:42 1989
--- hdrs.c	Wed May  3 15:33:47 1989
***************
*** 178,183 ****
--- 178,185 ----
  	    cnt = top;
      } else if (cnt > 0 && srch < 0)
  	cnt = max(cnt - screen, 0);
+     else
+ 	cnt = max(cnt, 0);
  
      for (;pageful<screen && cnt<msg_cnt && isoff(glob_flags, WAS_INTR); cnt++) {
  	if (!iscurses && !show_deleted && first_char == 'h'
*** /tmp/,RCSt1010587	Fri May  5 12:34:50 1989
--- main.c	Thu May  4 10:53:53 1989
***************
*** 3,9 ****
  #include "mush.h"
  #include "options.h"
  
! #undef PATCHDATE /* Here because EVERYTHING depends on mush.h */
  
  #if defined(sun) && defined(M_DEBUG)
  cpu()
--- 3,9 ----
  #include "mush.h"
  #include "options.h"
  
! #define PATCHDATE "5/04/89" /* Here because EVERYTHING depends on mush.h */
  
  #if defined(sun) && defined(M_DEBUG)
  cpu()
*** /tmp/,RCSt1010587	Fri May  5 12:34:54 1989
--- misc.c	Thu May  4 12:40:45 1989
***************
*** 429,434 ****
--- 429,436 ----
  			sizeof (char *) * (unsigned)(cnt + STR_ARRAY));
  		do  {
  		    int chars = count_chars(&buf, s);
+ 		    if (chars < 0)
+ 			break;
  		    if (*--buf) {
  			s[chars++] = '\n', s[chars] = 0;
  			lines++;
***************
*** 441,446 ****
--- 443,450 ----
  	else if (istool >= 2 && start_pager) {
  	    cnt = lines = 0;
  	    strings = (char **)malloc((unsigned)sizeof (char *));
+ 	    if (tool->tl_flags&TOOL_ICONIC)
+ 		win_getrect(msg_sw->ts_windowfd, &msg_rect);
  	    do_clear();
  	    lock_cursors();
  	} else if (!buf && !start_pager) { /* pager is done */
*** /tmp/,RCSt1010587	Fri May  5 12:34:56 1989
--- msgs.c	Wed May  3 22:31:12 1989
***************
*** 8,13 ****
--- 8,14 ----
  long flg;
  {
      char buf[32], *pager = NULL;
+ 
      if (ison(msg[n].m_flags, DELETE) && !do_set(set_options, "show_deleted")) {
  	print("Message %d deleted; ", n+1);
  #ifdef SUNTOOL
*** /tmp/,RCSt1010587	Fri May  5 12:35:00 1989
--- mush.1	Thu May  4 10:50:29 1989
***************
*** 398,404 ****
  .PP
  .I Mush
  allows you to sort your mail according to various constraints such
! as time, status (new, unread, deleted, etc.), author and subject.
  See the
  .B sort
  command in the COMMANDS section for more information on sorting.
--- 398,404 ----
  .PP
  .I Mush
  allows you to sort your mail according to various constraints such
! as time, size, status (new, unread, deleted, etc.), author and subject.
  See the
  .B sort
  command in the COMMANDS section for more information on sorting.
***************
*** 2756,2761 ****
--- 2756,2762 ----
  \-	reverse sort order
  a	sort by author (alphabetical)
  d	sort by date
+ l	sort by length of message
  s	sort by subject ignoring \*QRe:\*U
  R	sort by subject (alphabetical)
  S	sort by message status
*** /tmp/,RCSt1010587	Fri May  5 12:35:18 1989
--- sort.c	Thu May  4 10:50:30 1989
***************
*** 11,16 ****
--- 11,17 ----
  register char *argv[], list[];
  {
      int status_cmp(), author_cmp(), date_cmp(), subject_cmp(), subj_with_re();
+     int size_cmp();
      SIGRET (*oldint)(), (*oldquit)();
      int (*how)() = status_cmp;
      int n, offset = -1, range = 0;
***************
*** 27,32 ****
--- 28,34 ----
  		when 's': how = subject_cmp;
  		when 'R': how = subj_with_re;
  		when 'S': how = status_cmp;
+ 		when 'l': how = size_cmp; /* length compare */
  		when 'i': ignore_case = TRUE;
  		otherwise: return help(0, "sort", cmd_help);
  	    }
***************
*** 146,151 ****
--- 148,168 ----
      return strcmp(buf1, buf2) * order;
  }
  
+ /* compare messages according to size (length) */
+ size_cmp(msg1, msg2)
+ register struct msg *msg1, *msg2;
+ {
+     if (ison(glob_flags, WAS_INTR))
+ 	longjmp(sortbuf, 1);
+     if (msg1 < msg || msg2 < msg) {
+ 	wprint("sort botch trying to sort %d and %d\n", msg1-msg, msg2-msg);
+ 	return 0;
+     }
+     Debug("sizes: (%d): %d, (%d): %d\"\n",
+ 	msg1-msg, msg1->m_size, msg2-msg, msg2->m_size);
+     return (msg1->m_size - msg2->m_size) * order;
+ }
+ 
  /*
   * Subject comparison ignoring Re:  subject_to() appends an Re: if there is
   * any subject whatsoever.
***************
*** 154,159 ****
--- 171,177 ----
  register struct msg *msg1, *msg2;
  {
      char buf1[HDRSIZ], buf2[HDRSIZ];
+     register char *p1, *p2;
  
      if (ison(glob_flags, WAS_INTR))
  	longjmp(sortbuf, 1);
***************
*** 161,172 ****
  	wprint("sort botch trying to sort %d and %d\n", msg1-msg, msg2-msg);
  	return 0;
      }
!     (void) subject_to(msg1 - msg, buf1);
!     (void) subject_to(msg2 - msg, buf2);
!     Debug("subjects: (%d): \"%s\" (%d): \"%s\"\n", msg1-msg,buf1,msg2-msg,buf2);
      if (ignore_case)
! 	return lcase_strncmp(buf1, buf2, -1) * order;
!     return strcmp(buf1, buf2) * order;
  }
  
  /*
--- 179,200 ----
  	wprint("sort botch trying to sort %d and %d\n", msg1-msg, msg2-msg);
  	return 0;
      }
!     p1 = subject_to(msg1 - msg, buf1);
!     p2 = subject_to(msg2 - msg, buf2);
!     Debug("subjects: (%d): \"%s\" (%d): \"%s\"\n", msg1-msg, p1, msg2-msg, p2);
!     if (p1) {
! 	p1 += 4;
! 	while (isspace(*p1))
! 	    p1++;
!     }
!     if (p2) {
! 	p2 += 4;
! 	while (isspace(*p2))
! 	    p2++;
!     }
      if (ignore_case)
! 	return lcase_strncmp(p1, p2, -1) * order;
!     return strcmp(p1, p2) * order;
  }
  
  /*
*** /tmp/,RCSt1010826	Fri May  5 12:35:29 1989
--- hdr_procs.c	Thu May  4 10:50:25 1989
***************
*** 147,158 ****
      else switch(value) {
  	case 0: argv[1] = "d";
  	when 1: argv[1] = "a";
! 	when 2: argv[1] = "s";
! 	when 3: argv[1] = "S";
! 	when 4: argv[1] = "R";
! 	when 5: help(hdr_panel_sw->ts_windowfd, "sort", tool_help);
      }
!     if (value != 5) {
  	(void) sort(2, argv, NULL);
  	(void) do_hdrs(0, DUBL_NULL, NULL);
      }
--- 147,159 ----
      else switch(value) {
  	case 0: argv[1] = "d";
  	when 1: argv[1] = "a";
! 	when 2: argv[1] = "l";
! 	when 3: argv[1] = "s";
! 	when 4: argv[1] = "S";
! 	when 5: argv[1] = "R";
! 	when 6: help(hdr_panel_sw->ts_windowfd, "sort", tool_help);
      }
!     if (value != 6) {
  	(void) sort(2, argv, NULL);
  	(void) do_hdrs(0, DUBL_NULL, NULL);
      }
*** /tmp/,RCSt1010826	Fri May  5 12:35:31 1989
--- main_panel.c	Thu May  4 10:50:26 1989
***************
*** 91,96 ****
--- 91,97 ----
  	PANEL_MENU_TITLE_STRING, 	"Sort Messages",
  	PANEL_CHOICE_STRINGS, 		"By Date",
  					"By Author",
+ 					"By Size",
  					"By Subject",
  					"By Subject (ignore Re:)",
  					"By Status",
*** /tmp/,RCSt1010826	Fri May  5 12:35:33 1989
--- rite.c	Thu May  4 12:42:18 1989
***************
*** 123,129 ****
      register int cnt;
      register char newline = 0;
  
!     cnt = count_chars(&s, buf);
  
      if (*--s)
  	newline = *s; /* newline may or may not be a '\n' */
--- 123,130 ----
      register int cnt;
      register char newline = 0;
  
!     if ((cnt = count_chars(&s, buf)) < 0)
! 	return 0;
  
      if (*--s)
  	newline = *s; /* newline may or may not be a '\n' */
***************
*** 155,160 ****
--- 156,163 ----
  {
      int cnt = 0, max_len = (msg_rect.r_width - 10) / l_width(curfont) + 1;
  
+     if (max_len < 1)
+ 	return -1;
      while ((*p = *((*s)++)) && *p != '\n' && cnt < max_len)
  	if (*p == '\t')
  	    do *p++ = ' ';
-- 
Bart Schaefer       "And if you believe that, you'll believe anything."
							-- DangerMouse
CSNET / Internet                schaefer@cse.ogc.edu
UUCP                            ...{sun,tektronix,verdix}!ogccse!schaefer