home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / b / bmh02src.zip / SHOW.C < prev    next >
C/C++ Source or Header  |  1992-08-16  |  3KB  |  114 lines

  1. /*
  2.    show.c : Copyright Paul Healy, EI9GL, 1992.
  3.  
  4.    911227 : Added this header
  5.    920620 : Version 0.1
  6.             - doesn't remember current folder
  7.             - doesn't support listing of a subrange
  8. */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13. #include "buffer.h"
  14. #include "rc.h"
  15. #include "misc.h"
  16. #include "help.h"
  17. #include "pager.h"
  18. #include "current.h"
  19.  
  20. #ifdef BMH
  21. #define main show_main
  22. #endif
  23.  
  24. static int started_page = 0;
  25.  
  26. static int
  27. showmsg(FILE *fp, int i, char **start, char **end)
  28. {
  29.    char line[256];
  30.  
  31.    if (!started_page) {
  32.       started_page = 1;
  33.       page_setup();
  34.       }
  35.  
  36.    sprintf(line, "(Message %s:%d)", currentfolder(NULL), i); /* no \n ?? */
  37.    (void) page_puts(line);
  38.  
  39.    while (getstring(start, end, line, sizeof(line)) != NULL) {
  40.       if (strncmp(line, "From ", 5) == 0) {
  41.          fflush(fp);
  42.          return 1; /* have hit next message */
  43.          }
  44.       else if (fp == stdout)
  45.          (void) page_puts(line); /* need to move to the next msg anyway */
  46.       else {
  47.          if (line[0] != '\0')  /* fputs returns EOF on being asked to */
  48.                                /* write an empty string... */
  49.             if ( fputs(line, fp) == EOF ) {
  50.                fprintf(stderr, "showmsg: error writing message # %d\n", i);
  51.                return -1;
  52.                }
  53.          if ( fputc('\n', fp) == EOF) {
  54.             fprintf(stderr, "showmsg: error writing message # %d\n", i);
  55.             return -1;
  56.             }
  57.          }
  58.       }
  59.    return 0;
  60. }
  61.  
  62. static void   
  63. readmsgs(FILE *fp, char *p, char *end, int argc, char *argv[], int msg)
  64. {
  65.    char s[256];
  66.    int i = 0;
  67.  
  68.    while (1) {
  69.       while ( *p!='F' )
  70.          p++;
  71.       if ( (p==end) && (refill(&p, &end) != 0) )
  72.          break;
  73.       else { /* may have found a From */
  74.          if (*(p-1) != '\n') {
  75.             p++;
  76.             continue;
  77.             }
  78.          getstring(&p, &end, s, sizeof(s));
  79.          if (strncmp(s, "From ", 5) == 0) {
  80.             i++;
  81.             while(wanted(i, argc, argv, msg) == 1)
  82.                if (showmsg(fp, i, &p, &end) == 0)
  83.                   return ; /* eof */
  84.                else
  85.                   i++;
  86.             }
  87.          }
  88.       }
  89. }
  90.  
  91. int
  92. main(int argc, char *argv[])
  93. {
  94.    char *p, *end, *s;
  95.    int msg;
  96.  
  97.    dohelp(argc, argv, "show [+folder] <msg 1> ... <msg n>");
  98.  
  99.    if (setupbm()==-1)
  100.       return -1;
  101.  
  102.    if (getcurrent(argc, argv, &s, &msg) == -1)
  103.       return -1;
  104.    
  105.    if (loadmail("show", s, &p, &end) == -1)
  106.       return -1;
  107.  
  108.    started_page = 0;
  109.  
  110.    readmsgs(stdout, p, end, argc, argv, msg);
  111.  
  112.    return lastmsg(argc, argv);
  113. }
  114.