00001
00024 #include "PlayListConverter.h"
00025 #include "config.h"
00026 #include <unistd.h>
00027 #include <getopt.h>
00028 #include <string>
00029 #include <list>
00030 #include <iostream>
00031
00032 using namespace std;
00033
00035 const char c_about[] = "An application to transform rmp (.emp) files into other "
00036 "formats & and launch associated applications\n"
00037 "usage : " PACKAGE " [options] emp_file\n"
00038 "options :\n"
00039 "\t--format - process the file with this format (may be specified more than once)\n"
00040 "\t--no-wait - dont wait for a process to finish before processing the next format\n"
00041 "\t--help - show this help\n"
00042 "\t--list - display the list of available formats\n";
00043
00045 struct CommandLineOptions {
00046 PlayListConverter::Options options;
00047 string emp_file;
00048 };
00049
00050
00051
00052 void parse_options(int argc, char* argc[], CommandLineOptions& options);
00053 void show_help();
00054 void list_formats();
00055
00057 int main(int argc, char* argv[])
00058 {
00059 CommandLineOptions cmdline;
00060 parse_options(argc, argv, cmdline);
00061
00062 if (cmdline.emp_file.empty() )
00063 show_help();
00064
00065 PlayListConverter converter;
00066 converter.load_config();
00067 converter.set_options(cmdline.options);
00068 converter.process_rmp(cmdline.emp_file.c_str());
00069
00070 return 0;
00071 }
00072
00074
00079 void parse_options(int argc, char** argv, CommandLineOptions& cmdline)
00080 {
00081 static struct option long_cmdline[] = {
00082 {"format", 1, 0, 'f'},
00083 {"no-wait", 0, 0, 'n'},
00084 {"help", 0, 0, 'h'},
00085 {"list", 0, 0, 'l'},
00086 {0, 0, 0, 0}
00087 };
00088
00089 int option_index(0), c;
00090
00091 while((c = getopt_long(argc, argv, "nh?lf:", long_cmdline, &option_index)) != -1) {
00092 switch (c) {
00093 case 'f':
00094 if (optarg) {
00095 cmdline.options.formats.push_back(optarg);
00096 }
00097 break;
00098 case 'n':
00099 cmdline.options.wait_for_child = false;
00100 break;
00101 case 'h':
00102 case '?':
00103 show_help();
00104 break;
00105 case 'l':
00106 list_formats();
00107 break;
00108 }
00109 }
00110
00111 if (optind < argc) {
00112 if (argv[optind])
00113 cmdline.emp_file = argv[optind++];
00114 }
00115
00116 }
00117
00119 void show_help()
00120 {
00121 cout << endl << PACKAGE << " - version " << PACKAGE_VERSION << endl
00122 << c_about << endl;
00123 exit(0);
00124 }
00125
00127 void list_formats()
00128 {
00129 PlayListConverter::FormatDescList formats;
00130
00131 PlayListConverter::get_formats(formats);
00132
00133 cout << "Available formats are : " << endl;
00134 PlayListConverter::FormatDescList::iterator iter;
00135
00136 for(iter = formats.begin(); iter != formats.end(); ++iter) {
00137 cout << iter->name << "\t\t- " << iter->desc << endl;
00138 }
00139
00140
00141 exit(0);
00142 }