home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Run Magazine ReRun 1986 January & February
/
rerun-1986-01-02.d64
/
dfrestructure
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-09-20
|
5KB
|
168 lines
4600 rem datafile utility program dfrestructure (c)1985 by mike konshak
4602 poke53280,7:poke53281,0:print"[158]":goto4620
4604 rem--get
4606 geta$:ifa$=""then4606
4608 return
4610 rem--disk error
4612 input#15,en,em$,et,es:if(en<20)or(en=62)thenet=0:return
4614 print" [150]disk error[146]"en"[157], "em$","et"[157],"es"[158]":et=8
4616 print" press any key[146] to return to menu":gosub4606:close5:close15:return
4618 rem----start menu
4620 clr:print"[147] datafile restructure program "
4622 print" this program will alter the structure"
4624 print" of a sequential record file created by"
4626 print" the datafile[146] database management"
4628 print" system, written by mike konshak."
4630 print" the following options are possible:"
4632 print" * change the name of a field"
4634 print" * change the length of a field"
4636 print" * add a field "
4638 print" * delete a field "
4640 print" option 2 will increase or decrease"
4642 print" the total number of records in a file."
4644 print" option 3 will decrease the number of"
4646 print" records and some existing records may"
4648 print" be lost. option 4 will increase the"
4650 print" total number of records, eliminating"
4652 print" the data found in the chosen field."
4654 print" press c[146]ontinue, $[146] directory or q[146]uit"
4656 gosub4606:ifa$="q"thenend
4658 ifa$="$"thengosub4896:goto4620
4660 ifa$<>"c"then4656
4662 rem----open file - read structure
4664 print"[147] change datafile structure [146]"
4666 print" insert a disk containing the datafile"
4668 print" file to be restructured. press return[146]"
4670 print" without an entry to exit."
4672 input" name of datafile ";nf$:ifnf$=""then4654
4674 open15,8,15:open5,8,5,"0:df] "+nf$+",s,r":gosub4612:ifet=8then4654
4676 ifen=62thengosub4614:goto4654
4678 input#5,r,f,x:gosub4612:ifet=8then4654
4680 dim f$(f+2),l%(f+2),rec$(x+1,f+2),k%(x+1)
4682 forn=1tof:input#5,f$(n),l%(n):nextn:gosub4612:ifet=8then4654
4684 close5:close15:goto4710
4686 rem----print field info for reference
4688 print"[147] field name(length) for "+nf$+"[158]"
4690 oe=1:if(f/2)=int(f/2)thenoe=0
4692 of=int(f/2):fori=1toof+oe
4694 print" "i"[146]"f$(i)l%(i);
4696 ifoe=1then4700
4698 printtab(19)""i+of"[146]"f$(i+of)l%(i+of):goto4702
4700 ifi+of<fthenprinttab(19)""i+of+1"[146]"f$(i+of+1)l%(i+of+1)
4702 nexti:print
4704 printr"records are possible in file"
4706 printx"records are currently present":return
4708 rem----choose option
4710 gosub4688:print" change n[146]ame of field"
4712 print" l[146]ength of field"
4714 print" or a[146]dd another field"
4716 print" d[146]elete a field"
4718 print" $[146] disk directory"
4720 print" e[146]xit to beginning"
4722 print" press the appropriate key "
4724 print" only one option may be performed "
4726 k=0:gosub4606:ifa$="e"then4620
4728 ifa$="$"thengosub4896:goto4710
4730 ifa$="n"thenk=1
4732 ifa$="l"thenk=2
4734 ifa$="a"thenk=3
4736 ifa$="d"thenk=4
4738 onkgoto4742,4754,4766,4778:goto4726
4740 rem----change field name
4742 gosub4688:input" change name of field # ? 0[157][157][157]";cf:ifcf=<0then4710
4744 ifcf>fthenprint"[145]":goto4742
4746 print" enter new field name:":print" ? ";f$(cf)
4748 input"[145]";f$:iff$=f$(cf)then4710
4750 ft=f:goto4784
4752 rem----change field length
4754 gosub4688:input" change length of field # ? 0[157][157][157]";cf:ifcf=<0then4710
4756 ifcf>fthenprint"[145]":goto4754
4758 print" enter new field length:":print" ?";l%(cf)
4760 input"[145]";l%:ifl%=l%(cf)then4710
4762 l%(cf)=l%:ft=f:goto4784
4764 rem----add new field
4766 gosub4688:print" add new field #";f+1
4768 print" title of new field":print" ? >":input"[145]";f$
4770 print" length of new field":print" ? 0":input"[145]";l%
4772 ifl%=0then4710
4774 ft=f+1:cf=f+1:goto4784
4776 rem----delete existing field
4778 gosub4688:input" delete which field? 0[157][157][157]";cf:ifcf=0then4710
4780 ft=f-1
4782 rem----calculate # records
4784 mem=29293:rl=0
4786 forj=0tof:ifk=4andj=cfthen4790
4788 rl=rl+l%(j)
4790 nextj:ifk=3thenrl=rl+l%
4792 rl=rl+3*(ft+1)+5
4794 nr=int((mem-12*(ft+1)-2100)/rl)
4796 print" your selections will allow approx"
4798 printnr;"records. a[146]ccept or r[146]eject?"
4800 gosub4606:ifa$="r"then4710
4802 ifa$<>"a"then4800
4804 rem----load file
4806 open15,8,15:open5,8,5,"0:df] "+nf$+",s,r":gosub4612:ifet=8then4710
4808 ifen=62thengosub4614:goto4710
4810 input#5,r,f,x:gosub4612:ifet=8then4710
4812 forn=1tof:input#5,f$(n),l%(n):nextn:gosub4612:ifet=8then4710
4814 fori=1tox:print" reading record #";i;"[145][145]"
4816 forn=1tof:input#5,rec$(i,n):nextn:nexti:print:gosub4612:ifet=8then4710
4818 fori=1tox:print" reading pointers";i;"[145][145]":input#5,k%(i):nexti
4820 s=st:ifs<>0then4824
4822 input#5,e$:gosub4612
4824 close5:close15
4826 rem----save restructured file
4828 ifk=1thenf$(cf)=f$
4830 ifk=2thenl%(cf)=l%
4832 cr$=chr$(13):print"[147] insert the disk to receive the file."
4834 print" enter name of restructured file to be"
4836 print" saved (12 characters max). if the old"
4838 print" file name is chosen, the old file"
4840 print" will be renamed with !old."
4842 print" ";nf$:input"[145]";nf$:ifnf$=""then4710
4844 open15,8,15:print#15,"s0:df] "+left$(nf$,8)+"!old"
4846 gosub4612:ifet=8then4710
4848 print#15,"r0:df] "+left$(nf$,8)+"!old=df] "+nf$:gosub4612:ifet=8then4710
4850 open5,8,5,"0:df] "+nf$+",s,w":gosub4612:ifet=8then4710
4852 ifx>nrthenx=nr
4854 print#5,nr;cr$;ft;cr$;x
4856 forn=1tof:ifk=4andn=cfthen4860
4858 print#5,f$(n);cr$;l%(n)
4860 nextn:ifk=3thenprint#5,f$;cr$;l%
4862 gosub4612:ifet=8then4710
4864 fori=1tox:print" saving record #";i;"[145][145]"
4866 forn=1tof:ifk=4andn=cfthen4870
4868 print#5,rec$(k%(i),n)
4870 nextn:ifk=3thenprint#5,">"
4872 nexti:print:gosub4612:ifet=8then4710
4874 fori=1tox:print" saving pointers";i;"[145][145]":print#5,i:nexti
4876 print#5,"eof":gosub4612:ifet=8then4710
4878 close5:close15
4880 ifx>nrthenprint"the last"x-nr"records were deleted"
4882 rem--reread new structure
4884 open15,8,15:open5,8,5,"0:df] "+nf$+",s,r":gosub4612:ifet=8then4710
4886 ifen=62thengosub4614:goto4710
4888 input#5,r,f,x:gosub4612:ifet=8then4710
4890 forn=1tof:input#5,f$(n),l%(n):nextn:gosub4612:ifet=8then4710
4892 close5:close15:goto4710
4894 rem--directory
4896 open15,8,15:open5,8,0,"$0":print"[147]":gosub4612:ifet=8thenreturn
4898 get#5,a1$,a2$
4900 get#5,a1$,a2$
4902 get#5,a1$,a2$
4904 ifa1$<>""thena0=asc(a1$)
4906 ifa2$<>""thena0=a0+asc(a2$)*256
4908 printmid$(str$(a0),2);tab(3);
4910 get#5,a2$:ifst<>0then4928
4912 ifa2$<>chr$(34)then4910
4914 get#5,a2$:ifa2$<>chr$(34)thenprint""a2$"[146]";:goto4914
4916 get#5,a2$:ifa2$=chr$(32)then4916
4918 printtab(20);:a3$=""
4920 a3$=a3$+a2$:get#5,a2$:ifa2$<>""then4920
4922 printleft$(a3$,3)
4924 geta$:ifa$<>""thengosub4932
4926 ifst=0then4900
4928 print" blocks free";:a0=0
4930 close5:close15:printtab(25)"press any key[146]":gosub4606:return
4932 gosub4606:return