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

Diff of /mailutils/frm/frm.c

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

revision 1.10 by alainm, Mon Nov 12 03:37:38 2001 UTC revision 1.11 by gray, Fri Feb 22 13:18:36 2002 UTC
# Line 26  Line 26 
26  #include <unistd.h>  #include <unistd.h>
27  #include "getopt.h"  #include "getopt.h"
28    
29    #include <mu_argp.h>
30  #include <mailutils/mailbox.h>  #include <mailutils/mailbox.h>
31  #include <mailutils/header.h>  #include <mailutils/header.h>
32  #include <mailutils/registrar.h>  #include <mailutils/registrar.h>
33  #include <mailutils/observer.h>  #include <mailutils/observer.h>
34  #include <mailutils/address.h>  #include <mailutils/address.h>
35    
 static int action (observer_t, size_t);  
 static void usage (const char *argv);  
   
 static struct option long_options[] =  
 {  
   {"debug", no_argument, 0, 'd'},  
   {"help", no_argument, 0, 'h'},  
   {"field", required_argument, 0, 'f'},  
   {"to", no_argument, 0, 'l'},  
   {"number", no_argument, 0, 'n'},  
   {"Quiet", no_argument, 0, 'Q'},  
   {"query", no_argument, 0, 'q'},  
   {"summary", no_argument, 0, 'S'},  
   {"status", required_argument, 0, 's'},  
   {"align", no_argument, 0, 't'},  
   {"version", no_argument, 0, 'v'},  
   {0, 0, 0, 0}  
 };  
   
 const char *short_options ="dhf:lnQqSs:tv";  
   
