Replace types that use only 0 and 1 with bool (#18) (#58)

* Start replacing int with bool where possible (#18)

* Continue replacing int with bool where possible (#18)

* Continue replacing int with bool where possible (#18)

* Run fmt
This commit is contained in:
Hocuri
2019-05-11 12:07:09 +02:00
committed by Lars-Magnus Skog
parent 7266b64c66
commit 569c924a0c
17 changed files with 196 additions and 208 deletions

View File

@@ -37,8 +37,8 @@ pub unsafe fn dc_create_chat_by_msg_id(context: &dc_context_t, msg_id: uint32_t)
let mut send_event: libc::c_int = 0i32;
let msg: *mut dc_msg_t = dc_msg_new_untyped(context);
let chat: *mut dc_chat_t = dc_chat_new(context);
if !(0 == dc_msg_load_from_db(msg, context, msg_id)
|| 0 == dc_chat_load_from_db(chat, (*msg).chat_id)
if !(!dc_msg_load_from_db(msg, context, msg_id)
|| !dc_chat_load_from_db(chat, (*msg).chat_id)
|| (*chat).id <= 9i32 as libc::c_uint)
{
chat_id = (*chat).id;
@@ -129,9 +129,8 @@ pub unsafe fn dc_block_chat(context: &dc_context_t, chat_id: uint32_t, new_block
sqlite3_finalize(stmt);
}
// TODO should return bool /rtn
pub unsafe fn dc_chat_load_from_db(chat: *mut dc_chat_t, chat_id: uint32_t) -> libc::c_int {
let mut success: libc::c_int = 0i32;
pub unsafe fn dc_chat_load_from_db(chat: *mut dc_chat_t, chat_id: uint32_t) -> bool {
let mut success = false;
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
if !(chat.is_null() || (*chat).magic != 0xc4a7c4a7u32) {
dc_chat_empty(chat);
@@ -146,7 +145,7 @@ pub unsafe fn dc_chat_load_from_db(chat: *mut dc_chat_t, chat_id: uint32_t) -> l
if !(sqlite3_step(stmt) != 100i32) {
if !(0 == set_from_stmt(chat, stmt)) {
success = 1i32
success = true
}
}
}
@@ -227,9 +226,7 @@ pub unsafe fn dc_create_chat_by_contact_id(
dc_unblock_chat(context, chat_id);
send_event = 1i32
}
} else if 0i32 == dc_real_contact_exists(context, contact_id)
&& contact_id != 1i32 as libc::c_uint
{
} else if !dc_real_contact_exists(context, contact_id) && contact_id != 1i32 as libc::c_uint {
dc_log_warning(
context,
0i32,
@@ -297,7 +294,7 @@ pub unsafe fn dc_create_or_lookup_nchat_by_contact_id(
return;
}
contact = dc_contact_new(context);
if !(0 == dc_contact_load_from_db(contact, &context.sql.clone().read().unwrap(), contact_id)) {
if dc_contact_load_from_db(contact, &context.sql.clone().read().unwrap(), contact_id) {
chat_name =
if !(*contact).name.is_null() && 0 != *(*contact).name.offset(0isize) as libc::c_int {
(*contact).name
@@ -518,7 +515,7 @@ unsafe fn prepare_msg_common<'a>(
17281240262373992796 => {
dc_unarchive_chat(context, chat_id);
chat = dc_chat_new(context);
if 0 != dc_chat_load_from_db(chat, chat_id) {
if dc_chat_load_from_db(chat, chat_id) {
if (*msg).state != 18i32 {
(*msg).state = 20i32
}
@@ -1209,7 +1206,7 @@ pub unsafe fn dc_get_draft(context: &dc_context_t, chat_id: uint32_t) -> *mut dc
return 0 as *mut dc_msg_t;
}
draft_msg = dc_msg_new_untyped(context);
if 0 == dc_msg_load_from_db(draft_msg, context, draft_msg_id) {
if !dc_msg_load_from_db(draft_msg, context, draft_msg_id) {
dc_msg_unref(draft_msg);
return 0 as *mut dc_msg_t;
}
@@ -1436,7 +1433,7 @@ pub unsafe fn dc_get_next_media(
let mut i: libc::c_int;
let cnt: libc::c_int;
if !(0 == dc_msg_load_from_db(msg, context, curr_msg_id)) {
if dc_msg_load_from_db(msg, context, curr_msg_id) {
list = dc_get_chat_media(
context,
(*msg).chat_id,
@@ -1512,7 +1509,7 @@ pub unsafe fn dc_delete_chat(context: &dc_context_t, chat_id: uint32_t) {
let obj: *mut dc_chat_t = dc_chat_new(context);
let mut q3: *mut libc::c_char = 0 as *mut libc::c_char;
if !(chat_id <= 9i32 as libc::c_uint) {
if !(0 == dc_chat_load_from_db(obj, chat_id)) {
if !(!dc_chat_load_from_db(obj, chat_id)) {
q3 = sqlite3_mprintf(
b"DELETE FROM msgs_mdns WHERE msg_id IN (SELECT id FROM msgs WHERE chat_id=%i);\x00"
as *const u8 as *const libc::c_char,
@@ -1593,7 +1590,7 @@ pub unsafe fn dc_get_chat(context: &dc_context_t, chat_id: uint32_t) -> *mut dc_
let mut success: libc::c_int = 0i32;
let obj: *mut dc_chat_t = dc_chat_new(context);
if !(0 == dc_chat_load_from_db(obj, chat_id)) {
if !(!dc_chat_load_from_db(obj, chat_id)) {
success = 1i32
}
@@ -1714,9 +1711,8 @@ pub unsafe fn dc_add_contact_to_chat_ex(
dc_reset_gossiped_timestamp(context, chat_id);
/*this also makes sure, not contacts are added to special or normal chats*/
if !(0i32 == real_group_exists(context, chat_id)
|| 0i32 == dc_real_contact_exists(context, contact_id)
&& contact_id != 1i32 as libc::c_uint
|| 0i32 == dc_chat_load_from_db(chat, chat_id))
|| !dc_real_contact_exists(context, contact_id) && contact_id != 1i32 as libc::c_uint
|| !dc_chat_load_from_db(chat, chat_id))
{
if !(dc_is_contact_in_chat(context, chat_id, 1i32 as uint32_t) == 1i32) {
dc_log_event(
@@ -1902,9 +1898,7 @@ pub unsafe fn dc_remove_contact_from_chat(
{
/* we do not check if "contact_id" exists but just delete all records with the id from chats_contacts */
/* this allows to delete pending references to deleted contacts. Of course, this should _not_ happen. */
if !(0i32 == real_group_exists(context, chat_id)
|| 0i32 == dc_chat_load_from_db(chat, chat_id))
{
if !(0i32 == real_group_exists(context, chat_id) || !dc_chat_load_from_db(chat, chat_id)) {
if !(dc_is_contact_in_chat(context, chat_id, 1i32 as uint32_t) == 1i32) {
dc_log_event(
context,
@@ -2017,9 +2011,7 @@ pub unsafe fn dc_set_chat_name(
|| *new_name.offset(0isize) as libc::c_int == 0i32
|| chat_id <= 9i32 as libc::c_uint)
{
if !(0i32 == real_group_exists(context, chat_id)
|| 0i32 == dc_chat_load_from_db(chat, chat_id))
{
if !(0i32 == real_group_exists(context, chat_id) || !dc_chat_load_from_db(chat, chat_id)) {
if strcmp((*chat).name, new_name) == 0i32 {
success = 1i32
} else if !(dc_is_contact_in_chat(context, chat_id, 1i32 as uint32_t) == 1i32) {
@@ -2089,9 +2081,7 @@ pub unsafe fn dc_set_chat_profile_image(
let mut msg: *mut dc_msg_t = dc_msg_new_untyped(context);
let mut new_image_rel: *mut libc::c_char = 0 as *mut libc::c_char;
if !(chat_id <= 9i32 as libc::c_uint) {
if !(0i32 == real_group_exists(context, chat_id)
|| 0i32 == dc_chat_load_from_db(chat, chat_id))
{
if !(0i32 == real_group_exists(context, chat_id) || !dc_chat_load_from_db(chat, chat_id)) {
if !(dc_is_contact_in_chat(context, chat_id, 1i32 as uint32_t) == 1i32) {
dc_log_event(
context,
@@ -2178,7 +2168,7 @@ pub unsafe fn dc_forward_msgs(
let original_param: *mut dc_param_t = dc_param_new();
if !(msg_ids.is_null() || msg_cnt <= 0i32 || chat_id <= 9i32 as libc::c_uint) {
dc_unarchive_chat(context, chat_id);
if !(0 == dc_chat_load_from_db(chat, chat_id)) {
if !(!dc_chat_load_from_db(chat, chat_id)) {
curr_timestamp = dc_create_smeared_timestamps(context, msg_cnt);
idsstr = dc_arr_to_string(msg_ids, msg_cnt);
q3 = sqlite3_mprintf(
@@ -2192,7 +2182,7 @@ pub unsafe fn dc_forward_msgs(
break;
}
let src_msg_id: libc::c_int = sqlite3_column_int(stmt, 0i32);
if 0 == dc_msg_load_from_db(msg, context, src_msg_id as uint32_t) {
if !dc_msg_load_from_db(msg, context, src_msg_id as uint32_t) {
break;
}
dc_param_set_packed(original_param, (*(*msg).param).packed);