home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
xbase
/
library
/
dbase
/
duplicat
/
moddbf.prg
< prev
Wrap
Text File
|
1987-02-26
|
8KB
|
235 lines
** MODDBF.PRG - utility for creating and editting text files from which to
** create new or modified structures from existing datafiles
** copyright Steve Titterud 1987
close data
set status off
set scoreboard off
set menu off
set talk off
set safety off
set echo off
set heading off
clear
text && delete this help text if desired or when no longer needed...
The MODIFY STRUCTURE command is a rather unwieldy way to change a
datafile's structure, if the changes are complex: e.g., rearranging
field order when there are a large number of fields. There are other
methods more convenient in some cases. This is a utility I have used,
and maybe it might save you some work, too.
The following program expects input of a source datafile name and a
target datafile name. The source file is a datafile whose structure
you intend to modify. The target file will be a structure extended file
which may be used to generate the newly structured file with the
CREATE FROM commmand, after its data is modified.
First, we create the structure file from the source, then, USEing it,
write a text file with the COPY TO...SDF command, then edit this SDF file
with your editor. Then, with any blank (zapped) structure file in use,
APPEND FROM...SDF the editted text file. The last steps will then
be to rename the original datafile (as a backup for source), CREATE FROM
the newly formed structure file, and lastly, append from the renamed
source file into the new file. By the way, you can do the same process
with a structure extended file as the source!!
This sounds complicated, but in practice is quite simple - try it!
endtext
wait
clear
text
Some conventions assumed here:
- pressing <Esc> during input will abort the program; there is
little error-checking in the program; modify to suit your needs
- if you do not give a file extension, .DBF will be supplied for
the source file, .EXT will be supplied for the structure file.
- the text file output in the COPY TO...SDF command is given
the same filename as the source, but for the extension .SDF.
- in the final append operation (if chosen) from the original
source file to the new structure, the source file is renamed
by changing its extension to .OLD - the newly structured file
takes the same name as the source had at the beginning
- if you choose to NOT append from the source into the altered
structure, the original source file is left unaltered
- the MODI COMM command is used to call the editor; if you don't
have an editor specified in CONFIG.DB, you will get the dBase
editor; keep edits in same columnar format as in the SDF file, else
you may get unpredictable results when creating and/or appending
endtext
wait
clear
changeit=.T.
quitter=.F.
do while .not. quitter
clear
source=space(12)
target=space(12)
@ 10,15 say "What file to modify?" get source
@ 12,15 say "(Default extension of .DBF supplied if none given.)"
read
r=readkey()
if r=12 .or. r=268
close data
return
endif
source=upper(ltrim(rtrim(source)))
if .not. "."$source
source=source+".DBF"
else
if right(source,1)="."
source=source+"DBF"
endif
endif
if .not. file('&source')
clear
@ 10,15 say "File "+source+" not found! Try again!"
@ 23,0
wait
clear
source=space(12)
loop
endif
clear
@ 10,15 say "Name for file with new structure ?" get target
@ 12,15 say "(Default extension of .EXT supplied if none given.)"
read
r=readkey()
if r=12 .or. r=268
close data
return
endif
target=upper(ltrim(rtrim(target)))
if .not. "."$target
target=target+".EXT"
else
if right(target,1)="."
target=target+"EXT"
endif
endif
targetsdf=upper(ltrim(rtrim(substr(target,1,at(".",target)-1)))+".sdf")
clear
@ 10,15 say "Capturing structure to "+target+"..."
use &source
if file('&target')
erase &target
endif
copy to &target stru exte
use &target
clear
wait "Press any key to view current structure of "+target+"..."
?
?
disp all
wait "Press any key to copy this structure to text file for edit..."
clear
@ 10,15 say "Copying structure to text file "+targetsdf+" and loading editor..."
if file('&targetsdf')
erase &targetsdf
endif
copy to &targetsdf sdf
modi comm &targetsdf
clear
loadnew=.T.
@ 10,15 say "Load editted values for structure into "+target+" (Y/N)?" get loadnew
read
r=readkey()
if r=12 .or. r=268
close data
return
endif
if loadnew
zap
appe from &targetsdf sdf
clear
wait "Press any key to view new structure in "+target+"."
?
?
disp all
?
wait
clear
changeit=.T.
@ 10,15 say "Append from original source into new structure? (Y/N)" get changeit
read
r=readkey()
if r=12 .or. r=268
close data
return
endif
endif
if .not. changeit
clear
? source+" is left unaltered and as it was found by this program."
?
? target+" now holds the new structure for "+source+" as a dBase file."
?
? targetsdf+" holds the structure as an undelimited text file."
?
? "You may now use "+target+" to create a new "+source+" with the"
? "altered structure represented in "+target+" by the following"
? "commands from the dBase dot prompt:"
?
? " . rename "+source+" to <new filename for &source.>"
? " . create "+source+" from "+target
? " . use "+source
? " . appe from <new filename for &source.>"
?
? "You could also re-edit the text file "+targetsdf+" in order to further"
? "modify its structure. You would then take any file created with the"
? "COPY STRUCTURE EXTENDED command, zap it, and:"
?
? " . appe from "+targetsdf+" sdf"
?
? "Then use the series of commands above to load the new structure with"
? "the data in the file with the former structure."
wait
clear
else
clear
oldsource=stuff(source,at(".",source)+1,3,"OLD")
oldsource=upper(oldsource)
if file('&oldsource')
erase &oldsource
endif
rename &source. to &oldsource.
@ 10,15 say "Renaming "+source+" to "+oldsource+", creating new"
@ 11,15 say "file "+source+" from "+target+" structure, appending"
@ 12,15 say "data values from "+oldsource+" to new "+source+"."
create &source from &target
use &source
appe from &oldsource
clear
?
? "The original source file is now saved as "+oldsource+"."
?
? "The newly structured file is saved as "+source+", with data values"
? "appended from "+oldsource+"."
?
? "The file "+target+" holds the new structure."
?
? "The file "+targetsdf+" holds the new structure as an undelimited text file."
?
?
?
?
wait
endif
clear
@ 10,15 say "Quit (Y/N)?" get quitter
read
r=readkey()
if r=12 .or. r=268
close data
return
endif
enddo
close data
clear
return