remove unnecessary mutability, replace c_int with bool in view_directory

master
Lukáš Hozda 4 years ago
parent 515d53bb97
commit a78cd07095

@ -135,10 +135,10 @@ impl BrowserState {
pub unsafe fn download_file( pub unsafe fn download_file(
&mut self, &mut self,
mut host: &str, host: &str,
mut port: u16, port: u16,
mut selector: &str, selector: &str,
mut file: &mut File, file: &mut File,
) -> bool { ) -> bool {
if self.config.verbose { if self.config.verbose {
eprintln!("downloading [{}]...", selector); eprintln!("downloading [{}]...", selector);
@ -165,9 +165,9 @@ impl BrowserState {
pub unsafe fn download_temp( pub unsafe fn download_temp(
&mut self, &mut self,
mut host: &str, host: &str,
mut port: u16, port: u16,
mut selector: &str, selector: &str,
) -> bool { ) -> bool {
let mut tmpfile = match NamedTempFile::new() { let mut tmpfile = match NamedTempFile::new() {
Ok(f) => f, Ok(f) => f,
@ -186,11 +186,11 @@ impl BrowserState {
pub unsafe fn add_link( pub unsafe fn add_link(
&mut self, &mut self,
mut which: char, which: char,
mut name: String, name: String,
mut host: String, host: String,
mut port: u16, port: u16,
mut selector: String, selector: String,
) { ) {
let mut a: char = '\0'; let mut a: char = '\0';
let mut b: char = '\0'; let mut b: char = '\0';
@ -283,10 +283,10 @@ impl BrowserState {
pub unsafe fn view_directory( pub unsafe fn view_directory(
&mut self, &mut self,
mut host: &str, host: &str,
mut port: u16, port: u16,
mut selector: &str, selector: &str,
mut make_current: libc::c_int, make_current: bool,
) { ) {
let stream = dial(&host, port, selector); let stream = dial(&host, port, selector);
let mut buffer = String::new(); let mut buffer = String::new();
@ -297,7 +297,7 @@ impl BrowserState {
}; };
/* only adapt current prompt when successful */ /* only adapt current prompt when successful */
/* make history entry */ /* make history entry */
if make_current != 0 { if make_current {
self.add_history(); self.add_history();
} }
/* don't overwrite the current_* things... */ /* don't overwrite the current_* things... */
@ -331,10 +331,10 @@ impl BrowserState {
pub unsafe fn view_file( pub unsafe fn view_file(
&mut self, &mut self,
mut cmd: &str, cmd: &str,
mut host: &str, host: &str,
mut port: u16, port: u16,
mut selector: &str, selector: &str,
) { ) {
if !self.download_temp(host, port, selector) { if !self.download_temp(host, port, selector) {
return; return;
@ -362,9 +362,9 @@ impl BrowserState {
pub unsafe fn view_download( pub unsafe fn view_download(
&mut self, &mut self,
mut host: &str, host: &str,
mut port: u16, port: u16,
mut selector: &str, selector: &str,
) { ) {
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();
@ -390,16 +390,16 @@ impl BrowserState {
}; };
// O_CREAT, O_NOCTTY, O_WRONLY, O_EXCL // O_CREAT, O_NOCTTY, O_WRONLY, O_EXCL
if !self.download_file(host, port, selector, &mut file) { if !self.download_file(host, port, selector, &mut file) {
println!("error: eunable to download [{}]", selector); println!("error: unable to download [{}]", selector);
fs::remove_file(filename).expect("failed to delete file"); fs::remove_file(filename).expect("failed to delete file");
} }
} }
pub unsafe fn view_search( pub unsafe fn view_search(
&mut self, &mut self,
mut host: &str, host: &str,
mut port: u16, port: u16,
mut selector: &str, selector: &str,
) { ) {
let search_selector: String = match input("enter search string: ").as_str() { let search_selector: String = match input("enter search string: ").as_str() {
"" => { "" => {
@ -408,10 +408,10 @@ impl BrowserState {
} }
s => format!("{}\t{}", selector, s), s => format!("{}\t{}", selector, s),
}; };
self.view_directory(host, port, &search_selector, 1 as libc::c_int); self.view_directory(host, port, &search_selector, true);
} }
pub unsafe fn view_history(&mut self, mut key: Option<usize>) { pub unsafe fn view_history(&mut self, key: Option<usize>) {
let mut history_key: usize = 0; let mut history_key: usize = 0;
let mut a: char = '\0'; let mut a: char = '\0';
let mut b: char = '\0'; let mut b: char = '\0';
@ -440,7 +440,7 @@ impl BrowserState {
&(*l).host, &(*l).host,
(*l).port, (*l).port,
&(*l).selector, &(*l).selector,
0 as libc::c_int, false,
); );
return; return;
} }
@ -471,7 +471,7 @@ impl BrowserState {
&self.parsed_host.clone(), &self.parsed_host.clone(),
self.parsed_port.clone(), self.parsed_port.clone(),
&self.parsed_selector.clone(), &self.parsed_selector.clone(),
0 as libc::c_int, false,
); );
} else { } else {
println!("invalid gopher URI: {}", bookmark,); println!("invalid gopher URI: {}", bookmark,);
@ -492,7 +492,7 @@ impl BrowserState {
&(*h).host, &(*h).host,
(*h).port, (*h).port,
&(*h).selector, &(*h).selector,
0 as libc::c_int, false,
); );
} }
/* history is history... :) */ /* history is history... :) */
@ -522,7 +522,7 @@ impl BrowserState {
&(*l).host, &(*l).host,
(*l).port, (*l).port,
&(*l).selector, &(*l).selector,
1 as libc::c_int, true,
); );
} }
'7' => { '7' => {
@ -664,7 +664,7 @@ impl BrowserState {
&self.parsed_host.clone(), &self.parsed_host.clone(),
self.parsed_port.clone(), self.parsed_port.clone(),
&self.parsed_selector.clone(), &self.parsed_selector.clone(),
0 as libc::c_int, false,
); /* to display the prompt */ ); /* to display the prompt */
loop { loop {
// todo color prompt // todo color prompt
@ -685,7 +685,7 @@ impl BrowserState {
&self.current_host.clone(), &self.current_host.clone(),
self.current_port, self.current_port,
&self.current_selector.clone(), &self.current_selector.clone(),
0 as libc::c_int, false,
); );
} }
Some('.') => { Some('.') => {
@ -711,7 +711,7 @@ impl BrowserState {
&self.parsed_host.clone(), &self.parsed_host.clone(),
self.parsed_port.clone(), self.parsed_port.clone(),
&self.parsed_selector.clone(), &self.parsed_selector.clone(),
1 as libc::c_int, true,
); );
} else { } else {
println!("invalid gopher URI"); println!("invalid gopher URI");

Loading…
Cancel
Save