Gentoo Archives: gentoo-commits

From: "Petteri Räty" <betelgeuse@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/libbash:master commit in: scripts/, src/core/, bashast/, test/
Date: Wed, 27 Apr 2011 15:12:01
Message-Id: 33d754abccf45c6144be7341dcccca03623ad418.betelgeuse@gentoo
1 commit: 33d754abccf45c6144be7341dcccca03623ad418
2 Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
3 AuthorDate: Mon Apr 25 10:03:39 2011 +0000
4 Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
5 CommitDate: Tue Apr 26 07:09:25 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=33d754ab
7
8 Walker: support special variables in var_ref
9
10 The syntax for special variables is now supported. Only $? has a
11 runtime now.
12
13 ---
14 bashast/libbashWalker.g | 6 ++++++
15 scripts/var_def.bash | 6 ++++++
16 scripts/var_def.bash.result | 6 ++++++
17 src/core/interpreter.h | 8 ++++++++
18 test/script_compiler.sh | 2 +-
19 5 files changed, 27 insertions(+), 1 deletions(-)
20
21 diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
22 index eec0218..11b4c19 100644
23 --- a/bashast/libbashWalker.g
24 +++ b/bashast/libbashWalker.g
25 @@ -268,6 +268,12 @@ var_ref [bool double_quoted] returns[std::string libbash_value]
26 else
27 walker->get_all_elements(libbash_string, $libbash_value);
28 }
29 + |^(VAR_REF TIMES) { std::cerr << "$* has not been implemented yet" << std::endl; }
30 + |^(VAR_REF AT) { std::cerr << "$@ has not been implemented yet" << std::endl; }
31 + |^(VAR_REF POUND) { std::cerr << "$# has not been implemented yet" << std::endl; }
32 + |^(VAR_REF QMARK) { $libbash_value = walker->get_status<std::string>(); }
33 + |^(VAR_REF MINUS) { std::cerr << "$- has not been implemented yet" << std::endl; }
34 + |^(VAR_REF BANG) { std::cerr << "$! has not been implemented yet" << std::endl; }
35 |^(VAR_REF libbash_string=var_expansion) { $libbash_value = libbash_string; };
36
37 command
38
39 diff --git a/scripts/var_def.bash b/scripts/var_def.bash
40 index 56f8f8d..9b27dc3 100644
41 --- a/scripts/var_def.bash
42 +++ b/scripts/var_def.bash
43 @@ -35,3 +35,9 @@ ARRAY10="${ARRAY05[*]}"
44 FOO001="networkmanager"
45 FOO002="0.8.2"
46 FOO003=${FOO001}-${FOO002}
47 +FOO004=$*
48 +FOO004=$@
49 +FOO004=$#
50 +FOO004=$?
51 +FOO004=$-
52 +FOO004=$!
53
54 diff --git a/scripts/var_def.bash.result b/scripts/var_def.bash.result
55 index 292b9c7..e840ebe 100644
56 --- a/scripts/var_def.bash.result
57 +++ b/scripts/var_def.bash.result
58 @@ -1,3 +1,8 @@
59 +$* has not been implemented yet
60 +$@ has not been implemented yet
61 +$# has not been implemented yet
62 +$- has not been implemented yet
63 +$! has not been implemented yet
64 ARRAY01=1 2 3 4 5
65 ARRAY02=1 2 4 5
66 ARRAY03=2 3
67 @@ -18,6 +23,7 @@ EMPTY_ARRAY=
68 FOO001=networkmanager
69 FOO002=0.8.2
70 FOO003=networkmanager-0.8.2
71 +FOO004=
72 HOMEPAGE=http://sunpinyin.googlecode.com
73 IUSE=
74 KEYWORDS=~amd64 ~x86
75
76 diff --git a/src/core/interpreter.h b/src/core/interpreter.h
77 index 9d14f7d..5a90e53 100644
78 --- a/src/core/interpreter.h
79 +++ b/src/core/interpreter.h
80 @@ -485,6 +485,14 @@ public:
81 set_value("?", status);
82 }
83
84 + /// \brief get the return status of the last command
85 + /// \param the value of the return status
86 + template <typename T=int>
87 + T get_status(void)
88 + {
89 + return resolve<T>("?");
90 + }
91 +
92 /// \brief define a new global variable
93 /// \param the name of the variable
94 /// \param the value of the variable
95
96 diff --git a/test/script_compiler.sh b/test/script_compiler.sh
97 index d409673..021855e 100755
98 --- a/test/script_compiler.sh
99 +++ b/test/script_compiler.sh
100 @@ -4,7 +4,7 @@ declare -i error=0
101
102 for script in $@
103 do
104 - ./variable_printer $script | diff -u $script.result -
105 + ./variable_printer $script 2>&1 | diff -u $script.result -
106 error+=$?
107 done