home *** CD-ROM | disk | FTP | other *** search
- *****************************************************************
- FUNCTION DBNAMES
- *****************************************************************
-
- * Reads a data dictionary and tests for existance of databases
- * named in it. Extracts database names and text descriptions.
-
- * Copyright(c) 1991 -- James Occhiogrosso
-
- LOCAL dbf_type := handle := 0
- PARAMETERS app_def, dbf_texts, dbf_names
- PRIVATE dbf_name := ret_value := textline := ''
-
- * Check passed parameters
-
- * Return P if number of parameters is wrong
- IF PCOUNT() != 3
- RETURN 'P'
-
- * Return P if parameters are wrong type
- ELSEIF TYPE('app_def') != 'C' .OR. TYPE('dbf_names') != 'A' ;
- .OR. TYPE('dbf_texts') != 'A'
- RETURN 'P'
-
- ELSE
- * Open data dictionary file
- handle = FOPEN(app_def)
- IF handle <= 0
- * File cannot be opened - return D
- RETURN 'D'
- ENDIF
- ENDIF
-
- * Get first database definition line from data dictionary
- dbf_name = GETDBFDEF()
-
- DO WHILE .NOT. EMPTY(dbf_name)
-
- * Check database name. If database exists, test for
- * associated memo file. If either is missing, exit
- * the loop and return the missing file name.
-
- IF FILE(dbf_name + '.dbf')
-
- dbf_type = ISMEMO(dbf_name)
- IF dbf_type = 1
- * Memo file missing, return its name
- IF .NOT. FILE(dbf_name + '.dbt')
- ret_value = dbf_name + '.dbt'
- EXIT
- ENDIF
- ELSEIF dbf_type = -1
- * Memo file error, return its name
- ret_value = dbf_name
- EXIT
- ENDIF
-
- ELSE
- * Database missing, return its name
- ret_value = dbf_name
- EXIT
- ENDIF
-
- * Add database name and associated text to arrays
- IF EMPTY(ret_value)
- AADD(dbf_names, dbf_name)
- AADD(dbf_texts, SUBSTR(textline, 1, 60))
- ENDIF
-
- * Get next database definition line from data dictionary.
- dbf_name = GETDBFDEF()
-
- ENDDO WHILE .NOT. EMPTY(dbf_name)
-
- RETURN ret_value
-
-
- *****************************************************************
- STATIC FUNCTION GETDBFDEF
- *****************************************************************
-
- * Read data dictionary file line by line, looking for a database
- * definition line (DBFDEF), or end of file marker.
-
- textline = '*'
- DO WHILE (UPPER(SUBSTR(textline, 1, 7)) != 'ENDFILE' .AND. ;
- UPPER(SUBSTR(textline, 1, 6)) != 'DBFDEF') .OR. ;
- (SUBSTR(textline, 1, 1) $ '*#' .OR. EMPTY(textline))
- textline = LTRIM(FREADLINE(handle))
- ENDDO
-
- IF UPPER(SUBSTR(textline, 1, 7)) = 'ENDFILE'
- * Done, close data dictionary file and return
- FCLOSE(handle)
- RETURN ''
- ELSE
- * Strip "DBFDEF" code identifier and return filename
- textline = LTRIM(SUBSTR(textline, 7))
- dbf_name = PARSE(@textline)
- ENDIF
-
- RETURN dbf_name
-
-