mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-08-11 20:50:42 +02:00
commit bash-20040816 snapshot
This commit is contained in:
@@ -78,6 +78,8 @@ int xpg_echo = 1;
|
||||
int xpg_echo = 0;
|
||||
#endif /* DEFAULT_ECHO_TO_XPG */
|
||||
|
||||
extern int posixly_correct;
|
||||
|
||||
/* Print the words in LIST to standard output. If the first word is
|
||||
`-n', then don't print a trailing newline. We also support the
|
||||
echo syntax from Version 9 Unix systems. */
|
||||
@@ -91,6 +93,9 @@ echo_builtin (list)
|
||||
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)
|
||||
{
|
||||
/* If it appears that we are handling options, then make sure that
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
This file is echo.def, from which is created echo.c.
|
||||
It implements the builtin "echo" in Bash.
|
||||
|
||||
Copyright (C) 1987-2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
Bash is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2, or (at your option) any later
|
||||
version.
|
||||
|
||||
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Bash; see the file COPYING. If not, write to the Free Software
|
||||
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
|
||||
$PRODUCES echo.c
|
||||
#include <config.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashansi.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../shell.h"
|
||||
|
||||
$BUILTIN echo
|
||||
$FUNCTION echo_builtin
|
||||
$DEPENDS_ON V9_ECHO
|
||||
$SHORT_DOC echo [-neE] [arg ...]
|
||||
Output the ARGs. If -n is specified, the trailing newline is
|
||||
suppressed. If the -e option is given, interpretation of the
|
||||
following backslash-escaped characters is turned on:
|
||||
\a alert (bell)
|
||||
\b backspace
|
||||
\c suppress trailing newline
|
||||
\E escape character
|
||||
\f form feed
|
||||
\n new line
|
||||
\r carriage return
|
||||
\t horizontal tab
|
||||
\v vertical tab
|
||||
\\ backslash
|
||||
\num the character whose ASCII code is NUM (octal).
|
||||
|
||||
You can explicitly turn off the interpretation of the above characters
|
||||
with the -E option.
|
||||
$END
|
||||
|
||||
$BUILTIN echo
|
||||
$FUNCTION echo_builtin
|
||||
$DEPENDS_ON !V9_ECHO
|
||||
$SHORT_DOC echo [-n] [arg ...]
|
||||
Output the ARGs. If -n is specified, the trailing newline is suppressed.
|
||||
$END
|
||||
|
||||
#if defined (V9_ECHO)
|
||||
# define VALID_ECHO_OPTIONS "neE"
|
||||
#else /* !V9_ECHO */
|
||||
# define VALID_ECHO_OPTIONS "n"
|
||||
#endif /* !V9_ECHO */
|
||||
|
||||
/* System V machines already have a /bin/sh with a v9 behaviour. We
|
||||
give Bash the identical behaviour for these machines so that the
|
||||
existing system shells won't barf. Regrettably, the SUS v2 has
|
||||
standardized the Sys V echo behavior. This variable is external
|
||||
so that we can have a `shopt' variable to control it at runtime. */
|
||||
#if defined (DEFAULT_ECHO_TO_XPG)
|
||||
int xpg_echo = 1;
|
||||
#else
|
||||
int xpg_echo = 0;
|
||||
#endif /* DEFAULT_ECHO_TO_XPG */
|
||||
|
||||
/* Print the words in LIST to standard output. If the first word is
|
||||
`-n', then don't print a trailing newline. We also support the
|
||||
echo syntax from Version 9 Unix systems. */
|
||||
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)
|
||||
{
|
||||
/* If it appears that we are handling options, then make sure that
|
||||
all of the options specified are actually valid. Otherwise, the
|
||||
string should just be echoed. */
|
||||
temp++;
|
||||
|
||||
for (i = 0; temp[i]; i++)
|
||||
{
|
||||
if (strchr (VALID_ECHO_OPTIONS, temp[i]) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/* echo - and echo -<nonopt> both mean to just echo the arguments. */
|
||||
if (*temp == 0 || temp[i])
|
||||
break;
|
||||
|
||||
/* All of the options in TEMP are valid options to ECHO.
|
||||
Handle them. */
|
||||
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 /* V9_ECHO */
|
||||
default:
|
||||
goto just_echo; /* XXX */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
just_echo:
|
||||
|
||||
clearerr (stdout); /* clear error before writing and testing success */
|
||||
|
||||
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); /* Fix for bug in SunOS 5.5 printf(3) */
|
||||
#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))
|
||||
{
|
||||
clearerr (stdout);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
+13
-1
@@ -94,6 +94,8 @@ int
|
||||
bg_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int r;
|
||||
|
||||
if (job_control == 0)
|
||||
{
|
||||
sh_nojobs ((char *)NULL);
|
||||
@@ -104,7 +106,17 @@ bg_builtin (list)
|
||||
return (EX_USAGE);
|
||||
list = loptend;
|
||||
|
||||
return (fg_bg (list, 0));
|
||||
/* This relies on the fact that fg_bg() takes a WORD_LIST *, but only acts
|
||||
on the first member (if any) of that list. */
|
||||
do
|
||||
{
|
||||
r = fg_bg (list, 0);
|
||||
if (list)
|
||||
list = list->next;
|
||||
}
|
||||
while (list);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/* How to put a job into the foreground/background. */
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
This file is fg_bg.def, from which is created fg_bg.c.
|
||||
It implements the builtins "bg" and "fg" in Bash.
|
||||
|
||||
Copyright (C) 1987-2003 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
Bash is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2, or (at your option) any later
|
||||
version.
|
||||
|
||||
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Bash; see the file COPYING. If not, write to the Free Software
|
||||
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||
|
||||
$PRODUCES fg_bg.c
|
||||
|
||||
$BUILTIN fg
|
||||
$FUNCTION fg_builtin
|
||||
$DEPENDS_ON JOB_CONTROL
|
||||
$SHORT_DOC fg [job_spec]
|
||||
Place JOB_SPEC in the foreground, and make it the current job. If
|
||||
JOB_SPEC is not present, the shell's notion of the current job is
|
||||
used.
|
||||
$END
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "../bashtypes.h"
|
||||
#include <signal.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../bashintl.h"
|
||||
|
||||
#include "../shell.h"
|
||||
#include "../jobs.h"
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
extern char *this_command_name;
|
||||
|
||||
static int fg_bg __P((WORD_LIST *, int));
|
||||
|
||||
/* How to bring a job into the foreground. */
|
||||
int
|
||||
fg_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int fg_bit;
|
||||
register WORD_LIST *t;
|
||||
|
||||
if (job_control == 0)
|
||||
{
|
||||
sh_nojobs ((char *)NULL);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
if (no_options (list))
|
||||
return (EX_USAGE);
|
||||
list = loptend;
|
||||
|
||||
/* If the last arg on the line is '&', then start this job in the
|
||||
background. Else, fg the job. */
|
||||
for (t = list; t && t->next; t = t->next)
|
||||
;
|
||||
fg_bit = (t && t->word->word[0] == '&' && t->word->word[1] == '\0') == 0;
|
||||
|
||||
return (fg_bg (list, fg_bit));
|
||||
}
|
||||
#endif /* JOB_CONTROL */
|
||||
|
||||
$BUILTIN bg
|
||||
$FUNCTION bg_builtin
|
||||
$DEPENDS_ON JOB_CONTROL
|
||||
$SHORT_DOC bg [job_spec]
|
||||
Place JOB_SPEC in the background, as if it had been started with
|
||||
`&'. If JOB_SPEC is not present, the shell's notion of the current
|
||||
job is used.
|
||||
$END
|
||||
|
||||
#if defined (JOB_CONTROL)
|
||||
/* How to put a job into the background. */
|
||||
int
|
||||
bg_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
if (job_control == 0)
|
||||
{
|
||||
sh_nojobs ((char *)NULL);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
if (no_options (list))
|
||||
return (EX_USAGE);
|
||||
list = loptend;
|
||||
|
||||
return (fg_bg (list, 0));
|
||||
}
|
||||
|
||||
/* How to put a job into the foreground/background. */
|
||||
static int
|
||||
fg_bg (list, foreground)
|
||||
WORD_LIST *list;
|
||||
int foreground;
|
||||
{
|
||||
sigset_t set, oset;
|
||||
int job, status, old_async_pid;
|
||||
|
||||
BLOCK_CHILD (set, oset);
|
||||
job = get_job_spec (list);
|
||||
|
||||
if (job < 0 || job >= job_slots || jobs[job] == 0)
|
||||
{
|
||||
if (job != DUP_JOB)
|
||||
sh_badjob (list ? list->word->word : "current");
|
||||
|
||||
goto failure;
|
||||
}
|
||||
|
||||
/* Or if jobs[job]->pgrp == shell_pgrp. */
|
||||
if (IS_JOBCONTROL (job) == 0)
|
||||
{
|
||||
builtin_error (_("job %d started without job control"), job + 1);
|
||||
goto failure;
|
||||
}
|
||||
|
||||
if (foreground == 0)
|
||||
{
|
||||
old_async_pid = last_asynchronous_pid;
|
||||
last_asynchronous_pid = jobs[job]->pgrp; /* As per Posix.2 5.4.2 */
|
||||
}
|
||||
|
||||
status = start_job (job, foreground);
|
||||
|
||||
if (status >= 0)
|
||||
{
|
||||
/* win: */
|
||||
UNBLOCK_CHILD (oset);
|
||||
return (status);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (foreground == 0)
|
||||
last_asynchronous_pid = old_async_pid;
|
||||
|
||||
failure:
|
||||
UNBLOCK_CHILD (oset);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
}
|
||||
#endif /* JOB_CONTROL */
|
||||
Reference in New Issue
Block a user