home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a013 / 1.ddi / SOURCE.EXE / F_MMOPAC.PRG < prev    next >
Encoding:
Text File  |  1991-01-25  |  2.3 KB  |  82 lines

  1. *****************************************************************
  2. FUNCTION MEMOPACK (packlist)
  3. *****************************************************************
  4.  
  5. * Removes unused memo data from a database DBT file
  6.  
  7. * Copyright(c) 1991 - James Occhiogrosso
  8.  
  9. #include "set.ch"
  10.  
  11. LOCAL counter, old_delete, real_recs, ret_value
  12.  
  13. PRIVATE temp_file
  14.  
  15. ret_value = ''
  16.  
  17. * Get a unique temporary database file name
  18. temp_file = TEMPFILE('DBF')
  19.  
  20. * Strip its extension
  21. temp_file = SUBSTR(temp_file, 1, AT('.', temp_file) - 1)
  22.  
  23. FOR counter = 1 TO LEN(packlist)
  24.  
  25.      * Make sure all files in passed array exist
  26.      IF .NOT. FILE(packlist[counter] + '.DBF') .OR. .NOT. ;
  27.                 FILE(packlist[counter] + '.DBT')
  28.          ret_value = '1 - ' + packlist[counter]
  29.          EXIT
  30.      ENDIF
  31.  
  32.      * Open database and get record count
  33.      USE (packlist[counter])
  34.      real_recs = LASTREC()
  35.  
  36.      * Save deleted setting and set deleted off.
  37.      * (So that deleted records are copied)
  38.      old_delete = SET(_SET_DELETED, .F.)
  39.              
  40.      * Copy to temporary file name and open it
  41.      COPY TO &temp_file
  42.      USE &temp_file
  43.  
  44.      * Restore original deleted setting
  45.      SET(_SET_DELETED, old_delete)
  46.  
  47.      IF LASTREC() = real_recs
  48.          * Copy succeeded if record count is same
  49.          USE
  50.          IF FILE(temp_file + '.DBT')
  51.  
  52.              * Erasing old files
  53.              ERASE (packlist[counter] + '.dbf')
  54.              ERASE (packlist[counter] + '.dbt')
  55.  
  56.              * Make sure they were erased
  57.              IF ( FILE(packlist[counter]+'.DBF') .OR. ;
  58.                   FILE(packlist[counter]+'.DBT') )
  59.                  * If they are still present, we cannot rename
  60.                  ret_value = '2 - ' + packlist[counter]
  61.                  EXIT
  62.              ENDIF
  63.  
  64.              * Rename temporary files to passed name
  65.              RENAME (temp_file + '.DBF') TO ;
  66.                     (packlist[counter] + '.dbf')
  67.              RENAME (temp_file + '.DBT') TO ;
  68.                     (packlist[counter] + '.dbt')
  69.          ELSE
  70.              * Temporary DBT file is missing
  71.              ret_value = '3 - ' + packlist[counter]
  72.              EXIT
  73.          ENDIF
  74.      ELSE
  75.          * Database was copied incorrectly
  76.          ret_value = '4 - ' + packlist[counter]
  77.          EXIT
  78.      ENDIF
  79. NEXT
  80. RETURN ret_value
  81.  
  82.