diff src/server.c @ 49:5ecb646acf97 noffle

[svn] Article numbering bug fixes
author bears
date Sat, 06 May 2000 17:56:50 +0100
parents 32ba1198c6fa
children 125d79c9e586
line wrap: on
line diff
--- a/src/server.c	Sat May 06 17:55:22 2000 +0100
+++ b/src/server.c	Sat May 06 17:56:50 2000 +0100
@@ -1,7 +1,7 @@
 /*
   server.c
 
-  $Id: server.c 51 2000-05-05 23:49:38Z uh1763 $
+  $Id: server.c 55 2000-05-06 16:56:50Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -32,6 +32,7 @@
 #include "log.h"
 #include "online.h"
 #include "outgoing.h"
+#include "over.h"
 #include "post.h"
 #include "protocol.h"
 #include "pseudo.h"
@@ -224,17 +225,27 @@
         }
 }
 
+static Bool
+needsPseudoGenInfo( const char *grp )
+{
+    return ! ( Grp_local( grp )
+	       || Fetchlist_contains( grp )
+	       || Online_true() );
+}
+
 static void
 readCont( const char *name )
 {
     Fetchlist_read();
     Cont_read( name );
-    if ( ! Grp_local ( name )
-	 && ! Fetchlist_contains( name )
-	 && ! Online_true() )
+    if ( needsPseudoGenInfo( name ) )
     { 
         Pseudo_appGeneralInfo();
-        Grp_setFirstLast( name, Cont_first(), Cont_last() );
+	/* This adds the pseudo message to the overview contents
+	   but NOT to the group info. If an article gets added,
+	   the group info will get updated then from the
+	   contents, so the article number will be preserved.
+	   Otherwise it will be lost when the content is discarded. */
     }
 }
 
@@ -643,13 +654,25 @@
 static void
 printActive( Str result, const char *grp )
 {
+    int last;
+    
+    /* If there will be a pseudo gen info message waiting when we join
+       this group, fiddle the group numbers to show it. */
+    last = Grp_last( grp );
+    if ( needsPseudoGenInfo( grp ) )
+	last++;
+    
     snprintf( result, MAXCHAR, "%s %d %d %c",
-              grp, Grp_last( grp ), Grp_first( grp ), Grp_postAllow( grp ) );
+              grp, last, Grp_first( grp ), Grp_postAllow( grp ) );
 }
 
 static void
 doListActive( const char *pat )
 {
+    /* We need to read the fetchlist so we know whether a pseudo
+       gen info article needs to be faked when printing the group
+       last. */
+    Fetchlist_read();
     printGroups( pat, &printActive );
 }
 
@@ -1210,12 +1233,18 @@
             ++(*numb);
 }
 
+/*
+  Note this only handles a subset of headers. But they are all
+  the headers any newsreader should need to work properly.
+
+  That last sentence will at some stage be proved wrong.
+ */
 static Bool
 doXhdr( char *arg, const Cmd *cmd )
 {
     int first, last, i, n, numb;
-    enum { SUBJ, FROM, DATE, MSG_ID, REF, BYTES, LINES } what;
-    const char *p;
+    enum { SUBJ, FROM, DATE, MSG_ID, REF, BYTES, LINES, XREF } what;
+    const char *p, *msgId;
     const Over *ov;
     Str whatStr;
 
@@ -1241,6 +1270,8 @@
         what = BYTES;
     else if ( strcmp( whatStr, "lines" ) == 0 )
         what = LINES;
+    else if ( strcmp( whatStr, "xref" ) == 0 )
+        what = XREF;
     else
     {
         putStat( STAT_HEAD_FOLLOWS, "Unknown header (empty list follows)" );
@@ -1248,7 +1279,14 @@
         return TRUE;
     }
     p = Utl_restOfLn( arg, 1 );
-    parseRange( p, &first, &last, &numb );
+    if ( p[ 0 ] == '<' )
+    {
+	first = last = Cont_find( p );
+	if ( first < 0 )
+	    numb = 0;
+    }
+    else
+	parseRange( p, &first, &last, &numb );
     if ( numb == 0 )
         putStat( STAT_NO_ART_SELECTED, "No articles selected" );
     else
@@ -1282,6 +1320,13 @@
                 case LINES:
                     putTxtLn( "%lu %d", n, Ov_lines( ov ) );
                     break;
+		case XREF:
+		    msgId = Ov_msgId( ov );
+		    if ( Pseudo_isGeneralInfo( msgId ) )
+			putTxtLn( "%lu %s:%lu", n, serv.grp, n );
+		    else
+			putTxtLn( "%lu %s", n, Db_xref( msgId ) );
+		    break;
                 default:
                     ASSERT( FALSE );
                 }
@@ -1405,18 +1450,15 @@
         return TRUE;
     parseRange( arg, &first, &last, &n );
     if ( n == 0 )
-        putStat( STAT_NO_ART_SELECTED, "No articles selected" );
-    else
-    {
-        putStat( STAT_OVERS_FOLLOW, "Overview %ld-%ld", first, last );
-        for ( i = first; i <= last; ++i )
-            if ( ( ov = Cont_get( i ) ) )
-                putTxtLn( "%lu\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t",
-                          Ov_numb( ov ), Ov_subj( ov ), Ov_from( ov ),
-                          Ov_date( ov ), Ov_msgId( ov ), Ov_ref( ov ),
-                          Ov_bytes( ov ), Ov_lines( ov ) );
-        putEndOfTxt();
-    }
+	first = last = serv.artPtr;
+    putStat( STAT_OVERS_FOLLOW, "Overview %ld-%ld", first, last );
+    for ( i = first; i <= last; ++i )
+	if ( ( ov = Cont_get( i ) ) )
+	    putTxtLn( "%lu\t%s\t%s\t%s\t%s\t%s\t%d\t%d\t",
+		      Ov_numb( ov ), Ov_subj( ov ), Ov_from( ov ),
+		      Ov_date( ov ), Ov_msgId( ov ), Ov_ref( ov ),
+		      Ov_bytes( ov ), Ov_lines( ov ) );
+    putEndOfTxt();
     return TRUE;
 }