~ubuntu-branches/ubuntu/saucy/jack-audio-connection-kit/saucy

« back to all changes in this revision

Viewing changes to tools/alias.c

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2008-12-06 11:05:15 UTC
  • mfrom: (4.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20081206110515-xa9v9pajr9jqvfvg
Tags: 0.115.6-1ubuntu1
* Merge from Debian unstable, remaining Ubuntu changes:
  - Redirect stderr in bash completion (Debian #504488).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <unistd.h>
 
4
#include <string.h>
 
5
#include <getopt.h>
 
6
 
 
7
#include <config.h>
 
8
 
 
9
#include <jack/jack.h>
 
10
 
 
11
char * my_name;
 
12
 
 
13
void
 
14
show_version (void)
 
15
{
 
16
        fprintf (stderr, "%s: JACK Audio Connection Kit version " VERSION "\n",
 
17
                my_name);
 
18
}
 
19
 
 
20
void
 
21
show_usage (void)
 
22
{
 
23
        show_version ();
 
24
        fprintf (stderr, "\nUsage: %s [options] portname alias\n", my_name);
 
25
        fprintf (stderr, "List active Jack ports, and optionally display extra information.\n\n");
 
26
        fprintf (stderr, "Display options:\n");
 
27
        fprintf (stderr, "        -u, --unalias         remove `alias' as an alias for `port'\n");
 
28
        fprintf (stderr, "        -h, --help            Display this help message\n");
 
29
        fprintf (stderr, "        --version             Output version information and exit\n\n");
 
30
        fprintf (stderr, "For more information see http://jackaudio.org/\n");
 
31
}
 
32
 
 
33
int
 
34
main (int argc, char *argv[])
 
35
{
 
36
        jack_client_t *client;
 
37
        jack_status_t status;
 
38
        char* portname;
 
39
        char* alias;
 
40
        int unset = 0;
 
41
        int ret;
 
42
        int c;
 
43
        int option_index;
 
44
        extern int optind;
 
45
        jack_port_t* port;
 
46
        
 
47
        struct option long_options[] = {
 
48
                { "unalias", 0, 0, 'u' },
 
49
                { "help", 0, 0, 'h' },
 
50
                { "version", 0, 0, 'v' },
 
51
                { 0, 0, 0, 0 }
 
52
        };
 
53
 
 
54
        if (argc < 3) {
 
55
                show_usage ();
 
56
                return 1;
 
57
        }
 
58
 
 
59
        my_name = strrchr(argv[0], '/');
 
60
        if (my_name == 0) {
 
61
                my_name = argv[0];
 
62
        } else {
 
63
                my_name ++;
 
64
        }
 
65
 
 
66
        while ((c = getopt_long (argc, argv, "uhv", long_options, &option_index)) >= 0) {
 
67
                switch (c) {
 
68
                case 'u':
 
69
                        unset = 1;
 
70
                        break;
 
71
                case 'h':
 
72
                        show_usage ();
 
73
                        return 1;
 
74
                        break;
 
75
                case 'v':
 
76
                        show_version ();
 
77
                        return 1;
 
78
                        break;
 
79
                default:
 
80
                        show_usage ();
 
81
                        return 1;
 
82
                        break;
 
83
                }
 
84
        }
 
85
 
 
86
        portname = argv[optind++];
 
87
        alias = argv[optind];
 
88
 
 
89
        /* Open a client connection to the JACK server.  Starting a
 
90
         * new server only to list its ports seems pointless, so we
 
91
         * specify JackNoStartServer. */
 
92
        //JOQ: need a new server name option
 
93
 
 
94
        client = jack_client_open ("lsp", JackNoStartServer, &status);
 
95
 
 
96
        if (client == NULL) {
 
97
                if (status & JackServerFailed) {
 
98
                        fprintf (stderr, "JACK server not running\n");
 
99
                } else {
 
100
                        fprintf (stderr, "jack_client_open() failed, "
 
101
                                 "status = 0x%2.0x\n", status);
 
102
                }
 
103
                return 1;
 
104
        }
 
105
 
 
106
        if ((port = jack_port_by_name (client, portname)) == 0) {
 
107
                fprintf (stderr, "No port named \"%s\"\n", portname);
 
108
                return 1;
 
109
        }
 
110
 
 
111
        if (!unset) {
 
112
                ret = jack_port_set_alias (port, alias);
 
113
        } else {
 
114
                ret = jack_port_unset_alias (port, alias);
 
115
        }
 
116
 
 
117
        jack_client_close (client);
 
118
 
 
119
        return ret;
 
120
        
 
121
}