home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a067 / 1.img / GRUMP501.EXE / INDEXBAR.PRG < prev    next >
Encoding:
Text File  |  1991-07-16  |  5.4 KB  |  163 lines

  1. /*
  2.    Program: INDEXBAR()
  3.    System: GRUMPFISH LIBRARY
  4.    Author: Greg Lief
  5.    Special Thanks to:
  6.            - John Stolte @ Omicron Software for "showcount"
  7.            - Kevin Farley for his various suggestions
  8.    Copyright (c) 1988-90, Greg Lief
  9.    Clipper 5.x version
  10.    Compile instructions: clipper indexbar /n/w/a
  11.  
  12.    Procs & Fncts: IndexBar()
  13.                 : GFShowBar()
  14.                 : GFKillBar()
  15.  
  16.            Calls: SHADOWBOX()   (function in $SHADOWB.PRG)
  17.  
  18.    IndexBar() displays a graph showing percentage complete when
  19.    indexing files.  When indexing is complete, IndexBar() will
  20.    then strip the graph UDF() call from the .NTX file so that you
  21.    don't have to look at the graph when the index is updated.
  22.  
  23. */
  24.  
  25. //───── begin preprocessor directives
  26.  
  27. #include "grump.ch"
  28. #include "fileio.ch"
  29.  
  30. //───── end preprocessor directives
  31.  
  32. //───── begin global declarations
  33.  
  34. static num_recs        // total number of records in current database
  35.                        // I put it here instead of referring to RECCOUNT()
  36.                        // because it speeds things up a klick or two
  37.  
  38. //───── end global declarations
  39.  
  40. /*
  41.     Function: IndexBar()
  42.     Syntax:   IndexBar(<filename>, <index key>, <row>, <showcount>)
  43.               <filename> = name of index file... to be displayed FYI
  44.               <index key> = self-explanatory -- if not passed, will
  45.               be assumed to be the same as the index filename
  46.               <row> = row at which to place window (default: 9)
  47.               <showcount> = logical parameter indicating whether or not
  48.                             to display record counter along with graph
  49.     Example:  IndexBar('customer', 'lname')
  50.     Returns:  Logical: .T. if index is built, .F. if not
  51.     Notes:    will not process empty database files
  52. */
  53. function indexbar(cfile, mkey, mrow, showcount)
  54. local ret_val := .f., xx, oldscrn, maincolor, hicolor, bkey
  55. default mkey to cfile
  56. default showcount to .f.
  57. GFSaveEnv()
  58. //───── make sure that the index key expression is valid to preclude a crash!
  59. if ! valtype(mkey) $ "UE"
  60.    bKey := makeblock(mkey)       // see GRUMP.CH for MakeBlock()
  61.    default mrow to 9
  62.    set index to
  63.    //───── no point in going thru this rigmarole on an empty database (which
  64.    //───── would give us zero divide, a/k/a "the great divide")
  65.    if lastrec() > 0
  66.       num_recs := reccount()
  67.       AddExtension(cfile, "NTX")
  68.       ColorSet(C_MESSAGE)
  69.       oldscrn := shadowbox(mrow, 08, mrow + 6, 71, 2)
  70.       @ mrow + 3, 10 ssay '│'
  71.       @ mrow + 3, 69 ssay '│'
  72.       @ mrow + 4, 10 ssay '╘' + replicate("═════╧", 9) + '════╛'
  73.       @ mrow + 5, 10 ssay '0'
  74.       for xx = 1 to 10
  75.          @ mrow + 5, 14 + (xx - 1) * 6 ssay str(10 * xx, 3)
  76.       next
  77.       SCRNCENTER(mrow + 1, "Creating index file " + cfile + "...")
  78.       ColorSet(C_APICK_STATUSBAR)
  79.       @ mrow + 3, 11 ssay replicate(chr(177), 58)
  80.       ColorSet(C_APICK_INDICATOR)
  81.       go top
  82.       index on gfshowbar(bkey, recno(), showcount) to (cfile)
  83.       dbClearIndex()
  84.       gfkillbar(cfile, mkey)
  85.       dbSetIndex(cfile)
  86.       byebyebox(oldscrn)
  87.       ret_val := .t.
  88.    else
  89.       dbCreateIndex(cfile, mkey, bkey)
  90.    endif
  91. endif
  92. GFRestEnv()
  93. return ret_val
  94.  
  95. * end function IndexBar()
  96. *--------------------------------------------------------------------*
  97.  
  98.  
  99. /*
  100.     Function: GFShowBar()
  101.     Syntax:   GFShowBar(<index key>)
  102.               <index key> = self-explanatory
  103.     Purpose:  Display status graph whilst indexing
  104.     Example:  See above -- NOT MEANT FOR USE AS A STANDALONE
  105.     Returns:  the index key for each record
  106. */
  107. function gfshowbar(bkey, nrec, showcount)
  108. if nrec <= num_recs
  109.    if showcount
  110.       ColorSet(C_MESSAGE)
  111.       if recno() != num_recs
  112.          SCRNCENTER(row() - 1,"Indexing Record " + ltrim(str(nrec)) + ;
  113.                 " of " + ltrim(str(num_recs)))
  114.       else
  115.          SCRNCENTER(row() - 1, space(18) + "Finished !" + space(18))
  116.       endif
  117.       setpos(row()+1, 1)     // reset to proper row
  118.       ColorSet(C_APICK_INDICATOR)
  119.    endif
  120.    @ row(), 11 ssay replicate(chr(219), nrec / num_recs * 58)
  121. endif
  122. return eval(bkey)
  123.  
  124. * end function GFShowBar()
  125. *--------------------------------------------------------------------*
  126.  
  127.  
  128. /*
  129.     Function: GFKillBar()
  130.     Syntax:   GFKillBar(<filename>)
  131.               <filename> = name of index file to be modified - enclose
  132.               in quotes - .NTX extension assumed.
  133.     Purpose:  Strip out the call to SHOWGRAPH()
  134.     Example:  GFKillBar('name.ntx')
  135.     Returns:  Logical: True (.T.) if successful, False (.F.) if not
  136. */
  137. static function gfkillbar(cfile, mkey)
  138. local handle, buffer, pos, ret_val := .f.
  139. /*
  140.    only attempt to open the .ntx low-level if we are guaranteed that no
  141.    indexes are currently open!  trying to do a low-level write on an open
  142.    .ntx file will cause lost clusters, general confusion, and a major
  143.    headache for you the developer, so try to avoid it like the plague
  144. */
  145. if indexord() == 0
  146.    AddExtension(cfile, "NTX")
  147.    handle := fopen(cfile, FO_READWRITE)
  148.    if ferror() == 0
  149.       fseek(handle, 22)      // skip past .NTX header
  150.       buffer := mkey + replicate(chr(0), 254 - len(mkey))
  151.       if fwrite(handle, buffer) = 254
  152.          ret_val := .t.
  153.       endif
  154.       fclose(handle)
  155.    endif
  156. endif
  157. return(ret_val)
  158.  
  159. * end static function GFKillBar()
  160. *--------------------------------------------------------------------*
  161.  
  162. * eof indexbar.prg
  163.