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 92c668c
Show file tree
Hide file tree
Showing 36 changed files with 2,107 additions and 2,254 deletions.
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 LLVM 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
71 changes: 30 additions & 41 deletions src/GSettingsBackend.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
*
* 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';
Expand Down Expand Up @@ -65,9 +65,8 @@ 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);

mkdg_log(DEBUG, "mkdg_g_settings_read_value(-,-,%s)", key);
Expand All @@ -80,38 +79,30 @@ 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)
{
return (gchar *) key;
gchar *mkdg_g_settings_backend_get_key(MkdgBackend *backend,
const gchar *section, const gchar *key,
gpointer userData) {
return (gchar *)key;
}

GValue *mkdg_g_settings_backend_read_value(MkdgBackend * backend,
GValue * value,
const gchar * section,
const gchar * key, gpointer userData)
{
GSettings *config = (GSettings *) backend->config;
GValue *mkdg_g_settings_backend_read_value(MkdgBackend *backend, GValue *value,
const gchar *section,
const gchar *key,
gpointer userData) {
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)
{
GSettings *config = (GSettings *) backend->config;
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));

mkdg_log(DEBUG, "mkdg_g_settings_write_value(-,%s,%s) %s",
Expand All @@ -122,22 +113,20 @@ gboolean mkdg_g_settings_backend_write_value(MkdgBackend *
g_settings_sync();
if (!result) {
mkdg_log(ERROR,
"mkdg_g_settings_backend_write_value(-,%s,%s,%s,-): Fail g_settings_set_value",
"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 119 in src/GSettingsBackend.c

View check run for this annotation

Codecov / codecov/patch

src/GSettingsBackend.c#L116-L119

Added lines #L116 - L119 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);
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
28 changes: 14 additions & 14 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,16 @@
*/

#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 +52,8 @@ GValue *mkdg_g_settings_read_value(GSettings * settings,
*
*/

MkdgBackend *mkdg_g_settings_backend_new(const gchar * schemaId,
const gchar * basePath,
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 92c668c

Please sign in to comment.