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

  1. /*
  2.     File......: GT_Skip.prg
  3.     Author....: Martin Bryant
  4.     BBS.......: The Dark Knight Returns
  5.     Net/Node..: 050/069
  6.     User Name.: Martin Bryant
  7.     Date......: 11/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 11/02/93
  17.     PD Revision.
  18. */
  19.  
  20. /*  $DOC$
  21.  *  $FUNCNAME$
  22.  *      GT_SKIP()
  23.  *  $CATEGORY$
  24.  *      General
  25.  *  $ONELINER$
  26.  *      Move the filepointer n valid records from the current
  27.  *  $SYNTAX$
  28.  *      GT_Skip([<bWhile>],[<bFor>],[<nRecords>],[<lEof>]) -> nMoved
  29.  *  $ARGUMENTS$
  30.  *      <bWhile> Code block giving a while clause.
  31.  *
  32.  *      <bFor> Code block giving a for clause.
  33.  *
  34.  *      <nRecords> is the number of records to move down the
  35.  *      file. Ie negative requires movement towards to
  36.  *      begining of file.
  37.  *  $RETURNS$
  38.  *      nMoved
  39.  *  $DESCRIPTION$
  40.  *      Reposition the filepointer n valid records from the
  41.  *      current.
  42.  *  $EXAMPLES$
  43.  *  $SEEALSO$
  44.  *
  45.  *  $INCLUDE$
  46.  *
  47.  *  $END$
  48.  */
  49.  
  50. #include "GT_LIB.ch"
  51.  
  52. FUNCTION GT_Skip(bWhile,bFor,nRecords,lEof)
  53.  
  54. LOCAL nCount := 0
  55. LOCAL nSafeOne := RECNO()
  56.  
  57. Default bWhile to { | | .T. }
  58. Default bFor to { | | .T. }
  59. Default nRecords to 0
  60. Default lEof to .T.
  61.  
  62. DO CASE
  63.  
  64.     CASE ( nRecords == 0 ) .OR. ( LASTREC() = 0 )
  65.         // Move of 0 requested, or no records
  66.         DBSKIP(0)
  67.  
  68.     CASE (nRecords > 0)
  69.         // Forward
  70.         nCount := -1
  71.  
  72.         BEGIN SEQUENCE
  73.  
  74.             DBEVAL( { || nSafeOne := RECNO() ;
  75.                 ,IF(++nCount=nRecords,BREAK(NIL),NIL) } ;
  76.                 ,bFor,bWhile,NIL,NIL,.T.)
  77.  
  78.             DBGOTO(IF(lEof,LASTREC()+01,nSafeOne))
  79.  
  80.             nCount := MAX(0,nCount)
  81.  
  82.         END SEQUENCE
  83.  
  84.     CASE (nRecords < 0)
  85.         // Move backwards
  86.  
  87.         DO WHILE  .T.
  88.  
  89.             DBSKIP(-1)
  90.  
  91.             DO CASE
  92.  
  93.                 CASE BOF() .OR. .NOT. EVAL(bWhile)
  94.                     // Not in while condition
  95.  
  96.                     IF lEof
  97.                         DBGOTO(LASTREC()+01)
  98.                     ELSE
  99.                         DBGOTO(nSafeOne)
  100.                     ENDIF
  101.  
  102.                     EXIT
  103.  
  104.                 CASE EVAL(bFor)
  105.                     //  For OK
  106.  
  107.                     nCount--
  108.                     nSafeOne := RECNO()
  109.  
  110.                     IF nRecords = nCount
  111.                         EXIT
  112.                     ENDIF
  113.  
  114.                 OTHERWISE
  115.                     // In while but not for
  116.  
  117.             ENDCASE
  118.  
  119.         ENDDO
  120.  
  121.     OTHERWISE
  122.         // Nothing
  123.         DBSKIP(0)
  124.  
  125. ENDCASE
  126.  
  127. /*
  128.     End of GT_Skip()
  129. */
  130. RETURN(nCount)
  131.