home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 25.15. Two simultaneous browse windows, one with
- a listing of database file names and the
- other with corresponding field structures.
- Calls ArraySkip(), which is in Listing 25.11 (CHP2511.PRG)
- Author: Craig Yellick
- Excerpted from "Clipper 5: A Developer's Guide"
- Copyright (c) 1991 M&T Books
- 501 Galveston Drive
- Redwood City, CA 94063-4728
- (415) 366-3600
- */
-
- //───── NOTE: must compile with the /N option!
-
- function DBFdirect(fileSpec)
- /*
- Call this function from DOS. It will display
- two browse windows, one with database file name
- information and one with the field structure of
- the currently highlighted database.
-
- If you think this routine would form an excellent
- base for a general purpose database utility and are
- already dreaming up specifications and features...
- you've been bitten by that Clipper 5.0 bug and we
- wish you well! Turn off the lights when you leave
- and try to get some sleep once and a while.
- */
- #include "inkey.ch"
- #include "directry.ch"
- #include "dbstruct.ch"
-
- local dir_, stru_
- local dbf, dirPos
- local stru, struPos
- local i, bytes, col, key
-
- // Default filespec if none specified.
- if fileSpec = nil
- fileSpec := "*.dbf"
- elseif .not. ("." $ fileSpec)
- fileSpec += ".dbf"
- endif
-
- setcursor(0)
- @ 0,0 clear
- @ 1,0 say padc("Database Directory & Structure Viewer: " ;
- +fileSpec, 80)
- @ 2,0 say "Loading..."
-
- // Load directory entries.
- dir_ := directory(fileSpec)
- if len(dir_) = 0
- @ 2,0
- @ 2,0 say "No files found."
- return nil
- endif
-
- // This array will hold database structures.
- stru_ := {}
-
- // For each database file in the directory...
- for i := 1 to len(dir_)
- @ 2,11 say i
- use (dir_[i, DBS_NAME]) shared
-
- // Add record and field counts to the directory array.
- aadd(dir_[i], lastrec())
- aadd(dir_[i], fcount())
-
- // Add current database's structure to the array.
- aadd(stru_, dbstruct())
- use
- next i
-
- // Sum the file sizes.
- bytes := 0
- aeval(dir_, { |f_| bytes += f_[F_SIZE] } )
-
- // Clear the "loading" message.
- @ 2,0
-
- // Draw the static portions of the screen.
- @ 4,1 say "Up/Down, PgUp/PgDn"
- @ 5,0 to 15,52
- @ 16,1 say ltrim(transform(bytes, "999,999,999")) ;
- +" bytes in " ;
- +ltrim(str(len(dir_))) +" files."
-
- @ 4,54 say "Left/Right, Tab/ShiftTab"
- @ 5,53 to 15,79
-
- // Construct a browse object for the directory array.
- //
- dirPos := 1
- dbf := TBrowseNew(6,1,14,51)
- dbf:headSep := "--"
- dbf:colSep := "|"
- dbf:goTopBlock := { | | dirPos := 1 }
- dbf:goBottomBlock := { | | dirPos := len(dir_) }
- dbf:skipBlock := { |n| ArraySkip(len(dir_), @dirPos, n) }
-
- // Directory window columns.
- dbf:addcolumn(TBColumnNew("File Name", ;
- { || padr(dir_[dirPos, F_NAME], 12) } ))
- dbf:addcolumn(TBColumnNew("Size", ;
- { || transform(dir_[dirPos, F_SIZE], "99,999,999 ") } ))
- dbf:addcolumn(TBColumnNew("Date", ;
- { || dir_[dirPos, F_DATE] } ))
- dbf:addcolumn(TBColumnNew("Records", ;
- { || transform(dir_[dirPos, 6], "999,999 ") } ))
- dbf:addcolumn(TBColumnNew("Fields", ;
- { || transform(dir_[dirPos, 7], "999") } ))
-
- // Construct a browse object for the structure array.
- //
- struPos := 1
- stru := TBrowseNew(6,54,14,78)
- stru:headSep := "--"
- stru:colSep := "|"
- stru:goTopBlock := { | | struPos := 1 }
- stru:goBottomBlock := { | | struPos := len(stru_) }
- stru:skipBlock := ;
- { |n| ArraySkip(len(stru_[dirPos]), @struPos, n) }
-
- // Structure window columns.
- stru:addcolumn(TBColumnNew("Field", ;
- { || padr(stru_[dirPos, struPos, DBS_NAME], 10) } ))
- stru:addcolumn(TBColumnNew("Type", ;
- { || padc(stru_[dirPos, struPos, DBS_TYPE], 4) } ))
- stru:addcolumn(TBColumnNew("Width", ;
- { || str(stru_[dirPos, struPos, DBS_LEN], 5) } ))
- stru:addcolumn(TBColumnNew("Dec", ;
- { || str(stru_[dirPos, struPos, DBS_DEC], 3) } ))
-
- do while .t.
-
- // If the directory window position was altered,
- // we must update the structure window to match it.
- if .not. dbf:stable
- stru:rowPos := 1
- stru:goTop()
- stru:refreshAll()
- endif
-
- // Stabilize both windows.
- do while (.not. dbf:stabilize()) .and. (nextkey() = 0)
- enddo
- do while (.not. stru:stabilize()) .and. (nextkey() = 0)
- enddo
-
- // Update the structure summary lines.
- @ 16,54
- @ 17,54
- bytes := 0
- aeval(stru_[dirPos], { |s_| bytes += s_[DBS_LEN] } )
- @ 16,54 say ltrim(str(bytes)) +" bytes per record,"
- @ 17,54 say ltrim(str(len(stru_[dirPos]))) +" fields."
-
- key := inkey(0)
-
- // Database window navigation keys
- do case
- case key = K_UP
- dbf:up()
- case key = K_DOWN
- dbf:down()
- case key = K_PGUP
- dbf:pageUp()
- case key = K_PGDN
- dbf:pageDown()
-
- // Structure window navigation keys.
- case key = K_LEFT
- stru:up()
- case key = K_RIGHT
- stru:down()
- case key = K_TAB
- stru:pageDown()
- case key = K_SH_TAB
- stru:pageUp()
- case key = K_ESC
- exit
- endcase
- enddo
- setcursor(1)
- return nil
-
- // end of file CHP2515.PRG
-