# include // getopt # include "qwav.hh" # include "qexception.hh" #include #ifdef NLS # include # include # define _(s) gettext (s) #else # define _(s) (s) #endif void usage () { cerr << ' ' << APPNAME << _(": join wav files\n"); cerr << _(" syntax: ") << APPNAME << _(" [option]... file1 file2...\n"); cerr << _(" -h, --help: show this help and exit\n"); cerr << _(" -o, --output : send output to . otherwise, append to \n"); cerr << _(" -v, --verbose: verbose\n"); cerr << _(" -V, --version: show version and exit\n"); } int main (int argc, char **argv) { bool verbose=false; string outfile; static struct option long_options[] = { {"help",no_argument,0,'h'}, {"output",required_argument,0,'o'}, {"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 if (argc==1) { usage(); return 1; } int option; // supress getopt error message opterr = 0; while ((option = getopt_long(argc, argv, "ho:vV",long_options,0)) != EOF) switch (option) { case 'h': usage(); return 0; break; case 'o': outfile=optarg; 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<2) { cerr << APPNAME << _(": at least two files to join must be specified\n"); usage(); return 1; } argv += optind; qwav *wav; try { // resolve which is the first file if (outfile!="") { wav = new qwav(*argv); if (verbose) cerr << _("copying '") << *argv << _("' to '") << outfile << "'..."; wav->dup(outfile); if (verbose) cerr << "ok." << endl; delete wav; wav = new qwav (outfile,qwav::READWRITE); } else wav = new qwav(*argv,qwav::READWRITE); // append the rest of the files while (*++argv) { qwav ww(*argv); if (verbose) cerr << _("appending '") << ww.getName() << _("' to '") << wav->getName() << "'..."; wav->append(ww); if (verbose) cerr << "ok." << endl; } } catch (qexception e) { cerr << *argv << ": " << e << endl; return 1; } if (verbose) cerr << *wav << endl; delete wav; return 0; }