summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReuben Thomas <rrt@sc3d.org>2021-11-08 11:49:32 +0000
committerReuben Thomas <rrt@sc3d.org>2021-11-08 11:49:32 +0000
commit7903b7460c93d5bf68e1b37b2f7ed573d8586e94 (patch)
tree91c36c98ac3f0b400542c4ee01874fc3420e54ec
parentb459f39b30bf66aedcce4db2a78b8df27375774c (diff)
downloadenchant-7903b7460c93d5bf68e1b37b2f7ed573d8586e94.tar.gz
Remove redundant braces; merge initializers with declarations
This also makes the style of the code more consistent.
-rw-r--r--src/enchant.c13
-rw-r--r--src/lib.c61
-rw-r--r--src/pwl.c57
3 files changed, 42 insertions, 89 deletions
diff --git a/src/enchant.c b/src/enchant.c
index 3735231..228d0cb 100644
--- a/src/enchant.c
+++ b/src/enchant.c
@@ -128,10 +128,9 @@ print_utf (const char * str)
if (native) {
fwrite (native, 1, bytes_written, stdout);
g_free (native);
- } else {
+ } else
/* Assume that it's already utf8 and glib is just being stupid. */
printf ("%s", str);
- }
}
static int
@@ -364,9 +363,9 @@ parse_file (FILE * in, IspellMode_t mode, gboolean countLines, gchar *dictionary
ssize_t mis_len = comma - mis;
ssize_t cor_len = strlen(str->str) - (cor - str->str);
enchant_dict_store_replacement(dict, mis, mis_len, cor, cor_len);
- } else if (g_str_has_prefix(str->str, "$$wc")) { /* Return the extra word chars list */
+ } else if (g_str_has_prefix(str->str, "$$wc"))
+ /* Return the extra word chars list */
printf("%s\n", enchant_dict_get_extra_word_characters(dict));
- }
}
break;
@@ -406,9 +405,8 @@ parse_file (FILE * in, IspellMode_t mode, gboolean countLines, gchar *dictionary
}
}
- if (mode == MODE_A && corrected_something) {
+ if (mode == MODE_A && corrected_something)
putchar('\n');
- }
g_string_truncate (str, 0);
fflush (stdout);
}
@@ -437,9 +435,8 @@ int main (int argc, char ** argv)
g_get_charset(&charset);
#ifdef _WIN32
/* If reading from stdin, its CP may not be the system CP (which glib's locale gives us) */
- if (GetFileType(GetStdHandle(STD_INPUT_HANDLE)) == FILE_TYPE_CHAR) {
+ if (GetFileType(GetStdHandle(STD_INPUT_HANDLE)) == FILE_TYPE_CHAR)
charset = g_strdup_printf("CP%u", GetConsoleCP());
- }
#endif
int optchar;
diff --git a/src/lib.c b/src/lib.c
index 496d1f6..6ffee68 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -166,10 +166,8 @@ enchant_is_valid_dictionary_tag(const char * const tag)
{
const char * it;
for (it = tag; *it; ++it)
- {
- if(!g_ascii_isalnum(*it) && *it != '_')
- return 0;
- }
+ if(!g_ascii_isalnum(*it) && *it != '_')
+ return 0;
return it != tag; /*empty tag invalid*/
}
@@ -836,14 +834,10 @@ enchant_load_providers_in_dir (EnchantBroker * broker, const char *dir_name)
}
}
else
- {
- g_module_close (module);
- }
+ g_module_close (module);
}
else
- {
- g_warning ("Error loading plugin: %s\n", g_module_error());
- }
+ g_warning ("Error loading plugin: %s\n", g_module_error());
g_free (filename);
#ifdef _WIN32
@@ -961,10 +955,8 @@ enchant_get_ordered_providers (EnchantBroker * broker, const char * const tag)
/* append providers not in the list, or from an unordered list */
for (GSList * iter = broker->provider_list; iter != NULL; iter = g_slist_next (iter))
- {
- if (!g_slist_find (list, iter->data))
- list = g_slist_append (list, iter->data);
- }
+ if (!g_slist_find (list, iter->data))
+ list = g_slist_append (list, iter->data);
return list;
}
@@ -1084,9 +1076,7 @@ _enchant_broker_request_dict (EnchantBroker * broker, const char *const tag)
GSList * list = enchant_get_ordered_providers (broker, tag);
for (GSList *listIter = list; listIter != NULL; listIter = g_slist_next (listIter))
{
- EnchantProvider * provider;
-
- provider = (EnchantProvider *) listIter->data;
+ EnchantProvider * provider = (EnchantProvider *) listIter->data;
if (provider->request_dict)
{
@@ -1122,9 +1112,7 @@ enchant_broker_request_dict (EnchantBroker * broker, const char *const tag)
char * normalized_tag = enchant_normalize_dictionary_tag (tag);
if(!enchant_is_valid_dictionary_tag(normalized_tag))
- {
- enchant_broker_set_error (broker, "invalid tag character found");
- }
+ enchant_broker_set_error (broker, "invalid tag character found");
else if ((dict = _enchant_broker_request_dict (broker, normalized_tag)) == NULL)
{
char * iso_639_only_tag = enchant_iso_639_from_tag (normalized_tag);
@@ -1250,20 +1238,16 @@ enchant_provider_dictionary_exists (EnchantProvider * provider, const char * con
int exists = 0;
if (provider->dictionary_exists)
- {
- exists = (*provider->dictionary_exists) (provider, tag);
- }
+ exists = (*provider->dictionary_exists) (provider, tag);
else
{
size_t n_dicts;
char ** dicts = (*provider->list_dicts) (provider, &n_dicts);
for (size_t i = 0; i < n_dicts; i++)
- {
- if (!strcmp(dicts[i], tag)) {
- exists = 1;
- break;
- }
+ if (!strcmp(dicts[i], tag)) {
+ exists = 1;
+ break;
}
enchant_free_string_list (dicts);
@@ -1283,10 +1267,9 @@ _enchant_broker_dict_exists (EnchantBroker * broker, const char * const tag)
if (g_hash_table_lookup (broker->dict_map, (gpointer) tag) != NULL)
return 1;
- for (GSList *list = broker->provider_list; list != NULL; list = g_slist_next (list)) {
+ for (GSList *list = broker->provider_list; list != NULL; list = g_slist_next (list))
if (enchant_provider_dictionary_exists ((EnchantProvider *) list->data, tag))
return 1;
- }
return 0;
}
@@ -1303,19 +1286,13 @@ enchant_broker_dict_exists (EnchantBroker * broker, const char * const tag)
int exists = 0;
if(!enchant_is_valid_dictionary_tag(normalized_tag))
- {
- enchant_broker_set_error (broker, "invalid tag character found");
- }
+ enchant_broker_set_error (broker, "invalid tag character found");
else if ((exists = _enchant_broker_dict_exists (broker, normalized_tag)) == 0)
{
- char * iso_639_only_tag;
-
- iso_639_only_tag = enchant_iso_639_from_tag (normalized_tag);
+ char * iso_639_only_tag = enchant_iso_639_from_tag (normalized_tag);
if (strcmp (normalized_tag, iso_639_only_tag) != 0)
- {
- exists = _enchant_broker_dict_exists (broker, iso_639_only_tag);
- }
+ exists = _enchant_broker_dict_exists (broker, iso_639_only_tag);
free (iso_639_only_tag);
}
@@ -1343,9 +1320,8 @@ enchant_dict_is_word_character (EnchantDict * dict, uint32_t uc_in, size_t n)
gunichar uc = (gunichar)uc_in;
/* Accept quote marks anywhere except at the end of a word */
- if (uc == g_utf8_get_char("'") || uc == g_utf8_get_char("’")) {
+ if (uc == g_utf8_get_char("'") || uc == g_utf8_get_char("’"))
return n < 2;
- }
GUnicodeType type = g_unichar_type(uc);
@@ -1365,9 +1341,8 @@ enchant_dict_is_word_character (EnchantDict * dict, uint32_t uc_in, size_t n)
return 1; /* Enchant 1.3.0 defines word chars like this. */
case G_UNICODE_DASH_PUNCTUATION:
- if ((n == 1) && (type == G_UNICODE_DASH_PUNCTUATION)) {
+ if ((n == 1) && (type == G_UNICODE_DASH_PUNCTUATION))
return 1; /* hyphens only accepted within a word. */
- }
/* Fallthrough */
case G_UNICODE_CONTROL:
diff --git a/src/pwl.c b/src/pwl.c
index 0801e30..23c812d 100644
--- a/src/pwl.c
+++ b/src/pwl.c
@@ -347,9 +347,7 @@ void enchant_pwl_add(EnchantPWL *pwl,
}
if (fwrite (word, sizeof(char), len, f) == (size_t)len)
- {
- putc ('\n', f);
- }
+ putc ('\n', f);
enchant_unlock_file (f);
fclose (f);
}
@@ -664,9 +662,8 @@ static void enchant_pwl_suggest_cb(char* match,EnchantTrieMatcher* matcher)
size_t loc;
for(loc=0; loc < sugg_list->n_suggs; loc++) {
/* Better than an existing suggestion, so stop */
- if(sugg_list->sugg_errs[loc] > matcher->num_errors) {
+ if(sugg_list->sugg_errs[loc] > matcher->num_errors)
break;
- }
/* Already in the list with better score, just return */
if(strcmp(match,sugg_list->suggs[loc])==0) {
g_free(match);
@@ -695,9 +692,8 @@ static void enchant_pwl_suggest_cb(char* match,EnchantTrieMatcher* matcher)
static void enchant_trie_free(EnchantTrie* trie)
{
/* Don't try to free NULL or the EOSTrie pointer */
- if(trie == NULL || trie == EOSTrie) {
+ if(trie == NULL || trie == EOSTrie)
return;
- }
/* Because we have not set a destroy function for the hashtable
* (to make code cleaner below), we need to explicitly free all
@@ -721,9 +717,8 @@ static void enchant_trie_free_cb(void* key _GL_UNUSED_PARAMETER,
static EnchantTrie* enchant_trie_insert(EnchantTrie* trie,const char *const word)
{
- if (trie == NULL) {
+ if (trie == NULL)
trie = g_new0(EnchantTrie, 1);
- }
if (trie->value == NULL) {
if (trie->subtries == NULL) {
@@ -765,10 +760,10 @@ static void enchant_trie_remove(EnchantTrie* trie,const char *const word)
if (trie->value == NULL) {
if (trie->subtries != NULL) {
/* Store multiple words in subtries */
- if (word[0] == '\0') {
+ if (word[0] == '\0')
/* End-of-string is marked with special node */
g_hash_table_remove(trie->subtries, "");
- } else {
+ else {
ssize_t nxtCh = (ssize_t)(g_utf8_next_char(word) - word);
char *tmpWord = g_strndup(word, nxtCh);
EnchantTrie *subtrie = g_hash_table_lookup(trie->subtries, tmpWord);
@@ -800,12 +795,9 @@ static void enchant_trie_remove(EnchantTrie* trie,const char *const word)
g_list_free(keys);
}
}
- } else {
- if(strcmp(trie->value, word) == 0)
- {
- g_free(trie->value);
- trie->value = NULL;
- }
+ } else if(strcmp(trie->value, word) == 0) {
+ g_free(trie->value);
+ trie->value = NULL;
}
}
@@ -831,9 +823,8 @@ static void enchant_trie_find_matches(EnchantTrie* trie,EnchantTrieMatcher *matc
g_return_if_fail(matcher);
/* Can't match in the empty trie */
- if(trie == NULL) {
+ if(trie == NULL)
return;
- }
/* Bail out if over the error limits */
if(matcher->num_errors > matcher->max_errors){
@@ -844,12 +835,10 @@ static void enchant_trie_find_matches(EnchantTrie* trie,EnchantTrieMatcher *matc
if (trie == EOSTrie) {
size_t word_len = strlen(matcher->word);
int errs = matcher->num_errors;
- if((ssize_t)word_len > matcher->word_pos) {
+ if((ssize_t)word_len > matcher->word_pos)
matcher->num_errors = errs + word_len - matcher->word_pos;
- }
- if (matcher->num_errors <= matcher->max_errors) {
+ if (matcher->num_errors <= matcher->max_errors)
matcher->cbfunc(g_strdup(matcher->path),matcher);
- }
matcher->num_errors = errs;
return;
}
@@ -860,21 +849,16 @@ static void enchant_trie_find_matches(EnchantTrie* trie,EnchantTrieMatcher *matc
int errs = matcher->num_errors;
value = trie->value;
if(matcher->mode == case_insensitive)
- {
- value = g_utf8_strdown(value, -1);
- }
+ value = g_utf8_strdown(value, -1);
matcher->num_errors = errs + edit_dist(value,
&(matcher->word[matcher->word_pos]));
if(matcher->mode == case_insensitive)
- {
- g_free(value);
- }
+ g_free(value);
- if (matcher->num_errors <= matcher->max_errors) {
+ if (matcher->num_errors <= matcher->max_errors)
matcher->cbfunc(g_strconcat(matcher->path,
trie->value,NULL),
matcher);
- }
matcher->num_errors = errs;
return;
}
@@ -919,10 +903,9 @@ static void enchant_trie_find_matches_cb(void* keyV,void* subtrieV,void* matcher
ssize_t nxtChI = (ssize_t) (g_utf8_next_char(&matcher->word[matcher->word_pos]) - matcher->word);
- /* Dont handle actual matches, that's already done */
- if (strncmp(key,&matcher->word[matcher->word_pos],nxtChI-matcher->word_pos) == 0) {
+ /* Don't handle actual matches, that's already done */
+ if (strncmp(key,&matcher->word[matcher->word_pos],nxtChI-matcher->word_pos) == 0)
return;
- }
enchant_trie_matcher_pushpath(matcher,key);
@@ -1018,9 +1001,8 @@ static void enchant_trie_matcher_poppath(EnchantTrieMatcher* matcher,int num)
{
g_return_if_fail(matcher->path_pos >= 0);
matcher->path_pos = matcher->path_pos - num;
- if(matcher->path_pos < 0) {
+ if(matcher->path_pos < 0)
matcher->path_pos = 0;
- }
matcher->path[matcher->path_pos] = '\0';
}
@@ -1043,9 +1025,8 @@ static int edit_dist(const char* utf8word1, const char* utf8word2)
for (glong j = 1; j < len2+1; j++) {
int cost = word1[i-1] != word2[j-1];
int v1 = table[(i-1)*(len2+1)+j] + 1;
- if (i > 1 && j > 1 && word1[i-1] == word2[j-2] && word1[i-2] == word2[j-1]) {
+ if (i > 1 && j > 1 && word1[i-1] == word2[j-2] && word1[i-2] == word2[j-1])
v1 = MIN (v1, table[(i-2)*(len2+1)+(j-2)] + cost);
- }
int v2 = table[i*(len2+1)+(j-1)] + 1;
int v3 = table[(i-1)*(len2+1)+(j-1)] + cost;