Utilities 3 (Disk 38) (Mar 1987) : c / DevAvail.c

/* DevAvail by John V Pope 25 May '87
/* 
/* This program was inspired by a message I read recently on CompuServe(TM).
/*   It is intend to allow for checking for the existence of a device so as
/* to allow a startup-sequence file to determine whether or not to AddBuffers
/* and such.
/* 
/* Usage: DevAvail <DEVICE>
/*        Where DEVICE is any legal AmigaDOS device (or directory) name.
/*
/* Additionally the argument "?" and lack of any arguments prints out a usage
/* banner.
/* 
/* The program will FAIL (return error 20) if the device does not exist.
/* Therefore usage is the same as programs such as ASK and PAUSE.
/* 
/* Example:
/*       Failat 25          ;Anything above 20 here is just fine.
/*       DevAvail DF1:      ;Determine if DF1: is available 
/*       If NOT ERROR       ;Checking for DevAvail return code...
/*       AddBuffers DF1: 25 ;I can access that device now.
/*       Endif
/* 
/* Permission is granted for unlimited use of any type whatsoever. Just leave
/*  all credits atatched.
*/

#include <libraries/dosextens.h>

/* #define DEBUG
*/

#define BANNER "\nDevAvail by John V Pope 25 May 87.\
\nUsage: DevAvail <DEVICE>\
\n       Where DEVICE is any legal AmigaDOS device (or directory) name.\
\nFail code 20 returns to Execute if not available."

#define FAIL 20   /* keeps from having to add another include */

main(argc,argv)
int argc;
char *argv[];
{
struct Process *pr;

   if(argc != 2 || !strcmp(argv[1],"?"))
      {
      puts(BANNER);
      }else
         {
         pr=(struct Process *)FindTask(0L); /* Find me. */
         pr->pr_WindowPtr = -1; /* No Dos requesters, please. */
#ifdef DEBUG
         puts(argv[1]);
#endif
         if(DeviceProc(argv[1])==NULL)
            {
#ifdef DEBUG
            puts("Device Not Found.");
#endif
            exit(FAIL);     /* Couldn't find it so error is returned */
            }
#ifdef DEBUG
             else
               puts("Device exists.");
#endif
         }
}/* Just fall off the end of the world to indicate a device exists */