Hello maintainers,

I've encountered bug that fish scripts cannot receive arguments. The
following is my patch. Please review it. Also you can cherry-pick it
from http://gitorious.org/~grissiom/fish-shell/grissioms-fish-shell ;)

=============================================
>From 27df727ca11dfeac74214609771eacfccd4d5c08 Mon Sep 17 00:00:00 2001
From: Grissiom <[email protected]>
Date: Sun, 3 Oct 2010 11:46:26 +0800
Subject: [PATCH] don't parse the options that should be passed to fish scripts

This commit makes fish_parse_opt stop at first non-option argument,
which expected as fish script name and pass the remaining argument to
that script. I also updated the test cases.
---
 .gitignore       |    4 +---
 fish.c           |    8 ++++----
 tests/test.fish  |   37 +++++++++++++++++++++++++++++++++++++
 tests/top.err    |    6 ++++++
 tests/top.out    |    6 ++++++
 tests/top.status |    1 +
 6 files changed, 55 insertions(+), 7 deletions(-)
 create mode 100644 tests/top.err
 create mode 100644 tests/top.out
 create mode 100644 tests/top.status

diff --git a/.gitignore b/.gitignore
index 43bbc2c..db57763 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,7 +29,5 @@ share/man/
 toc.txt
 user_doc/
 xsel-0.9.6/
-tests/tmp.out
-tests/tmp.err
-tests/tmp.status
+tests/*tmp.*
 tests/foo.txt
diff --git a/fish.c b/fish.c
index 459eb27..062c9a7 100644
--- a/fish.c
+++ b/fish.c
@@ -66,7 +66,7 @@ Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA  02111-1307, USA.
 /**
    The string describing the single-character options accepted by the
main fish binary
 */
-#define GETOPT_STRING "hilnvc:p:d:"
+#define GETOPT_STRING "+hilnvc:p:d:"

 /**
    Parse init files
@@ -328,7 +328,7 @@ int main( int argc, char **argv )
                        else
                        {
                                char **ptr;
-                               char *file = *(argv+1);
+                               char *file = *(argv+(my_optind++));
                                int i;
                                string_buffer_t sb;
                                int fd;
@@ -340,11 +340,11 @@ int main( int argc, char **argv )
                                        return 1;
                                }

-                               if( *(argv+2))
+                               if( *(argv+my_optind))
                                {
                                        sb_init( &sb );

-                                       for( i=1,ptr = argv+2; *ptr;
i++, ptr++ )
+                                       for( i=1,ptr = argv+my_optind;
*ptr; i++, ptr++ )
                                        {
                                                if( i != 1 )
                                                        sb_append(
&sb, ARRAY_SEP_STR );
diff --git a/tests/test.fish b/tests/test.fish
index 74e562b..610c966 100755
--- a/tests/test.fish
+++ b/tests/test.fish
@@ -4,6 +4,43 @@
 # instad of using autotest to provide additional
 # testing for fish. :-)

+
+if [ "$argv" != '-n' ]
+  # begin...end has bug in error redirecting...
+  begin
+    ../fish -n ./test.fish ^top.tmp.err
+    ../fish -n ./test.fish -n ^^top.tmp.err
+    ../fish ./test.fish -n ^^top.tmp.err
+  end | tee top.tmp.out
+  echo $status >top.tmp.status
+  set res ok
+  if diff top.tmp.out top.out >/dev/null
+  else
+       set res fail
+       echo Output differs for file test.fish
+  end
+
+  if diff top.tmp.err top.err >/dev/null
+  else
+       set res fail
+       echo Error output differs for file test.fish
+  end
+
+  if test (cat top.tmp.status) = (cat top.status)
+  else
+       set res fail
+       echo Exit status differs for file test.fish
+  end
+
+  if test $res = ok;
+       echo File test.fish tested ok
+  else
+       echo File test.fish failed tests
+  end;
+
+  exit
+end
+
 echo Testing high level script functionality

 for i in *.in
diff --git a/tests/top.err b/tests/top.err
new file mode 100644
index 0000000..73a623c
--- /dev/null
+++ b/tests/top.err
@@ -0,0 +1,6 @@
+fish: Expected redirection specification, got token of type '$i'
+/usr/local/src/grissioms-fish-shell/tests/test.fish (line 51):
../fish <$i >tmp.out ^tmp.err
+                                                                          ^
+fish: Expected redirection specification, got token of type '$i'
+/usr/local/src/grissioms-fish-shell/tests/test.fish (line 51):
../fish <$i >tmp.out ^tmp.err
+                                                                          ^
diff --git a/tests/top.out b/tests/top.out
new file mode 100644
index 0000000..c3a60ba
--- /dev/null
+++ b/tests/top.out
@@ -0,0 +1,6 @@
+Testing high level script functionality
+File test1.in tested ok
+File test2.in tested ok
+File test3.in tested ok
+File test4.in tested ok
+File test5.in tested ok
diff --git a/tests/top.status b/tests/top.status
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/tests/top.status
@@ -0,0 +1 @@
+0
-- 
1.7.1
=============================================

-- 
Cheers,
Grissiom

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to