fix building when PATH_MAX is not defined. (should fix debian bug 320736)
[jack.git] / tools / alias.c
blob5a5d523737acdc6dd761e1973fa972e4b3667ddb
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <getopt.h>
7 #include <config.h>
9 #include <jack/jack.h>
11 char * my_name;
13 void
14 show_version (void)
16 fprintf (stderr, "%s: JACK Audio Connection Kit version " VERSION "\n",
17 my_name);
20 void
21 show_usage (void)
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");
33 int
34 main (int argc, char *argv[])
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;
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 }
54 if (argc < 3) {
55 show_usage ();
56 return 1;
59 my_name = strrchr(argv[0], '/');
60 if (my_name == 0) {
61 my_name = argv[0];
62 } else {
63 my_name ++;
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;
86 portname = argv[optind++];
87 alias = argv[optind];
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
94 client = jack_client_open ("lsp", JackNoStartServer, &status);
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);
103 return 1;
106 if ((port = jack_port_by_name (client, portname)) == 0) {
107 fprintf (stderr, "No port named \"%s\"\n", portname);
108 return 1;
111 if (!unset) {
112 ret = jack_port_set_alias (port, alias);
113 } else {
114 ret = jack_port_unset_alias (port, alias);
117 jack_client_close (client);
119 return ret;