Commit 6567d383 6567d383b2fbc7c333d59f7878432ecb7912b83f by Sergey Poznyakoff

Main functions.

1 parent 1f2f9ff2
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include "guimb.h"
19 #include "getopt.h"
20
21 static char short_options[] = "de:f:g:hm:v";
22 static struct option long_options[] = {
23 {"debug", no_argument, 0, 'd'},
24 {"expression", required_argument, 0, 'e'},
25 {"file", required_argument, 0, 'f'},
26 {"help", no_argument, 0, 'h'},
27 {"guile-command", required_argument, 0, 'g'},
28 {"version", no_argument, 0, 'v'},
29 {0, 0, 0, 0}
30 };
31
32 char *program_file;
33 char *program_expr;
34 int debug_guile;
35
36 static void usage (void);
37
38 static int g_size;
39 static int g_argc;
40 static char **g_argv;
41
42 #define ARG_INC 16
43
44 void
45 append_arg (char *arg)
46 {
47 if (g_argc == g_size)
48 {
49 g_size += ARG_INC;
50 g_argv = realloc (g_argv, g_size * sizeof (g_argv[0]));
51 if (!g_argv)
52 {
53 util_error ("not enough memory");
54 exit (1);
55 }
56 }
57 g_argv[g_argc++] = arg;
58 }
59
60 int
61 main (int argc, char *argv[])
62 {
63 int c;
64
65 while ((c = getopt_long (argc, argv, short_options, long_options, NULL))
66 != -1)
67 switch (c)
68 {
69 case 'd':
70 debug_guile = 1;
71 break;
72 case 'f':
73 program_file = optarg;
74 break;
75 case 'e':
76 program_expr = optarg;
77 break;
78 case 'g':
79 append_arg (optarg);
80 break;
81 case 'h':
82 usage ();
83 exit (0);
84 case 'v':
85 printf ("guimb (" PACKAGE " " VERSION ")\n");
86 exit (0);
87 default:
88 fprintf (stderr,
89 "Invalid argument. Try guimb --help for more info\n");
90 exit (1);
91 }
92 append_arg (NULL);
93 g_argc--;
94
95 /* Register the desired formats. */
96 {
97 list_t lst;
98 registrar_get_list (&lst);
99 list_append (lst, mbox_record);
100 list_append (lst, path_record);
101 list_append (lst, pop_record);
102 list_append (lst, imap_record);
103 /* Possible supported mailers. */
104 list_append (lst, sendmail_record);
105 list_append (lst, smtp_record);
106 }
107
108 collect_open_mailbox_file ();
109 if (argv[optind])
110 {
111 for (; argv[optind]; optind++)
112 collect_append_file (argv[optind]);
113 }
114 else
115 collect_append_file ("-");
116 run_main (g_argc, g_argv);
117 }
118
119 static char usage_str[] =
120 "Usage: guimb [OPTIONS] [MBOX ...]\n"
121 "Process the contents of the specified mailboxes using a Scheme program\n"
122 "or expression.\n"
123 "Options are:\n"
124 " -d, --debug Start with debugging evaluator and backtraces.\n"
125 " -e, --expression EXPR Execute scheme expression.\n"
126 " -f, --file PROGFILE Read program from PROGFILE.\n"
127 " -g, --guile-command ARG Append ARG to the command line passed to guile\n"
128 " program.\n"
129 " -h, --help Display help message.\n"
130 " -v, --version Display program version.\n"
131 "\n"
132 "When both --file and --expression are specified, file is evaluated first.\n"
133 "If no mailboxes are specified the standard input is read.\n";
134
135 void
136 usage ()
137 {
138 printf ("%s\n" "Report bugs to <bug-mailutils@gnu.org>\n", usage_str);
139 }