Commit 34ffae30 34ffae308e6bcca8fcf9042f4213dcb9fc90c1ab by Sergey Poznyakoff

Do not put empty or comment lines into readline history. Handle keyboard

interrupts properly.
Implemented `warranty' command.
Warn user about arrival of a new mail.
1 parent 926bc7a9
Showing 1 changed file with 61 additions and 14 deletions
...@@ -23,6 +23,7 @@ unsigned int cursor; ...@@ -23,6 +23,7 @@ unsigned int cursor;
23 unsigned int realcursor; 23 unsigned int realcursor;
24 unsigned int total; 24 unsigned int total;
25 FILE *ofile; 25 FILE *ofile;
26 int interactive;
26 27
27 const char *argp_program_version = "mail (" PACKAGE ") " VERSION; 28 const char *argp_program_version = "mail (" PACKAGE ") " VERSION;
28 const char *argp_program_bug_address = "<bug-mailutils@gnu.org>"; 29 const char *argp_program_bug_address = "<bug-mailutils@gnu.org>";
...@@ -130,10 +131,29 @@ mail_cmdline(void *closure, int cont) ...@@ -130,10 +131,29 @@ mail_cmdline(void *closure, int cont)
130 { 131 {
131 struct mail_env_entry *pev = closure; 132 struct mail_env_entry *pev = closure;
132 char *prompt = NULL; 133 char *prompt = NULL;
134 char *rc;
133 135
134 if (mail_is_terminal()) 136 while (1)
135 prompt = pev->set && pev->value != NULL ? pev->value : "? "; 137 {
136 return readline (prompt); 138 if (!mailbox_is_updated (mbox))
139 {
140 mailbox_messages_count (mbox, &total);
141 fprintf (ofile, "New mail has arrived\n");
142 }
143
144 if (interactive)
145 prompt = pev->set && pev->value != NULL ? pev->value : "? ";
146
147 rc = readline (prompt);
148
149 if (ml_got_interrupt())
150 {
151 util_error("Interrupt");
152 continue;
153 }
154 break;
155 }
156 return rc;
137 } 157 }
138 158
139 int 159 int
...@@ -159,6 +179,7 @@ main (int argc, char **argv) ...@@ -159,6 +179,7 @@ main (int argc, char **argv)
159 list_append (bookie, sendmail_record); 179 list_append (bookie, sendmail_record);
160 } 180 }
161 181
182 interactive = isatty (fileno(stdin));
162 signal (SIGPIPE, SIG_IGN); 183 signal (SIGPIPE, SIG_IGN);
163 184
164 /* set up the default environment */ 185 /* set up the default environment */
...@@ -181,14 +202,21 @@ main (int argc, char **argv) ...@@ -181,14 +202,21 @@ main (int argc, char **argv)
181 /* set defaults for execution */ 202 /* set defaults for execution */
182 util_do_command ("set noallnet"); 203 util_do_command ("set noallnet");
183 util_do_command ("set noappend"); 204 util_do_command ("set noappend");
184 if (isatty (fileno(stdin))) { util_do_command ("set asksub"); } 205 if (interactive)
185 else { util_do_command ("set noasksub"); } 206 {
207 util_do_command ("set asksub");
208 util_do_command ("set crt");
209 }
210 else
211 {
212 util_do_command ("set noasksub");
213 util_do_command ("set nocrt");
214 }
186 util_do_command ("set noaskbcc"); 215 util_do_command ("set noaskbcc");
187 util_do_command ("set askcc"); 216 util_do_command ("set askcc");
188 util_do_command ("set noautoprint"); 217 util_do_command ("set noautoprint");
189 util_do_command ("set nobang"); 218 util_do_command ("set nobang");
190 util_do_command ("set nocmd"); 219 util_do_command ("set nocmd");
191 util_do_command ("set nocrt");
192 util_do_command ("set nodebug"); 220 util_do_command ("set nodebug");
193 util_do_command ("set nodot"); 221 util_do_command ("set nodot");
194 util_do_command ("set escape=~"); 222 util_do_command ("set escape=~");
...@@ -205,7 +233,7 @@ main (int argc, char **argv) ...@@ -205,7 +233,7 @@ main (int argc, char **argv)
205 util_do_command ("set noonehop"); 233 util_do_command ("set noonehop");
206 util_do_command ("set nooutfolder"); 234 util_do_command ("set nooutfolder");
207 util_do_command ("set nopage"); 235 util_do_command ("set nopage");
208 util_do_command ("set prompt=?"); /* FIXME: "set prompt=\"? \"" */ 236 util_do_command ("set prompt=\"? \"");
209 util_do_command ("set noquiet"); 237 util_do_command ("set noquiet");
210 util_do_command ("set norecord"); 238 util_do_command ("set norecord");
211 util_do_command ("set save"); 239 util_do_command ("set save");
...@@ -265,11 +293,8 @@ main (int argc, char **argv) ...@@ -265,11 +293,8 @@ main (int argc, char **argv)
265 /* Or acting as a normal reader */ 293 /* Or acting as a normal reader */
266 else 294 else
267 { 295 {
268 /* Initialize readline */ 296 ml_readline_init ();
269 #ifdef WITH_READLINE 297 mail_set_my_name(args.user);
270 rl_readline_name = "mail";
271 rl_attempted_completion_function = (CPPFunction*)util_command_completion;
272 #endif
273 298
274 /* open the mailbox */ 299 /* open the mailbox */
275 if (args.file == NULL) 300 if (args.file == NULL)
...@@ -299,7 +324,6 @@ main (int argc, char **argv) ...@@ -299,7 +324,6 @@ main (int argc, char **argv)
299 util_do_command ("z."); 324 util_do_command ("z.");
300 325
301 prompt = util_find_env ("prompt"); 326 prompt = util_find_env ("prompt");
302 mail_set_is_terminal(isatty(0));
303 mail_mainloop(mail_cmdline, (void*) prompt, 1); 327 mail_mainloop(mail_cmdline, (void*) prompt, 1);
304 fprintf (ofile, "\n"); 328 fprintf (ofile, "\n");
305 util_do_command ("quit"); 329 util_do_command ("quit");
...@@ -339,7 +363,7 @@ mail_mainloop(char *(*input) __P((void *, int)), void *closure, int do_history) ...@@ -339,7 +363,7 @@ mail_mainloop(char *(*input) __P((void *, int)), void *closure, int do_history)
339 cmd = util_stripwhite (command); 363 cmd = util_stripwhite (command);
340 util_do_command (cmd); 364 util_do_command (cmd);
341 #ifdef WITH_READLINE 365 #ifdef WITH_READLINE
342 if (do_history) 366 if (do_history && !(isspace(cmd[0]) || cmd[0] == '#'))
343 add_history (cmd); 367 add_history (cmd);
344 #endif 368 #endif
345 if (command) 369 if (command)
...@@ -347,6 +371,29 @@ mail_mainloop(char *(*input) __P((void *, int)), void *closure, int do_history) ...@@ -347,6 +371,29 @@ mail_mainloop(char *(*input) __P((void *, int)), void *closure, int do_history)
347 } 371 }
348 } 372 }
349 373
374 static char warranty_stmt[] =
375 "GNU mailutils - a suite of utilities for electronic mail\n\
376 Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.\n\
377 \n\
378 This program is free software; you can redistribute it and/or modify\n\
379 it under the terms of the GNU General Public License as published by\n\
380 the Free Software Foundation; either version 2, or (at your option)\n\
381 any later version.\n\
382 \n\
383 This program is distributed in the hope that it will be useful,\n\
384 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
385 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
386 GNU General Public License for more details.\n\
387 \n\
388 You should have received a copy of the GNU General Public License\n\
389 along with this program; if not, write to the Free Software\n\
390 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n";
350 391
392 int
393 mail_warranty(int argc, char **argv)
394 {
395 fprintf (ofile, "%s", warranty_stmt);
396 return 0;
397 }
351 398
352 399
......