home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / gt_derr.prg < prev    next >
Text File  |  1993-10-14  |  4KB  |  128 lines

  1. /*
  2.  * File......: GT_Derr.prg
  3.  * Author....: Niall Scott
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Niall Scott
  7.  * Date......: 29/06/93
  8.  * Revision..: 1.0
  9.  * Log file..: $Logfile$
  10.  *
  11.  * This is an original work by Niall R Scott and is placed in the
  12.  * public domain.
  13.  *
  14.  * Modification history:
  15.  * ---------------------
  16.  *
  17.  * Rev 1.0  29/06/93
  18.  * Initial Revision
  19.  */
  20.  
  21.  
  22. /*  $DOC$
  23.  *  $FUNCNAME$
  24.  *      GT_ERRDISC()
  25.  *  $CATEGORY$
  26.  *      Error System
  27.  *  $ONELINER$
  28.  *      Check a disc read/write error and recover from it.
  29.  *  $SYNTAX$
  30.  *      bNewHandler := {|e| GT_ErrDisc(e, bOldHandler)}
  31.  *  $ARGUMENTS$
  32.  *      e - Error object
  33.  *        bOldHandler - Previous Error Handler
  34.  *  $RETURNS$
  35.  *        An array of three elements
  36.  *        Elem[1] := Error Message
  37.  *        Elem[2] := User Action
  38.  *        Elem[3] := Error number - useful if you want to
  39.  *                   divert to another routine e.g. for formatting
  40.  *  $DESCRIPTION$
  41.  *      Error handler for use with disc read/writes
  42.  *        to enable recovery from disc problems.
  43.  *        MUST Be Used within BEGIN SEQUENCE/END SEQUENCE construct
  44.  *  $EXAMPLES$
  45.  *        FUNCTION DiscErr()
  46.  *            Local oOldHandler
  47.  *            Local nTries := 0
  48.  *            Local nAns
  49.  *            local aArrErr
  50.  *
  51.  *           // Set up the New handler and pass old handler as a parameter
  52.  *           bNewHandler := {|e| ErrDisc(e, bOldHandler)}
  53.  *           bOldHandler := ErrorBlock(bNewHandler)
  54.  *
  55.  *            WHILE (.t.)
  56.  *                BEGIN SEQUENCE
  57.  *
  58.  *                    // Floppy disc access here
  59.  *                    fopen('a:\missing.zxy')
  60.  *
  61.  *                    //For low Level functions that don't normally use the
  62.  *                    // error system
  63.  *                     GT_LOWERR()
  64.  *
  65.  *                    // This is the recovery section of the Begin/End Sequence
  66.  *                    // construct.  A BREAK statement got us to this point.
  67.  *                RECOVER USING aErrArr
  68.  *
  69.  *                    // Allow the user three attempts
  70.  *                    if nTries++ < 3
  71.  *                        ...
  72.  *                        ...
  73.  *                        ...
  74.  *                        // Your recovery code
  75.  *                        ...
  76.  *                        ...
  77.  *                        ...
  78.  *                        Do Case
  79.  *                        Case nAns == 2
  80.  *                            EXIT
  81.  *                        Case nAns == 3
  82.  *                            QUIT
  83.  *                        EndCase
  84.  *                    ENDIF
  85.  *                END SEQUENCE
  86.  *            ENDDO
  87.  *        RETURN NIL
  88.  *  $SEEALSO$
  89.  *      GT_LOWERR()
  90.  *  $INCLUDE$
  91.  *      GT_Lower.ch
  92.  *  $END$
  93.  */
  94.  
  95. #include "GT_LIB.ch"
  96. #include "GT_Lower.ch"
  97.  
  98. FUNCTION ErrDisc( oErr, bOld )
  99.     LOCAL nDiskStat
  100.     LOCAL aErrors := {19,21,23,25,26,27,29,30,31,34}
  101.     LOCAL aErrMsg := {  ;
  102.                        {"Disc Drive Write Protected","Please unprotect and retry."    ,1  } ,;
  103.                        {"Drive not ready",      "Please insert disc and try again. "  ,2  } ,;
  104.                        {"Data Error",           "Please insert new disc and try again",3  } ,;
  105.                        {"Seek Error",           "Please insert new disc and try again",4  } ,;
  106.                        {"Unknown Media Type",   "Please insert new disc and try again",5  } ,;
  107.                        {"Sector Not Found",     "Please insert new disc and try again",6  } ,;
  108.                        {"Error Writing to disc","Please insert new disc and try again",7  } ,;
  109.                        {"Error reading Disc",   "Please insert new disc and try again",8  } ,;
  110.                        {"Disc not Formatted",   "Please insert new disc and try again",9  } ,;
  111.                        {"Invalid Disc Change",  "Please insert old disc and try again",10 } ;
  112.                       }
  113.  
  114.     LOCAL oOldErr
  115.  
  116.     nDiskStat := ASCAN(aErrors, oErr:OsCode)
  117.  
  118.     if oErr:GenCode == 21 .and. nDiskStat > 0
  119.         //A noise to attract the user's attention
  120.         TONE( 500,  3)
  121.         TONE( 750,  5)
  122.         TONE(2000, 12)
  123.  
  124.         BREAK aErrMsg[nDiskStat]
  125.     ENDIF
  126.  
  127. RETURN (EVAL(bOld, oErr))
  128.