Commit edc010f2 edc010f2c2c0f875d61a44b6ff82f2768a37f2d8 by Alain Magloire

* mail/echo.c: Make it aware of escape char '\'.

        * mail/next.c: Should print the message also.
        * mail/previous.c: Should print the message also.
        * mail/util.c(util_do_command): Memory leak cmd
        was not free(cmd).  An empty line means now "next".
1 parent f96b8316
2002-03-13 Sergey Poznyakoff
* mail/echo.c: Make it aware of escape char '\'.
* mail/next.c: Should print the message also.
* mail/previous.c: Should print the message also.
* mail/util.c(util_do_command): Memory leak cmd
was not free(cmd). An empty line means now "next".
2002-03-13 Sergey Poznyakoff
* include/mailutils/Makefile.am: Added types.h
* argp/{argp-eexst.c,argp-namefrob.h,argp.h,
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2001 Free Software Foundation, Inc.
Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -21,6 +21,8 @@
* ec[ho] string ...
*/
static int echo (char *s);
int
mail_echo (int argc, char **argv)
{
......@@ -28,8 +30,120 @@ mail_echo (int argc, char **argv)
if (argc > 1)
{
for (i = 1; i < argc - 1; i++)
fprintf (ofile, "%s ", argv[i]);
fprintf (ofile, "%s\n", argv[argc - 1]);
{
echo (argv[i]);
fputc (' ', ofile);
}
/* Last argument. */
if (echo(argv[argc - 1]) == 0)
fputc ('\n', ofile);
}
return 0;
}
/* Cumbersome switch for checking escape char '\'
if present replace with appropriately.
Return of 1 means to not print newline. */
static int
echo (char *s)
{
int process_escape = 0;
int c;
if (s == NULL)
return 0;
for (; (c = *s) != 0; s++)
{
if (process_escape)
{
switch (c)
{
/* \a Bell. */
case 'a':
c = '\a';
break;
/* \b Backspace. */
case 'b':
c = '\b';
break;
/* \c means not to print ending newline. */
/* Bail out and tell the caller not to print newline. */
case 'c':
return 1;
break;
/* \f Formfeed. */
case 'f':
c = '\f';
break;
/* \n Newline. */
case 'n':
c = '\n';
break;
/* \r Carriage return. */
case 'r':
c = '\r';
break;
/* \t Tab. */
case 't':
c = '\t';
break;
/* \v Vertical Tab. */
case 'v':
c = '\v';
break;
/* Escape sequence. */
case '\\':
c = '\\';
break;
/* \0x99 for example, let strtol() handle it. */
/* WARNING: Side effects because of strtol(). */
case '0':
{
long number = strtol (s, &s, 0);
switch (number)
{
case LONG_MIN:
case LONG_MAX:
/* if (errno == ERANGE) */
/* fputc (c, ofile); */
break;
default:
fprintf (ofile, "%d", number);
s--;
continue;
}
}
break;
/* Can not be here. */
case '\0':
return 0;
break;
/* \\ means \ It was not an escape char. */
default:
fputc ('\\', ofile);
}
process_escape =0;
}
else if (c == '\\') /* Find the escape char, go back and process. */
{
process_escape = 1;
continue;
}
fputc (c, ofile);
}
return 0;
}
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -30,6 +30,7 @@
# include <alloca.h>
#endif
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2001 Free Software Foundation, Inc.
Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -29,7 +29,6 @@ mail_next (int argc, char **argv)
{
cursor++;
realcursor++;
return 0;
}
else
{
......@@ -38,7 +37,7 @@ mail_next (int argc, char **argv)
cursor = list->msg_part[0];
realcursor = cursor;
msgset_free (list);
return 0;
}
util_do_command("print");
return 1;
}
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2001 Free Software Foundation, Inc.
Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -29,7 +29,6 @@ mail_previous (int argc, char **argv)
{
cursor--;
realcursor--;
return 0;
}
else
{
......@@ -39,7 +38,7 @@ mail_previous (int argc, char **argv)
cursor = list->msg_part[0];
realcursor = cursor;
msgset_free (list);
return 0;
}
util_do_command ("print");
return 1;
}
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -97,20 +97,29 @@ util_do_command (const char *c, ...)
{
struct mail_command_entry entry;
if (cmd[0] == '#')
/* Ignore comments */
if (cmd[0] == '#') {
free (cmd);
return 0;
}
if (argcv_get (cmd, delim, NULL, &argc, &argv) != 0)
return argcv_free (argc, argv);
/* Hitting return i.e. no command, is equivalent to next
according to the POSIX spec. */
if (cmd[0] == '\0') {
free (cmd);
cmd = strdup ("next");
}
entry = util_find_entry (mail_command_table, argv[0]);
if (if_cond () == 0 && (entry.flags & EF_FLOW) == 0)
if (argcv_get (cmd, delim, NULL, &argc, &argv) == 0)
{
argcv_free (argc, argv);
return 0;
entry = util_find_entry (mail_command_table, argv[0]);
/* Make sure we are not in any if/else */
if (! (if_cond () == 0 && (entry.flags & EF_FLOW) == 0))
command = entry.func;
}
command = entry.func;
free (cmd);
}
else
command = util_command_get ("quit");
......