Imported from ../bash-4.0-rc1.tar.gz.
[platform/upstream/bash.git] / builtins / fg_bg.def
index 9d379e8..ae7e904 100644 (file)
@@ -1,23 +1,22 @@
 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, 1989, 1991 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 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 3 of the License, 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.
+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.
+You should have received a copy of the GNU General Public License
+along with Bash.  If not, see <http://www.gnu.org/licenses/>.
 
 $PRODUCES fg_bg.c
 
@@ -25,9 +24,14 @@ $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.
+Move job to the foreground.
+
+Place the job identified by JOB_SPEC in the foreground, making it the
+current job.  If JOB_SPEC is not present, the shell's notion of the
+current job is used.
+
+Exit Status:
+Status of command placed in foreground, or failure if an error occurs.
 $END
 
 #include <config.h>
@@ -39,9 +43,12 @@ $END
 #  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;
@@ -58,12 +65,13 @@ fg_builtin (list)
 
   if (job_control == 0)
     {
-      builtin_error ("no job control");
+      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. */
@@ -78,10 +86,15 @@ fg_builtin (list)
 $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.
+$SHORT_DOC bg [job_spec ...]
+Move jobs to the background.
+
+Place the jobs identified by each JOB_SPEC in the background, as if they
+had been started with `&'.  If JOB_SPEC is not present, the shell's notion
+of the current job is used.
+
+Exit Status:
+Returns success unless job control is not enabled or an error occurs.
 $END
 
 #if defined (JOB_CONTROL)
@@ -90,16 +103,31 @@ int
 bg_builtin (list)
      WORD_LIST *list;
 {
+  int r;
+
   if (job_control == 0)
     {
-      builtin_error ("no job control");
+      sh_nojobs ((char *)NULL);
       return (EXECUTION_FAILURE);
     }
 
   if (no_options (list))
     return (EX_USAGE);
+  list = loptend;
+
+  /* This relies on the fact that fg_bg() takes a WORD_LIST *, but only acts
+     on the first member (if any) of that list. */
+  r = EXECUTION_SUCCESS;
+  do
+    {
+      if (fg_bg (list, 0) == EXECUTION_FAILURE)
+       r = EXECUTION_FAILURE;
+      if (list)
+       list = list->next;
+    }
+  while (list);
 
-  return (fg_bg (list, 0));
+  return r;
 }
 
 /* How to put a job into the foreground/background. */
@@ -110,29 +138,31 @@ fg_bg (list, foreground)
 {
   sigset_t set, oset;
   int job, status, old_async_pid;
+  JOB *j;
 
   BLOCK_CHILD (set, oset);
   job = get_job_spec (list);
 
-  if (job < 0 || job >= job_slots || jobs[job] == 0)
+  if (INVALID_JOB (job))
     {
       if (job != DUP_JOB)
-       builtin_error ("%s: no such job", list ? list->word->word : "current");
+       sh_badjob (list ? list->word->word : _("current"));
 
       goto failure;
     }
 
-  /* Or if jobs[job]->pgrp == shell_pgrp. */
+  j = get_job_by_jid (job);
+  /* Or if j->pgrp == shell_pgrp. */
   if (IS_JOBCONTROL (job) == 0)
     {
-      builtin_error ("job %%%d started without job control", job + 1);
+      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 */
+      last_asynchronous_pid = j->pgrp; /* As per Posix.2 5.4.2 */
     }
 
   status = start_job (job, foreground);
@@ -141,7 +171,7 @@ fg_bg (list, foreground)
     {
     /* win: */
       UNBLOCK_CHILD (oset);
-      return (status);
+      return (foreground ? status : EXECUTION_SUCCESS);
     }
   else
     {