/[mailutils]/mailutils/guimb/main.c
ViewVC logotype

Diff of /mailutils/guimb/main.c

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

revision 1.5 by gray, Sun Oct 14 08:34:24 2001 UTC revision 1.6 by gray, Mon Jan 21 14:58:41 2002 UTC
# Line 18  Line 18 
18  #include "guimb.h"  #include "guimb.h"
19  #include "getopt.h"  #include "getopt.h"
20    
21  static char short_options[] = "de:f:g:hm:u:v{";  static char short_options[] = "de:f:g:hM:m:s:u::v{";
22  static struct option long_options[] = {  static struct option long_options[] = {
23    {"debug", no_argument, 0, 'd'},    {"debug", no_argument, 0, 'd'},
24    {"expression", required_argument, 0, 'e'},    {"expression", required_argument, 0, 'e'},
25    {"file", required_argument, 0, 'f'},    {"file", required_argument, 0, 'f'},
26    {"help", no_argument, 0, 'h'},    {"help", no_argument, 0, 'h'},
27    {"guile-command", required_argument, 0, 'g'},    {"guile-command", required_argument, 0, 'g'},
28    {"mailbox", required_argument, 0, 'm'},    {"maildir", required_argument, 0, 'm'},
29    {"user", required_argument, 0, 'u'},    {"mailbox", required_argument, 0, 'M'},
30      {"source", required_argument, 0, 's'},
31      {"user", optional_argument, 0, 'u'},
32    {"version", no_argument, 0, 'v'},    {"version", no_argument, 0, 'v'},
33    {0, 0, 0, 0}    {0, 0, 0, 0}
34  };  };
# Line 36  char *program_expr; Line 38  char *program_expr;
38  int debug_guile;  int debug_guile;
39  char *user_name;  char *user_name;
40  char *default_mailbox;  char *default_mailbox;
41    char *maildir = MU_PATH_MAILDIR;
42    
43  static void usage (void);  static void usage (void);
44    char * who_am_i ();
45    
46  static int g_size;  static int g_size;
47  static int g_argc;  static int g_argc;
# Line 64  int Line 69  int
69  main (int argc, char *argv[])  main (int argc, char *argv[])
70  {  {
71    int c;    int c;
72      int stop = 0;
73      guimb_param_t param;
74      struct guimb_data gd;
75        
76    append_arg ("");    append_arg ("");
77    while ((c = getopt_long (argc, argv, short_options, long_options, NULL))    while (!stop
78           != -1)           && (c = getopt_long (argc, argv, short_options, long_options, NULL))
79                 != -1)
80      switch (c)      switch (c)
81        {        {
82        case 'd':        case 'd':
# Line 85  main (int argc, char *argv[]) Line 94  main (int argc, char *argv[])
94        case 'h':        case 'h':
95          usage ();          usage ();
96          exit (0);          exit (0);
97        case 'm':        case 'M':
98          default_mailbox = optarg;          default_mailbox = optarg;
99          break;          break;
100          case 'm':
101            maildir = optarg;
102            break;
103        case 'u':        case 'u':
104          user_name = optarg;          user_name = optarg ? optarg : who_am_i ();
105            break;
106          case 's':
107            program_file = optarg;
108            stop = 1;
109          break;          break;
110        case 'v':        case 'v':
111          printf ("guimb (" PACKAGE " " VERSION ")\n");          printf ("guimb (" PACKAGE " " VERSION ")\n");
# Line 109  main (int argc, char *argv[]) Line 125  main (int argc, char *argv[])
125          optind++;          optind++;
126          break;          break;
127        default:        default:
         fprintf (stderr,  
                  "Invalid argument (-%c). Try guimb --help for more info\n",  
                  c);  
128          exit (1);          exit (1);
129        }        }
   
   if (program_file)  
       g_argv[0] = program_file;  
130    
131      if (stop)
132        for (; optind < argc; optind++)
133          append_arg (argv[optind]);
134    
135      if (!user_name)
136        user_name = who_am_i ();
137      
138      maildir = mu_normalize_maildir (maildir);
139      if (!maildir)
140        {
141          util_error ("Badly formed maildir: %s", maildir);
142          exit (1);
143        }
144      
145      if (program_file)
146        g_argv[0] = program_file;
147      else if (!program_expr)
148        {
149          usage ();
150          exit (0);
151        }
152        
153    /* Register the desired formats. */    /* Register the desired formats. */
154    {    {
155      list_t lst;      list_t lst;
# Line 131  main (int argc, char *argv[]) Line 163  main (int argc, char *argv[])
163      list_append (lst, smtp_record);      list_append (lst, smtp_record);
164    }    }
165    
166    if (default_mailbox && !argv[optind])    if (!argv[optind])
167      {      {
168        append_arg (default_mailbox);        if (default_mailbox)
169            append_arg (default_mailbox);
170        collect_open_default ();        collect_open_default ();
171      }      }
172    else    else
# Line 155  main (int argc, char *argv[]) Line 188  main (int argc, char *argv[])
188    append_arg (NULL);    append_arg (NULL);
189    g_argc--;    g_argc--;
190    
191    run_main (g_argc, g_argv);    /* Finish creating input mailbox */
192      collect_create_mailbox ();
193    
194      gd.program_file = program_file;
195      gd.program_expr = program_expr;
196      
197      param.debug_guile = debug_guile;
198      param.mbox = mbox;
199      param.user_name = user_name;
200      param.init = NULL;
201      param.catch_body = guimb_catch_body;
202      param.catch_handler = guimb_catch_handler;
203      param.next = NULL;
204      param.exit = guimb_exit;
205      param.data = &gd;
206      mu_process_mailbox (g_argc, g_argv, &param);
207      /*NOTREACHED*/
208      return 0;
209    }
210    
211    char *
212    who_am_i ()
213    {
214      char *name = getenv ("LOGNAME");
215      if (!name)
216        {
217          name = getenv ("USER");
218          if (!name)
219            name = strdup (getlogin ());
220        }
221      return name;
222  }  }
223    
224  static char usage_str[] =  static char usage_str[] =

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

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