🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #22756

Re: building trn

#22756
From: Robert Boutwell
Date: Thu, 13 Jun 1996 00:00
140 lines
4966 bytes
In article <31BF2CBA.41C6@utkux.utcc.utk.edu>,
Hank Pike  <hank@utkux.utcc.utk.edu> wrote:
>Has anyone had any problems with trn, specifically where it prompts you
>with new news groups and you answer 'N' and it does not append those
>groups to the .newsrc file and the next time you run trn you get the
>same questions.  Any comments would be appreciated.

*******************************************************************

Here is the explanation and the patch that I mentioned in my previous
message.  They are from the "trn FAQ".

This FAQ is maintained by Peter J. Kappesser <pjkappes@mailbox.syr.edu> 
and is archived at
<URL:ftp://rtfm.mit.edu/pub/usenet/news.software.readers/>. 



Subject: BLYC: Patches for "leap year bug"
Contributors: Duncan Gibson <duncan@yc.estec.esa.nl>, 
	Erez Zadok <ezk@news.cs.columbia.edu>, John Line <jml4@cus.cam.ac.uk>,
	Peter Kappesser <pjkappes@mailbox.syr.edu>,
	Anne Bennett <anne@alcor.concordia.ca>

Since January 1, 1996 on some systems, every time users run trn, they may
be asked whether they want to subscribe to new newsgroups which they have
previously declined by answering 'n' or 'N'. The reason is that, as of the
first second of 1996, trn miscomputed the number of leap years, and was
therefore off by one whole day, reporting that the date of the news server
was exactly 24 hours into the future, thus thinking that these "new" 
newsgroups could not have been seen at all. 

Either of two patches will fix the problem. The "simple patch" works until
the year 2100, and is preferred by Wayne Davison (since it uses a simple
division, instead of a loop, and he doesn't expect people to still be
using trn at that time anyway). The "fancy patch" is accurate until the
year 2400. 

Although the line numbers are for trn 3.6, the code will work in
strn-0.9.2 at the appropriate place. 


SIMPLE PATCH THAT WORKS UNTIL 2100

Submitted by Miquel van Smoorenburg <miquels@debian.het.net>

---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
------- nntp.c -------
*** /tmp/da005NK	Thu Jan  1 00:00:00 1970
--- nntp.c	Wed Jan  3 20:43:11 1996
***************
*** 319,326 ****
      for (month--; month; month--)
  	day += maxdays[month];

!     ss = ((((year-1970) * 365 + (year-1968)/4 + day - 1) * 24L + hh) *
60
! 	  + mm) * 60 + ss;

      return ss;
  }
--- 319,326 ----
      for (month--; month; month--)
  	day += maxdays[month];

!     ss = ((((year-1970) * 365 + (year-1969)/4 + day - 1) * 24L + hh) *
60
!         + mm) * 60 + ss;

      return ss;
  }
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---


FANCY PATCH THAT WORKS UNTIL 2400

Submitted by Paul Close <pdc@lunch.engr.sgi.com>

---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
--- trn-3.6/nntp.c	Fri Nov 18 22:01:23 1994
+++ nntp.c.leap	Fri Jan  5 16:38:33 1996
@@ -285,12 +285,13 @@
 
 /* This is a 1-relative list */
 static int maxdays[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,
31 };
+#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) ==
0)
 
 time_t
 nntp_time()
 {
     char *s;
-    int year, month, day, hh, mm;
+    int year, month, day, hh, mm, y;
     time_t ss;
 
     nntp_command("XDATE" + (CompliantServer? 0 : 1));
@@ -306,11 +307,11 @@
     s[4] = '\0';
     year = atoi(s);
 
-    /* This simple algorithm will be valid until the year 2400 */
-    if (year % 4)
-	maxdays[2] = 28;
-    else
+    if (isleap(year))
 	maxdays[2] = 29;
+    else
+	maxdays[2] = 28;
+
     if (month < 1 || month > 12 || day < 1 || day > maxdays[month]
      || hh < 0 || hh > 23 || mm < 0 || mm > 59
      || ss < 0 || ss > 59)
@@ -319,8 +320,12 @@
     for (month--; month; month--)
 	day += maxdays[month];
 
-    ss = ((((year-1970) * 365 + (year-1968)/4 + day - 1) * 24L + hh) * 60
-	  + mm) * 60 + ss;
+    for (y = 1970; y < year; y++)
+	if (isleap(y))
+	    day += 366;
+	else
+	    day += 365;
+    ss += (((day - 1) * 24L + hh) * 60 + mm) * 60;
 
     return ss;
 }
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---

------------------------------

*********************************************************************
-- 
--
Bob Boutwell          Jamaica Plain, MA          boutwell@shore.net

Technical Details
Message-ID: <4pq60k$fu4@northshore.shore.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: <31BF2CBA.41C6@utkux.utcc.utk.edu>

Show Full Headers
Complete Article Headers
Message-ID: <4pq60k$fu4@northshore.shore.net>
Subject: Re: building trn
Date: Thu, 13 Jun 1996 00:00:00 +0000
From: boutwell@shore.net (Robert Boutwell)
References: <31BF2CBA.41C6@utkux.utcc.utk.edu>
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: 160056321
Organization: Shore.Net; a service of Eco Software, Inc. (info@shore.net)
Newsgroups: news.software.readers