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

  1. /*
  2.     File......: GT_MemRest.prg
  3.     Author....: Martin Bryant
  4.     BBS.......: The Dark Knight Returns
  5.     Net/Node..: 050/069
  6.     User Name.: Martin Bryant
  7.     Date......: 04/02/93
  8.     Revision..: 1.0
  9.  
  10.     This is an original work by Martin Bryant and is placed
  11.     in the public domain.
  12.  
  13.     Modification history:
  14.     ---------------------
  15.  
  16.     Rev 1.0 04/02/93
  17.     PD Revision.
  18. */
  19.  
  20. /*  $DOC$
  21.  *  $FUNCNAME$
  22.  *      GT_MEMREST()
  23.  *  $CATEGORY$
  24.  *      File I/O
  25.  *  $ONELINER$
  26.  *      To Restore variables from a .mem file
  27.  *  $SYNTAX$
  28.  *      GT_MemRest(<cFile>,[<cFilter>],[<bFunc>], ;
  29.  *      [<nSeconds>],[<nPause>]) => lSuccess
  30.  *  $ARGUMENTS$
  31.  *      <cFile> is the name, including path and extention,
  32.  *      of the file to Restore from.
  33.  *
  34.  *      <cFilter> is the specification of the variables to
  35.  *      Save again if using the code block function.
  36.  *
  37.  *      <bFunc> is an optional code block to evaluate. If
  38.  *      this is evaluated then the same specifications are
  39.  *      used to re-save the file.
  40.  *
  41.  *      <nSeconds> is the time to wait.
  42.  *
  43.  *      <nPause> is the time interval between attempts.
  44.  *  $RETURNS$
  45.  *      .T. / .F.
  46.  *  $DESCRIPTION$
  47.  *      To Restore variables from a .mem file
  48.  *  $EXAMPLES$
  49.  *      // Where pCount is PRIVATE ....
  50.  *      IF .NOT. GT_MemRest('System.mem','p*',{ | | pCount ++ })
  51.  *          ? 'Error'
  52.  *      ENDIF
  53.  *  $SEEALSO$
  54.  *
  55.  *  $INCLUDE$
  56.  *
  57.  *  $END$
  58.  */
  59.  
  60. #include "GT_LIB.ch"
  61.  
  62. #define HEIGHT  06
  63. #define WIDTH   16
  64.  
  65. FUNCTION GT_MemRest(cFile,cFilter,bFunc,nSeconds,nPause)
  66.  
  67. LOCAL cScreen := ''
  68. LOCAL nBottom := INT((MAXROW() + HEIGHT)/2)
  69. LOCAL nKey := 0
  70. LOCAL nLeft := INT((MAXCOL() - WIDTH)/2)
  71. LOCAL nRight := nLeft - WIDTH
  72. LOCAL nTop := nBottom - HEIGHT
  73. Local lMessage := .F.
  74. Local lSuccess := .F.
  75.  
  76. Default cFile to 'System.mem'
  77. Default cFilter to '*'
  78. Default bFunc to NIL
  79. Default nSeconds to 120
  80. Default nPause to 0.5
  81.  
  82. DO WHILE (.NOT. lSuccess) .AND. (nSeconds > 0) .AND. ;
  83.     (nKey != K_ESC)
  84.  
  85.     // Restore ?
  86.     RESTORE FROM (cFile) ADDITIVE
  87.     lSuccess := (FERROR() == 0)
  88.  
  89.     IF .NOT. lSuccess
  90.  
  91.         // Wait and retry
  92.         IF .NOT. lMessage
  93.  
  94.             // Rest
  95.             cScreen := RestSCREEN(nTop,nLeft,nBottom,nRight)
  96.  
  97.             // Display
  98.             GT_Window(nTop,nLeft,nBottom,nRight,BOX_SS, ;
  99.                 NIL,'Saving ....',.T.)
  100.  
  101.             // Position for message
  102.             @ nTop+02, nLeft+02 SAY 'Timeout:'
  103.             @ nTop+04, nLeft+02 SAY ;
  104.                 PADC('Esc∙Exit',WIDTH-03)
  105.  
  106.             lMessage := .T.
  107.  
  108.         ENDIF
  109.  
  110.         @ nTop+02, nLeft+09 SAY PADR(INT(nSeconds),3)
  111.         nKey := INKEY(nPause)
  112.         nSeconds -= nPause
  113.  
  114.     ENDIF
  115.  
  116. ENDDO
  117.  
  118. IF lMessage
  119.     RESTSCREEN(nTop,nLeft,nBottom,nRight,cScreen)
  120. ENDIF
  121.  
  122.  
  123. IF lSuccess .AND. bFunc != NIL
  124.     EVAL(bFunc)
  125.     lSuccess := GT_MemSave(cFile,cFilter)
  126. End If
  127.  
  128. /*
  129.     End of GT_MemRest()
  130. */
  131. RETURN(lSuccess)
  132.