remove more useless mutability, fix warnings, remove features

master
Lukáš Hozda 4 years ago
parent a78cd07095
commit 3d540d8a3d

@ -1,16 +1,5 @@
#![allow(
dead_code,
mutable_transmutes,
non_camel_case_types,
non_snake_case,
non_upper_case_globals,
unused_assignments,
unused_mut
)]
#![register_tool(c2rust)]
#![feature(const_raw_ptr_to_usize_cast, extern_types, main, register_tool)]
extern crate libc;
#![feature(main)]
extern crate tempfile;
extern crate simple_input;
@ -113,7 +102,7 @@ impl BrowserState {
}
pub unsafe fn load_config<P: AsRef<Path>>(&mut self, filename: P) {
let mut file = match File::open(filename) {
let file = match File::open(filename) {
Ok(f) => BufReader::new(f),
Err(_) => {
return;
@ -143,7 +132,7 @@ impl BrowserState {
if self.config.verbose {
eprintln!("downloading [{}]...", selector);
}
let mut stream = dial(&host, port, selector);
let stream = dial(&host, port, selector);
if stream.is_none() {
eprintln!("error: downloading [{}] failed", selector);
return false;
@ -198,7 +187,7 @@ impl BrowserState {
if host.is_empty() || port == 0 || selector.is_empty() {
return;
}
let mut link = Link {
let link = Link {
which: Some(which as u8 as char),
key: self.link_key,
host,
@ -220,7 +209,7 @@ impl BrowserState {
}
pub unsafe fn add_history(&mut self) {
let mut link: Link = Link {
let link: Link = Link {
which: None,
key: 0,
host: self.current_host.clone(),
@ -368,7 +357,7 @@ impl BrowserState {
) {
let mut filename: String =
Path::new(selector).file_name().unwrap_or_default().to_string_lossy().into();
let mut line: String = match input(&format!(
let line: String = match input(&format!(
"enter filename for download [{}]: ",
filename
))
@ -416,7 +405,7 @@ impl BrowserState {
let mut a: char = '\0';
let mut b: char = '\0';
let mut c: char = '\0';
let mut link: Option<Box<Link>> = None;
let mut link: Option<Box<Link>>;
if self.history.is_none() {
println!("(empty history)");
return;
@ -451,15 +440,13 @@ impl BrowserState {
};
}
pub unsafe fn view_bookmarks(&mut self, mut key: Option<usize>) {
let mut i: usize = 0;
pub unsafe fn view_bookmarks(&mut self, key: Option<usize>) {
let mut a: char = '\0';
let mut b: char = '\0';
let mut c: char = '\0';
if key.is_none() {
println!("(bookmarks)");
i = 0;
for bookmark in &self.bookmarks {
for (i, bookmark) in self.bookmarks.iter().enumerate() {
make_key_str(i, &mut a, &mut b, &mut c);
println!("{}{}{} {}", a, b, c, bookmark);
}
@ -501,7 +488,7 @@ impl BrowserState {
}
}
pub unsafe fn follow_link(&mut self, mut key: usize) -> bool {
pub unsafe fn follow_link(&mut self, key: usize) -> bool {
let mut link: Option<Box<Link>> = self.links.clone();
while let Some(ref l) = link {
@ -569,7 +556,7 @@ impl BrowserState {
return false;
}
pub unsafe fn download_link(&mut self, mut key: usize) {
pub unsafe fn download_link(&mut self, key: usize) {
let mut link: Option<Box<Link>> = self.links.clone();
while let Some(l) = link {
if (*l).key != key {
@ -626,14 +613,12 @@ impl BrowserState {
true
}
pub unsafe fn init(&mut self, mut argc: usize, mut argv: Vec<String>) -> libc::c_int {
let mut i: usize = 0;
let mut uri: String = String::new();
pub unsafe fn init(&mut self, argc: usize, argv: Vec<String>) -> i32 {
let mut i: usize = 1;
/* copy defaults */
self.init_config();
uri = self.config.start_uri.clone();
let mut uri: String = self.config.start_uri.clone();
/* parse command line */
i = 1;
while i < argc {
if argv[i].chars().next() == Some('-') {
match argv[i].chars().skip(1).next() {
@ -754,9 +739,9 @@ pub fn banner(to_error: bool) {
}
pub unsafe fn dial(
mut host: &str,
mut port: u16,
mut selector: &str,
host: &str,
port: u16,
selector: &str,
) -> Option<TcpStream> {
let mut stream = match TcpStream::connect((host, port)) {
Ok(s) => s,
@ -774,7 +759,7 @@ pub unsafe fn dial(
Some(stream)
}
pub unsafe fn make_key(mut c1: char, mut c2: char, mut c3: char) -> Option<usize> {
pub unsafe fn make_key(c1: char, c2: char, c3: char) -> Option<usize> {
if c1 == '\0' || c2 == '\0' {
return None;
}
@ -794,10 +779,10 @@ pub unsafe fn make_key(mut c1: char, mut c2: char, mut c3: char) -> Option<usize
}
}
pub unsafe fn make_key_str(
mut key: usize,
mut c1: &mut char,
mut c2: &mut char,
mut c3: &mut char,
key: usize,
c1: &mut char,
c2: &mut char,
c3: &mut char,
) {
if key
< ('z' as usize - 'a' as usize + 1 as usize)
@ -830,7 +815,7 @@ pub unsafe fn is_valid_directory_entry(kind: char) -> bool {
}
}
pub unsafe fn view_telnet(mut host: &str, mut port: u16) {
pub unsafe fn view_telnet(host: &str, port: u16) {
println!("executing: telnet {} {}", host, port);
// TODO check stdio
@ -847,6 +832,6 @@ pub unsafe fn view_telnet(mut host: &str, mut port: u16) {
#[main]
pub fn main() {
let mut state = BrowserState::new();
let mut args: Vec<String> = env::args().collect();
let args: Vec<String> = env::args().collect();
unsafe { exit(state.init(args.len() - 1, args) as i32) }
}

Loading…
Cancel
Save