home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / c / actlib11 / tvtools / format.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-14  |  2.8 KB  |  101 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #include <bios.h>
  4. #include <stdio.h>
  5. #include <process.h>
  6.  
  7. #define Uses_MsgBox
  8. #define Uses_TApplication
  9.  
  10. #include "tvtools.h"
  11. #include "tools.h"
  12.  
  13.  
  14. char *checkMsg = " \n\03Checking Floppy format...";
  15.  
  16. /***
  17.  *
  18.  *  Function   :    formatFloppy
  19.  *
  20.  *  Topics     :    Format a  floppy if needed.
  21.  *
  22.  *  Decisions  :    - Calls the DOS command FORMAT x: [/T:nn /N:nn] /V:""
  23.  *                  - A check is performed after the format.
  24.  *                  - If DOS version >= 4.0 use the /AUTOTEST switch
  25.  *                    (undocumented) to skip prompt.
  26.  *                  - If DOS version >= 5.0 use the /U switch
  27.  *                    to speed up format.
  28.  *
  29.  *  Parameters :    in    int  floppy ( 0 = A:, 1 = B: )
  30.  *
  31.  *  Return     :    cmOK or cmCancel
  32.  *
  33.  ***/
  34.  
  35. ushort formatFloppy( int floppy )
  36.  
  37. { if ( floppy < 0 || floppy > 1 ) return cmCancel;
  38.  
  39.   char buffer[512];
  40.   int status;
  41.  
  42.   StatusBox( checkMsg );
  43.   do status = biosdisk( 4, floppy, 0, 0, 1, 1, buffer );
  44.   while ( status == 0x06 );
  45.   RemoveStatusBox();
  46.  
  47.   if ( ! status ) return cmOK;  // already formatted
  48.  
  49.   char *density = "";
  50.  
  51.   if ( getdensity(floppy) == 1440 )
  52.      {
  53.        status = messageBox( "\03Is the Floppy a High Density one ?\n \n"
  54.                             "\03(1.44 Mb)",
  55.                             mfYesNoCancel
  56.                           );
  57.        if ( status == cmCancel ) return cmCancel;
  58.        if ( status == cmNo ) density = "/N:9 /T:80";
  59.      }
  60.  
  61.   sprintf( buffer, "format %c: %s /v:\"\"", floppy + 'A', density );
  62.   if ( _osmajor >= 4 ) strcat( buffer, " /autotest" );  // Undocumented: no confirmation
  63. // Bug of MS-DOS 5.0
  64. //  if ( _osmajor >= 5 ) strcat( buffer, " /u" );         // To speed up format
  65.  
  66.   do { // Format floppy
  67.  
  68.        if ( (status == 0x03) &&
  69.             messageBox( "\03Floppy is write-protected.\n \n"
  70.                         "\03Correct and retry?",
  71.                         mfOKCancel
  72.                       ) != cmOK
  73.           ) return cmCancel;
  74.  
  75.        if ( (status == 0x80) &&
  76.             messageBox( "\03Floppy is not correctly inserted.\n \n"
  77.                         "\03Correct and retry?",
  78.                         mfOKCancel
  79.                       ) != cmOK
  80.           ) return cmCancel;
  81.  
  82.        StatusBox( checkMsg );
  83.        appSystem( buffer );
  84.        RemoveStatusBox();
  85.  
  86.        StatusBox( checkMsg );
  87.        do status = biosdisk( 4, floppy, 0, 0, 1, 1, buffer );
  88.        while ( status == 0x06 );
  89.        RemoveStatusBox();
  90.  
  91.        if ( ! status ) return cmOK;
  92.  
  93.        if ( messageBox( "\03Floppy is not formatted.\n \n"
  94.                         "\03Retry ?",
  95.                         mfOKCancel
  96.                       ) != cmOK
  97.           ) return cmCancel;
  98.  
  99.      } while ( 1 );
  100. }
  101.