Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
ion
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
redox-os
ion
Commits
45d93b31
Commit
45d93b31
authored
6 years ago
by
stratact
Committed by
Michael Aaron Murphy
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix multiple variable assignments to the way humans think (Fixes
#774
)
parent
5549f842
No related branches found
No related tags found
1 merge request
!794
Fix multiple variable assignments to the way humans think (Fixes #774)
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib/shell/assignments.rs
+26
-12
26 additions, 12 deletions
src/lib/shell/assignments.rs
with
26 additions
and
12 deletions
src/lib/shell/assignments.rs
+
26
−
12
View file @
45d93b31
...
...
@@ -5,6 +5,7 @@ use itoa;
use
parser
::
assignments
::
*
;
use
shell
::
history
::
ShellHistory
;
use
std
::{
collections
::
HashMap
,
env
,
ffi
::
OsStr
,
fmt
::{
self
,
Display
},
io
::{
self
,
BufWriter
,
Write
},
mem
,
os
::
unix
::
ffi
::
OsStrExt
,
str
,
};
...
...
@@ -144,14 +145,15 @@ impl VariableStore for Shell {
}
fn
local
(
&
mut
self
,
action
:
LocalAction
)
->
i32
{
let
actions
=
match
action
{
let
mut
collected
:
HashMap
<&
str
,
ReturnValue
>
=
HashMap
::
new
();
let
(
actions_step1
,
actions_step2
)
=
match
action
{
LocalAction
::
List
=>
{
list_vars
(
&
self
);
return
SUCCESS
;
}
LocalAction
::
Assign
(
ref
keys
,
op
,
ref
vals
)
=>
AssignmentActions
::
new
(
keys
,
op
,
vals
),
LocalAction
::
Assign
(
ref
keys
,
op
,
ref
vals
)
=>
(
AssignmentActions
::
new
(
keys
,
op
.clone
(),
vals
),
AssignmentActions
::
new
(
keys
,
op
,
vals
)
)
,
};
for
action
in
actions
{
for
action
in
actions
_step1
{
match
action
{
Ok
(
Action
::
UpdateArray
(
key
,
Operator
::
Equal
,
expression
))
=>
{
match
value_check
(
self
,
&
expression
,
key
.kind
)
{
...
...
@@ -162,7 +164,7 @@ impl VariableStore for Shell {
if
key
.name
==
"HISTORY_IGNORE"
{
self
.update_ignore_patterns
(
&
values
);
}
self
.variables
.set_array
(
key
.name
,
values
)
collected
.insert
(
key
.name
,
ReturnValue
::
Vector
(
values
)
);
}
Err
(
why
)
=>
{
eprintln!
(
"ion: assignment error: {}: {}"
,
key
.name
,
why
);
...
...
@@ -178,25 +180,21 @@ impl VariableStore for Shell {
return
FAILURE
;
}
Ok
(
Action
::
UpdateString
(
key
,
operator
,
expression
))
=>
{
if
[
"HOME"
,
"PWD"
,
"MWD"
,
"SWD"
,
"?"
]
.contains
(
&
key
.name
)
{
if
[
"HOME"
,
"HOST"
,
"PWD"
,
"MWD"
,
"SWD"
,
"?"
]
.contains
(
&
key
.name
)
{
eprintln!
(
"ion: not allowed to set {}"
,
key
.name
);
return
FAILURE
;
}
match
value_check
(
self
,
&
expression
,
key
.kind
)
{
Ok
(
ReturnValue
::
Str
(
value
))
=>
{
let
key_name
:
&
str
=
&
key
.name
;
let
lhs
=
self
.variables
.get_var
(
key
_
name
)
.get_var
(
key
.
name
)
.unwrap_or_else
(||
String
::
from
(
"0"
));
let
lhs
=
&*
lhs
as
*
const
str
;
let
result
=
math
(
unsafe
{
&*
lhs
},
key
.kind
,
operator
,
&
value
,
|
value
|
{
self
.set_var
(
key_name
,
unsafe
{
str
::
from_utf8_unchecked
(
value
)
})
math
(
&
lhs
,
key
.kind
,
operator
,
&
value
,
|
value
|
{
collected
.insert
(
key
.name
,
ReturnValue
::
Str
(
unsafe
{
str
::
from_utf8_unchecked
(
value
)
}
.to_owned
()));
});
if
let
Err
(
why
)
=
result
{
...
...
@@ -218,6 +216,22 @@ impl VariableStore for Shell {
}
}
for
action
in
actions_step2
{
match
action
{
Ok
(
Action
::
UpdateArray
(
key
,
_
,
_
))
=>
{
if
let
ReturnValue
::
Vector
(
ref
values
)
=
collected
[
key
.name
]
{
self
.variables
.set_array
(
key
.name
,
(
*
values
)
.clone
());
}
}
Ok
(
Action
::
UpdateString
(
key
,
_
,
_
))
=>
{
if
let
ReturnValue
::
Str
(
ref
value
)
=
collected
[
key
.name
]
{
self
.set_var
(
key
.name
,
value
);
}
}
_
=>
unreachable!
(),
}
}
SUCCESS
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment