home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / p / probld.zip / FILE_BLD.PRG next >
Text File  |  1992-10-13  |  8KB  |  292 lines

  1. *╓─────────────────────────────────────────────────────────╖
  2. *║                                                         ║
  3. *║                       FILE_BLD.PRG                      ║
  4. *║                                                         ║
  5. *╟─────────────────────────────────────────────────────────╢
  6. *║                                                         ║
  7. *║ Scott D. Grabo                                          ║
  8. *║                                                         ║
  9. *║ Copyright (c) 1992 Third Wave Software                  ║
  10. *║ 4529 Logsdon Drive                                      ║
  11. *║ Annandale, VA  22003                                    ║
  12. *║                                                         ║
  13. *╟─────────────────────────────────────────────────────────╢
  14. *║    COMMENTS :    This is the interface through which the    ║ 
  15. *║              end user can pick which files will be      ║ 
  16. *║              built.                                     ║  
  17. *║                                                         ║  
  18. *║  SYNTAX   :  IF file_bld(<ExpC1>, <ExpL1>, <ExpC2>)     ║  
  19. *║              <ExpC1>  path to be used as default        ║  
  20. *║              <ExpL1>  called by developer, or in app    ║  
  21. *║              <ExpC2>  default file to placed in target  ║  
  22. *║                       list box                          ║  
  23. *║                                                         ║  
  24. *║  RETURNS  :  Logical                                    ║  
  25. *║                                                         ║  
  26. *║  CALLED BY:  MAIN_VAL.PRG                               ║ 
  27. *║                                                         ║ 
  28. *║  CALLS    :  PICKERV.PRG                                ║ 
  29. *║              MAKE_CDX.PRG                               ║  
  30. *║              MAKE_DBF.PRG                               ║  
  31. *║              OPEN_DBF.PRG                               ║  
  32. *╙─────────────────────────────────────────────────────────╜
  33. PARAMETER ;
  34.   file_path, ;
  35.   interactiv, ;
  36.   dbf_2_bld
  37.   
  38. PRIVATE ;
  39.   m.file_path, ;
  40.   m.interactiv, ;
  41.   m.dbf_2_bld, ;
  42.   old_defa, ;
  43.   old_path, ;
  44.   window_str, ;
  45.   source_str, ;
  46.   target_str, ;
  47.   counter, ;
  48.   length, ;
  49.   was_built
  50.  
  51. WAIT WINDOW ;
  52.   "Setting up the File Builder..." ;
  53.   NOWAIT
  54.       
  55. *
  56. * Let's save the default for restoration later
  57. m.old_defa = SET("DEFAULT") + SYS(2003)
  58. m.old_path = SET("PATH")
  59.  
  60. *
  61. * If no path was provided, just use the current path
  62. IF NOT TYPE("m.file_path") = "C" OR EMPTY(m.file_path)
  63.     m.file_path = m.old_defa
  64. ENDIF
  65.  
  66. m.window_str = "Rebuild files in " + TRIM(UPPER(m.file_path))
  67. m.source_str = "System files" 
  68. m.target_str = "Files to be rebuilt"
  69.  
  70. *
  71. * Since this routine can be used for both development
  72. * _and_ the final product, provide a flag for handling it
  73. * with the development environment (interactive) vs. in
  74. * the field.
  75. IF m.interactiv
  76.     IF USED("structur")
  77.         SELECT structur
  78.      ELSE
  79.         SELECT 0
  80.         USE structur NOUPDATE
  81.     ENDIF
  82.     SET ORDER TO TAG name_filtr
  83.     GOTO TOP
  84.  
  85.     SET DEFAULT TO (m.file_path)
  86.  ELSE
  87.     CLOSE DATA
  88.     SET DEFAULT TO (m.file_path)
  89.  
  90.     IF USED("structur")
  91.         SELECT structur
  92.      ELSE
  93.         SELECT 0
  94.         USE structur NOUPDATE
  95.     ENDIF
  96.     SET ORDER TO TAG name_filtr
  97.     GOTO TOP
  98. ENDIF
  99.  
  100. *
  101. * If we told it to build a specific file, flesh out the
  102. * target array for the picker.
  103. IF TYPE("m.dbf_2_bld") = "C" AND SEEK(m.dbf_2_bld)
  104.     *
  105.     * Seed the target array with the name of the .DBF
  106.     * that was passed.
  107.     COPY TO ARRAY a_dbf_tgt ;
  108.       NEXT 1 ;
  109.       FIELDS ;
  110.         structur.dbf_call, ;
  111.         structur.dbf_name
  112.         
  113.     COUNT TO m.length
  114.     GOTO TOP
  115.     
  116.     *
  117.     * Build out the source array for all .DBFs except
  118.     * the one that was passed.
  119.     IF m.length > 1
  120.         COPY TO ARRAY a_dbf_src ;
  121.           FOR NOT structur.dbf_name = m.dbf_2_bld ;
  122.           FIELDS ;
  123.             structur.dbf_call, ;
  124.             structur.dbf_name
  125.      ELSE
  126.          DIMENSION a_dbf_src[01, 02]
  127.         STORE "" TO ;
  128.           a_dbf_src[01, 01], a_dbf_src[01, 02]
  129.     ENDIF
  130.  ELSE
  131.     *
  132.     * If this is during development, assume the developer
  133.     * will pick and choose the files to rebuild.
  134.     IF m.interactiv
  135.         DIMENSION a_dbf_tgt[01, 02]
  136.         STORE "" TO ;
  137.           a_dbf_tgt[01, 01], a_dbf_tgt[01, 02]
  138.     
  139.         GOTO TOP
  140.         
  141.         COPY TO ARRAY a_dbf_src ;
  142.           FIELDS ;
  143.                structur.dbf_call, ;
  144.             structur.dbf_name
  145.      ELSE
  146.          *
  147.          * Otherwise, assume the user will want to rebuild
  148.          * _all_ the files...
  149.         DIMENSION a_dbf_src[01, 02]
  150.         STORE "" TO ;
  151.           a_dbf_src[01, 01], a_dbf_src[01, 02]
  152.     
  153.         GOTO TOP
  154.         
  155.         COPY TO ARRAY a_dbf_tgt ;
  156.           FIELDS ;
  157.                structur.dbf_call, ;
  158.             structur.dbf_name
  159.     ENDIF        
  160. ENDIF
  161.  
  162. *
  163. * We should only use this during development:  let's use
  164. * the DOS database name _and_ the dbf_call field for the
  165. * display, since we'll recognize it more quickly by its
  166. * system name than by its description.  Normally, the
  167. * arrays are initialized with only the dbf_call value
  168. * be used for display.
  169. IF m.interactive
  170.     PRIVATE src_len, tgt_len
  171.     m.src_len = ALEN(a_dbf_src, 01)
  172.     m.tgt_len = ALEN(a_dbf_tgt, 01)
  173.     FOR m.counter = 1 TO m.src_len
  174.         
  175.         a_dbf_src[m.counter, 01] = ;
  176.           a_dbf_src[m.counter, 02] + "  " + ;
  177.           a_dbf_src[m.counter, 01]
  178.  
  179.     ENDFOR
  180.     
  181.     FOR m.counter = 1 TO m.tgt_len
  182.         
  183.         a_dbf_tgt[m.counter, 01] = ;
  184.           a_dbf_tgt[m.counter, 02] + "  " + ;
  185.           a_dbf_tgt[m.counter, 01]
  186.  
  187.     ENDFOR
  188.     
  189.     RELEASE m.src_len, m.tgt_len
  190. ENDIF        
  191.     
  192. *
  193. * Let's LOOP until we've either built all the selected files, 
  194. * or the user says, "That's enough."  First, initialize a 
  195. * flag that'll tell us whether or not a build was even 
  196. * attempted.
  197. m.was_built = .F.
  198.  
  199. DO WHILE .T.
  200.     m.counter = 0
  201.     
  202.     *
  203.     * If at least one was picked, and ESCape was not pressed
  204.     IF pickerv( ;
  205.       @a_dbf_src, ;
  206.       @a_dbf_tgt, ;
  207.       m.window_str, ;
  208.       m.source_str, ;
  209.       m.target_str, ;
  210.       0, ;
  211.       .F.)
  212.         m.was_built = .T.
  213.           m.length = ALEN(a_dbf_tgt, 01) 
  214.     
  215.         *
  216.         * We'll now scroll through the target array
  217.         * for as long as there are target array elements
  218.         DO WHILE m.length > 0
  219.     
  220.             *
  221.             * If the build was successful, then put the
  222.             * build file data back into the source array.
  223.             IF make_dbf(TRIM(a_dbf_tgt[01, 02]), "", .T.)
  224.                 DIMENSION a_dbf_src[ALEN(a_dbf_src, 01) + 1, 02]
  225.                 a_dbf_src[ALEN(a_dbf_src, 01), 01] = ;
  226.                   a_dbf_tgt[01, 01]
  227.                 a_dbf_src[ALEN(a_dbf_src, 01), 02] = ;
  228.                   a_dbf_tgt[01, 02]
  229.              ELSE
  230.                 *
  231.                 * Otherwise, we'll build out a temp array
  232.                 * to hold the failed build filenames.  This
  233.                 * temp array will then be turned back into
  234.                 * our target at the end of the process, and
  235.                 * we'll loop back to the picker again, with
  236.                 * the failed builds in the target box.
  237.                  m.counter = m.counter + 1 
  238.                  DIMENSION a_not_made[m.counter, 02]
  239.                  a_not_made[m.counter, 01] = a_dbf_tgt[01, 01] 
  240.                  a_not_made[m.counter, 02] = a_dbf_tgt[01, 02] 
  241.             ENDIF
  242.  
  243.             *
  244.             * Either way, we'll shorten the target array
  245.             = ADEL(a_dbf_tgt, 01)
  246.             m.length = m.length - 1 
  247.  
  248.             IF m.length > 0
  249.                 DIMENSION a_dbfname[m.length, 02]
  250.             ENDIF
  251.     
  252.         ENDDO
  253.     ENDIF
  254.  
  255.     *
  256.     * The only way that m.counter could be > 0 is if a build
  257.     * failed.  If so, we'll copy the error-holding array to the
  258.     * target array, and LOOP back to try it again for just 
  259.     * those that didn't build correctly.
  260.     IF m.counter >= 1
  261.         m.length = ALEN(a_not_made, 01)
  262.         DIMENSION a_dbf_tgt[m.length, 02]
  263.         = ACOPY(a_not_made, a_dbf_tgt)
  264.         
  265.         RELEASE a_not_made
  266.  
  267.         m.target_str = "Build failed for these" 
  268.         m.window_str = "File Rebuild - Trying again..." 
  269.      ELSE
  270.          EXIT
  271.     ENDIF
  272.  
  273. ENDDO
  274.  
  275. WAIT WINDOW ;
  276.   "Resetting files..." ;
  277.   NOWAIT
  278.       
  279. SET DEFAULT TO &old_defa
  280. SET PATH TO &old_path
  281.  
  282. *
  283. * You might want to disable these three lines if you intend
  284. * to use the dictionary for more than file rebuilds in your
  285. * application.
  286. IF NOT m.interactiv
  287.      USE IN structur
  288. ENDIF    
  289.  
  290. WAIT CLEAR
  291.  
  292. RETURN m.was_built