home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.lbl.gov / 2014.05.ftp.ee.lbl.gov.tar / ftp.ee.lbl.gov / bmd-1.0beta.tar.Z / bmd-1.0beta.tar / bmd-1.0beta / app / mtools / mrsel.c < prev    next >
C/C++ Source or Header  |  1991-08-21  |  2KB  |  85 lines

  1. /*
  2.  * Copyright (c) 1990 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Lawrence Berkeley Laboratory,
  11.  * Berkeley, CA.  The name of the University may not be used to
  12.  * endorse or promote products derived from this software without
  13.  * specific prior written permission.
  14.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  15.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  16.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include <sys/types.h>
  21. #include <sys/time.h>
  22. #include <sys/file.h>
  23. #include <sys/ioctl.h>
  24. #include <sundev/midi.h>
  25.  
  26. #ifndef lint
  27. static char rcsid[] =
  28.     "@(#) $Header: mrsel.c,v 1.1 91/08/20 22:14:50 mccanne Exp $";
  29. #endif
  30.  
  31. usage()
  32. {
  33.     fprintf(stderr, "Usage: msel [-p port] [-a]\n");
  34.     exit(1);
  35. }
  36.  
  37. main(argc, argv)
  38.     int argc;
  39.     char **argv;
  40. {
  41.     int fd, cc, c, port;
  42.     struct midibuf mb;
  43.     int aflag = 0;
  44.     fd_set fds, fdinit;
  45.  
  46.     extern char *optarg;
  47.  
  48.     port = 1;
  49.     while ((c = getopt(argc, argv, "ap:")) != -1) {
  50.         switch(c) {
  51.  
  52.         case 'a':
  53.             ++aflag;
  54.             break;
  55.  
  56.         case 'p':
  57.             port = atoi(optarg);
  58.             break;
  59.  
  60.         default:
  61.             usage();
  62.         }
  63.     }
  64.     fd = midi_open(O_RDONLY, port);
  65.     if (aflag && ioctl(fd, BMDFILTER, 0) < 0) {
  66.         perror("BMDFILTER");
  67.         exit(1);
  68.     }
  69.     FD_ZERO(&fdinit);
  70.     FD_SET(fd, &fdinit);
  71.     while (1) {
  72.         fds = fdinit;
  73.         if (select(fd + 1, &fds, 0, 0, 0) < 0) {
  74.             perror("select");
  75.             exit(1);
  76.         }
  77.         cc = read(fd, &mb, sizeof mb);
  78.         if (cc < 0) {
  79.             perror("read");
  80.             exit(-1);
  81.         }
  82.         printf("read %d\n", cc);
  83.     }
  84. }
  85.