summaryrefslogtreecommitdiffabout
path: root/tools/mididump.cc
blob: 83b7086accb7c0b0250dc9fe63b8f08f2b0075da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <getopt.h>
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
using namespace std;
#include <konforka/exception.h>
#include <midillo/SMF.h>
using namespace midillo;

#include "config.h"
#define PHEADER PACKAGE " " VERSION " - mididump - dump midi files"
#define PCOPY "Copyright (c) 2006 Klever Group"

static void usage(const char *p) {
    cerr << PHEADER << endl
	<< PCOPY << endl << endl
	<< " " << p << " [options] [<input-file>[ <output-file>]]" << endl << endl
	<< " -h, --help" << endl
	<< " --usage          display this text" << endl
	<< " -V, --version    display version number" << endl
	<< " -L, --license    show license" << endl;
}

main(int argc,char **argv) {
    try {
	while(true) {
	    static struct option opts[] = {
		{ "help", no_argument, 0, 'h' },
		{ "usage", no_argument, 0, 'h' },
		{ "version", no_argument, 0, 'V' },
		{ "license", no_argument, 0, 'L' },
		{ NULL, 0, 0, 0 }
	    };
	    int c = getopt_long(argc,argv,"f:hVLl",opts,NULL);
	    if(c==-1)
		break;
	    switch(c) {
		case 'h':
		    usage(*argv);
		    exit(0);
		    break;
		case 'V':
		    cerr << VERSION << endl;
		    exit(0);
		    break;
		case 'L':
		    extern const char *COPYING;
		    cerr << COPYING << endl;
		    exit(0);
		    break;
		default:
		    cerr << "Huh??" << endl;
		    break;
	    }
	}
	const char *infile = "-";
	if(optind<argc)
	    infile = argv[optind++];
	const char *oufile = "-";
	if(optind<argc)
	    oufile = argv[optind++];
	if(optind<argc) {
	    usage(*argv);
	    exit(1);
	}
	SMF_t in(infile);
	if(strcmp(oufile,"-")) {
	    ofstream s(oufile); s << in;
	}else{
	    cout << in;
	}
	return 0;
    }catch(konforka::exception& e) {
	cerr << "Oops... Konforka exception:" << endl
	    << " what: " << e.what() << endl
	    << " where: " << e.where() << endl;
	return 1;
    }catch(exception& e) {
	cerr << "Oops... Exception:" << endl
	    << " what: " << e.what() << endl;
	return 1;
    }
}