diff --git a/main.cpp b/main.cpp index ae639e7..ffdafaa 100644 --- a/main.cpp +++ b/main.cpp @@ -15,27 +15,38 @@ FcChar8 * toFcChar8(const char * sc) { return result; } -int main() { +void print_help(const string & program_name) { + cout << "Usage: " << program_name << "\"Font Pattern\"" << endl; + cout << "Note: better to quote all your pattern," << endl; + cout << " since bash will split them into multi word if not" << endl; +} + +int main(int argc, char ** argv) { FcPattern * fcp = FcPatternCreate(); - string line; - getline(cin, line); + if (argc != 2) { + cout << "Wrong usage!" << endl; + print_help(argv[0]); - line += ','; - size_t l = 0, r = line.find(",", 0); + exit(-1); + } + + string patterns = argv[1]; + + patterns += ','; + size_t l = 0, r = patterns.find(",", 0); while (r != string::npos) { - FcChar8 * queryName = toFcChar8(line.substr(l, r - l).c_str()); + FcChar8 * queryName = toFcChar8(patterns.substr(l, r - l).c_str()); FcPatternAddString(fcp, FC_FAMILY, queryName); delete[] queryName; l = r + 1; - r = line.find(",", l + 1); + r = patterns.find(",", l + 1); } FcChar8 * resultName = nullptr; FcConfigSubstitute(nullptr, fcp, FcMatchPattern); - cout << "========================" << endl; for (int i = 0; FcPatternGetString(fcp, FC_FAMILY, i, &resultName) == FcResultMatch; ++i) { cout << resultName << endl; }