home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 122.lha / Arp_v1.1 / Demos / Devices.c < prev    next >
C/C++ Source or Header  |  1986-11-20  |  3KB  |  104 lines

  1. /* Devices.c -- arp.library demo, uses DA lists to determine what devices
  2.  *        are connected to the system. -=+SDB+=-
  3.  *
  4.  * Copyright (c) 1987, Scott Ballantyne
  5.  * Use and abuse as you please.
  6.  *
  7.  * MANX:
  8.  * cc Devices.c
  9.  * ln Devices.o -larp -lc
  10.  *
  11.  * Lattice:
  12.  * lc Devices.c
  13.  * blink lib:c.o Devices.o to Devices lib lib:arp.lib lib:lc.lib lib:amiga.lib
  14.  */
  15.  
  16. #include <exec/types.h>
  17. #include <libraries/arpbase.h>
  18. #include <arpfunctions.h>
  19.  
  20. struct DirectoryEntry    *DeviceList = NULL;    /* List header */
  21.  
  22. #define ARG_DEVICES    1
  23. #define ARG_DISKS    2
  24. #define ARG_VOLUMES    3
  25. #define ARG_ASSIGNS    4
  26.  
  27. char *CLI_Template = "DEVICES/S,DISKS/S,VOLUMES/S,ASSIGNS/S";
  28. /* Example of a more extended help message */
  29. /* It would be pleasant if more programs extended this sort of help */
  30.  
  31. #ifdef AZTEC_C    /* Lattice doesn't do well with long strings */
  32. char *CLI_Help =
  33. "Displays devices connected to this system.\nYou may enter:\n\
  34. \tDEVICES -- To display all devices (this is default)\n\
  35. \tDISKS   -- To display all diskbased devices\n\
  36. \tVOLUMES -- To display all volumes\n\
  37. \tASSIGNS -- To display all logical assignments\n\n\
  38. Or you may enter any combination of the above.  Note that\n\
  39. DEVICES DISKS is the same as simply DISKS\n";
  40. #else
  41. char *CLI_Help = "Displays devices connected to this system:\n\
  42. \tDEVICES -- For devices\n\
  43. \tDISKS   -- For disk devices\n\
  44. \tVOLUMES -- for Volumes\n\
  45. \tASSIGNS -- for logicals\n\nOr any combination of the above\n\n";
  46. #endif
  47.  
  48. VOID main(argc, argv)
  49. int argc;
  50. char **argv;
  51. {
  52.     LONGBITS WhichDevices = 0;
  53.     LONG    numdevs;
  54.     register struct DirectoryEntry *dev;
  55.  
  56.     if (argc < 2 )    /* set default */
  57.         WhichDevices |= DLF_DEVICES;
  58.  
  59.     /* Find out which switches were used, if any */
  60.  
  61.     if ( argv[ARG_DEVICES] )
  62.         WhichDevices |= DLF_DEVICES;
  63.     if ( argv[ARG_DISKS] )
  64.         WhichDevices |= ( DLF_DEVICES | DLF_DISKONLY );
  65.     if ( argv[ARG_VOLUMES] )
  66.         WhichDevices |= DLF_VOLUMES;
  67.     if ( argv[ARG_ASSIGNS] )
  68.         WhichDevices |= DLF_DIRS;
  69.  
  70.     /* Now get the requested devices */
  71.  
  72.     if ( (numdevs = AddDADevs( &DeviceList, WhichDevices )) == 0 )
  73.     {
  74.         Puts("No entries found");
  75.         exit(0);
  76.     }
  77.     Printf("Found %ld entries\n", numdevs);
  78.     /* Now display the name and the type of device it is. */
  79.  
  80.     for ( dev = DeviceList; dev; dev = dev->de_Next)
  81.     {
  82.     
  83.         Printf("%-32s", dev->de_Name);
  84.         switch (dev->de_Type)
  85.         {
  86.             case DLX_DEVICE:
  87.                 Puts("Resident device");
  88.                 break;
  89.             case DLX_VOLUME:
  90.                 Puts("Volume [mounted]");
  91.                 break;
  92.             case DLX_UNMOUNTED:
  93.                 Puts("Volume [not mounted]");
  94.                 break;
  95.             case DLX_ASSIGN:
  96.                 Puts("Logical Assignment");
  97.                 break;
  98.             default:
  99.                 Puts("Encountered Device of mystery!");
  100.         }
  101.     }
  102.     FreeDAList(DeviceList);
  103. }
  104.