/[mailutils]/mailutils/readmsg/readmsg.c
ViewVC logotype

Diff of /mailutils/readmsg/readmsg.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by sroberts, Tue Feb 26 04:35:31 2002 UTC revision 1.7 by gray, Wed Aug 7 23:07:05 2002 UTC
# Line 18  Line 18 
18  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
19  # include <config.h>  # include <config.h>
20  #endif  #endif
21    #include <mailutils/argp.h>
22    
23  #include "readmsg.h"  #include "readmsg.h"
24    
25  #define WEEDLIST_SEPARATOR  " :,"  #define WEEDLIST_SEPARATOR  " :,"
26    
 static void usage __P ((int, const char *));  
27  static void print_header __P ((message_t, int no_header, int all_header, const char *weedlst));  static void print_header __P ((message_t, int no_header, int all_header, const char *weedlst));
28  static void print_body __P ((message_t));  static void print_body __P ((message_t));
29  static int  string_starts_with __P ((const char * s1, const char *s2));  static int  string_starts_with __P ((const char * s1, const char *s2));
30    
31  const char *short_options = "adnhpf:w:";  const char *argp_program_version = "readmsg (" PACKAGE_STRING ")";
32  static struct option long_options[] =  static char doc[] = "GNU readmsg -- print messages";
33    static error_t readmsg_parse_opt  __P((int key, char *arg,
34                                           struct argp_state *astate));
35    
36    static struct argp_option options[] =
37  {  {
38    {"debug", no_argument, 0, 'd'},    { "debug", 'd', 0, 0, "Display debugging information", 1 },
39    {"header", no_argument, 0, 'h'},    { "header", 'h', 0, 0, "Display entire header", 1 },
40    {"weedlist", required_argument, 0, 'w'},    { "weedlist", 'w', "LIST", 0, "List of header names separated by whitespace or commas", 1 },
41    {"folder", no_argument, 0, 'f'},    { "folder", 'f', "FOLDER", 0, "Folder to use", 1 },
42    {"no-header", no_argument, 0, 'n'},    { "no-header", 'n', 0, 0, "Exclude all headers", 1 },
43    {"form-feeds", no_argument, 0, 'p'},    { "form-feeds", 'p', 0, 0, "Output formfeeds between messages", 1 },
44    {"show-all-match", required_argument, 0, 'a'},    { "show-all-match", 'a', "PATTERN", 0,
45    {"help", no_argument, 0, '&'},      "Print all messages matching PATTERN", 1 },
   {"version", no_argument, 0, 'v'},  
46    {0, 0, 0, 0}    {0, 0, 0, 0}
47  };  };
48    
49    static struct argp argp = {
50      options,
51      readmsg_parse_opt,
52      NULL,
53      doc,
54      NULL,
55      NULL, NULL
56    };
57    
58    static const char *readmsg_argp_capa[] = {
59      "common",
60      "mailbox",
61      NULL
62    };
63    
64    int dbug = 0;
65    const char *mailbox_name = NULL;
66    const char *weedlist = NULL;
67    int no_header = 0;
68    int all_header = 0;
69    int form_feed = 0;
70    int show_all = 0;
71    
72    static error_t
73    readmsg_parse_opt (int key, char *arg, struct argp_state *astate)
74    {
75      switch (key)
76        {
77        case 'd':
78          dbug++;
79          break;
80    
81        case 'h':
82          all_header = 1;
83          break;
84    
85        case 'f':
86          mailbox_name = optarg;
87          break;
88    
89        case 'w':
90          weedlist = optarg;
91          break;
92    
93        case 'n':
94          no_header = 1;
95          break;
96    
97        case 'p':
98          form_feed = 1;
99          break;
100              
101        case 'a':
102          show_all = 1;
103          break;
104    
105        default:
106          return ARGP_ERR_UNKNOWN;
107        }
108      return 0;
109    }
110    
111  static int  static int
112  string_starts_with (const char * s1, const char *s2)  string_starts_with (const char * s1, const char *s2)
113  {  {
# Line 62  string_starts_with (const char * s1, con Line 128  string_starts_with (const char * s1, con
128  }  }
129    
130  static void  static void
131  print_header (message_t message, int no_header, int all_headers, const char *weedlist)  print_header (message_t message, int no_header, int all_headers,
132                  const char *weedlist)
133  {  {
134    header_t header = NULL;    header_t header = NULL;
135    
# Line 79  print_header (message_t message, int no_ Line 146  print_header (message_t message, int no_
146        char buf[128];        char buf[128];
147    
148        header_get_stream (header, &stream);        header_get_stream (header, &stream);
149        while (stream_read (stream, buf, sizeof (buf) - 1, offset, &len) == 0 && len != 0)        while (stream_read (stream, buf, sizeof (buf) - 1, offset, &len) == 0
150                 && len != 0)
151          {          {
152            buf[len] ='\0';            buf[len] ='\0';
153            printf ("%s", buf);            printf ("%s", buf);
# Line 130  print_body (message_t message) Line 198  print_body (message_t message)
198    size_t len = 0;    size_t len = 0;
199    message_get_body (message, &body);    message_get_body (message, &body);
200    body_get_stream (body, &stream);    body_get_stream (body, &stream);
201    while (stream_read (stream, buf, sizeof (buf) - 1, offset, &len) == 0 && len != 0)  
202      while (stream_read (stream, buf, sizeof (buf) - 1, offset, &len) == 0
203             && len != 0)
204      {      {
205        buf[len] ='\0';        buf[len] ='\0';
206        printf ("%s", buf);        printf ("%s", buf);
# Line 138  print_body (message_t message) Line 208  print_body (message_t message)
208      }      }
209  }  }
210    
 static void  
 usage (int status, const char *prognam)  
 {  
   if (status == 0)  
     {  
       printf ("GNU Mailutils.\n");  
       printf ("Usage: %s [OPTIONS]\n\n", prognam);  
       printf ("  -d, --debug              display debuging information\n");  
       printf ("  -h, --header             display the entire header\n");  
       printf ("  -f, --folder=FILE        folder to use\n");  
       printf ("  -w, --weelist=LIST       list of header names separated by whitespace or commas\n");  
       printf ("  -n, --no-header          exclude all headers\n");  
       printf ("  -p, --form-feeds         put form-feeds between messages instead of newline\n");  
       printf ("  -a, --show-all-match     print all message matching PATTERN\n");  
       printf ("      --help               display this help and exit\n");  
       printf ("  -v, --version            display version information and exit\n");  
       printf ("\nReport bugs to bug-mailutils@gnu.org\n");  
     }  
   else  
     {  
       printf ("Try: %s --help\n", prognam);  
     }  
   exit (status);  
 }  
   
   
211  /* This is still work in progress  */  /* This is still work in progress  */
212  /* FIXME: Parse options:  See readmsg(1) part of elm:  /* FIXME: Parse options:  See readmsg(1) part of elm:
213     readmsg 1 3 0     readmsg 1 3 0
# Line 176  main (int argc, char **argv) Line 220  main (int argc, char **argv)
220    int *set = NULL;    int *set = NULL;
221    int n = 0;    int n = 0;
222    int i;    int i;
223    int c;    int index;
   int dbug = 0;  
   const char *mailbox_name = NULL;  
   const char *weedlist = NULL;  
   int no_header = 0;  
   int all_header = 0;  
   int form_feed = 0;  
   int show_all = 0;  
224    mailbox_t mbox = NULL;    mailbox_t mbox = NULL;
225    
226    while ((c = getopt_long (argc, argv, short_options, long_options, NULL))    mu_argp_parse (&argp, &argc, &argv, 0, readmsg_argp_capa, &index, NULL);
          != -1)  
     {  
       switch (c)  
         {  
         case 'd':  
           dbug++;  
           break;  
   
         case 'h':  
           all_header = 1;  
           break;  
   
         case 'f':  
           mailbox_name = optarg;  
           break;  
   
         case 'w':  
           weedlist = optarg;  
           break;  
   
         case 'n':  
           no_header = 1;  
           break;  
   
         case 'p':  
           form_feed = 1;  
           break;  
   
         case 'a':  
           show_all = 1;  
           break;  
   
         case '&':  
           usage (0, argv[0]);  
           break;  
   
         case 'v':  
           printf ("Mailutils 0.0.0: readmsg\n");  
           exit (0);  
           break;  
   
         default:  
           usage (1, argv[0]);  
           break;  
         }  
     }  
   
227    
228    /* Registration.  */    /* Registration.  */
229    {    {
# Line 273  main (int argc, char **argv) Line 263  main (int argc, char **argv)
263    /* Build an array containing the message number.  */    /* Build an array containing the message number.  */
264    argc -= optind;    argc -= optind;
265    if (argc > 0)    if (argc > 0)
266      msglist (mbox, show_all, argc, &argv[optind], &set, &n);      msglist (mbox, show_all, argc, &argv[index], &set, &n);
267    
268    for (i = 0; i < n; ++i)    for (i = 0; i < n; ++i)
269      {      {
# Line 282  main (int argc, char **argv) Line 272  main (int argc, char **argv)
272        status = mailbox_get_message (mbox, set[i], &msg);        status = mailbox_get_message (mbox, set[i], &msg);
273        if (status != 0)        if (status != 0)
274          {          {
275            fprintf (stderr, "mailbox_get_message - %s\n", mu_errstring (status));            fprintf (stderr, "mailbox_get_message - %s\n",
276                       mu_errstring (status));
277            exit (2);            exit (2);
278          }          }
279    

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26