Skip to content

Commit

Permalink
Merge branch 'master' into fix-typos
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj authored Aug 6, 2023
2 parents d83e047 + c8b099d commit 0f46161
Show file tree
Hide file tree
Showing 196 changed files with 4,761 additions and 7,018 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: Chromium
SortIncludes: false
13 changes: 13 additions & 0 deletions .github/workflows/commit-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,24 @@ on:
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout last commit
uses: actions/checkout@v3
- name: Install clang-format
run: sudo apt install -y clang-format
- name: Lint
run: find src -name '*.cc' -o -name '*.h' | xargs clang-format -Werror --dry-run || { echo Please lint your code by '"'"find src -name '*.cc' -o -name '*.h' | xargs clang-format -i"'"'.; false; }

linux:
needs: lint
uses: ./.github/workflows/linux-build.yml

macos:
needs: lint
uses: ./.github/workflows/macos-build.yml

windows:
needs: lint
uses: ./.github/workflows/windows-build.yml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ env.bat
node_modules/
*~
.*.swp
.cache/
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ option(BOOST_USE_SIGNALS2 "Boost use signals2 instead of signals" ON)
option(ENABLE_ASAN "Enable Address Sanitizer (Unix Only)" OFF)
option(INSTALL_PRIVATE_HEADERS "Install private headers (usually needed for externally built Rime plugins)" OFF)
option(ENABLE_EXTERNAL_PLUGINS "Enable loading of externally built Rime plugins (from directory set by RIME_PLUGINS_DIR variable)" OFF)
option(ENABLE_THREADING "Enable threading for deployer" ON)

