CMarkdown::HSTR CMarkdown::_HSTR::Convert(const Converter &converter) { HSTR H = this; size_t s = SysStringByteLen(B); if (size_t d = converter.Convert(A, s, 0, 0)) { H = (HSTR)SysAllocStringByteLen(0, d); converter.Convert(A, s, H->A, d); SysFreeString(B); } return H; }
int main (int argc, char *argv[]) { try { static struct option long_options[] = { { "source-encoding", required_argument, NULL, 's' }, { "id3v1-encoding", required_argument, NULL, '1' }, { "id3v2-encoding", required_argument, NULL, '2' }, { "preserve-unicode", no_argument, NULL, 'p' }, { "preview", no_argument, NULL, 'w' }, { "version", no_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' }, { "quiet", no_argument, NULL, 'q' }, { NULL, 0, NULL, 0 } }; int long_options_ret; std::string source_encoding; std::string id3v1_encoding = "none"; std::string id3v2_encoding = "none"; bool preserve_unicode = false; bool preview = false; bool usage_ok = true; bool verbose = true; if(argc == 1) { printf("%s", msg::usage); exit(1); } while ( (long_options_ret = getopt_long (argc, argv, "s:1:2:pwdvhq", long_options, NULL)) != -1 ) { switch (long_options_ret) { case 's': source_encoding = optarg; tolower(source_encoding); break; case '1': id3v1_encoding = optarg; tolower(id3v1_encoding); break; case '2': id3v2_encoding = optarg; tolower(id3v2_encoding); break; case 'p': preserve_unicode = true; break; case 'w': preview = true; break; case 'v': printf("%s %s\n", PACKAGE, PACKAGE_VERSION); printf("%s", msg::copyright); exit (1); break; case 'h': printf("%s", msg::usage); exit(1); case 'q': verbose = false; break; default: usage_ok = false; break; } } if (usage_ok && source_encoding.empty ()) { printf("%s", msg::nosenc); usage_ok = false; } if(optind == argc) { printf("%s", msg::nofiles); usage_ok = false; } if (!usage_ok) { printf("%s", msg::seehelp); exit (1); } TagLib::ID3v2::FrameFactory::instance()->setDefaultTextEncoding (TagLib::String::UTF8); for (int i=optind;i<argc;i++) { TagLib::MPEG::File mp3file(argv[i]); if (!mp3file.isOpen ()) { throw msg::nofile(argv[i]); } TagLib::Tag *tag = mp3file.tag(); if(tag->isEmpty()) { printf("%s", msg::emptyfile(argv[i]).c_str()); } else { Converter converter ( source_encoding, id3v1_encoding, id3v2_encoding, mp3file.ID3v1Tag (true), mp3file.ID3v2Tag (true), preserve_unicode ); converter.Convert (tag->title (), &TagLib::Tag::setTitle); converter.Convert (tag->artist (), &TagLib::Tag::setArtist); converter.Convert (tag->album (), &TagLib::Tag::setAlbum); converter.Convert (tag->comment (), &TagLib::Tag::setComment); converter.Convert (tag->genre (), &TagLib::Tag::setGenre); if (preview) { converter.printTags(argv[i]); } else { mp3file.strip(~converter.Tags()); if (!mp3file.save (converter.Tags ())) { printf("%s", msg::writefail(argv[i]).c_str()); } else if(verbose) { printf("%s", msg::filedone(argv[i]).c_str()); } } } } exit (0); } catch (const std::string &e) { printf ("%s", msg::error(e).c_str()); exit (1); } catch (const char *e) { printf ("%s", msg::error(e).c_str()); exit (1); } return 1; }