-rw-r--r-- | tools/mididump.cc | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/tools/mididump.cc b/tools/mididump.cc index 83b7086..604bcc0 100644 --- a/tools/mididump.cc +++ b/tools/mididump.cc | |||
@@ -1,84 +1,85 @@ | |||
1 | #include <getopt.h> | 1 | #include <getopt.h> |
2 | #include <iostream> | 2 | #include <iostream> |
3 | #include <fstream> | 3 | #include <fstream> |
4 | #include <string> | 4 | #include <string> |
5 | #include <algorithm> | 5 | #include <algorithm> |
6 | #include <cstring> | ||
6 | using namespace std; | 7 | using namespace std; |
7 | #include <konforka/exception.h> | 8 | #include <konforka/exception.h> |
8 | #include <midillo/SMF.h> | 9 | #include <midillo/SMF.h> |
9 | using namespace midillo; | 10 | using namespace midillo; |
10 | 11 | ||
11 | #include "config.h" | 12 | #include "config.h" |
12 | #define PHEADER PACKAGE " " VERSION " - mididump - dump midi files" | 13 | #define PHEADER PACKAGE " " VERSION " - mididump - dump midi files" |
13 | #define PCOPY "Copyright (c) 2006 Klever Group" | 14 | #define PCOPY "Copyright (c) 2006 Klever Group" |
14 | 15 | ||
15 | static void usage(const char *p) { | 16 | static void usage(const char *p) { |
16 | cerr << PHEADER << endl | 17 | cerr << PHEADER << endl |
17 | << PCOPY << endl << endl | 18 | << PCOPY << endl << endl |
18 | << " " << p << " [options] [<input-file>[ <output-file>]]" << endl << endl | 19 | << " " << p << " [options] [<input-file>[ <output-file>]]" << endl << endl |
19 | << " -h, --help" << endl | 20 | << " -h, --help" << endl |
20 | << " --usage display this text" << endl | 21 | << " --usage display this text" << endl |
21 | << " -V, --version display version number" << endl | 22 | << " -V, --version display version number" << endl |
22 | << " -L, --license show license" << endl; | 23 | << " -L, --license show license" << endl; |
23 | } | 24 | } |
24 | 25 | ||
25 | main(int argc,char **argv) { | 26 | main(int argc,char **argv) { |
26 | try { | 27 | try { |
27 | while(true) { | 28 | while(true) { |
28 | static struct option opts[] = { | 29 | static struct option opts[] = { |
29 | { "help", no_argument, 0, 'h' }, | 30 | { "help", no_argument, 0, 'h' }, |
30 | { "usage", no_argument, 0, 'h' }, | 31 | { "usage", no_argument, 0, 'h' }, |
31 | { "version", no_argument, 0, 'V' }, | 32 | { "version", no_argument, 0, 'V' }, |
32 | { "license", no_argument, 0, 'L' }, | 33 | { "license", no_argument, 0, 'L' }, |
33 | { NULL, 0, 0, 0 } | 34 | { NULL, 0, 0, 0 } |
34 | }; | 35 | }; |
35 | int c = getopt_long(argc,argv,"f:hVLl",opts,NULL); | 36 | int c = getopt_long(argc,argv,"f:hVLl",opts,NULL); |
36 | if(c==-1) | 37 | if(c==-1) |
37 | break; | 38 | break; |
38 | switch(c) { | 39 | switch(c) { |
39 | case 'h': | 40 | case 'h': |
40 | usage(*argv); | 41 | usage(*argv); |
41 | exit(0); | 42 | exit(0); |
42 | break; | 43 | break; |
43 | case 'V': | 44 | case 'V': |
44 | cerr << VERSION << endl; | 45 | cerr << VERSION << endl; |
45 | exit(0); | 46 | exit(0); |
46 | break; | 47 | break; |
47 | case 'L': | 48 | case 'L': |
48 | extern const char *COPYING; | 49 | extern const char *COPYING; |
49 | cerr << COPYING << endl; | 50 | cerr << COPYING << endl; |
50 | exit(0); | 51 | exit(0); |
51 | break; | 52 | break; |
52 | default: | 53 | default: |
53 | cerr << "Huh??" << endl; | 54 | cerr << "Huh??" << endl; |
54 | break; | 55 | break; |
55 | } | 56 | } |
56 | } | 57 | } |
57 | const char *infile = "-"; | 58 | const char *infile = "-"; |
58 | if(optind<argc) | 59 | if(optind<argc) |
59 | infile = argv[optind++]; | 60 | infile = argv[optind++]; |
60 | const char *oufile = "-"; | 61 | const char *oufile = "-"; |
61 | if(optind<argc) | 62 | if(optind<argc) |
62 | oufile = argv[optind++]; | 63 | oufile = argv[optind++]; |
63 | if(optind<argc) { | 64 | if(optind<argc) { |
64 | usage(*argv); | 65 | usage(*argv); |
65 | exit(1); | 66 | exit(1); |
66 | } | 67 | } |
67 | SMF_t in(infile); | 68 | SMF_t in(infile); |
68 | if(strcmp(oufile,"-")) { | 69 | if(strcmp(oufile,"-")) { |
69 | ofstream s(oufile); s << in; | 70 | ofstream s(oufile); s << in; |
70 | }else{ | 71 | }else{ |
71 | cout << in; | 72 | cout << in; |
72 | } | 73 | } |
73 | return 0; | 74 | return 0; |
74 | }catch(konforka::exception& e) { | 75 | }catch(konforka::exception& e) { |
75 | cerr << "Oops... Konforka exception:" << endl | 76 | cerr << "Oops... Konforka exception:" << endl |
76 | << " what: " << e.what() << endl | 77 | << " what: " << e.what() << endl |
77 | << " where: " << e.where() << endl; | 78 | << " where: " << e.where() << endl; |
78 | return 1; | 79 | return 1; |
79 | }catch(exception& e) { | 80 | }catch(exception& e) { |
80 | cerr << "Oops... Exception:" << endl | 81 | cerr << "Oops... Exception:" << endl |
81 | << " what: " << e.what() << endl; | 82 | << " what: " << e.what() << endl; |
82 | return 1; | 83 | return 1; |
83 | } | 84 | } |
84 | } | 85 | } |