set(RIME_DATA_DIR "${CMAKE_INSTALL_FULL_DATADIR}/rime-data" CACHE STRING "Target directory for Rime data")
set(RIME_PLUGINS_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/rime-plugins" CACHE STRING "Target directory for externally built Rime plugins")
Expand Down Expand Up @@ -97,6 +98,10 @@ endif()

find_package(Threads)

if(NOT ENABLE_THREADING)
add_definitions(-DRIME_NO_THREADING)
endif()

if(BUILD_TEST)
find_package(GTest REQUIRED)
if(GTEST_FOUND)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Community:
- [emacs-rime](https://github.com/DogLooksGood/emacs-rime): frontend for Emacs
- [fcitx-rime](https://github.com/fcitx/fcitx-rime): Fcitx frontend for Linux
- [fcitx5-rime](https://github.com/fcitx/fcitx5-rime): Fcitx5 frontend for Linux
- [iRime](https://github.com/jimmy54/iRime): frontend for iOS
- [Hamster](https://github.com/imfuxiao/Hamster): frontend for iOS
- [PIME](https://github.com/EasyIME/PIME): frontend for Windows
- [Trime](https://github.com/osfans/trime): frontend for Android
- [XIME](https://github.com/stackia/XIME): frontend for macOS
Expand Down
32 changes: 25 additions & 7 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ set build_dir_base=build
set build_dir_suffix=
set build_config=Release
set build_boost=0
set build_boost_x86=0
set build_boost_x64=0
set build_boost_arm64=0
set boost_build_variant=release
Expand All @@ -47,6 +48,10 @@ set enable_logging=ON
if "%1" == "" goto end_parsing_cmdline_options
if "%1" == "clean" set clean=1
if "%1" == "boost" set build_boost=1
if "%1" == "boost_x86" (
set build_boost=1
set build_boost_x86=1
)
if "%1" == "boost_x64" (
set build_boost=1
set build_boost_x64=1
Expand Down Expand Up @@ -134,34 +139,47 @@ set bjam_options=%bjam_options%^
cxxflags="/Zc:threadSafeInit- "

set bjam_options_x86=%bjam_options%^
define=BOOST_USE_WINAPI_VERSION=0x0501
define=BOOST_USE_WINAPI_VERSION=0x0501^
architecture=x86^
address-model=32

set bjam_options_x64=%bjam_options%^
define=BOOST_USE_WINAPI_VERSION=0x0502^
address-model=64^
--stagedir=stage_x64
architecture=x86^
address-model=64

set bjam_options_arm64=%bjam_options%^
define=BOOST_USE_WINAPI_VERSION=0x0A00^
architecture=arm^
address-model=64

if %build_boost% == 1 (
if %build_boost_x86% == 0 (
if %build_boost_x64% == 0 (
if %build_boost_arm64% == 0 (
rem default architecture
set build_boost_x86=1
))))

if %build_boost% == 1 (
pushd %BOOST_ROOT%
if not exist b2.exe call .\bootstrap.bat
if errorlevel 1 goto error

if %build_boost_arm64% == 1 (
b2 %bjam_options_arm64% stage %boost_compiled_libs%
) else (
if %build_boost_x86% == 1 (
b2 %bjam_options_x86% stage %boost_compiled_libs%
if errorlevel 1 goto error
)
if errorlevel 1 goto error

if %build_boost_x64% == 1 (
b2 %bjam_options_x64% stage %boost_compiled_libs%
if errorlevel 1 goto error
)

if %build_boost_arm64% == 1 (
b2 %bjam_options_arm64% stage %boost_compiled_libs%
if errorlevel 1 goto error
)
popd
)

Expand Down
12 changes: 6 additions & 6 deletions env.bat.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ rem Customize your build environment and save the modified copy to env.bat
set RIME_ROOT=%CD%

rem REQUIRED: path to Boost source directory
if not defined BOOST_ROOT set BOOST_ROOT=%RIME_ROOT%\deps\boost_1_76_0
if not defined BOOST_ROOT set BOOST_ROOT=%RIME_ROOT%\deps\boost_1_78_0

rem OPTIONAL: architecture, Visual Studio version and platform toolset
rem set ARCH=Win32
rem set BJAM_TOOLSET=msvc-14.2
rem set CMAKE_GENERATOR="Visual Studio 16 2019"
rem set PLATFORM_TOOLSET=v142
rem architecture, Visual Studio version and platform toolset
set ARCH=Win32
set BJAM_TOOLSET=msvc-14.2
set CMAKE_GENERATOR="Visual Studio 16 2019"
set PLATFORM_TOOLSET=v142

rem OPTIONAL: path to additional build tools
rem set DEVTOOLS_PATH=%ProgramFiles%\Git\cmd;%ProgramFiles%\CMake\bin;C:\Python27;
2 changes: 1 addition & 1 deletion env.vs2017_xp.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set RIME_ROOT=%CD%
rem REQUIRED: path to Boost source directory
if not defined BOOST_ROOT set BOOST_ROOT=%RIME_ROOT%\deps\boost_1_69_0

rem OPTIONAL: architecture, Visual Studio version and platform toolset
rem architecture, Visual Studio version and platform toolset
set ARCH=Win32
set BJAM_TOOLSET=msvc-14.1
set CMAKE_GENERATOR="Visual Studio 15 2017"
Expand Down
4 changes: 2 additions & 2 deletions env.vs2019.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ rem Customize your build environment and save the modified copy to env.bat
set RIME_ROOT=%CD%

rem REQUIRED: path to Boost source directory
if not defined BOOST_ROOT set BOOST_ROOT=%RIME_ROOT%\deps\boost_1_76_0
if not defined BOOST_ROOT set BOOST_ROOT=%RIME_ROOT%\deps\boost_1_78_0

rem OPTIONAL: architecture, Visual Studio version and platform toolset
rem architecture, Visual Studio version and platform toolset
set ARCH=Win32
set BJAM_TOOLSET=msvc-14.2
set CMAKE_GENERATOR="Visual Studio 16 2019"
Expand Down
4 changes: 2 additions & 2 deletions env.vs2022.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ rem Customize your build environment and save the modified copy to env.bat
set RIME_ROOT=%CD%

rem REQUIRED: path to Boost source directory
if not defined BOOST_ROOT set BOOST_ROOT=%RIME_ROOT%\deps\boost_1_76_0
if not defined BOOST_ROOT set BOOST_ROOT=%RIME_ROOT%\deps\boost_1_78_0

rem OPTIONAL: architecture, Visual Studio version and platform toolset
rem architecture, Visual Studio version and platform toolset
set ARCH=Win32
set BJAM_TOOLSET=msvc-14.3
set CMAKE_GENERATOR="Visual Studio 17 2022"
Expand Down
2 changes: 1 addition & 1 deletion install-boost.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ setlocal

if not defined RIME_ROOT set RIME_ROOT=%CD%

if not defined boost_version set boost_version=1.76.0
if not defined boost_version set boost_version=1.78.0
set boost_x_y_z=%boost_version:.=_%

if not defined BOOST_ROOT set BOOST_ROOT=%RIME_ROOT%\deps\boost_%boost_x_y_z%
Expand Down
28 changes: 11 additions & 17 deletions src/rime/algo/algebra.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ void Script::Merge(const string& s,
auto e = std::find(m.begin(), m.end(), x);
if (e == m.end()) {
m.push_back(y);
}
else {
} else {
SpellingProperties& zz(e->properties);
if (yy.type < zz.type)
zz.type = yy.type;
Expand All @@ -53,19 +52,18 @@ void Script::Dump(const string& file_name) const {
for (const value_type& v : *this) {
bool first = true;
for (const Spelling& s : v.second) {
out << (first ? v.first : "") << '\t'
<< s.str << '\t'
<< "-ac?!"[s.properties.type] << '\t'
<< s.properties.credibility << '\t'
<< s.properties.tips << std::endl;
out << (first ? v.first : "") << '\t' << s.str << '\t'
<< "-ac?!"[s.properties.type] << '\t' << s.properties.credibility
<< '\t' << s.properties.tips << std::endl;
first = false;
}
}
out.close();
}

bool Projection::Load(an<ConfigList> settings) {
if (!settings) return false;
if (!settings)
return false;
calculation_.clear();
Calculus calc;
bool success = true;
Expand All @@ -76,12 +74,11 @@ bool Projection::Load(an<ConfigList> settings) {
success = false;
break;
}
const string &formula(v->str());
const string& formula(v->str());
an<Calculation> x;
try {
x.reset(calc.Parse(formula));
}
catch (boost::regex_error& e) {
} catch (boost::regex_error& e) {
LOG(ERROR) << "Error parsing formula '" << formula << "': " << e.what();
}
if (!x) {
Expand All @@ -107,8 +104,7 @@ bool Projection::Apply(string* value) {
try {
if (x->Apply(&s))
modified = true;
}
catch (std::runtime_error& e) {
} catch (std::runtime_error& e) {
LOG(ERROR) << "Error applying calculation: " << e.what();
return false;
}
Expand All @@ -132,8 +128,7 @@ bool Projection::Apply(Script* value) {
bool applied = false;
try {
applied = x->Apply(&s);
}
catch (std::runtime_error& e) {
} catch (std::runtime_error& e) {
LOG(ERROR) << "Error applying calculation: " << e.what();
return false;
}
Expand All @@ -145,8 +140,7 @@ bool Projection::Apply(Script* value) {
if (x->addition() && !s.str.empty()) {
temp.Merge(s.str, s.properties, v.second);
}
}
else {
} else {
temp.Merge(v.first, SpellingProperties(), v.second);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/rime/algo/algebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Projection {
RIME_API bool Apply(string* value);
// {z, y, x} -> {a, b, c, d}
RIME_API bool Apply(Script* value);

protected:
vector<of<Calculation>> calculation_;
};
Expand Down
13 changes: 5 additions & 8 deletions src/rime/algo/calculus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace rime {

const double kAbbreviationPenalty = -0.6931471805599453; // log(0.5)
const double kFuzzySpellingPenalty = -0.6931471805599453; // log(0.5)
const double kAbbreviationPenalty = -0.6931471805599453; // log(0.5)
const double kFuzzySpellingPenalty = -0.6931471805599453; // log(0.5)

Calculus::Calculus() {
Register("xlit", &Transliteration::Parse);
Expand All @@ -23,8 +23,7 @@ Calculus::Calculus() {
Register("abbrev", &Abbreviation::Parse);
}

void Calculus::Register(const string& token,
Calculation::Factory* factory) {
void Calculus::Register(const string& token, Calculation::Factory* factory) {
factories_[token] = factory;
}

Expand Down Expand Up @@ -55,8 +54,7 @@ Calculation* Transliteration::Parse(const vector<string>& args) {
const char* pr = right.c_str();
uint32_t cl, cr;
map<uint32_t, uint32_t> char_map;
while ((cl = utf8::unchecked::next(pl)),
(cr = utf8::unchecked::next(pr)),
while ((cl = utf8::unchecked::next(pl)), (cr = utf8::unchecked::next(pr)),
cl && cr) {
char_map[cl] = cr;
}
Expand Down Expand Up @@ -113,8 +111,7 @@ Calculation* Transformation::Parse(const vector<string>& args) {
bool Transformation::Apply(Spelling* spelling) {
if (!spelling || spelling->str.empty())
return false;
string result = boost::regex_replace(spelling->str,
pattern_, replacement_);
string result = boost::regex_replace(spelling->str, pattern_, replacement_);
if (result == spelling->str)
return false;
spelling->str.swap(result);
Expand Down
2 changes: 1 addition & 1 deletion src/rime/algo/calculus.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace rime {

class Calculation {
public:
using Factory = Calculation* (const vector<string>& args);
using Factory = Calculation*(const vector<string>& args);

Calculation() = default;
virtual ~Calculation() = default;
Expand Down
8 changes: 4 additions & 4 deletions src/rime/algo/dynamics.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ inline double formula_d(double d, double t, double da, double ta) {
inline double formula_p(double s, double u, double t, double d) {
const double kM = 1 / (1 - exp(-0.005));
double m = s - (s - u) * pow((1 - exp(-t / 10000)), 10);
return (d < 20) ? m + (0.5 - m) * (d / kM) :
m + (1 - m) * (pow(4, (d / kM)) - 1) / 3;
return (d < 20) ? m + (0.5 - m) * (d / kM)
: m + (1 - m) * (pow(4, (d / kM)) - 1) / 3;
}

}
}
} // namespace algo
} // namespace rime
Loading

0 comments on commit 0f46161

Please sign in to comment.