From 8608daa7dc9f24325192a2bb4eb6a24d93a926ce Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Thu, 8 Aug 2019 00:53:03 +0200 Subject: [PATCH 1/3] remove goto --- src/dc_imex.rs | 154 +++---------------------------------------------- 1 file changed, 9 insertions(+), 145 deletions(-) diff --git a/src/dc_imex.rs b/src/dc_imex.rs index 5cb407b49..c5cb2c933 100644 --- a/src/dc_imex.rs +++ b/src/dc_imex.rs @@ -508,7 +508,7 @@ pub unsafe fn dc_normalize_setup_code( #[allow(non_snake_case)] pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: *mut dc_job_t) { - let mut current_block: u64; + let mut ok_to_continue1 = true; let mut success: libc::c_int = 0; let mut ongoing_allocated_here: libc::c_int = 0; let what: libc::c_int; @@ -536,179 +536,43 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: *mut dc_job_t) 0, "Import/export: Cannot create private key or private key not available.", ); - current_block = 3568988166330621280; + ok_to_continue1 = false; } else { dc_create_folder(context, ¶m1_s); - current_block = 4495394744059808450; } - } else { - current_block = 4495394744059808450; } - match current_block { - 3568988166330621280 => {} - _ => match what { + if ok_to_continue1 { + match what { 1 => { - current_block = 10991094515395304355; - match current_block { - 2973387206439775448 => { - if 0 == import_backup(context, param1.as_ptr()) { - current_block = 3568988166330621280; - } else { - current_block = 1118134448028020070; - } - } - 11250025114629486028 => { - if 0 == import_self_keys(context, param1.as_ptr()) { - current_block = 3568988166330621280; - } else { - current_block = 1118134448028020070; - } - } - 12669919903773909120 => { - if 0 == export_backup(context, param1.as_ptr()) { - current_block = 3568988166330621280; - } else { - current_block = 1118134448028020070; - } - } - _ => { if 0 == export_self_keys(context, param1.as_ptr()) { - current_block = 3568988166330621280; } else { - current_block = 1118134448028020070; - } - } - } - match current_block { - 3568988166330621280 => {} - _ => { info!(context, 0, "Import/export completed.",); success = 1 - } - } + } } 2 => { - current_block = 11250025114629486028; - match current_block { - 2973387206439775448 => { - if 0 == import_backup(context, param1.as_ptr()) { - current_block = 3568988166330621280; - } else { - current_block = 1118134448028020070; - } - } - 11250025114629486028 => { if 0 == import_self_keys(context, param1.as_ptr()) { - current_block = 3568988166330621280; } else { - current_block = 1118134448028020070; - } - } - 12669919903773909120 => { - if 0 == export_backup(context, param1.as_ptr()) { - current_block = 3568988166330621280; - } else { - current_block = 1118134448028020070; - } - } - _ => { - if 0 == export_self_keys(context, param1.as_ptr()) { - current_block = 3568988166330621280; - } else { - current_block = 1118134448028020070; - } - } - } - match current_block { - 3568988166330621280 => {} - _ => { info!(context, 0, "Import/export completed.",); success = 1 - } - } + } } 11 => { - current_block = 12669919903773909120; - match current_block { - 2973387206439775448 => { - if 0 == import_backup(context, param1.as_ptr()) { - current_block = 3568988166330621280; - } else { - current_block = 1118134448028020070; - } - } - 11250025114629486028 => { - if 0 == import_self_keys(context, param1.as_ptr()) { - current_block = 3568988166330621280; - } else { - current_block = 1118134448028020070; - } - } - 12669919903773909120 => { if 0 == export_backup(context, param1.as_ptr()) { - current_block = 3568988166330621280; } else { - current_block = 1118134448028020070; - } - } - _ => { - if 0 == export_self_keys(context, param1.as_ptr()) { - current_block = 3568988166330621280; - } else { - current_block = 1118134448028020070; - } - } - } - match current_block { - 3568988166330621280 => {} - _ => { info!(context, 0, "Import/export completed.",); success = 1 - } - } + } } 12 => { - current_block = 2973387206439775448; - match current_block { - 2973387206439775448 => { if 0 == import_backup(context, param1.as_ptr()) { - current_block = 3568988166330621280; } else { - current_block = 1118134448028020070; - } - } - 11250025114629486028 => { - if 0 == import_self_keys(context, param1.as_ptr()) { - current_block = 3568988166330621280; - } else { - current_block = 1118134448028020070; - } - } - 12669919903773909120 => { - if 0 == export_backup(context, param1.as_ptr()) { - current_block = 3568988166330621280; - } else { - current_block = 1118134448028020070; - } - } - _ => { - if 0 == export_self_keys(context, param1.as_ptr()) { - current_block = 3568988166330621280; - } else { - current_block = 1118134448028020070; - } - } - } - match current_block { - 3568988166330621280 => {} - _ => { info!(context, 0, "Import/export completed.",); success = 1 - } - } + } } _ => {} - }, + } } } } From 4f1a25e1bfdc5a32b9e34942bd47ea93b9f7488e Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Thu, 8 Aug 2019 01:07:35 +0200 Subject: [PATCH 2/3] cargo fmt --- src/dc_imex.rs | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/dc_imex.rs b/src/dc_imex.rs index c5cb2c933..4867c458c 100644 --- a/src/dc_imex.rs +++ b/src/dc_imex.rs @@ -544,32 +544,32 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: *mut dc_job_t) if ok_to_continue1 { match what { 1 => { - if 0 == export_self_keys(context, param1.as_ptr()) { - } else { - info!(context, 0, "Import/export completed.",); - success = 1 - } + if 0 == export_self_keys(context, param1.as_ptr()) { + } else { + info!(context, 0, "Import/export completed.",); + success = 1 + } } 2 => { - if 0 == import_self_keys(context, param1.as_ptr()) { - } else { - info!(context, 0, "Import/export completed.",); - success = 1 - } + if 0 == import_self_keys(context, param1.as_ptr()) { + } else { + info!(context, 0, "Import/export completed.",); + success = 1 + } } 11 => { - if 0 == export_backup(context, param1.as_ptr()) { - } else { - info!(context, 0, "Import/export completed.",); - success = 1 - } + if 0 == export_backup(context, param1.as_ptr()) { + } else { + info!(context, 0, "Import/export completed.",); + success = 1 + } } 12 => { - if 0 == import_backup(context, param1.as_ptr()) { - } else { - info!(context, 0, "Import/export completed.",); - success = 1 - } + if 0 == import_backup(context, param1.as_ptr()) { + } else { + info!(context, 0, "Import/export completed.",); + success = 1 + } } _ => {} } From cf49acff67b56957b9ba8a050aaf48d3604173c5 Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Thu, 8 Aug 2019 01:09:41 +0200 Subject: [PATCH 3/3] part 2 --- src/dc_imex.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/dc_imex.rs b/src/dc_imex.rs index 4867c458c..e45a634c6 100644 --- a/src/dc_imex.rs +++ b/src/dc_imex.rs @@ -508,7 +508,7 @@ pub unsafe fn dc_normalize_setup_code( #[allow(non_snake_case)] pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: *mut dc_job_t) { - let mut ok_to_continue1 = true; + let mut ok_to_continue = true; let mut success: libc::c_int = 0; let mut ongoing_allocated_here: libc::c_int = 0; let what: libc::c_int; @@ -536,37 +536,33 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: *mut dc_job_t) 0, "Import/export: Cannot create private key or private key not available.", ); - ok_to_continue1 = false; + ok_to_continue = false; } else { dc_create_folder(context, ¶m1_s); } } - if ok_to_continue1 { + if ok_to_continue { match what { 1 => { - if 0 == export_self_keys(context, param1.as_ptr()) { - } else { + if 0 != export_self_keys(context, param1.as_ptr()) { info!(context, 0, "Import/export completed.",); success = 1 } } 2 => { - if 0 == import_self_keys(context, param1.as_ptr()) { - } else { + if 0 != import_self_keys(context, param1.as_ptr()) { info!(context, 0, "Import/export completed.",); success = 1 } } 11 => { - if 0 == export_backup(context, param1.as_ptr()) { - } else { + if 0 != export_backup(context, param1.as_ptr()) { info!(context, 0, "Import/export completed.",); success = 1 } } 12 => { - if 0 == import_backup(context, param1.as_ptr()) { - } else { + if 0 != import_backup(context, param1.as_ptr()) { info!(context, 0, "Import/export completed.",); success = 1 }