home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / emx / test / hw_io.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-24  |  1.5 KB  |  74 lines

  1. /* hw_io.c (emx+gcc) */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <sys/hw.h>
  7.  
  8.  
  9. static void usage (void)
  10. {
  11.   fputs ("Usage: hw_io [-s] [-p <port>] [-a <from> <to>]\n", stderr);
  12.   exit (1);
  13. }
  14.  
  15.  
  16. int main (int argc, char *argv[])
  17. {
  18.   int opt_s, i, lo, hi, port, def_range;
  19.   unsigned char buf[256];
  20.   char *q;
  21.  
  22.   opt_s = 0; port = 0x40; def_range = 1;
  23.   i = 1;
  24.   while (i < argc)
  25.     {
  26.       if (strcmp (argv[i], "-s") == 0)
  27.         {
  28.           opt_s = 1; ++i;
  29.         }
  30.       else if (strcmp (argv[i], "-p") == 0 && argc - i >= 2)
  31.         {
  32.           errno = 0;
  33.           port = strtol (argv[i+1], &q, 0);
  34.           if (errno != 0 || *q != 0 || port < 0 || port > 255)
  35.             usage ();
  36.           i += 2;
  37.         }
  38.       else if (strcmp (argv[i], "-a") == 0 && argc - i >= 3)
  39.         {
  40.           errno = 0;
  41.           lo = strtol (argv[i+1], &q, 0);
  42.           if (errno != 0 || *q != 0)
  43.             usage ();
  44.           hi = strtol (argv[i+2], &q, 0);
  45.           if (errno != 0 || *q != 0)
  46.             usage ();
  47.           def_range = 0;
  48.           i += 3;
  49.         }
  50.       else
  51.         usage ();
  52.     }
  53.   if (def_range)
  54.     {
  55.       lo = port; hi = port;
  56.     }
  57.   if (_portaccess (lo, hi) != 0)
  58.     {
  59.       perror ("_portaccess");
  60.       return (1);
  61.     }
  62.   if (opt_s)
  63.     for (;;)
  64.       {
  65.         _inps8 (port, buf, sizeof (buf));
  66.         for (i = 0; i < sizeof (buf); ++i)
  67.           printf ("  %.2x", buf[i]);
  68.       }
  69.   else
  70.     for (;;)
  71.       printf ("  %.2x", _inp8 (port));
  72.   return (0);
  73. }
  74.