home *** CD-ROM | disk | FTP | other *** search
- * ╔══════════════════════════════════════════════════════════════════════╗
- * ║ DDGEN.PRG ║
- * ╠══════════════════════════════════════════════════════════════════════╣
- * ║ ║
- * ║ Author: Gene Clark (202)252-6363 ║
- * ║ Created: October 20, 1985 ║
- * ╚══════════════════════════════════════════════════════════════════════╝
- *
- * This program reads the structure of your designated dBASEIII file and
- * creates a data dictionary, containing the data file's structure and a
- * description of each data field. You supply the field description
- * ("DEFINITION"), and this program supplies the rest.
- *
- SET TALK OFF
- SET DELIM OFF
- CLEAR ALL
- CLEAR
- ACTIVE=.T.
- DO WHILE ACTIVE
- CLEAR
- @ 1,10 SAY "╔══════════════════════════════════════════════════════╗"
- @ 2,10 SAY "║ dBASE III Database Data Dictionary Generator ║"
- @ 3,10 SAY "╚══════════════════════════════════════════════════════╝"
- @ 5,3 SAY " This program creates a dBASEIII data dictionary for a data file you"
- @ 6,3 SAY " specify. The resulting data dictionary is actually another dBASEIII"
- @ 7,3 SAY " data base file with the same filename as your data file, but with an"
- @ 8,3 SAY " extent of .DIC . Once the .DIC file is created, it can be USEd like"
- @ 9,3 SAY " any .DBF file as long as you USE it with the fully qualified name."
- @ 10,4 SAY "You will be asked to provide the dBASEIII data base file name, a 54-"
- @ 11,4 SAY "character description of the file, and a 54-character definition of"
- @ 12,4 SAY "each field in the data base file."
- @ 14,0
- IF .NOT.FILE('DDGEN.DBF').AND..NOT.FILE('..\DDGEN.DBF')
- ? " The DDGEN.DBF Master File is Missing -- Program Aborted"
- RETURN
- ENDIF
- ACCE " Please enter the database name: " TO NFILE
- NFILE = UPPER(NFILE)
- DFILE = NFILE+".DIC"
- MFILE = NFILE+".DBF"
- @ 16,0 CLEAR
- * look for the .DBF - if it's not there, exit
- IF .NOT. FILE('&MFILE')
- @ 17,10 SAY "File &MFILE doesn't exist... EXITING."
- SET DELIM ON
- RETURN
- ENDIF
- USE &MFILE
- * take a look at the file structure before starting
- CLEAR
- ? "THIS IS THE STRUCTURE OF YOUR DESIGNATED FILE:"
- ?
- DISPLAY STRUCTURE
- ?
- ? "====================================="
- ?
- ACCEPT "Press <CR> =====> " TO X
- CLEAR
- DEFN=SPACE(54)
- * memvar DEFN allows for a 54 char. general description of the file.
- @ 7,5 SAY "(This description will be saved in the 1st record of the .DIC file.)"
- @ 5,0 SAY "Description, &MFILE: " GET DEFN
- READ
- * STRUCTURE EXTENDED creates a database containing only the names,
- * length, type and decimal spaces for your file
- COPY TO {} STRUCTURE EXTENDED
- CLEAR
- * DDGEN.DBF is the structure of the data dictionary file. The
- * resulting data dictionary file will have the same file name as
- * the .DBF file, but will have a file extent of ".DIC". The .DIC
- * file will be a dBASEIII data base file, however, and can be "USED"
- * just like any other data base file.
- COPY FILE DDGEN.DBF TO &DFILE
- SELE A
- USE &DFILE
- * Make the first record of the .DIC file be the descriptor of the entire
- * data base.
- APPEND BLANK
- REPLACE NUM WITH "DBF", FIELD_NAME WITH NFILE, T WITH "D", DEFINITION WITH DEFN
- APPEND FROM {}
- GO 2
- SELE B
- USE {}
- COUNTER = 1
- SELE A
- DO WHILE .NOT.EOF()
- REPLACE NUM WITH STR(COUNTER,3), T WITH B->FIELD_TYPE, LEN WITH B->FIELD_LEN
- IF (B->FIELD_DEC>0)
- REPLACE DEC WITH B->FIELD_DEC
- ENDIF
- SELE B
- SKIP
- SELE A
- SKIP
- COUNTER = COUNTER + 1
- ENDDO
- SELE B
- USE
- ERASE {}.DBF
- SELE A
- GO 2
- CLEAR
- @ 1,0 SAY "Data File: " + MFILE + " (" + DEFN + ")"
- @ 2,0 SAY "_______________________________________________________"
- @ 2,55 SAY "________________________"
- @ 4,0 SAY "Num Field Name T Len Dec"
- @ 4,45 SAY "Field Definition"
- @ 5,0 SAY "=== ========== = === ==="
- @ 5,25 SAY "======================================================"
- LINE = 6
- COUNTER = 1
- * Cycle through the list of field names to allow addition of definitions
- DO WHILE .NOT. EOF()
- @ LINE,0 SAY NUM
- @ LINE,4 SAY FIELD_NAME
- @ LINE,15 SAY T
- @ LINE,17 SAY LEN
- @ LINE,21 SAY DEC
- @ LINE,25 GET DEFINITION
- READ
- CLEAR GETS
- SKIP
- * increment the line and field counters
- LINE=LINE+1
- COUNTER=COUNTER+1
- * if we filled up one screen, clear for another
- IF LINE=24
- @ 6,0 CLEAR
- LINE=6
- ENDIF
- ENDDO
- * end of file? Print or display it.
- CLEAR
- WAIT "Display or Print the data dictionary?" TO P
- P=UPPER(P)
- @ 1,0 CLEAR
- IF P = "P"
- ACCEPT "Turn on the printer and press <CR> =======> " TO X
- CLEAR
- @ 10,20 SAY "Printing the data dictionary for "+MFILE
- SET DEVICE TO PRINT
- ENDIF
- COUNTER=1
- HEADING=.T.
- GO 2
- DO WHILE .NOT. EOF()
- IF HEADING
- @ 1,0 SAY "dBASEIII DATA BASE FILE DICTIONARY"
- @ 1,57 SAY "Today's Date:"
- @ 1,71 SAY DATE()
- @ 3,0 SAY "Data File: " + MFILE
- @ 3,40 SAY "Dictionary File: " + DFILE
- @ 4,0 SAY "File Description: " + DEFN
- @ 5,0 SAY "======================================================="
- @ 5,55 SAY "========================"
- @ 6,0 SAY "Num Field Name T Len Dec"
- @ 6,45 SAY "Field Definition"
- @ 7,0 SAY "=== ========== = === ==="
- @ 7,25 SAY "======================================================"
- LINE=8
- HEADING=.F.
- ENDIF
- @ LINE,0 SAY NUM
- @ LINE,4 SAY FIELD_NAME
- @ LINE,15 SAY T
- @ LINE,17 SAY LEN
- @ LINE,21 SAY DEC
- @ LINE,25 SAY DEFINITION
- SKIP
- LINE = LINE+1
- COUNTER = COUNTER+1
- IF (LINE>56.AND.P="P")
- HEADING=.T.
- EJECT
- ENDIF
- IF (LINE>25.AND.P<>"P")
- HEADING=.T.
- WAIT " Hit any key to continue" TO X
- ENDIF
- ENDDO
- STORE LINE+1 TO LINE
- @ LINE,0 SAY "_______________________________________________________"
- @ LINE,55 SAY "________________________"
- IF P<>"P"
- WAIT " Last of Dictionary Lines -- Hit Any Key to Continue" TO X
- ENDIF
- SET DEVI TO SCREEN
- * finished printing
- IF P = "P"
- EJECT
- ENDIF
- CLEAR
- * check to see if there are any more files to be documented
- STORE ' ' TO ANS
- DO WHILE AT(ANS,'YN')=0
- @ 10,0 SAY "Do you wish to document another Database? ===> " ;
- GET ANS PICT '!'
- READ
- ENDDO
- * if not, exit the loop and the program
- IF ANS='N'
- STORE .F. TO ACTIVE
- ENDIF
- ENDDO
- @ 10,0
- @ 10,18 SAY "Data Dictionary(ies) Created -- Job Finished"
- SET DELIM ON
- RETURN
- ********* END OF FILE
-