#line 23 "echo.def"
#include <config.h>
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
#include "../bashansi.h"
#include <stdio.h>
#include "../shell.h"
#include "common.h"
#line 59 "echo.def"
#line 66 "echo.def"
#if defined (V9_ECHO)
# define VALID_ECHO_OPTIONS "neE"
#else
# define VALID_ECHO_OPTIONS "n"
#endif
#if defined (DEFAULT_ECHO_TO_XPG) || defined (STRICT_POSIX)
int xpg_echo = 1;
#else
int xpg_echo = 0;
#endif
extern int posixly_correct;
int
echo_builtin (list)
WORD_LIST *list;
{
int display_return, do_v9, i, len;
char *temp, *s;
do_v9 = xpg_echo;
display_return = 1;
if (posixly_correct && xpg_echo)
goto just_echo;
for (; list && (temp = list->word->word) && *temp == '-'; list = list->next)
{
temp++;
for (i = 0; temp[i]; i++)
{
if (strchr (VALID_ECHO_OPTIONS, temp[i]) == 0)
break;
}
if (*temp == 0 || temp[i])
break;
while (i = *temp++)
{
switch (i)
{
case 'n':
display_return = 0;
break;
#if defined (V9_ECHO)
case 'e':
do_v9 = 1;
break;
case 'E':
do_v9 = 0;
break;
#endif
default:
goto just_echo;
}
}
}
just_echo:
clearerr (stdout);
while (list)
{
i = len = 0;
temp = do_v9 ? ansicstr (list->word->word, STRLEN (list->word->word), 1, &i, &len)
: list->word->word;
if (temp)
{
if (do_v9)
{
for (s = temp; len > 0; len--)
putchar (*s++);
}
else
printf ("%s", temp);
#if defined (SunOS5)
fflush (stdout);
#endif
}
if (do_v9 && temp)
free (temp);
list = list->next;
if (i)
{
display_return = 0;
break;
}
if (list)
putchar(' ');
}
if (display_return)
putchar ('\n');
fflush (stdout);
if (ferror (stdout))
{
sh_wrerror ();
clearerr (stdout);
return (EXECUTION_FAILURE);
}
return (EXECUTION_SUCCESS);
}