ldrives / ldrives.c

#include <StdLib.H>
#include <StdIO.H>
#include <Dir.H>
#pragma hdrstop

#include "Stds\DLStdInc.H"
#include "DLUtils\DLUtils.H"
#include "Headers\ANSISfnc.H" /* for subst_strcmpi() */
#include "Replace\In1Char.H" /* for geronechar() */
/*-------------------------------------------------------------------------*/
static void ShowTitle(void);
static void TryDrives(const BOOL NoFloppies);
static void PrintDrive(const int drvNum);
static void ShowHelp(const char* ProgramName);
static void PauseBeforeExit(void);
/*-------------------------------------------------------------------------*/
int main(const int argc, const char* argv[])
{
  BOOL noFloppies = FALSE; /* If TRUE floppies A: and B: won't be accessed */
  BOOL noWait = FALSE; /* When TRUE program does not wait before exiting */
  BOOL doHelp = FALSE; /* Used so that ShowHelp() does not occur until all params are processed */
  int vi; /* Go though command line parameters */

  ShowTitle();

  if (argc > 1) /* Any parameters (apart from program name)? */
  {
    for (vi = 1; vi < argc; vi++) /* All user typed parameters */
    {
      if ( subst_stricmp(argv[vi], "/NW") == 0)
      {
        noWait = TRUE;
      }
      if ( subst_stricmp(argv[vi], "/?") == 0)
      {
        doHelp = TRUE;
      }
      if ( subst_stricmp(argv[vi], "/NF") == 0)
      {
        noFloppies = TRUE;
      }
    }
  }

  if (doHelp)
  {
    ShowHelp(argv[0]);
    if (!noWait) PauseBeforeExit();
    return EXIT_SUCCESS;
  }

  TryDrives(noFloppies);
  if (!noWait) PauseBeforeExit();
  return EXIT_SUCCESS;
}
/*-------------------------------------------------------------------------*/
static void ShowTitle()
{
  #ifdef __WIN32__
    const char os[] = "Win32";
  #elif _Windows
    const char os[] = "Windows";
  #else /* DOS */
    const char os[] = "DOS";
  #endif /*__WIN32__*/
  char titStr[128];
  unsigned int underliner;

  sprintf(titStr, "List accessable drives for %s V1.00, Copyright 2000 Daybo Logic", os);
  printf(titStr);
  printf("\n");

  /* Underline the title */
  for (underliner = 0; underliner < strlen(titStr); underliner++)
    printf("=");
  printf("\n");
}
/*-------------------------------------------------------------------------*/
static void TryDrives(const BOOL NoFloppies)
{
  int currentDrive = getdisk(); /* Save the current drive letter */
  int drive; /* Loop though drives */

  for (drive = 0; drive < 26; drive++)
  {
    if ( NoFloppies && (drive == 0 || drive == 1) ) /* This drive should not be logged by user request */
      continue; /* Move on to next one */
    setdisk(drive); /* Attempt to switch the the drive */
    if (getdisk() == drive) /* Managed drive switch? */
      PrintDrive(drive); /* Display the drive identifier to the caller */
  }

  setdisk(currentDrive); /* Restore DOS (or whatever) to old drive letter */
  return;
}
/*-------------------------------------------------------------------------*/
static void PrintDrive(const int drvNum)
{
  BYTE drvLetter;

  drvLetter = (BYTE)(drvNum + 'A'); /* Convert drive number to letter */
  printf("%c:\n", drvLetter);
  return;
}
/*-------------------------------------------------------------------------*/
static void ShowHelp(const char* ProgramName)
{
  printf("%s [/NF]\n\n", ProgramName);
  printf("   /? - Gets this help, not for normal use.\n");
  printf("   /NF - No floppies, does not try to access A: or B:\n");
  printf("   /NW - No wait when program ends, useful for batch work or when another\n");
  printf("         wait is provided by Windows or another GUI.\n");
  printf("\nThis program lists all usable drives, error messages such as\n"
         "drive not ready might occur reading floppies so to stop this kind\n"
         "of thing turn off access to floppy disks with /NF, then even if\n"
         "floppies are in A: or B: they will not be shown in the list.\n");
}
/*-------------------------------------------------------------------------*/
static void PauseBeforeExit()
{
  printf("*** PRESS ANY KEY TO EXIT ***");
  getonechar(); /* Wait for keypress */
  printf("\n"); /* Ready for possible DOS pronpt */
}
/*-------------------------------------------------------------------------*/
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.