home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 700-799 / ff713.lha / free / source / errors.c < prev    next >
C/C++ Source or Header  |  1992-08-19  |  3KB  |  116 lines

  1. /***************************************************************************
  2.  * errors.c:    Error-handling functions.
  3.  *
  4.  * Part of...
  5.  *
  6.  *    FREE:    Display free space on your disk volumes.
  7.  *        Author:  Daniel J. Barrett, barrett@cs.umass.edu.
  8.  *
  9.  * This program is Freely Distributable.  Make all the copies you want
  10.  * and give them away.  Use this code in any way you like.
  11. ***************************************************************************/
  12.  
  13. #include "free.h"
  14. #include "version.h"
  15.  
  16. /* The user made a mistake in invoking the program.  Give 'em hell. */
  17.  
  18. void Usage(char *prog)
  19. {
  20.     fprintf(stderr, "%s%s%s Version %s by Daniel Jay Barrett.\n",
  21.         HI_ON, prog, HI_OFF, VERSION);
  22.     fprintf(stderr, "Inspired by Tom Smythe's FREE on Fish Disk 66.\n");
  23.     fprintf(stderr, "This program is Freely Distributable.\n\n");
  24.  
  25.     fprintf(stderr,
  26. "Usage: %s%s%s [-%c%c] [-%c BYTES] [-%c LENGTH] [volume1] [volume2] ...\n\n",
  27.        HI_ON, prog, HI_OFF, OPT_BLOCKS, OPT_REQUESTORS, OPT_MALLOC,
  28.        OPT_VOLUME_NAME_LEN);
  29.  
  30.     fprintf(stderr, "\t-%c:\tDisplay blocks instead of bytes.\n",
  31.         OPT_BLOCKS);
  32.     fprintf(stderr, "\t-%c:\tEnable volume requestors.\n", OPT_REQUESTORS);
  33.     fprintf(stderr, "\t-%c:\tAllocate BYTES of memory for the output.\n",
  34.         OPT_MALLOC);
  35.     fprintf(stderr,
  36.        "\t-%c:\tSpecify the max LENGTH of a volume name (1 - %d).\n",
  37.        OPT_VOLUME_NAME_LEN, MAX_NAME_LEN);
  38.     
  39.     fprintf(stderr, "\nIf no volumes given, the environment ");
  40.     fprintf(stderr, "variable `%s' is used.\n", ENV_VARIABLE);
  41.     fprintf(stderr, "Example:  setenv %s \"df0:,df1:,ram:,dh0:\"\n\n",
  42.         ENV_VARIABLE);
  43.  
  44.     fprintf(stderr, "If %s does not exist, ", ENV_VARIABLE);
  45.     fprintf(stderr, "all known devices are listed (AmigaOS 2.0+)\n");
  46.     fprintf(stderr, "or \"%s\" is assumed (AmigaOS pre-2.0).\n",
  47.         DEFAULT_VOLUMES_OLD);
  48. }
  49.  
  50.  
  51. /* Given a particular error code, print the appropriate error message. */
  52.  
  53. void ErrorMsg(ERROR code)
  54. {
  55.     if (code)
  56.         fprintf(stderr, "ERROR! ");
  57.     switch (code)
  58.     {
  59.         case NO_ERROR:
  60.             break;
  61.         case ERROR_TOO_SMALL:
  62.             fprintf(stderr, "The output is too long to fit in " \
  63.                 "%d bytes.\n" \
  64.                 "Use the -%c option to increase memory " \
  65.                 "size.\n" \
  66.                    "Output TRUNCATED and possibly not accurate."\
  67.                    "\n\n", memSize, OPT_MALLOC);
  68.             break;
  69.         case ERROR_CANT_MALLOC:
  70.             fprintf(stderr, "Out of memory!\n");
  71.             break;
  72.         case ERROR_FORMAT_STRING:
  73.             fprintf(stderr, "Your -%c value must be an integer" \
  74.                 " between 1 and %d\n",
  75.                 OPT_VOLUME_NAME_LEN, MAX_NAME_LEN, ".");
  76.             break;
  77.         case ERROR_INFO:
  78.             fprintf(stderr, "Info() failed!\n");
  79.             break;
  80.         case ERROR_DOSLIST:
  81.             fprintf(stderr, "Could not get device list.\n");
  82.             break;
  83.         case ERROR_IMPOSSIBLE:
  84.         default:
  85.            fprintf(stderr, "This should never happen! (code=%d)\n" \
  86.                "There must be a bug in this program.\n",
  87.                code);
  88.            break;
  89.     }
  90. }
  91.  
  92.  
  93. /* If the user specified an illegal value (0 or less) as the argument of
  94.  * the option OPT_VOLUME_NAME_LEN, complain!  Then use the default value. */
  95.  
  96. void CheckVolumeNameLen(int *nameLen)
  97. {
  98.     if (*nameLen < 1 || *nameLen > MAX_NAME_LEN)
  99.     {
  100.         ErrorMsg(ERROR_FORMAT_STRING);
  101.         *nameLen = DEFAULT_NAME_LEN;
  102.     }
  103. }
  104.  
  105.  
  106. /* If the user specified an invalid volume name, complain!  A valid name
  107.  * must have at least 1 character (really two, but...), and its last
  108.  * character must be VOLUME_END_CHAR. */
  109.  
  110. int ValidDriveName(char *drive)
  111. {
  112.     int len = strlen(drive);
  113.  
  114.     return((len > 0)  &&  (drive[len-1] == VOLUME_END_CHAR));
  115. }
  116.