Christopher Faylor <[EMAIL PROTECTED]> writes:

>>   - add debugging feature: drop to shell upon failure
>
> I normally run mknetrel in the background.  In fact, I just added a
> couple of options to accommodate this.  They would conflict with this
> patch.

Ok.

> If you want to add this functionality, introduce an option.  I don't
> want to have this as the default.

Sure, that's inconvenient.  I thought about adding it to -x, but you
may well want to have a detailed, noninteractive log, at times.  So,
I decided to add -X option for this.

Also, I made -h exit successfully, not to annoy you or anything, saw
you were messing with this too.  Hope you like the way I did it.  I
thought about adding a help () funtion, but decided that would be
overkill.

What I really think we should also do, is to start the script with

    set -e

and let bash decide when something's wrong.  Then we can rid of stuff
like:

    mkdir foo || exit 1

It is annoying that you'll have to add '|| true' clauses to some
checks that are allowed to fail, but in general, I feel that a bourn
script *should* start with set -e.  Any sane interpreter stops upon
error.  What do you think?

Greetings,
Jan.

Btw: A very silly question, but I can't seem to get `cvs diff' to
     respect your (Cygwin's?) wishes of excluding the ChangeLog from
     the diff.  It doesn't grok -X,--exclude options, most annoying.
     How do you manage?

2002-07-09  Jan Nieuwenhuizen  <[EMAIL PROTECTED]>

        * bin/mknetrel: Invoke atexit () before exiting.
        (atexit): New function.
        (drop): New funtion.
        (usage): Return (previously: exit unsuccessfully).
        (setup): Add -X option to make mknetrel drop to shell upon error.
        Exit successfully for -h, unsuccessfully upon usage error.
        (setup1): Exit unsuccessfully upon usage error.
        
        * .cvsignore: Add .bash_mknetrel.

? pats
Index: .cvsignore
===================================================================
RCS file: /cvs/cygwin-apps/mknetrel/.cvsignore,v
retrieving revision 1.2
diff -p -u -r1.2 .cvsignore
--- .cvsignore  9 Jul 2002 03:32:14 -0000       1.2
+++ .cvsignore  9 Jul 2002 12:06:38 -0000
@@ -4,6 +4,7 @@ Makefile
 #*
 *.swp
 .cvsignore
+.bash_mknetrel
 build
 inst
 log
Index: ChangeLog
===================================================================
RCS file: /cvs/cygwin-apps/mknetrel/ChangeLog,v
retrieving revision 1.14
diff -p -u -r1.14 ChangeLog
--- ChangeLog   9 Jul 2002 06:01:59 -0000       1.14
+++ ChangeLog   9 Jul 2002 12:06:38 -0000
@@ -1,3 +1,15 @@
+2002-07-09  Jan Nieuwenhuizen  <[EMAIL PROTECTED]>
+
+       * bin/mknetrel: Invoke atexit () before exiting.
+       (atexit): New function.
+       (drop): New funtion.
+       (usage): Return (previously: exit unsuccessfully).
+       (setup): Add -X option to make mknetrel drop to shell upon error.
+       Exit successfully for -h, unsuccessfully upon usage error.
+       (setup1): Exit unsuccessfully upon usage error.
+       
+       * .cvsignore: Add .bash_mknetrel.
+
 2002-07-09  Christopher Faylor  <[EMAIL PROTECTED]>
 
        * bin/mknetrel (doconfig): Fix more quoting problems.
Index: bin/mknetrel
===================================================================
RCS file: /cvs/cygwin-apps/mknetrel/bin/mknetrel,v
retrieving revision 1.33
diff -p -u -r1.33 mknetrel
--- bin/mknetrel        9 Jul 2002 06:32:17 -0000       1.33
+++ bin/mknetrel        9 Jul 2002 12:06:38 -0000
@@ -32,6 +32,24 @@ read_user_config() {
     export knownpath
 }
 
+atexit () { :; }
+
+trap atexit 0 9 15
+
+# Interactive shell with state of bash at exit upon failure
+drop ()
+{
+    [ "$?" -eq 0 ] && trap - 0 9 15 && exit 0 || true
+    echo "$0: dropping to shell..."
+    set | sed -e 's/^\(BASH_VERSINFO=\)/#\1/' \
+       -e 's/^\(EUID=\)/#\1/' \
+       -e 's/^\(PPID=\)/#\1/' \
+       -e 's/^\(SHELLOPTS=\)/#\1/' \
+       -e 's/^\(UID=\)/#\1/' > .bash_mknetrel
+    echo "PS1='mknetrel-debug \w$ '" >> .bash_mknetrel
+    exec bash --rcfile .bash_mknetrel
+}
+
 setvars() {
     cd $netrel_root || exit 1
     here=`pwd`
@@ -86,19 +104,20 @@ setup() {
     read_user_config
     clean=false
     opt="-O2"
-    while getopts 'ihtbcCgNnxSoB' o; do
+    while getopts 'ihtbcCgNnxXSoB' o; do
        case "$o" in
            'b') rebuild() { dorebuild; } ;;
            'B') background() { return 0;}; output() { return 0;} ;;
            'c') config() { doconfig; }; rebuild() { dorebuild; } ;;
            'C') clean=: ;;
            'g') opt="-O2 -g"; rebuild() { dorebuild; } ;;
-           'h') usage ;;
+           'h') usage; exit 0;;
            'i') knownpath= ;;
            'n') mkdist() { :; } ;;
            'o') output() { return 0; } ;;
            'S') stripbins() { return 1; } ;;
            'x') verbose() { set -x; } ;;
+           'X') atexit() { drop; } ;;
            '?') exit 1 ;;
        esac
     done
@@ -107,6 +126,7 @@ setup() {
     what=$1
     if [ -z "$what" ]; then
        usage "missing package name"
+       exit 1
     fi
     setvars $what
 
@@ -122,6 +142,7 @@ setup1() {
     export PATH
     if [ -z "$what" ]; then
        usage "missing package name"
+       exit 1
     fi
 
     [ -d "$build" ] || clean=:
@@ -324,8 +345,8 @@ usage() {
  -o  Redirect output to $mknetrel_root/log/*.out
  -S  Don't strip binaries
  -t  Tag sourceware with release info
- -x  Verbose shell output"
-    exit 1
+ -x  Verbose shell output
+ -X  Drop to a shell upon error"
 }
 
 rest() {
        
-- 
Jan Nieuwenhuizen <[EMAIL PROTECTED]> | GNU LilyPond - The music typesetter
http://www.xs4all.nl/~jantien       | http://www.lilypond.org

Reply via email to