home *** CD-ROM | disk | FTP | other *** search
- /*
- Program: INDEXBAR()
- System: GRUMPFISH LIBRARY
- Author: Greg Lief
- Special Thanks to:
- - John Stolte @ Omicron Software for "showcount"
- - Kevin Farley for his various suggestions
- Copyright (c) 1988-90, Greg Lief
- Clipper 5.x version
- Compile instructions: clipper indexbar /n/w/a
-
- Procs & Fncts: IndexBar()
- : GFShowBar()
- : GFKillBar()
-
- Calls: SHADOWBOX() (function in $SHADOWB.PRG)
-
- IndexBar() displays a graph showing percentage complete when
- indexing files. When indexing is complete, IndexBar() will
- then strip the graph UDF() call from the .NTX file so that you
- don't have to look at the graph when the index is updated.
-
- */
-
- //───── begin preprocessor directives
-
- #include "grump.ch"
- #include "fileio.ch"
-
- //───── end preprocessor directives
-
- //───── begin global declarations
-
- static num_recs // total number of records in current database
- // I put it here instead of referring to RECCOUNT()
- // because it speeds things up a klick or two
-
- //───── end global declarations
-
- /*
- Function: IndexBar()
- Syntax: IndexBar(<filename>, <index key>, <row>, <showcount>)
- <filename> = name of index file... to be displayed FYI
- <index key> = self-explanatory -- if not passed, will
- be assumed to be the same as the index filename
- <row> = row at which to place window (default: 9)
- <showcount> = logical parameter indicating whether or not
- to display record counter along with graph
- Example: IndexBar('customer', 'lname')
- Returns: Logical: .T. if index is built, .F. if not
- Notes: will not process empty database files
- */
- function indexbar(cfile, mkey, mrow, showcount)
- local ret_val := .f., xx, oldscrn, maincolor, hicolor, bkey
- default mkey to cfile
- default showcount to .f.
- GFSaveEnv()
- //───── make sure that the index key expression is valid to preclude a crash!
- if ! valtype(mkey) $ "UE"
- bKey := makeblock(mkey) // see GRUMP.CH for MakeBlock()
- default mrow to 9
- set index to
- //───── no point in going thru this rigmarole on an empty database (which
- //───── would give us zero divide, a/k/a "the great divide")
- if lastrec() > 0
- num_recs := reccount()
- AddExtension(cfile, "NTX")
- ColorSet(C_MESSAGE)
- oldscrn := shadowbox(mrow, 08, mrow + 6, 71, 2)
- @ mrow + 3, 10 ssay '│'
- @ mrow + 3, 69 ssay '│'
- @ mrow + 4, 10 ssay '╘' + replicate("═════╧", 9) + '════╛'
- @ mrow + 5, 10 ssay '0'
- for xx = 1 to 10
- @ mrow + 5, 14 + (xx - 1) * 6 ssay str(10 * xx, 3)
- next
- SCRNCENTER(mrow + 1, "Creating index file " + cfile + "...")
- ColorSet(C_APICK_STATUSBAR)
- @ mrow + 3, 11 ssay replicate(chr(177), 58)
- ColorSet(C_APICK_INDICATOR)
- go top
- index on gfshowbar(bkey, recno(), showcount) to (cfile)
- dbClearIndex()
- gfkillbar(cfile, mkey)
- dbSetIndex(cfile)
- byebyebox(oldscrn)
- ret_val := .t.
- else
- dbCreateIndex(cfile, mkey, bkey)
- endif
- endif
- GFRestEnv()
- return ret_val
-
- * end function IndexBar()
- *--------------------------------------------------------------------*
-
-
- /*
- Function: GFShowBar()
- Syntax: GFShowBar(<index key>)
- <index key> = self-explanatory
- Purpose: Display status graph whilst indexing
- Example: See above -- NOT MEANT FOR USE AS A STANDALONE
- Returns: the index key for each record
- */
- function gfshowbar(bkey, nrec, showcount)
- if nrec <= num_recs
- if showcount
- ColorSet(C_MESSAGE)
- if recno() != num_recs
- SCRNCENTER(row() - 1,"Indexing Record " + ltrim(str(nrec)) + ;
- " of " + ltrim(str(num_recs)))
- else
- SCRNCENTER(row() - 1, space(18) + "Finished !" + space(18))
- endif
- setpos(row()+1, 1) // reset to proper row
- ColorSet(C_APICK_INDICATOR)
- endif
- @ row(), 11 ssay replicate(chr(219), nrec / num_recs * 58)
- endif
- return eval(bkey)
-
- * end function GFShowBar()
- *--------------------------------------------------------------------*
-
-
- /*
- Function: GFKillBar()
- Syntax: GFKillBar(<filename>)
- <filename> = name of index file to be modified - enclose
- in quotes - .NTX extension assumed.
- Purpose: Strip out the call to SHOWGRAPH()
- Example: GFKillBar('name.ntx')
- Returns: Logical: True (.T.) if successful, False (.F.) if not
- */
- static function gfkillbar(cfile, mkey)
- local handle, buffer, pos, ret_val := .f.
- /*
- only attempt to open the .ntx low-level if we are guaranteed that no
- indexes are currently open! trying to do a low-level write on an open
- .ntx file will cause lost clusters, general confusion, and a major
- headache for you the developer, so try to avoid it like the plague
- */
- if indexord() == 0
- AddExtension(cfile, "NTX")
- handle := fopen(cfile, FO_READWRITE)
- if ferror() == 0
- fseek(handle, 22) // skip past .NTX header
- buffer := mkey + replicate(chr(0), 254 - len(mkey))
- if fwrite(handle, buffer) = 254
- ret_val := .t.
- endif
- fclose(handle)
- endif
- endif
- return(ret_val)
-
- * end static function GFKillBar()
- *--------------------------------------------------------------------*
-
- * eof indexbar.prg
-