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

  1. *****************************************************************
  2. FUNCTION MAKENDX
  3. *****************************************************************
  4.  
  5. * Creates or recreates an application's index files
  6.  
  7. * Copyright(c) 1991 -- James Occhiogrosso
  8.  
  9. LOCAL counter := 1, old_cursor:= SETCURSOR(.F.), old_screen:= ''
  10.  
  11. PARAMETERS dbf_names, textline, text_row
  12. PRIVATE dbf_name := ndx_name := ndx_expr := ''
  13.  
  14. IF VALTYPE(dbf_names) != 'A'
  15.     * Called stand alone and incorrect parameter passed.
  16.     RETURN .F.
  17. ELSEIF LEN(dbf_names) = 0
  18.     * Called with no database names in array
  19.     RETURN .F.
  20. ENDIF
  21.  
  22. dbf_count := LEN(dbf_names)
  23.  
  24. * Test text_row argument. If NIL, MAKENDX was called directly.
  25. * Open data dictionary and read first line. Otherwise, file
  26. * is open, the file handle (obtained in MAKEDBF) is used, and
  27. * the pointer is on the next available line.
  28.  
  29. IF text_row = NIL
  30.  
  31.      * Not called from MAKEDBF, save screen
  32.      SAVE SCREEN TO old_screen
  33.  
  34.      * Note: If MAKENDX is called by MAKEDBF second argument
  35.      * passed is current line of data dictionary file.
  36.      * If called by itself, argument 2 is name of the
  37.      * dictionary. The third argument to position text
  38.      * exists only if called by MAKEDBF.
  39.  
  40.      * Open data dictionary file
  41.      handle = FOPEN(textline)
  42.      IF handle <= 0
  43.         * Critical error - return to DOS
  44.         ?? CHR(7)
  45.         ? 'Application definition file missing.'
  46.         SET CURSOR ON
  47.         QUIT
  48.      ENDIF
  49.  
  50.      * Display default screen and get first valid
  51.      * index definition line.
  52.      text_row = 7
  53.  
  54.      * Display MAKENDX installation screen
  55.      CLEAR SCREEN
  56.      @ 2, 7, 23, 70 BOX '╔═╗║╝═╚║ '
  57.      @ 2, 0 SAY ''
  58.      TEXT
  59.        ║                S Y S T E M     I N D E X I N G               ║
  60.        ╟──────────────────────────────────────────────────────────────╢
  61.        ║    Files that are being reindexed will be listed below.      ║
  62.        ║    Reindexing takes a few minutes.  Please be patient.       ║
  63.        ╟──────────────────────────────────────────────────────────────╢
  64.      ENDTEXT
  65.      textline = GETNDXDEF()
  66.  
  67. ELSE
  68.      * Check line passed by MAKEDBF
  69.      IF UPPER(SUBSTR(textline,1,6)) != 'NDXDEF'
  70.          * Not an index definition, get another line
  71.          textline = GETNDXDEF()
  72.      ELSE
  73.          * Strip NDXDEF code from line
  74.          textline = SUBSTR(textline,7)
  75.      ENDIF
  76.  
  77. ENDIF
  78.  
  79. * Get database name from index definition line
  80. dbf_name = PARSE(@textline)
  81.  
  82. FOR counter = 1 TO dbf_count
  83.  
  84.     * Trim and force filename to uppercase.
  85.     dbf_names[counter] = UPPER(TRIM(LTRIM(dbf_names[counter])))
  86.  
  87. NEXT
  88.  
  89. * If dictionary NDXDEF line matches a database name in
  90. * passed array, rebuild index per dictionary
  91.  
  92. DO WHILE .NOT. EMPTY(dbf_name)
  93.  
  94.     * Execute loop until we have a blank database name
  95.     * (Indicates a null return reading definitions file).
  96.  
  97.     IF (dbf_count = 1 .and. dbf_name = dbf_names[1]) .or. ;
  98.        (dbf_count > 1 .and. ASCAN(dbf_names, dbf_name) != 0)
  99.  
  100.         * Get index name and key expression.
  101.          ndx_name = PARSE(@textline)
  102.          ndx_expr = PARSE(@textline)
  103.  
  104.         * Scroll screen up if at bottom of window
  105.         IF text_row = 22
  106.              SCROLL(8, 9, 22, 68, 1)
  107.         ELSE
  108.             text_row = text_row + 1
  109.         ENDIF
  110.  
  111.         * Display balance of associated text
  112.         @ text_row, 7 SAY '║' + ' ' + SUBSTR(textline, 1, 60)
  113.         @ text_row, 70 SAY '║'
  114.  
  115.         * Reindex file
  116.         USE &dbf_name
  117.         INDEX ON &ndx_expr TO &ndx_name
  118.         USE
  119.  
  120.     ENDIF
  121.  
  122.     * Get the next valid index definition line
  123.     textline = GETNDXDEF()
  124.  
  125.     * Parse database name
  126.     dbf_name = PARSE(@textline)
  127.  
  128. ENDDO
  129.  
  130. * Restore screen if MAKENDX not called from MAKEDBF
  131. IF TYPE('old_screen') != 'U'
  132.     RESTORE SCREEN FROM old_screen
  133. ENDIF
  134.  
  135. SETCURSOR(old_cursor)
  136. RETURN .T.
  137.  
  138.  
  139. *****************************************************************
  140. STATIC FUNCTION GETNDXDEF
  141. *****************************************************************
  142.  
  143. * Locate and read next index definition (NDXDEF) line
  144.  
  145. * Get next defined line from data dictionary
  146. NEXTLINE()
  147.  
  148. * Check line. If not an index definition or
  149. * end of file, get another.
  150.  
  151. DO WHILE UPPER(SUBSTR(textline, 1, 6)) != 'NDXDEF' .AND. ;
  152.          UPPER(SUBSTR(textline, 1, 7)) != 'ENDFILE'
  153.  
  154.          * Get another line from definitions file
  155.          NEXTLINE()
  156. ENDDO
  157.  
  158. * Check for valid index definition line
  159.  
  160. IF UPPER(SUBSTR(textline, 1, 6)) != 'NDXDEF' .OR. ;
  161.     UPPER(SUBSTR(textline, 1, 7)) = 'ENDFILE'
  162.  
  163.     * No INDEX definitions exist, or we are at end of file
  164.     RETURN ''
  165.  
  166. ELSE
  167.     * Line is valid index definition, strip NDXDEF
  168.     * code identifier and return line
  169.  
  170.     RETURN LTRIM(SUBSTR(textline, 7))
  171.  
  172. ENDIF
  173.  
  174. *****************************************************************
  175. STATIC FUNCTION NEXTLINE  
  176. *****************************************************************
  177.  
  178. * Get next non-comment line in definitions file
  179.  
  180. * Initialize textline and test first character
  181. textline = '*'
  182. DO WHILE (SUBSTR(textline, 1, 1) $ '*#' .OR. EMPTY(textline))  ;
  183.         .AND. UPPER(SUBSTR(textline, 1, 7)) != 'ENDFILE'
  184.  
  185.      * If line is a comment or blank, skip it
  186.     textline = LTRIM(FREADLINE(handle))
  187.  
  188. ENDDO
  189.  
  190. RETURN NIL
  191.  
  192.