Merge "Add CommandExecutor for dicttoolkit."
This commit is contained in:
commit
61280c0b7f
14 changed files with 399 additions and 28 deletions
|
@ -16,6 +16,12 @@ LATIN_IME_DICT_TOOLKIT_MAIN_SRC_FILES := \
|
|||
dict_toolkit_main.cpp
|
||||
|
||||
LATIN_IME_DICT_TOOLKIT_SRC_FILES := \
|
||||
$(addprefix command_executors/, \
|
||||
diff_executor.cpp \
|
||||
header_executor.cpp \
|
||||
help_executor.cpp \
|
||||
info_executor.cpp \
|
||||
makedict_executor.cpp) \
|
||||
utils/command_utils.cpp
|
||||
|
||||
LATIN_IME_DICT_TOOLKIT_TEST_FILES := \
|
||||
|
|
|
@ -26,15 +26,14 @@ void usage(int argc, char **argv) {
|
|||
int main(int argc, char **argv) {
|
||||
if (argc < MIN_ARG_COUNT) {
|
||||
usage(argc, argv);
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
using namespace latinime::dicttoolkit;
|
||||
const CommandType commandType = CommandUtils::getCommandType(argv[1]);
|
||||
if (commandType == CommandType::Unknown) {
|
||||
CommandUtils::printCommandUnknownMessage(argv[0], argv[1]);
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
// TODO: Implement.
|
||||
fprintf(stderr, "Command '%s' has not been implemented yet.\n", argv[1]);
|
||||
return 0;
|
||||
const auto executor = CommandUtils::getCommandExecutor(commandType);
|
||||
return executor(argc - 1, argv + 1);
|
||||
}
|
||||
|
|
32
native/dicttoolkit/src/command_executors/diff_executor.cpp
Normal file
32
native/dicttoolkit/src/command_executors/diff_executor.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "command_executors/diff_executor.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
namespace latinime {
|
||||
namespace dicttoolkit {
|
||||
|
||||
const char *const DiffExecutor::COMMAND_NAME = "diff";
|
||||
|
||||
/* static */ int DiffExecutor::run(const int argc, char **argv) {
|
||||
fprintf(stderr, "Command '%s' has not been implemented yet.\n", COMMAND_NAME);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace dicttoolkit
|
||||
} // namespace latinime
|
37
native/dicttoolkit/src/command_executors/diff_executor.h
Normal file
37
native/dicttoolkit/src/command_executors/diff_executor.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LATINIME_DICT_TOOLKIT_DIFF_EXECUTOR_H
|
||||
#define LATINIME_DICT_TOOLKIT_DIFF_EXECUTOR_H
|
||||
|
||||
#include "dict_toolkit_defines.h"
|
||||
|
||||
namespace latinime {
|
||||
namespace dicttoolkit {
|
||||
|
||||
class DiffExecutor final {
|
||||
public:
|
||||
static const char *const COMMAND_NAME;
|
||||
|
||||
static int run(const int argc, char **argv);
|
||||
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(DiffExecutor);
|
||||
};
|
||||
|
||||
} // namespace dicttoolkit
|
||||
} // namepsace latinime
|
||||
#endif // LATINIME_DICT_TOOLKIT_DIFF_EXECUTOR_H
|
32
native/dicttoolkit/src/command_executors/header_executor.cpp
Normal file
32
native/dicttoolkit/src/command_executors/header_executor.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "command_executors/header_executor.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
namespace latinime {
|
||||
namespace dicttoolkit {
|
||||
|
||||
const char *const HeaderExecutor::COMMAND_NAME = "header";
|
||||
|
||||
/* static */ int HeaderExecutor::run(const int argc, char **argv) {
|
||||
fprintf(stderr, "Command '%s' has not been implemented yet.\n", COMMAND_NAME);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace dicttoolkit
|
||||
} // namespace latinime
|
37
native/dicttoolkit/src/command_executors/header_executor.h
Normal file
37
native/dicttoolkit/src/command_executors/header_executor.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LATINIME_DICT_TOOLKIT_HEADER_EXECUTOR_H
|
||||
#define LATINIME_DICT_TOOLKIT_HEADER_EXECUTOR_H
|
||||
|
||||
#include "dict_toolkit_defines.h"
|
||||
|
||||
namespace latinime {
|
||||
namespace dicttoolkit {
|
||||
|
||||
class HeaderExecutor final {
|
||||
public:
|
||||
static const char *const COMMAND_NAME;
|
||||
|
||||
static int run(const int argc, char **argv);
|
||||
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(HeaderExecutor);
|
||||
};
|
||||
|
||||
} // namespace dicttoolkit
|
||||
} // namepsace latinime
|
||||
#endif // LATINIME_DICT_TOOLKIT_HEADER_EXECUTOR_H
|
32
native/dicttoolkit/src/command_executors/help_executor.cpp
Normal file
32
native/dicttoolkit/src/command_executors/help_executor.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "command_executors/help_executor.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
namespace latinime {
|
||||
namespace dicttoolkit {
|
||||
|
||||
const char *const HelpExecutor::COMMAND_NAME = "help";
|
||||
|
||||
/* static */ int HelpExecutor::run(const int argc, char **argv) {
|
||||
fprintf(stderr, "Command '%s' has not been implemented yet.\n", COMMAND_NAME);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace dicttoolkit
|
||||
} // namespace latinime
|
37
native/dicttoolkit/src/command_executors/help_executor.h
Normal file
37
native/dicttoolkit/src/command_executors/help_executor.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LATINIME_DICT_TOOLKIT_HELP_EXECUTOR_H
|
||||
#define LATINIME_DICT_TOOLKIT_HELP_EXECUTOR_H
|
||||
|
||||
#include "dict_toolkit_defines.h"
|
||||
|
||||
namespace latinime {
|
||||
namespace dicttoolkit {
|
||||
|
||||
class HelpExecutor final {
|
||||
public:
|
||||
static const char *const COMMAND_NAME;
|
||||
|
||||
static int run(const int argc, char **argv);
|
||||
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(HelpExecutor);
|
||||
};
|
||||
|
||||
} // namespace dicttoolkit
|
||||
} // namepsace latinime
|
||||
#endif // LATINIME_DICT_TOOLKIT_HELP_EXECUTOR_H
|
32
native/dicttoolkit/src/command_executors/info_executor.cpp
Normal file
32
native/dicttoolkit/src/command_executors/info_executor.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "command_executors/info_executor.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
namespace latinime {
|
||||
namespace dicttoolkit {
|
||||
|
||||
const char *const InfoExecutor::COMMAND_NAME = "info";
|
||||
|
||||
/* static */ int InfoExecutor::run(const int argc, char **argv) {
|
||||
fprintf(stderr, "Command '%s' has not been implemented yet.\n", COMMAND_NAME);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace dicttoolkit
|
||||
} // namespace latinime
|
37
native/dicttoolkit/src/command_executors/info_executor.h
Normal file
37
native/dicttoolkit/src/command_executors/info_executor.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LATINIME_DICT_TOOLKIT_INFO_EXECUTOR_H
|
||||
#define LATINIME_DICT_TOOLKIT_INFO_EXECUTOR_H
|
||||
|
||||
#include "dict_toolkit_defines.h"
|
||||
|
||||
namespace latinime {
|
||||
namespace dicttoolkit {
|
||||
|
||||
class InfoExecutor final {
|
||||
public:
|
||||
static const char *const COMMAND_NAME;
|
||||
|
||||
static int run(const int argc, char **argv);
|
||||
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(InfoExecutor);
|
||||
};
|
||||
|
||||
} // namepsace dicttoolkit
|
||||
} // namespace latinime
|
||||
#endif // LATINIME_DICT_TOOLKIT_INFO_EXECUTOR_H
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "command_executors/makedict_executor.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
namespace latinime {
|
||||
namespace dicttoolkit {
|
||||
|
||||
const char *const MakedictExecutor::COMMAND_NAME = "makedict";
|
||||
|
||||
/* static */ int MakedictExecutor::run(const int argc, char **argv) {
|
||||
fprintf(stderr, "Command '%s' has not been implemented yet.\n", COMMAND_NAME);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace dicttoolkit
|
||||
} // namespace latinime
|
37
native/dicttoolkit/src/command_executors/makedict_executor.h
Normal file
37
native/dicttoolkit/src/command_executors/makedict_executor.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LATINIME_DICT_TOOLKIT_MAKEDICT_EXECUTOR_H
|
||||
#define LATINIME_DICT_TOOLKIT_MAKEDICT_EXECUTOR_H
|
||||
|
||||
#include "dict_toolkit_defines.h"
|
||||
|
||||
namespace latinime {
|
||||
namespace dicttoolkit {
|
||||
|
||||
class MakedictExecutor final {
|
||||
public:
|
||||
static const char *const COMMAND_NAME;
|
||||
|
||||
static int run(const int argc, char **argv);
|
||||
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(MakedictExecutor);
|
||||
};
|
||||
|
||||
} // namespace dicttoolkit
|
||||
} // namepsace latinime
|
||||
#endif // LATINIME_DICT_TOOLKIT_MAKEDICT_EXECUTOR_H
|
|
@ -16,30 +16,59 @@
|
|||
|
||||
#include "utils/command_utils.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "command_executors/diff_executor.h"
|
||||
#include "command_executors/header_executor.h"
|
||||
#include "command_executors/help_executor.h"
|
||||
#include "command_executors/info_executor.h"
|
||||
#include "command_executors/makedict_executor.h"
|
||||
|
||||
namespace latinime {
|
||||
namespace dicttoolkit {
|
||||
|
||||
const char *const CommandUtils::COMMAND_NAME_INFO = "info";
|
||||
const char *const CommandUtils::COMMAND_NAME_DIFF = "diff";
|
||||
const char *const CommandUtils::COMMAND_NAME_MAKEDICT = "makedict";
|
||||
const char *const CommandUtils::COMMAND_NAME_HEADER = "header";
|
||||
const char *const CommandUtils::COMMAND_NAME_HELP = "help";
|
||||
|
||||
/* static */ CommandType CommandUtils::getCommandType(const std::string &commandName) {
|
||||
if (commandName == COMMAND_NAME_INFO) {
|
||||
if (commandName == InfoExecutor::COMMAND_NAME) {
|
||||
return CommandType::Info;
|
||||
} else if (commandName == COMMAND_NAME_DIFF) {
|
||||
} else if (commandName == DiffExecutor::COMMAND_NAME) {
|
||||
return CommandType::Diff;
|
||||
} else if (commandName == COMMAND_NAME_MAKEDICT) {
|
||||
} else if (commandName == MakedictExecutor::COMMAND_NAME) {
|
||||
return CommandType::Makedict;
|
||||
} else if (commandName == COMMAND_NAME_HEADER) {
|
||||
} else if (commandName == HeaderExecutor::COMMAND_NAME) {
|
||||
return CommandType::Header;
|
||||
} else if (commandName == COMMAND_NAME_HELP) {
|
||||
} else if (commandName == HelpExecutor::COMMAND_NAME) {
|
||||
return CommandType::Help;
|
||||
} else {
|
||||
return CommandType::Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ void CommandUtils::printCommandUnknownMessage(const std::string &programName,
|
||||
const std::string &commandName) {
|
||||
fprintf(stderr, "Command '%s' is unknown. Try '%s %s' for more information.\n",
|
||||
commandName.c_str(), programName.c_str(), HelpExecutor::COMMAND_NAME);
|
||||
}
|
||||
|
||||
/* static */ std::function<int(int, char **)> CommandUtils::getCommandExecutor(
|
||||
const CommandType commandType) {
|
||||
switch (commandType) {
|
||||
case CommandType::Info:
|
||||
return InfoExecutor::run;
|
||||
case CommandType::Diff:
|
||||
return DiffExecutor::run;
|
||||
case CommandType::Makedict:
|
||||
return MakedictExecutor::run;
|
||||
case CommandType::Header:
|
||||
return HeaderExecutor::run;
|
||||
case CommandType::Help:
|
||||
return HelpExecutor::run;
|
||||
default:
|
||||
return [] (int, char **) -> int {
|
||||
printf("Command executor not found.");
|
||||
return 1;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace dicttoolkit
|
||||
} // namespace latinime
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
#ifndef LATINIME_DICT_TOOLKIT_COMMAND_UTILS_H
|
||||
#define LATINIME_DICT_TOOLKIT_COMMAND_UTILS_H
|
||||
|
||||
#include <cstdio>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "dict_toolkit_defines.h"
|
||||
|
@ -37,21 +38,12 @@ enum class CommandType : int {
|
|||
class CommandUtils {
|
||||
public:
|
||||
static CommandType getCommandType(const std::string &commandName);
|
||||
|
||||
static void printCommandUnknownMessage(const std::string &programName,
|
||||
const std::string &commandName) {
|
||||
fprintf(stderr, "Command '%s' is unknown. Try '%s %s' for more information.\n",
|
||||
commandName.c_str(), programName.c_str(), COMMAND_NAME_HELP);
|
||||
}
|
||||
const std::string &commandName);
|
||||
static std::function<int(int, char **)> getCommandExecutor(const CommandType commandType);
|
||||
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(CommandUtils);
|
||||
|
||||
static const char *const COMMAND_NAME_INFO;
|
||||
static const char *const COMMAND_NAME_DIFF;
|
||||
static const char *const COMMAND_NAME_MAKEDICT;
|
||||
static const char *const COMMAND_NAME_HEADER;
|
||||
static const char *const COMMAND_NAME_HELP;
|
||||
};
|
||||
} // namespace dicttoolkit
|
||||
} // namespace latinime
|
||||
|
|
Loading…
Reference in a new issue