]> git.alsa-project.org Git - alsa-utils.git/commitdiff
Accept the client name as address argument of aconnect and aseqnet.
authorTakashi Iwai <tiwai@suse.de>
Thu, 14 Sep 2000 10:19:45 +0000 (10:19 +0000)
committerTakashi Iwai <tiwai@suse.de>
Thu, 14 Sep 2000 10:19:45 +0000 (10:19 +0000)
You may use aconnect like this:
% aconnect External:0 Emu8000:1

seq/aconnect/aconnect.1
seq/aconnect/aconnect.c
seq/aseqnet/aseqnet.c

index 4d7592424634729169602fede71d48108c885969..ed34ea7d883cf626cc194c86dc3c7c044e73f37c 100644 (file)
@@ -36,6 +36,13 @@ option.
 .IP "" 4
 % aconnect -d 64:0 65:0
 .PP
+The address can be given using the client's name.
+.IP "" 4
+% aconnect External:0 Emu8000:1
+.PP
+Then the port 0 of the client matching with the string "External" is
+connected to the port 1 of the client matching with the "Emu8000".
+.PP
 Another function of
 .B aconnect
 is to list the present ports
@@ -54,9 +61,9 @@ client 0: 'System' [group=system] [type=kernel]
 .br
 1 'Announce        ' [group=system]
 .in -4
-client 64: '0: MIDI Synth' [group=] [type=kernel]
+client 64: 'External MIDI-0' [group=] [type=kernel]
 .in +4
-0 'card 0: synth-midi: 0' [group=device]
+0 'MIDI 0-0        ' [group=device]
 .in -4
 .PP
 Similary, to see the output ports, use
index aa552a4472e4d387263bacaa4b855e1e73659cc7..c0ccc9a1237e2d5c4639017bc359e4c84677d536 100644 (file)
@@ -50,17 +50,41 @@ static void usage(void)
 
 /*
  * parse command line to client:port
+ * NB: the given string will be broken.
  */
-static int parse_address(snd_seq_addr_t *addr, char *arg)
+static int parse_address(snd_seq_t *seq, snd_seq_addr_t *addr, char *arg)
 {
        char *p;
+       int client, port;
 
-       if (! isdigit(*arg))
-               return -1;
        if ((p = strpbrk(arg, ":.")) == NULL)
                return -1;
-       addr->client = atoi(arg);
-       addr->port = atoi(p + 1);
+       if ((port = atoi(p + 1)) < 0)
+               return -1;
+       addr->port = port;
+       if (isdigit(*arg)) {
+               client = atoi(arg);
+               if (client < 0)
+                       return -1;
+               addr->client = client;
+       } else {
+               /* convert from the name */
+               snd_seq_client_info_t cinfo;
+               int len;
+
+               *p = 0;
+               len = strlen(arg);
+               if (len <= 0)
+                       return -1;
+               cinfo.client = -1;
+               while (snd_seq_query_next_client(seq, &cinfo) >= 0) {
+                       if (! strncmp(cinfo.name, arg, len)) {
+                               addr->client = cinfo.client;
+                               return 0;
+                       }
+               }
+               return -1; /* not found */
+       }
        return 0;
 }
 
@@ -354,11 +378,11 @@ int main(int argc, char **argv)
 
        /* set subscription */
        memset(&subs, 0, sizeof(subs));
-       if (parse_address(&subs.sender, argv[optind]) < 0) {
+       if (parse_address(seq, &subs.sender, argv[optind]) < 0) {
                fprintf(stderr, "invalid sender address %s\n", argv[optind]);
                return 1;
        }
-       if (parse_address(&subs.dest, argv[optind + 1]) < 0) {
+       if (parse_address(seq, &subs.dest, argv[optind + 1]) < 0) {
                fprintf(stderr, "invalid destination address %s\n", argv[optind + 1]);
                return 1;
        }
index 8eab330286b7adc2f682082460c1fbcf079aa4ca..964019518d7600d59710c63b4e1fe7cd9f540402 100644 (file)
@@ -169,18 +169,42 @@ static void init_buf(void)
 }
 
 /*
- * parse client:port argument
+ * parse command line to client:port
+ * NB: the given string will be broken.
  */
-static int parse_addr(snd_seq_addr_t *addr, char *arg)
+static int parse_address(snd_seq_t *seq, snd_seq_addr_t *addr, char *arg)
 {
        char *p;
+       int client, port;
 
-       if (! isdigit(*arg))
-               return -1;
        if ((p = strpbrk(arg, ":.")) == NULL)
                return -1;
-       addr->client = atoi(arg);
-       addr->port = atoi(p + 1);
+       if ((port = atoi(p + 1)) < 0)
+               return -1;
+       addr->port = port;
+       if (isdigit(*arg)) {
+               client = atoi(arg);
+               if (client < 0)
+                       return -1;
+               addr->client = client;
+       } else {
+               /* convert from the name */
+               snd_seq_client_info_t cinfo;
+               int len;
+
+               *p = 0;
+               len = strlen(arg);
+               if (len <= 0)
+                       return -1;
+               cinfo.client = -1;
+               while (snd_seq_query_next_client(seq, &cinfo) >= 0) {
+                       if (! strncmp(cinfo.name, arg, len)) {
+                               addr->client = cinfo.client;
+                               return 0;
+                       }
+               }
+               return -1; /* not found */
+       }
        return 0;
 }
 
@@ -240,7 +264,7 @@ static void init_seq(char *source, char *dest)
        /* explicit subscriptions */
        if (source) {
                /* read subscription */
-               if (parse_addr(&addr, source) < 0) {
+               if (parse_address(handle, &addr, source) < 0) {
                        fprintf(stderr, "invalid source address %s\n", source);
                        exit(1);
                }
@@ -251,7 +275,7 @@ static void init_seq(char *source, char *dest)
        }
        if (dest) {
                /* write subscription */
-               if (parse_addr(&addr, dest) < 0) {
+               if (parse_address(handle, &addr, dest) < 0) {
                        fprintf(stderr, "invalid destination address %s\n", dest);
                        exit(1);
                }