home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / TCPIP / NNTP-1.000 / NNTP-1 / nntp.1.5.11t / server / nextlast.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-17  |  1.9 KB  |  89 lines

  1. #ifndef lint
  2. static char    *sccsid = "@(#)$Header: nextlast.c,v 1.6 90/07/05 23:09:40 sob Exp $";
  3. #endif
  4.  
  5. #include "common.h"
  6.  
  7. /*
  8.  * NEXT
  9.  * LAST
  10.  *
  11.  * Retrieve the message-id of the next or last article in the
  12.  * newsgroup.  Position the current article pointer to this
  13.  * article.
  14.  */
  15.  
  16. nextlast(argc, argv)
  17.     int    argc;
  18.     char    *argv[];
  19. {
  20.     char    artbuf[MAXPATHLEN], art_id[MAXBUFLEN];
  21.     int    oldptr;
  22.     int    next;
  23.  
  24.     if (!canread) {
  25.         printf("%d You only have permission to transfer, sorry.\r\n",
  26.             ERR_ACCESS);
  27.         (void) fflush(stdout);
  28.         return;
  29.     }
  30.  
  31.     if (!ingroup) {
  32.         printf("%d You are not currently in a newsgroup.\r\n",
  33.             ERR_NCING);
  34.         (void) fflush(stdout);
  35.         return;
  36.     }
  37.  
  38.     if (argc != 1) {
  39.         printf("%d NEXT/LAST need no arguments.\r\n", ERR_CMDSYN);
  40.         (void) fflush(stdout);
  41.         return;
  42.     }
  43.  
  44.     next = (argv[0][0] == 'n' || argv[0][0] == 'N');
  45.  
  46.     if (art_ptr < 0 || art_ptr >= num_arts) {
  47.         printf("%d No current article selected.\r\n",
  48.             ERR_NOCRNT);
  49.         (void) fflush(stdout);
  50.         return;
  51.     }
  52.  
  53.     if (next ? (art_ptr + 1 >= num_arts) : (art_ptr - 1 < 0)) {
  54.         printf("%d No %s article to retrieve.\r\n",
  55.         next ? ERR_NONEXT : ERR_NOPREV,  next ? "next" : "previous");
  56.         (void) fflush(stdout);
  57.         return;
  58.     }
  59.  
  60.     oldptr = art_ptr;
  61.     (void) sprintf(artbuf, "%d", art_array[next ? ++art_ptr : --art_ptr]);
  62.  
  63.     if (!valid_art(artbuf)) {
  64.         printf("%d Invalid article number: %s.\r\n", ERR_NOARTIG,
  65.             artbuf);
  66.         (void) fflush(stdout);
  67.         return;
  68.     }
  69.  
  70.     while (open_valid_art(artbuf, art_id) == NULL) {
  71.         if (((next) ? (++art_ptr >= num_arts) : (--art_ptr < 0))) {
  72.             printf("%d No %s article to retrieve.\r\n",
  73.                 next ? ERR_NONEXT : ERR_NOPREV,
  74.                 next ? "next" : "previous");
  75.             art_ptr = oldptr;
  76.             (void) fflush(stdout);
  77.             return;
  78.         }
  79.         (void) sprintf(artbuf, "%d", art_array[art_ptr]);
  80.     }
  81.  
  82.     printf("%d %s %s Article retrieved; request text separately.\r\n",
  83.         OK_NOTEXT, artbuf, art_id);
  84.  
  85.     if (argc > 1)
  86.         art_ptr = findart(artbuf);
  87.     (void) fflush(stdout);
  88. }
  89.