#include <stdexcept>
#include <exception>
#include <memory>
+#include <unistd.h>
#include "sqlite.h"
#include "kana2romaji.h"
using namespace std;
" -b search for entries beginning with <subject>\n"
" -f perform a fulltext search\n"
" -i case-insensitive search (implied by -b or -f)\n"
+ " -r also translate kana to romaji\n"
"\n"
" -j translate from japanese\n"
" -J translate to japanese\n"
bool fulltext = false;
bool beginning = false;
bool ci_search = false;
-
- class invalid_option : public std::runtime_error {
- invalid_option(const string& s) : std::runtime_error(s) {}
- };
+ bool show_romaji = false;
void getFrom(int argc, char** argv) {
int opt;
- while ((opt = getopt(argc, argv, "bfijJl:")) != -1)
+ while ((opt = getopt(argc, argv, "bfirjJl:")) != -1)
switch (opt) {
case 'b': beginning = true; break;
case 'f': fulltext = true; break;
case 'i': ci_search = true; break;
+ case 'r': show_romaji = true; break;
case 'j': source = JAPANESE; break;
case 'J': source = NOT_JAPANESE; break;
case 'l': target = optarg; break;
- case '?': throw invalid_argument(string("unrecognized option"));
+ case '?': throw invalid_argument(string("unrecognized option"));
}
}
}
sql::query("SELECT kana FROM reading WHERE entry=%s") % *value,
accumulate, &kana);
- string rom;
- kana2romaji(kana,rom);
if (kanji.size())
- cout << kanji << " (" << kana << ") (" << rom << ')' << endl;
+ cout << kanji << " (" << kana << ')';
else
- cout << kana << " (" << rom << ')' << endl;
+ cout << kana;
+
+ if(options::show_romaji) {
+ string rom;
+ kana2romaji(kana,rom);
+
+ cout << " (" << rom << ')';
+ }
+
+ cout << endl;
string sense;
db->exec(
if (options::source == options::JAPANESE && !isUTF8)
options::source = options::JAPANESE_ROMAJI;
else if (options::source == options::UNKNOWN)
- options::source = isUTF8 ? options::JAPANESE : options::NOT_JAPANESE;
+ options::source = isUTF8 ? options::JAPANESE : options::UNKNOWN;
}
int main(int argc, char** argv)
fromJapanese(subject);
else if (options::source == options::JAPANESE_ROMAJI)
fromRomaji(subject);
- else
+ else if (options::source == options::NOT_JAPANESE)
+ toJapanese(subject);
+ else { /* options::UNKNOWN */
+ fromRomaji(subject);
toJapanese(subject);
+ }
cout << entries << " match(es) found." << endl;
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
- cerr << e.what() << '\n';
- return EXIT_FAILURE;
+ cerr << e.what() << '\n';
+ return EXIT_FAILURE;
}