remove more useless mutability, fix warnings, remove features

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

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

Loading…
Cancel
Save