🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #42984

Re: [slrn] Could extract_article_header() return # of lines?

#42984
From: Lloyd Zusman
Date: Wed, 02 Sep 1998 00:00
134 lines
5424 bytes
On 2 Sep 1998 10:47:09 GMT, John E. Davis <davis@space.mit.edu> wrote:
> 
> [ ... ]
> 
>    The `lines' field of the header is treated internally as an integer
> by slrn.  Here is a patch to art.c that allows it to be returned as a
> string by `extract_acticle_header':
> 
> [ ... ]

Thank you for this patch.  I have recently posted a related patch that
addresses this problem as well as two other problems:

(1) the "whitespace" problem.  Look at the slrn_trim_string and
    slrn_skip_whitespace calls within this patch.
    
(2) a problem which occurs if the currently selected article's headers
    are being examined and the first argument of extract_article_header
    doesn't contain a trailing colon (e.g., "Lines" instead of "Lines:).

What do you think of these changes?

Lloyd Zusman
ljz@asfast.com

--------------------------- patch begins here ---------------------------
*** art.c.orig	Sun Aug 30 18:58:31 1998
--- art.c	Sun Aug 30 19:39:52 1998
***************
*** 868,873 ****
--- 868,875 ----
  char *slrn_extract_header (char *hdr, unsigned int len) /*{{{*/
  {
     Slrn_Article_Line_Type *l;
+    char *result = NULL;
+    int found;
     
     if (Slrn_Current_Header == NULL)
       return NULL;
***************
*** 878,895 ****
     if (Slrn_Current_Header != Header_Showing)
       {
  	if (0 == slrn_case_strncmp ((unsigned char *)"From: ", (unsigned char *)hdr, len))
! 	  return Slrn_Current_Header->from;
! 	if (0 == slrn_case_strncmp ((unsigned char *)"Subject: ", (unsigned char *)hdr, len))
! 	  return Slrn_Current_Header->subject;
! 	if (0 == slrn_case_strncmp ((unsigned char *)"Message-Id: ", (unsigned char *)hdr, len))
! 	  return Slrn_Current_Header->msgid;
! 	if (0 == slrn_case_strncmp ((unsigned char *)"Date: ", (unsigned char *)hdr, len))
! 	  return Slrn_Current_Header->date;
! 	if (0 == slrn_case_strncmp ((unsigned char *)"References: ", (unsigned char *)hdr, len))
! 	  return Slrn_Current_Header->refs;
! 	if (0 == slrn_case_strncmp ((unsigned char *)"Xref: ", (unsigned char *)hdr, len))
! 	  return Slrn_Current_Header->from;
! 	return NULL;
       }
     
     l = Slrn_Article_Lines;
--- 880,907 ----
     if (Slrn_Current_Header != Header_Showing)
       {
  	if (0 == slrn_case_strncmp ((unsigned char *)"From: ", (unsigned char *)hdr, len))
! 	  result = Slrn_Current_Header->from;
! 	else if (0 == slrn_case_strncmp ((unsigned char *)"Subject: ", (unsigned char *)hdr, len))
! 	  result = Slrn_Current_Header->subject;
! 	else if (0 == slrn_case_strncmp ((unsigned char *)"Message-Id: ", (unsigned char *)hdr, len))
! 	  result = Slrn_Current_Header->msgid;
! 	else if (0 == slrn_case_strncmp ((unsigned char *)"Date: ", (unsigned char *)hdr, len))
! 	  result = Slrn_Current_Header->date;
! 	else if (0 == slrn_case_strncmp ((unsigned char *)"References: ", (unsigned char *)hdr, len))
! 	  result = Slrn_Current_Header->refs;
! 	else if (0 == slrn_case_strncmp ((unsigned char *)"Xref: ", (unsigned char *)hdr, len))
! 	  result = Slrn_Current_Header->from;
! 	else if (0 == slrn_case_strncmp ((unsigned char *)"Lines: ", (unsigned char *)hdr, len))
! 	  {
! 	     static char line_buf[16];
! 	     sprintf(line_buf, "%d", Slrn_Current_Header->lines);
! 	     return line_buf;
! 	  }
! 	if (NULL == result)
! 	  return NULL;
! 
! 	slrn_trim_string(result);
! 	return slrn_skip_whitespace(result);
       }
     
     l = Slrn_Article_Lines;
***************
*** 903,909 ****
  	     if ((l->next != NULL) && (l->next->flags & WRAPPED_LINE))
  	       unwrap_line (l->next);
  	     
! 	     return l->buf + len;
  	  }
  	l = l->next;
       }
--- 915,948 ----
  	     if ((l->next != NULL) && (l->next->flags & WRAPPED_LINE))
  	       unwrap_line (l->next);
  	     
! 	     /* Someone might have supplied a header with no colon, such
! 	      * as "Subject".  Therefore, we cannot assume that the end of
! 	      * the supplied header string is the beginning of the data we
! 	      * wish to return.  We need to search for a colon and
! 	      * return the first non-whitespace character which follows it.
! 	      */
! 	     found = 0;
! 	     for (result = l->buf; '\0' != *result; result++)
! 	       {
! 		  if (' ' == *result || '\t' == *result)
! 		    {
! 		       /* ERROR! ... white space before colon.
! 			* Treat this as a non-match (should we?).
! 			*/
! 		       break;
! 		    }
! 		  else if (':' == *result)
! 		    {
! 		       result++;
! 		       found = 1;
! 		       break;
! 		    }
! 	       }
! 	     if (!found)
! 	       continue;
! 	     
! 	     slrn_trim_string(result);
! 	     return slrn_skip_whitespace(result);
  	  }
  	l = l->next;
       }

Technical Details
Message-ID: <slrn6uqtrh.crk.ljz@sunspot.tiac.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail
References: <slrn6uha35.l0.ljz@sunspot.tiac.net> <slrn6uoc7s.91.davis@mygir.davis.net>

Show Full Headers
Complete Article Headers
Message-ID: <slrn6uqtrh.crk.ljz@sunspot.tiac.net>
Subject: Re: [slrn] Could extract_article_header() return # of lines?
Date: Wed, 02 Sep 1998 00:00:00 +0000
From: ljz@asfast.com (Lloyd Zusman)
References: <slrn6uha35.l0.ljz@sunspot.tiac.net> <slrn6uoc7s.91.davis@mygir.davis.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail
X-Deja-AN: 387180174
Organization: As Fast
Reply-To: ljz@asfast.com (Lloyd Zusman)
Newsgroups: news.software.readers