home *** CD-ROM | disk | FTP | other *** search
- *****************************************************************
- FUNCTION MAKENDX
- *****************************************************************
-
- * Creates or recreates an application's index files
-
- * Copyright(c) 1991 -- James Occhiogrosso
-
- LOCAL counter := 1, old_cursor:= SETCURSOR(.F.), old_screen:= ''
-
- PARAMETERS dbf_names, textline, text_row
- PRIVATE dbf_name := ndx_name := ndx_expr := ''
-
- IF VALTYPE(dbf_names) != 'A'
- * Called stand alone and incorrect parameter passed.
- RETURN .F.
- ELSEIF LEN(dbf_names) = 0
- * Called with no database names in array
- RETURN .F.
- ENDIF
-
- dbf_count := LEN(dbf_names)
-
- * Test text_row argument. If NIL, MAKENDX was called directly.
- * Open data dictionary and read first line. Otherwise, file
- * is open, the file handle (obtained in MAKEDBF) is used, and
- * the pointer is on the next available line.
-
- IF text_row = NIL
-
- * Not called from MAKEDBF, save screen
- SAVE SCREEN TO old_screen
-
- * Note: If MAKENDX is called by MAKEDBF second argument
- * passed is current line of data dictionary file.
- * If called by itself, argument 2 is name of the
- * dictionary. The third argument to position text
- * exists only if called by MAKEDBF.
-
- * Open data dictionary file
- handle = FOPEN(textline)
- IF handle <= 0
- * Critical error - return to DOS
- ?? CHR(7)
- ? 'Application definition file missing.'
- SET CURSOR ON
- QUIT
- ENDIF
-
- * Display default screen and get first valid
- * index definition line.
- text_row = 7
-
- * Display MAKENDX installation screen
- CLEAR SCREEN
- @ 2, 7, 23, 70 BOX '╔═╗║╝═╚║ '
- @ 2, 0 SAY ''
- TEXT
- ║ S Y S T E M I N D E X I N G ║
- ╟──────────────────────────────────────────────────────────────╢
- ║ Files that are being reindexed will be listed below. ║
- ║ Reindexing takes a few minutes. Please be patient. ║
- ╟──────────────────────────────────────────────────────────────╢
- ENDTEXT
- textline = GETNDXDEF()
-
- ELSE
- * Check line passed by MAKEDBF
- IF UPPER(SUBSTR(textline,1,6)) != 'NDXDEF'
- * Not an index definition, get another line
- textline = GETNDXDEF()
- ELSE
- * Strip NDXDEF code from line
- textline = SUBSTR(textline,7)
- ENDIF
-
- ENDIF
-
- * Get database name from index definition line
- dbf_name = PARSE(@textline)
-
- FOR counter = 1 TO dbf_count
-
- * Trim and force filename to uppercase.
- dbf_names[counter] = UPPER(TRIM(LTRIM(dbf_names[counter])))
-
- NEXT
-
- * If dictionary NDXDEF line matches a database name in
- * passed array, rebuild index per dictionary
-
- DO WHILE .NOT. EMPTY(dbf_name)
-
- * Execute loop until we have a blank database name
- * (Indicates a null return reading definitions file).
-
- IF (dbf_count = 1 .and. dbf_name = dbf_names[1]) .or. ;
- (dbf_count > 1 .and. ASCAN(dbf_names, dbf_name) != 0)
-
- * Get index name and key expression.
- ndx_name = PARSE(@textline)
- ndx_expr = PARSE(@textline)
-
- * Scroll screen up if at bottom of window
- IF text_row = 22
- SCROLL(8, 9, 22, 68, 1)
- ELSE
- text_row = text_row + 1
- ENDIF
-
- * Display balance of associated text
- @ text_row, 7 SAY '║' + ' ' + SUBSTR(textline, 1, 60)
- @ text_row, 70 SAY '║'
-
- * Reindex file
- USE &dbf_name
- INDEX ON &ndx_expr TO &ndx_name
- USE
-
- ENDIF
-
- * Get the next valid index definition line
- textline = GETNDXDEF()
-
- * Parse database name
- dbf_name = PARSE(@textline)
-
- ENDDO
-
- * Restore screen if MAKENDX not called from MAKEDBF
- IF TYPE('old_screen') != 'U'
- RESTORE SCREEN FROM old_screen
- ENDIF
-
- SETCURSOR(old_cursor)
- RETURN .T.
-
-
- *****************************************************************
- STATIC FUNCTION GETNDXDEF
- *****************************************************************
-
- * Locate and read next index definition (NDXDEF) line
-
- * Get next defined line from data dictionary
- NEXTLINE()
-
- * Check line. If not an index definition or
- * end of file, get another.
-
- DO WHILE UPPER(SUBSTR(textline, 1, 6)) != 'NDXDEF' .AND. ;
- UPPER(SUBSTR(textline, 1, 7)) != 'ENDFILE'
-
- * Get another line from definitions file
- NEXTLINE()
- ENDDO
-
- * Check for valid index definition line
-
- IF UPPER(SUBSTR(textline, 1, 6)) != 'NDXDEF' .OR. ;
- UPPER(SUBSTR(textline, 1, 7)) = 'ENDFILE'
-
- * No INDEX definitions exist, or we are at end of file
- RETURN ''
-
- ELSE
- * Line is valid index definition, strip NDXDEF
- * code identifier and return line
-
- RETURN LTRIM(SUBSTR(textline, 7))
-
- ENDIF
-
- *****************************************************************
- STATIC FUNCTION NEXTLINE
- *****************************************************************
-
- * Get next non-comment line in definitions file
-
- * Initialize textline and test first character
- textline = '*'
- DO WHILE (SUBSTR(textline, 1, 1) $ '*#' .OR. EMPTY(textline)) ;
- .AND. UPPER(SUBSTR(textline, 1, 7)) != 'ENDFILE'
-
- * If line is a comment or blank, skip it
- textline = LTRIM(FREADLINE(handle))
-
- ENDDO
-
- RETURN NIL
-
-