From 3d540d8a3daf41a1d856213c410bdb59f26ebfbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hozda?= Date: Tue, 18 Aug 2020 20:24:17 +0200 Subject: [PATCH] remove more useless mutability, fix warnings, remove features --- src/main.rs | 65 +++++++++++++++++++++-------------------------------- 1 file changed, 25 insertions(+), 40 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0307046..838a983 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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>(&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> = None; + let mut link: Option>; 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) { - let mut i: usize = 0; + pub unsafe fn view_bookmarks(&mut self, key: Option) { 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> = 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> = 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) -> libc::c_int { - let mut i: usize = 0; - let mut uri: String = String::new(); + pub unsafe fn init(&mut self, argc: usize, argv: Vec) -> 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 { 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 { +pub unsafe fn make_key(c1: char, c2: char, c3: char) -> Option { 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 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 = env::args().collect(); + let args: Vec = env::args().collect(); unsafe { exit(state.init(args.len() - 1, args) as i32) } }