36  static char* show_field;  static char* show_field;
37  static int show_to;  static int show_to;
38  static int show_from = 1;  static int show_from = 1;
# Line 71  static int dbug; Line 51  static int dbug;
51  static int select_attribute;  static int select_attribute;
52  static int selected;  static int selected;
53    
54    static int action (observer_t, size_t);
55    
56    const char *argp_program_version = "frm (" PACKAGE ") " VERSION;
57    const char *argp_program_bug_address = "<bug-mailutils@gnu.org>";
58    static char doc[] = "GNU frm -- display From: lines";
59    
60    static struct argp_option options[] = {
61      {"debug", 'd', NULL, 0, "Enable debugging output", 0},
62      {"field", 'f', "NAME", 0,
63                                  "Header field to display", 0},
64      {"to", 'l', NULL, 0, "Include the To: information", 0},
65      {"number", 'n', NULL, 0, "Display message numbers", 0},
66      {"Quiet", 'Q', NULL, 0, "Very quiet", 0},
67      {"query", 'q', NULL, 0, "Print a message if unread mail", 0},
68      {"summary", 'S', NULL, 0, "Print a summary of messages", 0},
69      {"status", 's', "[nor]", 0,
70       "Select message with the specific attribute: [n]ew, [r]ead, [u]nread.", 0 },
71      {"align", 't', NULL, 0, "Try to align", 0},
72      {0, 0, 0, 0}
73    };
74    
75    static error_t
76    parse_opt (int key, char *arg, struct argp_state *state)
77    {
78      switch (key)
79        {
80        case 'd':
81          dbug++;
82          break;
83    
84        case 'f':
85          show_field = arg;
86          show_from = 0;
87          show_subject = 0;
88          align = 0;
89          break;
90    
91        case 'l':
92          show_to = 1;
93          break;
94    
95        case 'n':
96          show_number = 1;
97          break;
98    
99        case 'Q':
100          /* Very silent.  */
101          be_quiet += 2;
102          if (freopen("/dev/null", "w", stdout) == NULL)
103            {
104              perror ("Can not be very quiet");
105              exit (3);
106            }
107          break;
108    
109        case 'q':
110          be_quiet = show_query = 1;
111          break;
112    
113        case 'S':
114          show_summary = 1;
115          break;
116    
117        case 's':
118          if (optarg)
119            switch (*optarg)
120              {
121              case 'r':
122                select_attribute |= IS_READ;
123                break;
124                
125              case 'o':
126                select_attribute |= IS_OLD;
127                break;
128                
129              case 'n':
130                select_attribute |= IS_NEW;
131                break;
132                
133              }
134          break;
135          
136        case 't':
137          align = 1;
138          break;
139          
140        default:
141          return ARGP_ERR_UNKNOWN;
142        }
143      return 0;
144    }
145    
146    static struct argp argp = {
147      options,
148      parse_opt,
149      NULL,
150      doc,
151      mu_common_argp_child,
152      NULL, NULL
153    };
154    
155    
156  /* Retrieve the Personal Name from the header To: or From:  */  /* Retrieve the Personal Name from the header To: or From:  */
157  static int  static int
# Line 196  action (observer_t o, size_t type) Line 277  action (observer_t o, size_t type)
277    return 0;    return 0;
278  }  }
279    
 static void  
 usage (const char *argv)  
 {  
   printf ("GNU Mailutils.\n");  
   printf ("Usage: %s [OPTIONS]\n\n", argv);  
   printf ("  -d, --debug              display debuging information\n");  
   printf ("  -h, --help               display this help and exit\n");  
   printf ("  -f, --field=string       header field to display\n");  
   printf ("  -l, --to                 include the To: information\n");  
   printf ("  -n, --number             display the message numbered\n");  
   printf ("  -Q, --Quiet              very quiet\n");  
   printf ("  -q, --query              print a message if unread mail\n");  
   printf ("  -S, --summary            print a summary of messages\n");  
   printf ("  -s, --status=[nor]       select message with the specific \  
  attribute\n");  
   printf ("                           [n]ew, [r]ead, [u]nread.\n");  
   printf ("  -t, --align              Try to align\n");  
   printf ("  -v, --version            display version information and exit\n");  
   printf ("\nReport bugs to bug-mailutils@gnu.org\n");  
   exit (3);  
 }  
   
280  /* This is a clone of the elm program call "frm".  It is a good example on  /* This is a clone of the elm program call "frm".  It is a good example on
281     how to use the observable(callback) of libmailutils.  "frm" has to     how to use the observable(callback) of libmailutils.  "frm" has to
282     be very interactive, it is not possible to call mailbox_messages_count()     be very interactive, it is not possible to call mailbox_messages_count()
# Line 232  main(int argc, char **argv) Line 291  main(int argc, char **argv)
291    size_t total = 0;    size_t total = 0;
292    int c;    int c;
293    int status = 0;    int status = 0;
294      
295    while ((c = getopt_long (argc, argv, short_options, long_options, NULL))    mu_create_argcv (argc, argv, &argc, &argv);
296           != -1)    argp_parse (&argp, argc, argv, 0, &c, NULL);
     {  
       switch (c)  
         {  
         case 'd':  
           dbug++;  
           break;  
   
         case 'h':  
           usage (argv[0]);  
           break;  
   
         case 'f':  
           show_field = optarg;  
           show_from = 0;  
           show_subject = 0;  
           align = 0;  
           break;  
   
         case 'l':  
           show_to = 1;  
           break;  
   
         case 'n':  
           show_number = 1;  
           break;  
   
         case 'Q':  
           /* Very silent.  */  
           be_quiet += 2;  
           if (freopen("/dev/null", "w", stdout) == NULL)  
             {  
               perror ("Can not be very quiet");  
               exit (3);  
             }  
           break;  
   
         case 'q':  
           be_quiet = show_query = 1;  
           break;  
   
         case 'S':  
           show_summary = 1;  
           break;  
   
         case 's':  
           if (optarg)  
             switch (*optarg)  
               {  
               case 'r':  
                 select_attribute |= IS_READ;  
                 break;  
   
               case 'o':  
                 select_attribute |= IS_OLD;  
                 break;  
   
               case 'n':  
                 select_attribute |= IS_NEW;  
                 break;  
   
               }  
           break;  
   
         case 't':  
           align = 1;  
           break;  
   
         case 'v':  
           printf ("Mailutils 0.0.0: frm\n");  
           exit (3);  
           break;  
   
         default:  
           break;  
         }  
     }  
297    
298    /* have an argument */    /* have an argument */
299    if (optind < argc)    argc -= c;
300      mailbox_name = argv[optind];    argv += c;
301    
302      if (argc)
303        mailbox_name = argv[0];
304    
305    /* register the formats.  */    /* register the formats.  */
306    {    {

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

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