# include // getopt # include "qmp3.hh" # include "qexception.hh" #ifdef NLS # include # include # define _(s) gettext (s) #else # define _(s) (s) #endif void usage () { cerr << ' ' << APPNAME << _(": show info from mp3 files\n"); cerr << _(" syntax: ") << APPNAME << _(" [option]... file...\n"); cerr << _(" -c, --check: check the entire stream (slower but accurate)\n"); cerr << _(" -h, --help: show this help and exit\n"); cerr << _(" -s, --summary-only: show only the summary\n"); cerr << _(" -v, --verbose: verbose\n"); cerr << _(" -V, --version: show version and exit\n"); } int main (int argc, char **argv) { int option; bool verbose=false; bool summarize=false; bool check=false; static struct option long_options[] = { {"check",no_argument,0,'c'}, {"help",no_argument,0,'h'}, {"summary-only",no_argument,0,'s'}, {"verbose",no_argument,0,'v'}, {"version",no_argument,0,'V'}, {0,0,0,0} }; #ifdef NLS setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #endif // un altre dia, per defecte llegir *.mp3 ... if (argc==1) { usage(); return 1; } // supress getopt error message opterr = 0; while ((option = getopt_long(argc, argv, "chsvV",long_options,0)) != EOF) switch (option) { case 'c': check=true; break; case 'h': usage(); return 0; break; case 's': summarize=true; break; case 'v': verbose=true; break; case 'V': cerr << APPNAME << " - " << _("version") << ' ' << VERSION << _("build") << ' ' << __DATE__ << '\n'; return 0; break; case '?': default: cerr << APPNAME << ": " << _("option") << " '" << argv[optind-1] << "' " << _("is not recognized or bad used") << '\n'; usage(); return 1; } if (argc<=optind) { // haurķem de fer *.mp3 ... cerr << APPNAME << _(": no input file(s)") << endl; usage(); return 1; } u_int32_t files=0, errors=0; u_int32_t msduration, total_msduration=0; u_int32_t bytes, frames, total_bytes=0, total_frames=0; while (argv[optind]) { files++; try { qmp3 p(argv[optind]); if (!check && p.isVbr()) { if (verbose) cerr << p.getName() << _(": vbr detected => automatic check") << endl; check = true; } if (check) p.scan(); msduration = p.getMsDuration(); total_msduration += msduration; if (!summarize) cout << p; if (verbose) { bytes = p.getSize(); frames = p.getFrames(); if (!summarize) cout << " " << bytes << " bytes " << frames << " frames"; total_bytes += bytes; total_frames += frames; } if (!summarize) cout << endl; } catch (qexception e) { cerr << argv[optind] << ": " << e << endl; errors++; } optind++; } cout << files << _(" file") << (files>1?"s":""); if (errors) cout << errors << _(" error") << (errors>1?"s":""); if (verbose) { cout << " => " << total_msduration/60000 << ":"; cout.width(2); cout.fill('0'); cout << (total_msduration/1000)%60 << '.'; cout.width(3); cout.fill('0'); cout << total_msduration%1000 << " " << total_frames << " " << total_bytes << " bytes\n"; } else { cout << " => " << total_msduration/60000 << ':'; cout.width(2); cout.fill('0'); cout << (total_msduration/1000)%60 << '\n'; } }