bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

set0 builtin


From: Masatake YAMATO
Subject: set0 builtin
Date: Wed, 17 Sep 2008 20:50:59 +0900 (JST)

Hi,

To improve bashdb, a bash debugger, we submitted two patches to bash,
adding readfile builtin and removing bashdb.el ever. I hope you don't
forget it:)

We would like submit one more patch, adding set0 builtin.

The purpose of set0 in the debugger is that users often write programs
that refer to $0. For example to display a usage string or maybe they
change the behavior based on how they were called. So this helps in
making these programs act the same way and gives an alternative to
invoking with "bash --debugger".

The patch is for the latest bash-3.2 patch level 039.
We hope set0 is included in next version of bash.

Regards,
Masatake YAMATO

diff -ruN bash-3.2-patched/builtins/Makefile.in 
bash-3.2-work/builtins/Makefile.in
--- bash-3.2-patched/builtins/Makefile.in       2006-03-08 04:42:33.000000000 
+0900
+++ bash-3.2-work/builtins/Makefile.in  2008-09-17 20:09:33.000000000 +0900
@@ -121,7 +121,7 @@
        $(CC) -c $(CCFLAGS) $<
 
 DEFSRC =  $(srcdir)/alias.def $(srcdir)/bind.def $(srcdir)/break.def \
-         $(srcdir)/builtin.def $(srcdir)/caller.def \
+         $(srcdir)/builtin.def $(srcdir)/caller.def $(srcdir)/set0.def \
          $(srcdir)/cd.def $(srcdir)/colon.def \
          $(srcdir)/command.def $(srcdir)/declare.def $(srcdir)/echo.def \
          $(srcdir)/enable.def $(srcdir)/eval.def $(srcdir)/getopts.def \
@@ -140,7 +140,7 @@
                getopt.h 
 
 OFILES = builtins.o \
-       alias.o bind.o break.o builtin.o caller.o cd.o colon.o command.o \
+       alias.o bind.o break.o builtin.o caller.o set0.o cd.o colon.o command.o 
\
        common.o declare.o echo.o enable.o eval.o evalfile.o \
        evalstring.o exec.o \
        exit.o fc.o fg_bg.o hash.o help.o history.o jobs.o kill.o let.o \
@@ -243,6 +243,7 @@
 break.o: break.def
 builtin.o: builtin.def
 caller.o: caller.def
+set0.o: set0.def
 cd.o: cd.def
 colon.o: colon.def
 command.o: command.def
@@ -362,6 +363,12 @@
 caller.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h 
$(topdir)/variables.h $(topdir)/conftypes.h
 caller.o: $(srcdir)/common.h $(BASHINCDIR)/maxpath.h ./builtext.h
 caller.o: ${BASHINCDIR}/chartypes.h $(topdir)/bashtypes.h
+set0.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
+set0.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/quit.h 
$(topdir)/dispose_cmd.h
+set0.o: $(topdir)/make_cmd.h $(topdir)/subst.h $(topdir)/externs.h
+set0.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h 
$(topdir)/variables.h $(topdir)/conftypes.h
+set0.o: $(srcdir)/common.h $(BASHINCDIR)/maxpath.h ./builtext.h
+set0.o: ${BASHINCDIR}/chartypes.h $(topdir)/bashtypes.h
 cd.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h 
$(topdir)/error.h
 cd.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/quit.h 
$(topdir)/dispose_cmd.h
 cd.o: $(topdir)/make_cmd.h $(topdir)/subst.h $(topdir)/externs.h
@@ -591,6 +598,7 @@
 bind.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
 break.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
 caller.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
+set0.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
 cd.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
 common.c: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
 complete.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
diff -ruN bash-3.2-patched/builtins/set0.def bash-3.2-work/builtins/set0.def
--- bash-3.2-patched/builtins/set0.def  1970-01-01 09:00:00.000000000 +0900
+++ bash-3.2-work/builtins/set0.def     2008-09-17 20:31:42.000000000 +0900
@@ -0,0 +1,82 @@
+This file is caller.def, from which is created caller.c.  It implements the
+builtin "caller" in Bash.
+
+Copyright (C) 2008 Rocky Bernstein for 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 set0.c
+
+$BUILTIN set0
+$FUNCTION set0_builtin
+$DEPENDS_ON DEBUGGER
+$SHORT_DOC set0 STRING
+
+Set $0, the program name.
+$END
+
+#include <config.h>
+
+#include "../bashintl.h"
+
+#include "../shell.h"
+#include "common.h"
+
+#ifdef LOADABLE_BUILTIN
+#  include "builtins.h"
+#endif
+
+int 
+set0_builtin (WORD_LIST *list)
+{
+  /* Check parameters: there should be exactly one. */
+  if (list == 0) 
+    {
+      builtin_error (_("An argument (a variable name) is required."));
+      builtin_usage ();
+      return (EX_USAGE);
+    } 
+  else if (list->next) 
+    {
+      builtin_error (_("More than one argument passed; we want exactly one."));
+      builtin_usage ();
+      return (EX_USAGE);
+    }
+
+  if (dollar_vars[0])
+    free (dollar_vars[0]);
+  dollar_vars[0] = savestring(list->word->word);
+
+  return EXECUTION_SUCCESS;
+}
+
+#ifdef LOADABLE_BUILTIN
+static char *set0_doc[] = {
+  N_("Set $0, the program name."),
+  (char *)NULL
+};
+
+struct builtin set0_struct = {
+  "set0",              /* builtin name */
+  set0_builtin,                /* function implementing the builtin */
+  BUILTIN_ENABLED,     /* initial flags for builtin */
+  set0_doc,            /* array of long documentation strings. */
+  "set0 STRING",        /* usage synopsis; becomes short_doc */
+  0                    /* reserved for internal use */
+};
+
+#endif /* LOADABLE_BUILTIN */
diff -ruN bash-3.2-patched/doc/bash.1 bash-3.2-work/doc/bash.1
--- bash-3.2-patched/doc/bash.1 2008-09-10 15:39:53.000000000 +0900
+++ bash-3.2-work/doc/bash.1    2008-09-17 20:31:04.000000000 +0900
@@ -7863,6 +7863,9 @@
 The return status is always true unless an invalid option is encountered.
 .RE
 .TP
+\fBset0\fP \fIstring\fP
+Set \fB$0\fP, the program name.
+.TP
 \fBshift\fP [\fIn\fP]
 The positional parameters from \fIn\fP+1 ... are renamed to
 .B $1
diff -ruN bash-3.2-patched/doc/bashref.texi bash-3.2-work/doc/bashref.texi
--- bash-3.2-patched/doc/bashref.texi   2008-09-10 15:39:53.000000000 +0900
+++ bash-3.2-work/doc/bashref.texi      2008-09-17 20:34:18.000000000 +0900
@@ -2885,6 +2885,13 @@
 The return status is non-zero if @code{return} is used outside a function
 and not during the execution of a script by @code{.} or @code{source}.
 
address@hidden set0
address@hidden set0
address@hidden
+set0 @var{string}
address@hidden example
+Set @code{$0}, the program name.
+ 
 @item shift
 @btindex shift
 @example




reply via email to

[Prev in Thread] Current Thread [Next in Thread]