Commit f77e61f3 f77e61f35d100032edf9de27d6d1e51fbe05442e by Sergey Poznyakoff

Added --mailbox and --user options. Added escape for Scheme arguments (-{ and -}).

1 parent d614f668
...@@ -18,13 +18,15 @@ ...@@ -18,13 +18,15 @@
18 #include "guimb.h" 18 #include "guimb.h"
19 #include "getopt.h" 19 #include "getopt.h"
20 20
21 static char short_options[] = "de:f:g:hv"; 21 static char short_options[] = "de:f:g:hm:u:v{";
22 static struct option long_options[] = { 22 static struct option long_options[] = {
23 {"debug", no_argument, 0, 'd'}, 23 {"debug", no_argument, 0, 'd'},
24 {"expression", required_argument, 0, 'e'}, 24 {"expression", required_argument, 0, 'e'},
25 {"file", required_argument, 0, 'f'}, 25 {"file", required_argument, 0, 'f'},
26 {"help", no_argument, 0, 'h'}, 26 {"help", no_argument, 0, 'h'},
27 {"guile-command", required_argument, 0, 'g'}, 27 {"guile-command", required_argument, 0, 'g'},
28 {"mailbox", required_argument, 0, 'm'},
29 {"user", required_argument, 0, 'u'},
28 {"version", no_argument, 0, 'v'}, 30 {"version", no_argument, 0, 'v'},
29 {0, 0, 0, 0} 31 {0, 0, 0, 0}
30 }; 32 };
...@@ -32,7 +34,9 @@ static struct option long_options[] = { ...@@ -32,7 +34,9 @@ static struct option long_options[] = {
32 char *program_file; 34 char *program_file;
33 char *program_expr; 35 char *program_expr;
34 int debug_guile; 36 int debug_guile;
35 37 char *user_name;
38 char *output_mailbox;
39 int store_mailbox;
36 static void usage (void); 40 static void usage (void);
37 41
38 static int g_size; 42 static int g_size;
...@@ -61,7 +65,7 @@ int ...@@ -61,7 +65,7 @@ int
61 main (int argc, char *argv[]) 65 main (int argc, char *argv[])
62 { 66 {
63 int c; 67 int c;
64 68
65 append_arg (""); 69 append_arg ("");
66 while ((c = getopt_long (argc, argv, short_options, long_options, NULL)) 70 while ((c = getopt_long (argc, argv, short_options, long_options, NULL))
67 != -1) 71 != -1)
...@@ -82,18 +86,39 @@ main (int argc, char *argv[]) ...@@ -82,18 +86,39 @@ main (int argc, char *argv[])
82 case 'h': 86 case 'h':
83 usage (); 87 usage ();
84 exit (0); 88 exit (0);
89 case 'm':
90 output_mailbox = optarg;
91 store_mailbox = 1;
92 break;
93 case 'u':
94 user_name = optarg;
95 break;
85 case 'v': 96 case 'v':
86 printf ("guimb (" PACKAGE " " VERSION ")\n"); 97 printf ("guimb (" PACKAGE " " VERSION ")\n");
87 exit (0); 98 exit (0);
99 case '{':
100 for (;; optind++)
101 {
102 if (optind == argc)
103 {
104 fprintf (stderr, "guimb: missing -}\n");
105 exit (1);
106 }
107 if (strcmp (argv[optind], "-}") == 0)
108 break;
109 append_arg (argv[optind]);
110 }
111 optind++;
112 break;
88 default: 113 default:
89 fprintf (stderr, 114 fprintf (stderr,
90 "Invalid argument. Try guimb --help for more info\n"); 115 "Invalid argument (-%c). Try guimb --help for more info\n",
116 c);
91 exit (1); 117 exit (1);
92 } 118 }
119
93 if (program_file) 120 if (program_file)
94 g_argv[0] = program_file; 121 g_argv[0] = program_file;
95 append_arg (NULL);
96 g_argc--;
97 122
98 /* Register the desired formats. */ 123 /* Register the desired formats. */
99 { 124 {
...@@ -109,31 +134,53 @@ main (int argc, char *argv[]) ...@@ -109,31 +134,53 @@ main (int argc, char *argv[])
109 } 134 }
110 135
111 collect_open_mailbox_file (); 136 collect_open_mailbox_file ();
137 if (store_mailbox && !argv[optind])
138 {
139 append_arg (output_mailbox);
140 collect_append_file (output_mailbox);
141 }
142
112 if (argv[optind]) 143 if (argv[optind])
113 { 144 {
114 for (; argv[optind]; optind++) 145 for (; argv[optind]; optind++)
115 collect_append_file (argv[optind]); 146 {
147 append_arg (argv[optind]);
148 collect_append_file (argv[optind]);
149 }
116 } 150 }
117 else 151 else if (!store_mailbox)
118 collect_append_file ("-"); 152 collect_append_file ("-");
153
154 append_arg (NULL);
155 g_argc--;
156
119 run_main (g_argc, g_argv); 157 run_main (g_argc, g_argv);
120 } 158 }
121 159
122 static char usage_str[] = 160 static char usage_str[] =
123 "Usage: guimb [OPTIONS] [MBOX ...]\n" 161 "Usage: guimb [OPTIONS] [-{ SCRIPT-OPTIONS -}] [MBOX ...]\n"
124 "Process the contents of the specified mailboxes using a Scheme program\n" 162 "Process the contents of the specified mailboxes using a Scheme program\n"
125 "or expression.\n" 163 "or expression.\n"
126 "Options are:\n" 164 "Options are:\n"
127 " -d, --debug Start with debugging evaluator and backtraces.\n" 165 " -d, --debug Start with debugging evaluator and backtraces.\n"
128 " -e, --expression EXPR Execute scheme expression.\n" 166 " -e, --expression EXPR Execute scheme expression.\n"
129 " -f, --file PROGFILE Read program from PROGFILE.\n" 167 " -f, --file PROGFILE Read program from PROGFILE.\n"
130 " -g, --guile-command ARG Append ARG to the command line passed to guile\n" 168 " -g, --guile-command ARG Append ARG to the command line passed to guile.\n"
131 " program.\n" 169 " program.\n"
170 " -m, --mailbox MBOX Set default mailbox name.\n"
171 " -u, --user NAME Act as local MDA for user NAME.\n"
132 " -h, --help Display help message.\n" 172 " -h, --help Display help message.\n"
133 " -v, --version Display program version.\n" 173 " -v, --version Display program version.\n"
134 "\n" 174 "\n"
175 "Any arguments between -{ and -} are passed to the Scheme program verbatim.\n"
135 "When both --file and --expression are specified, file is evaluated first.\n" 176 "When both --file and --expression are specified, file is evaluated first.\n"
136 "If no mailboxes are specified the standard input is read.\n"; 177 "If no mailboxes are specified, the standard input is read.\n\n"
178 "The semantics of the default mailbox differs depending on whether\n"
179 "more mailbox arguments are specified in the command line. If they\n"
180 "are, any messages that are not deleted after executing the script\n"
181 "are appended to the default mailbox. Otherwise its contents is read,\n"
182 "processed and *replaced* by messages that remain undeleted after\n"
183 "executing the script.\n";
137 184
138 void 185 void
139 usage () 186 usage ()
......