@@ -22,10 +22,6 @@ INCLUDE_SEEN_PSST="${INCLUDE_SEEN_PSST-} _stack.inc.sh_"
22
22
# newValue: Value to push on stack.
23
23
# stackName: Name of the stack (no spaces, only letters and underscore).
24
24
#
25
- # RETURNS
26
- # 0: Success.
27
- # 1: Value could not be pushed to stack.
28
- #
29
25
# SAMPLE
30
26
# stack_push_psst "$value" "someStackName"
31
27
#
@@ -42,25 +38,19 @@ stack_push_psst()
42
38
# stackName=$2
43
39
44
40
# shellcheck disable=SC2034 # It is used but only indirect by eval
45
- _stackCountName_psst=" ${2} __stackCount_psst"
41
+ _countName_stack_psst=" ${2} __count_stack_psst"
42
+ eval " _count_stack_psst=\$ {$_countName_stack_psst -0}"
46
43
47
- eval " _stackCount_psst=\$ {$_stackCountName_psst -}"
48
- if [ -z " $_stackCount_psst " ]
49
- then
50
- _stackCount_psst=0
51
- fi
52
-
53
- _stackItemName_psst=" ${2} __$_stackCount_psst "
54
- _stackItemName_psst=" ${_stackItemName_psst} __stackItem_psst"
55
- _stackCount_psst=$(( _stackCount_psst + 1 ))
44
+ _itemName_stack_psst=" ${2} __${_count_stack_psst} _item_stack_psst"
45
+ _count_stack_psst=$(( _count_stack_psst + 1 ))
56
46
57
- eval " $_stackItemName_psst =\"\$ 1\" "
58
- eval " $_stackCountName_psst = $_stackCount_psst "
47
+ eval " $_itemName_stack_psst =\"\$ 1\" "
48
+ eval " $_countName_stack_psst = $_count_stack_psst "
59
49
60
50
unset _stackName_psst
61
- unset _stackCountName_psst
62
- unset _stackCount_psst
63
- unset _stackItemName_psst
51
+ unset _countName_stack_psst
52
+ unset _count_stack_psst
53
+ unset _itemName_stack_psst
64
54
}
65
55
66
56
@@ -80,7 +70,7 @@ stack_push_psst()
80
70
#
81
71
# RETURNS
82
72
# 0: Success.
83
- # 1 : No stack with that name has been found.
73
+ # 2 : No stack with that name has been found.
84
74
#
85
75
# SAMPLE
86
76
# if stack_pop_psst "someStackName" myResultVar
@@ -102,35 +92,33 @@ stack_pop_psst()
102
92
# resultVarName=$2
103
93
104
94
# shellcheck disable=SC2034 # It is used but only indirect by eval
105
- _stackCountName_psst =" ${1} __stackCount_psst "
106
- eval " _stackCount_psst =\$ {$_stackCountName_psst -}"
95
+ _countName_stack_psst =" ${1} __count_stack_psst "
96
+ eval " _count_stack_psst =\$ {$_countName_stack_psst -}"
107
97
108
- if [ -z " $_stackCount_psst " ]
98
+ if [ -z " $_count_stack_psst " ]
109
99
then
110
100
# Clean up and report error
111
- unset _stackCountName_psst
112
- unset _stackCount_psst
113
- return 1
101
+ unset _countName_stack_psst
102
+ unset _count_stack_psst
103
+ return 2
114
104
fi
115
105
116
- _stackCount_psst=$(( _stackCount_psst - 1 ))
117
-
118
- _stackItemName_psst=" ${1} __$_stackCount_psst "
119
- _stackItemName_psst=" ${_stackItemName_psst} __stackItem_psst"
106
+ _count_stack_psst=$(( _count_stack_psst - 1 ))
107
+ _itemName_stack_psst=" ${1} __${_count_stack_psst} _item_stack_psst"
120
108
121
- eval " $2 =\"\$ $_stackItemName_psst \" "
122
- unset " $_stackItemName_psst "
109
+ eval " $2 =\"\$ $_itemName_stack_psst \" "
110
+ unset " $_itemName_stack_psst "
123
111
124
- if [ $_stackCount_psst -eq 0 ]
112
+ if [ $_count_stack_psst -eq 0 ]
125
113
then
126
- unset " $_stackCountName_psst "
114
+ unset " $_countName_stack_psst "
127
115
else
128
- eval " $_stackCountName_psst = $_stackCount_psst "
116
+ eval " $_countName_stack_psst = $_count_stack_psst "
129
117
fi
130
118
131
- unset _stackCountName_psst
132
- unset _stackCount_psst
133
- unset _stackItemName_psst
119
+ unset _countName_stack_psst
120
+ unset _count_stack_psst
121
+ unset _itemName_stack_psst
134
122
}
135
123
136
124
@@ -147,7 +135,7 @@ stack_pop_psst()
147
135
#
148
136
# RETURNS
149
137
# 0: Stack does exist.
150
- # 1 : Stack does not exist.
138
+ # 2 : Stack does not exist.
151
139
#
152
140
# SAMPLE
153
141
# if stack_exists_psst "someStackName"
@@ -161,18 +149,18 @@ stack_exists_psst()
161
149
# variables in the main shell. Thus we need to be careful to not conflict
162
150
# when defining local variables.
163
151
164
- _stackCountName_psst =" ${1} __stackCount_psst "
165
- eval " _stackCount_psst =\$ {$_stackCountName_psst -}"
166
- unset _stackCountName_psst
152
+ _countName_stack_psst =" ${1} __count_stack_psst "
153
+ eval " _count_stack_psst =\$ {$_countName_stack_psst -}"
154
+ unset _countName_stack_psst
167
155
168
156
# stackName=$1
169
157
170
- if [ -n " ${_stackCount_psst -} " ]
158
+ if [ -n " ${_count_stack_psst -} " ]
171
159
then
172
- unset _stackCount_psst
160
+ unset _count_stack_psst
173
161
return 0
174
162
fi
175
163
176
- unset _stackCount_psst
177
- return 1
164
+ unset _count_stack_psst
165
+ return 2
178
166
}
0 commit comments