home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************
- * errors.c: Error-handling functions.
- *
- * Part of...
- *
- * FREE: Display free space on your disk volumes.
- * Author: Daniel Jay Barrett, barrett@cs.jhu.edu.
- *
- * This program is Freely Distributable. Make all the copies you want
- * and give them away. Use this code in any way you like.
- ***************************************************************************/
-
- #include "free.h"
-
- /* The user made a mistake in invoking the program. Give 'em hell. */
-
- void Usage(char *prog)
- {
- fprintf(stderr, "%s%s%s Version %s by Daniel Jay Barrett.\n",
- HI_ON, prog, HI_OFF, VERSION);
- fprintf(stderr, "Inspired by Tom Smythe's FREE on Fish Disk 66.\n");
- fprintf(stderr, "This program is Freely Distributable.\n\n");
-
- fprintf(stderr,
- "Usage: %s%s%s [-%c%c] [-%c BYTES] [-%c LENGTH] [volume1] [volume2] ...\n\n",
- HI_ON, prog, HI_OFF, OPT_BLOCKS, OPT_REQUESTORS, OPT_MALLOC,
- OPT_VOLUME_NAME_LEN);
-
- fprintf(stderr, "\t-%c:\tDisplay blocks instead of bytes.\n",
- OPT_BLOCKS);
- fprintf(stderr, "\t-%c:\tEnable volume requestors.\n", OPT_REQUESTORS);
- fprintf(stderr, "\t-%c:\tAllocate BYTES of memory for the output.\n",
- OPT_MALLOC);
- fprintf(stderr,
- "\t-%c:\tSpecify the max LENGTH of a volume name (1 - %d).\n",
- OPT_VOLUME_NAME_LEN, MAX_NAME_LEN);
-
- fprintf(stderr, "\nIf no volumes given, the environment ");
- fprintf(stderr, "variable `%s' is used.\n", ENV_VARIABLE);
- fprintf(stderr, "Example: setenv %s \"df0:,df1:,ram:,dh0:\"\n\n",
- ENV_VARIABLE);
-
- fprintf(stderr, "If %s does not exist,\n", ENV_VARIABLE);
- fprintf(stderr, "then the following devices are checked by default:\n");
- fprintf(stderr, "\t%s\n\n", DEFAULT_VOLUMES);
- }
-
-
- /* Given a particular error code, print the appropriate error message. */
-
- void ErrorMsg(ERROR code)
- {
- if (code)
- fprintf(stderr, "ERROR! ");
- switch (code)
- {
- case NO_ERROR:
- break;
- case ERROR_TOO_SMALL:
- fprintf(stderr,
- "%s%d%s%c%s%s",
- "The output is too long to fit in ",
- memSize, " bytes.\nUse the -", OPT_MALLOC,
- " option to increase memory size.\n",
- "Output TRUNCATED and possibly not accurate.\n\n");
- break;
- case ERROR_CANT_MALLOC:
- fprintf(stderr, "Can't allocate that much memory!\n");
- break;
- case ERROR_FORMAT_STRING:
- fprintf(stderr, "%s%c%s%d%s\n",
- "Your -", OPT_VOLUME_NAME_LEN,
- " value must be an integer between 1 and ",
- MAX_NAME_LEN, ".");
- break;
- case ERROR_IMPOSSIBLE:
- fprintf(stderr, "This should never happen!\n");
- fprintf(stderr, "There must be a bug in this program.\n");
- break;
- }
- }
-
-
- /* If the user specified an illegal value (0 or less) as the argument of
- * the option OPT_VOLUME_NAME_LEN, complain! Then use the default value. */
-
- void CheckVolumeNameLen(int *nameLen)
- {
- if (*nameLen < 1 || *nameLen > MAX_NAME_LEN)
- {
- ErrorMsg(ERROR_FORMAT_STRING);
- *nameLen = DEFAULT_NAME_LEN;
- }
- }
-
-
- /* If the user specified an invalid volume name, complain! A valid name
- * must have at least 1 character (really two, but...), and its last
- * character must be VOLUME_END_CHAR. */
-
- int ValidDriveName(char *drive)
- {
- int len = strlen(drive);
-
- return((len > 0) && (drive[len-1] == VOLUME_END_CHAR));
- }
-