From dfced76294726f33dacdc9d3670b76c10ac12f8a Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Wed, 14 Aug 2013 09:27:50 +0200 Subject: [PATCH] include: Use stdbool instead gboolean or near_bool_t This patch has been created via coccinelle: // Rule set 1 f(es, ( - FALSE + false | - TRUE + true ) ,...) @r2@ type T; identifier f; parameter list[n] ps; identifier i; @@ T f(ps, near_bool_t i, ...); @@ identifier r2.f; expression list [r.n] es; @@ f(es, ( - FALSE + false | - TRUE + true ) ,...) @@ typedef bool; @@ - near_bool_t + bool // Rule set 2 // This is not a beautiful script but it does the job. // Improvemtents are welcome. // Fix all assigments but do not convert yet the type @@ gboolean x; @@ x = ( - TRUE + true | - FALSE + false ) // Figure out which function signature will to be fixed... // when we have the defitition @r@ identifier f; parameter list[n] ps; identifier i; @@ f(ps, gboolean i, ...) { ... } // ... and now convert all call sites @@ identifier r.f; expression list [r.n] es; @@ f(es, ( - FALSE + false | - TRUE + true ) ,...) // Figure out which function signature will to be fixed... // when we have the declaration only @r2@ type T; identifier f; parameter list[n] ps; identifier i; @@ T f(ps, gboolean i, ...); // ... and now convert all call sites @@ identifier r2.f; expression list [r.n] es; @@ f(es, ( - FALSE + false | - TRUE + true ) ,...) // A handfull of the GLib hooks we can't change. Let's remember // all ther positions. // 1. timeouts @k1@ identifier f; position p; typedef gpointer; identifier ptr; @@ static gboolean@p f(gpointer ptr); @k2@ identifier f; position p; identifier ptr; @@ static gboolean@p f(gpointer ptr) { ... } // hash map iterator functions @k3@ identifier f; position p; identifier p1, p2, p3; @@ static gboolean@p f(gpointer p1, gpointer p2, gpointer p3) { ... } // 2. GIOChannel @k4@ identifier f; position p; typedef GIOChannel, GIOCondition; identifier ptr; identifier ch, cn; @@ static gboolean@p f(GIOChannel *ch, GIOCondition cn, gpointer ptr); @k5@ identifier f; position p; identifier ptr; identifier ch, cn; @@ static gboolean@p f(GIOChannel *ch, GIOCondition cn, gpointer ptr) { ... } // 3. GSourceFuncs @k6@ identifier f; position p; typedef GSource; identifier src; @@ static gboolean@p f(GSource *src, ...) { ... } // gdbus functions @k7@ identifier f; position p; typedef DBusConnection; identifier con; @@ static gboolean@p f(DBusConnection *con, ...) { ... } // Now convert all gboolean which are are not used for interactin // with GLib // Note here happens the magic! @@ typedef bool; position p != {k1.p,k2.p,k3.p,k4.p,k5.p,k6.p,k7.p}; @@ - gboolean@p + bool // Update all return types @@ identifier f; @@ bool f(...) { <... - return TRUE; + return true; ...> } @@ identifier f; @@ bool f(...) { <... - return FALSE; + return false; ...> } // Rule set 3 @@ expression E; symbol TRUE; symbol FALSE; @@ ( E - == TRUE | - TRUE == E + E | - E != TRUE + !E | - TRUE != E + !E | - E == FALSE + !E | - FALSE == E + !E | E - != FALSE | - FALSE != E + E ) --- include/ndef.h | 4 ++-- include/setting.h | 2 +- include/snep.h | 6 +++--- include/tag.h | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/ndef.h b/include/ndef.h index b554a79..5abdf34 100644 --- a/include/ndef.h +++ b/include/ndef.h @@ -61,9 +61,9 @@ near_ndef_prepare_smartposter_record(uint8_t uri_identifier, uint32_t uri_field_length, uint8_t *uri_field); -near_bool_t near_ndef_record_cmp_id(struct near_ndef_record *rec1, +bool near_ndef_record_cmp_id(struct near_ndef_record *rec1, struct near_ndef_record *rec2); -near_bool_t near_ndef_record_cmp_mime(struct near_ndef_record *rec1, +bool near_ndef_record_cmp_mime(struct near_ndef_record *rec1, struct near_ndef_record *rec2); diff --git a/include/setting.h b/include/setting.h index d287432..31a0426 100644 --- a/include/setting.h +++ b/include/setting.h @@ -28,7 +28,7 @@ extern "C" { #endif -near_bool_t near_setting_get_bool(const char *key); +bool near_setting_get_bool(const char *key); #ifdef __cplusplus } diff --git a/include/snep.h b/include/snep.h index 4ce6b9c..c908387 100644 --- a/include/snep.h +++ b/include/snep.h @@ -64,7 +64,7 @@ * from lower layers */ #define NEAR_SNEP_REQ_MAX_FRAGMENT_LENGTH 128 -typedef near_bool_t (*near_server_io) (int client_fd, void *snep_data); +typedef bool (*near_server_io) (int client_fd, void *snep_data); struct p2p_snep_data { uint8_t *nfc_data; @@ -73,13 +73,13 @@ struct p2p_snep_data { uint8_t *nfc_data_ptr; uint32_t adapter_idx; uint32_t target_idx; - gboolean respond_continue; + bool respond_continue; uint8_t request; near_tag_io_cb cb; struct p2p_snep_put_req_data *req; }; -near_bool_t near_snep_core_read(int client_fd, +bool near_snep_core_read(int client_fd, uint32_t adapter_idx, uint32_t target_idx, near_tag_io_cb cb, near_server_io req_get, diff --git a/include/tag.h b/include/tag.h index 412bc70..9c1330e 100644 --- a/include/tag.h +++ b/include/tag.h @@ -78,9 +78,9 @@ struct near_tag_driver { struct near_tag; struct near_tag *near_tag_get_tag(uint32_t adapter_idx, uint32_t target_idx); -void near_tag_set_ro(struct near_tag *tag, near_bool_t readonly); -void near_tag_set_blank(struct near_tag *tag, near_bool_t blank); -near_bool_t near_tag_get_blank(struct near_tag *tag); +void near_tag_set_ro(struct near_tag *tag, bool readonly); +void near_tag_set_blank(struct near_tag *tag, bool blank); +bool near_tag_get_blank(struct near_tag *tag); int near_tag_add_data(uint32_t adapter_idx, uint32_t target_idx, uint8_t *data, size_t data_length); int near_tag_add_records(struct near_tag *tag, GList *records, -- 2.7.4