Skip to content

Commit

Permalink
style: switch to use clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
kanru committed Feb 6, 2024
1 parent 50d4abb commit 29ba59e
Show file tree
Hide file tree
Showing 37 changed files with 3,753 additions and 2,786 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
BasedOnStyle: LLVM
BasedOnStyle: Mozilla
IndentWidth: 4
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# IBus-Chewing

IBus-Chewing is an IBus front-end of Chewing, an intelligent Chinese input method for Zhuyin (BoPoMoFo) users.
IBus-Chewing is an IBus front-end of Chewing, an intelligent Chinese input
method for Zhuyin (BoPoMoFo) users.

Following documents provide further instruction:

Expand All @@ -16,7 +17,9 @@ Bugs and enhancement can be filed to either:

# Development

We use **[K&R](https://en.wikipedia.org/wiki/Indent_style#K.26R_style), 4 spaces** coding style to make our review easier, so if you like to contribute, please set the git pre-commit hook by:
We use Mozilla coding style to make our review easier, so if you like to
contribute, please install clang-format and set the git pre-commit hook by:

```sh
ln -s ../../pre-commit .git/hooks/pre-commit
```
Expand Down
16 changes: 5 additions & 11 deletions pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@


function exit_print_error(){
if [[ -z $Indent ]];then
echo "Please install 'indent' and put it in system PATH," > /dev/stderr
if [[ -z $clang_format ]];then
echo "Please install 'clang-format' and put it in system PATH," > /dev/stderr
echo "or specify it in 'git config hooks.indent'" > /dev/stderr
exit 1
fi
}

trap exit_print_error EXIT
Indent="$(git config hooks.indent)" || Indent=$(which indent 2>/dev/null)
clang_format="$(git config hooks.indent)" || clang_format=$(command -v clang-format 2>/dev/null)

if git rev-parse --verify HEAD >/dev/null 2>&1; then
Against=HEAD
Expand All @@ -39,16 +39,10 @@ while read File; do
Ext=${File##*.}
case $Ext in
c|h)
echo "Indenting " $File > /dev/stderr
"$Indent" -kr --no-tabs\
--line-length 80\
--blank-lines-after-declarations\
--preprocessor-indentation 4\
"$File"
echo "clang-format " $File > /dev/stderr
$clang_format -i $File
;;
esac
echo "Chopping " $File > /dev/stderr
sed -r -i -e 's/[[:blank:]]+$//' $File
git add "$File"
done < <(git diff --cached --name-only $Against)

Expand Down
121 changes: 71 additions & 50 deletions src/GSettingsBackend.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,61 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/

#include <ibus.h>
#include <glib.h>
#include "MakerDialogUtil.h"
#include "GSettingsBackend.h"
#include "MakerDialogUtil.h"
#include <glib.h>
#include <ibus.h>

gchar *mkdg_g_variant_to_string(GVariant * gVar)
gchar*
mkdg_g_variant_to_string(GVariant* gVar)
{
static gchar result[MAKER_DIALOG_VALUE_LENGTH];

result[0] = '\0';
const GVariantType *gVType = g_variant_get_type(gVar);
const GVariantType* gVType = g_variant_get_type(gVar);

if (g_variant_type_is_subtype_of(gVType, G_VARIANT_TYPE_BOOLEAN)) {
g_snprintf(result, MAKER_DIALOG_VALUE_LENGTH,
g_snprintf(result,
MAKER_DIALOG_VALUE_LENGTH,
g_variant_get_boolean(gVar) ? "1" : "0");
} else if (g_variant_type_is_subtype_of(gVType, G_VARIANT_TYPE_UINT16)) {
g_snprintf(result, MAKER_DIALOG_VALUE_LENGTH, "%" G_GUINT16_FORMAT,
g_snprintf(result,
MAKER_DIALOG_VALUE_LENGTH,
"%" G_GUINT16_FORMAT,

Check warning on line 43 in src/GSettingsBackend.c

View check run for this annotation

Codecov / codecov/patch

src/GSettingsBackend.c#L41-L43

Added lines #L41 - L43 were not covered by tests
g_variant_get_uint16(gVar));
} else if (g_variant_type_is_subtype_of(gVType, G_VARIANT_TYPE_UINT32)) {
g_snprintf(result, MAKER_DIALOG_VALUE_LENGTH, "%" G_GUINT32_FORMAT,
g_snprintf(result,
MAKER_DIALOG_VALUE_LENGTH,
"%" G_GUINT32_FORMAT,
g_variant_get_uint32(gVar));
} else if (g_variant_type_is_subtype_of(gVType, G_VARIANT_TYPE_UINT64)) {
g_snprintf(result, MAKER_DIALOG_VALUE_LENGTH, "%" G_GUINT64_FORMAT,
g_snprintf(result,
MAKER_DIALOG_VALUE_LENGTH,
"%" G_GUINT64_FORMAT,

Check warning on line 53 in src/GSettingsBackend.c

View check run for this annotation

Codecov / codecov/patch

src/GSettingsBackend.c#L51-L53

Added lines #L51 - L53 were not covered by tests
g_variant_get_uint64(gVar));
} else if (g_variant_type_is_subtype_of(gVType, G_VARIANT_TYPE_INT16)) {
g_snprintf(result, MAKER_DIALOG_VALUE_LENGTH, "%" G_GINT16_FORMAT,
g_snprintf(result,
MAKER_DIALOG_VALUE_LENGTH,
"%" G_GINT16_FORMAT,

Check warning on line 58 in src/GSettingsBackend.c

View check run for this annotation

Codecov / codecov/patch

src/GSettingsBackend.c#L56-L58

Added lines #L56 - L58 were not covered by tests
g_variant_get_int16(gVar));
} else if (g_variant_type_is_subtype_of(gVType, G_VARIANT_TYPE_INT32)) {
g_snprintf(result, MAKER_DIALOG_VALUE_LENGTH, "%" G_GINT32_FORMAT,
g_snprintf(result,
MAKER_DIALOG_VALUE_LENGTH,
"%" G_GINT32_FORMAT,
g_variant_get_int32(gVar));
} else if (g_variant_type_is_subtype_of(gVType, G_VARIANT_TYPE_INT64)) {
g_snprintf(result, MAKER_DIALOG_VALUE_LENGTH, "%" G_GINT64_FORMAT,
g_snprintf(result,
MAKER_DIALOG_VALUE_LENGTH,
"%" G_GINT64_FORMAT,

Check warning on line 68 in src/GSettingsBackend.c

View check run for this annotation

Codecov / codecov/patch

src/GSettingsBackend.c#L66-L68

Added lines #L66 - L68 were not covered by tests
g_variant_get_int64(gVar));
} else if (g_variant_type_is_subtype_of(gVType, G_VARIANT_TYPE_STRING)) {
g_snprintf(result, MAKER_DIALOG_VALUE_LENGTH, "%s",
g_snprintf(result,
MAKER_DIALOG_VALUE_LENGTH,
"%s",

Check warning on line 73 in src/GSettingsBackend.c

View check run for this annotation

Codecov / codecov/patch

src/GSettingsBackend.c#L71-L73

Added lines #L71 - L73 were not covered by tests
g_variant_get_string(gVar, NULL));
}
return result;
Expand All @@ -65,10 +82,10 @@ gchar *mkdg_g_variant_to_string(GVariant * gVar)

#define KEY_BUFFER_SIZE 300

GValue *mkdg_g_settings_read_value(GSettings * settings,
GValue * value, const gchar * key)
GValue*
mkdg_g_settings_read_value(GSettings* settings, GValue* value, const gchar* key)
{
GVariant *confValue = g_settings_get_value(settings, key);
GVariant* confValue = g_settings_get_value(settings, key);

mkdg_log(DEBUG, "mkdg_g_settings_read_value(-,-,%s)", key);
if (confValue == NULL) {
Expand All @@ -80,64 +97,68 @@ GValue *mkdg_g_settings_read_value(GSettings * settings,
return value;
}


/*============================================
* Interface routines
*/
gchar *mkdg_g_settings_backend_get_key(MkdgBackend * backend,
const gchar * section,
const gchar * key, gpointer userData)
gchar*
mkdg_g_settings_backend_get_key(MkdgBackend* backend,
const gchar* section,
const gchar* key,
gpointer userData)
{
return (gchar *) key;
return (gchar*)key;
}

GValue *mkdg_g_settings_backend_read_value(MkdgBackend * backend,
GValue * value,
const gchar * section,
const gchar * key, gpointer userData)
GValue*
mkdg_g_settings_backend_read_value(MkdgBackend* backend,
GValue* value,
const gchar* section,
const gchar* key,
gpointer userData)
{
GSettings *config = (GSettings *) backend->config;
GSettings* config = (GSettings*)backend->config;

return mkdg_g_settings_read_value(config, value, key);
}


gboolean mkdg_g_settings_backend_write_value(MkdgBackend *
backend,
GValue *
value,
const gchar *
section,
const gchar *
key, gpointer userData)
gboolean
mkdg_g_settings_backend_write_value(MkdgBackend* backend,
GValue* value,
const gchar* section,
const gchar* key,
gpointer userData)
{
GSettings *config = (GSettings *) backend->config;
GVariant *confValue = g_variant_ref_sink(mkdg_g_value_to_g_variant(value));
GSettings* config = (GSettings*)backend->config;
GVariant* confValue = g_variant_ref_sink(mkdg_g_value_to_g_variant(value));

mkdg_log(DEBUG, "mkdg_g_settings_write_value(-,%s,%s) %s",
mkdg_g_value_to_string(value), key,
mkdg_log(DEBUG,
"mkdg_g_settings_write_value(-,%s,%s) %s",
mkdg_g_value_to_string(value),
key,
mkdg_g_variant_to_string(confValue));
gboolean result = g_settings_set_value(config, key, confValue);

g_settings_sync();
if (!result) {
mkdg_log(ERROR,
"mkdg_g_settings_backend_write_value(-,%s,%s,%s,-): Fail g_settings_set_value",
mkdg_g_value_to_string(value), section, key);
"mkdg_g_settings_backend_write_value(-,%s,%s,%s,-): Fail "
"g_settings_set_value",
mkdg_g_value_to_string(value),
section,
key);

Check warning on line 148 in src/GSettingsBackend.c

View check run for this annotation

Codecov / codecov/patch

src/GSettingsBackend.c#L144-L148

Added lines #L144 - L148 were not covered by tests
}
g_variant_unref(confValue);
return result;
}

MkdgBackend *mkdg_g_settings_backend_new(const gchar *
schemaId,
const gchar *
basePath, gpointer auxData)
MkdgBackend*
mkdg_g_settings_backend_new(const gchar* schemaId,
const gchar* basePath,
gpointer auxData)
{
GSettings *client = g_settings_new(schemaId);
MkdgBackend *result =
mkdg_backend_new(GSETTINGS_BACKEND_ID, (gpointer) client, basePath,
auxData);
GSettings* client = g_settings_new(schemaId);
MkdgBackend* result = mkdg_backend_new(
GSETTINGS_BACKEND_ID, (gpointer)client, basePath, auxData);

result->getKeyFunc = mkdg_g_settings_backend_get_key;
result->readFunc = mkdg_g_settings_backend_read_value;
Expand Down
33 changes: 18 additions & 15 deletions src/GSettingsBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/

/**
Expand All @@ -30,17 +31,18 @@
*/

#ifndef _MKDG_GSETTINGS_BACKEND_H_
# define _MKDG_GSETTINGS_BACKEND_H_
# include <stdio.h>
# include <glib.h>
# include <gio/gio.h>
# include "MakerDialogPropertySpec.h"
# include "MakerDialogBackend.h"
# define GSETTINGS_BACKEND_ID "gsettings"

GValue *mkdg_g_settings_read_value(GSettings * settings,
GValue * value, const gchar * key);
#define _MKDG_GSETTINGS_BACKEND_H_
#include "MakerDialogBackend.h"
#include "MakerDialogPropertySpec.h"
#include <gio/gio.h>
#include <glib.h>
#include <stdio.h>
#define GSETTINGS_BACKEND_ID "gsettings"

GValue*
mkdg_g_settings_read_value(GSettings* settings,
GValue* value,
const gchar* key);

/**
* mkdg_g_settings_backend_new:
Expand All @@ -52,8 +54,9 @@ GValue *mkdg_g_settings_read_value(GSettings * settings,
*
*/

MkdgBackend *mkdg_g_settings_backend_new(const gchar * schemaId,
const gchar * basePath,
gpointer auxData);
MkdgBackend*
mkdg_g_settings_backend_new(const gchar* schemaId,
const gchar* basePath,
gpointer auxData);

#endif /* _MKDG_GSETTINGS_BACKEND_H_ */
#endif /* _MKDG_GSETTINGS_BACKEND_H_ */
Loading

0 comments on commit 29ba59e

Please sign in to comment.