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
Package Registry
Container Registry
Model registry
Operate
Terraform modules
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
Enzo Cioppettini
ion
Commits
02f8587f
Commit
02f8587f
authored
9 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
Fix env::args to match libstd
parent
fc2fc688
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.rs
+22
-5
22 additions, 5 deletions
main.rs
to_num.rs
+59
-0
59 additions, 0 deletions
to_num.rs
with
81 additions
and
5 deletions
main.rs
+
22
−
5
View file @
02f8587f
...
...
@@ -8,7 +8,10 @@ use std::io::{Read, Write};
use
std
::
env
;
use
std
::
time
::
Duration
;
use
std
::
process
;
use
std
::
to_num
::
ToNum
;
use
self
::
to_num
::
ToNum
;
pub
mod
to_num
;
macro_rules!
readln
{
()
=>
({
...
...
@@ -72,7 +75,7 @@ impl<'a> Command<'a> {
main
:
Box
::
new
(|
args
:
&
Vec
<
String
>
|
{
match
args
.get
(
1
)
{
Some
(
path
)
=>
{
if
!
env
::
set_current_dir
(
&
path
)
{
if
env
::
set_current_dir
(
&
path
)
.is_err
()
{
println!
(
"Bad path: {}"
,
path
);
}
}
...
...
@@ -618,9 +621,16 @@ impl<'a> Application<'a> {
/// Run the application
pub
fn
main
(
&
mut
self
)
{
println!
(
"Type help for a command list"
);
if
let
Some
(
arg
)
=
env
::
args
()
.get
(
1
)
{
for
arg
in
env
::
args
()
.skip
(
1
)
{
let
cwd
=
match
env
::
current_dir
()
{
Ok
(
path
)
=>
format!
(
"{}"
,
&
path
),
Err
(
_
)
=>
"?"
.to_string
()
};
let
command
=
"run "
.to_string
()
+
arg
;
println!
(
"user@redox:{}# {}"
,
&
env
::
current_dir
()
.unwrap_or
(
"?"
.to_string
()),
command
);
println!
(
"user@redox:{}# {}"
,
cwd
,
command
);
self
.on_command
(
&
command
);
}
...
...
@@ -632,7 +642,14 @@ impl<'a> Application<'a> {
print!
(
"- "
);
}
}
print!
(
"user@redox:{}# "
,
&
env
::
current_dir
()
.unwrap_or
(
"?"
.to_string
()));
let
cwd
=
match
env
::
current_dir
()
{
Ok
(
path
)
=>
format!
(
"{}"
,
&
path
),
Err
(
_
)
=>
"?"
.to_string
()
};
print!
(
"user@redox:{}# "
,
cwd
);
if
let
Some
(
command_original
)
=
readln!
()
{
let
command
=
command_original
.trim
();
if
command
==
"exit"
{
...
...
This diff is collapsed.
Click to expand it.
to_num.rs
0 → 100644
+
59
−
0
View file @
02f8587f
//! Types convertable to integers
/// Parse the string to a integer using a given radix
pub
trait
ToNum
{
fn
to_num_radix
(
&
self
,
radix
:
usize
)
->
usize
;
fn
to_num_radix_signed
(
&
self
,
radix
:
usize
)
->
isize
;
fn
to_num
(
&
self
)
->
usize
;
fn
to_num_signed
(
&
self
)
->
isize
;
}
impl
ToNum
for
str
{
fn
to_num_radix
(
&
self
,
radix
:
usize
)
->
usize
{
if
radix
==
0
{
return
0
;
}
let
mut
num
=
0
;
for
c
in
self
.chars
()
{
let
digit
;
if
c
>=
'0'
&&
c
<=
'9'
{
digit
=
c
as
usize
-
'0'
as
usize
}
else
if
c
>=
'A'
&&
c
<=
'Z'
{
digit
=
c
as
usize
-
'A'
as
usize
+
10
}
else
if
c
>=
'a'
&&
c
<=
'z'
{
digit
=
c
as
usize
-
'a'
as
usize
+
10
}
else
{
break
;
}
if
digit
>=
radix
{
break
;
}
num
*=
radix
;
num
+=
digit
;
}
num
}
/// Parse the string as a signed integer using a given radix
fn
to_num_radix_signed
(
&
self
,
radix
:
usize
)
->
isize
{
if
self
.starts_with
(
'-'
)
{
-
(
self
[
1
..
]
.to_num_radix
(
radix
)
as
isize
)
}
else
{
self
.to_num_radix
(
radix
)
as
isize
}
}
/// Parse it as a unsigned integer in base 10
fn
to_num
(
&
self
)
->
usize
{
self
.to_num_radix
(
10
)
}
/// Parse it as a signed integer in base 10
fn
to_num_signed
(
&
self
)
->
isize
{
self
.to_num_radix_signed
(
10
)
}
}
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