home *** CD-ROM | disk | FTP | other *** search
- /*
- Function: FOTOCOPY()
- System: GRUMPFISH LIBRARY
- Author: Greg Lief
- Copyright (c) 1988-90, Greg Lief
- Clipper 5.01 Version
- Compile instructions: clipper fotocopy /n/w/a
- Inspired by Gary Van Slyke, Minneapolis, MN
- */
-
- //───── begin preprocessor directives
-
- #include "dbstruct.ch"
-
- //───── end preprocessor directives
-
- //───── begin global declarations
-
- static fields_ := {}
-
- //───── end global declarations
-
- /*
- Function: FotoCopy()
- Purpose: get the ball rolling
- */
- function fotocopy(calias1, calias2, calias3, calias4)
- local num_files := pcount(), ret_val := 0, xx
- fields_ := dbstruct() // dump current .dbf structure to array
- for xx = 1 to num_files
- ret_val += loopdloop(if(xx == 1, calias1, if(xx == 2, calias2, ;
- if(xx == 3, calias3, calias4))))
- next
- return ret_val
-
- * end function FotoCopy()
- *--------------------------------------------------------------------*
-
-
- /*
- Function: LoopDLoop()
- Purpose: Main loop to copy record into each database
- */
- static function loopdloop(calias)
- local fields2_ := {}, firstloop := .t., xx, ret_val := 1, element, ;
- wk_area := select(), had2open := .f., num_flds, cfield
- //───── determine whether target database is already open
- select(select(calias))
- if fcount() == 0
- if ! file(calias + '.dbf')
- ret_val := 0
- else
- use (calias)
- had2open := .t.
- endif
- endif
- if ret_val == 1
- num_flds := fcount()
- fields2_ := dbstruct()
- for xx = 1 to num_flds
- // check if this field is in the source database
- if (element := ascan(fields_, ;
- { |a| a[DBS_NAME] == fields2_[xx][DBS_NAME] } )) > 0
- // verify they are of the same type!
- if fields2_[xx][DBS_TYPE] == fields_[element][DBS_TYPE]
- if firstloop
- append blank
- firstloop := .f.
- endif
- cfield := fields2_[xx][DBS_NAME]
- * eval( fieldblock(cfield) , eval( fieldwblock(cfield, wk_area) ) )
- fieldput(fieldpos(cfield), (wk_area)->(fieldget(fieldpos(cfield))))
- endif
- endif
- next
- if had2open
- use
- endif
- endif
- select(wk_area)
- return ret_val
-
- * end static function LoopDLoop()
- *--------------------------------------------------------------------*
-
- * eof fotocopy.prg
-