home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Run Magazine ReRun: Productivity Pak 1
/
rerun-productivity-pak-i.d64
/
datafile
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-09-20
|
9KB
|
275 lines
10 rem datafile 3.3 (c)1983 by mike konshak
12 poke53280,13:poke53281,11:print"[158]":gosub16:ifx=0thengoto66
14 goto68
16 d$=chr$(0):mr$=d$:dr$=d$:s=0:b1$=d$:pw=0:cw=0:b$=chr$(32)
18 nc=0:nl=0:pg=0:f1=0:f2=0:f3=0:l$=d$:rl=0:sb$=d$:cr$=chr$(13):hn$=d$:id$=d$
20 a$=d$:c$=d$:t%=0:i$=d$:ck=0:i=0:j=0:k=0:l=0:m=0:n=0:rw=5:sf=0:z=0:e$="eof"
22 en=0:em$=d$:et=0:es=0:a1$=d$:a2$=d$:a3$=d$:s1$=d$:fl=0
23 mem=30000:return
24 dim f$(f+1),t%(f+1),l%(f+1):return
26 dim rec$(r+1,f+1),ml$(9,4),pc(10),tt$(5),hc$(9),k%(r+1):return
28 rem--get
30 geta$:ifa$=""then30
32 return
34 rem--create
36 ifck<>0thengosub394
38 print"[147] initialize datafile "
40 clr:gosub16:input"how many fields in each record? 0 [157][157][157][157]";f:iff=0then68
42 gosub24:fori=1tof
44 print"field #";i:print"title ? > "
46 print"length? 0 "
47 print"";tab(6);:inputf$(i):iff$(i)=""thenf$(i)=">"
48 printtab(6);:inputl%(i):ifl%(i)=0then68
49 nexti
50 rem--compute # records
52 forj=0tof:rl=rl+l%(j):nextj:rl=rl+3*(f+1)+5:r=int((mem-12*(f+1)-2100)/rl)
54 print" your selections will allow approx"
56 printr;"records. a[146]ccept or r[146]eject?"
58 gosub30:ifa$="r"then38
59 ifa$="a"thengosub26:ck=1
60 fori=1tof:iflen(f$(i))>s1thens1=len(f$(i))
62 nexti:goto68
64 rem--menu
66 print"[147] datafile 3.3 (c)1983 by mike konshak ":goto70
68 print"[147] datafile menu "
70 print" c[146]reate new file q[146]uit program
72 [153]" awaitdd record to current file"
74 [153]" mwaitodify record in current file"
76 [153]" dwaitelete record in current file"
78 [153]" vwaitiew file on screen
80 print" s[146]ort records by field
82 [153]" pwaitrint records by selection
84 print" r[146]ead old file from disk"
86 print" w[146]rite new file to disk
88 [153]" @wait disk drive commands
90 print" press the appropriate key "
92 print" there are";x;"records in memory"
94 ifr>0thenprint" space for";r-x;"more records[145]"
96 gosub30:ifa$="a"thengosub350:iffl=0then124
98 ifa$="m"thengosub354:iffl=0then244
100 ifa$="d"thengosub354:iffl=0then272
102 ifa$="c"then36
104 ifa$="r"then170
106 ifa$="p"thengosub354:iffl=0then358
108 ifa$="v"thengosub354:iffl=0then192
110 ifa$="w"thengosub350:iffl=0then144
112 ifa$="s"thengosub354:iffl=0then304
114 ifa$="q"then342
116 ifa$="@"then462
118 iffl<>0thenfl=0:goto68
120 goto96
122 rem--add records
124 fori=x+1tor:print"[147] press the return[146] key after each entry"
126 print" press return[146] without any entry to stop"
128 print" record number ";i;""
130 forn=1tof
132 printf$(n)spc(s1-len(f$(n)))" >[157][157][157]";:inputrec$(i,n)
133 ifrec$(i,n)=""thenrec$(i,n)=">"
134 iflen(rec$(i,n))>l%(n)thengosub140:goto132
135 ifrec$(i,n)="="thenrec$(i,n)=rec$(i-1,n)
136 ifrec$(i,1)=">"then x=i-1:ck=1:goto68
138 nextn:k%(i)=i:nexti:x=r:ck=1:goto68
140 print" [150]cannot exceed"+str$(l%(n))+" characters[146][158]":return
142 rem--save
144 print"[147]enter name of current file to be saved"
146 print"(12 characters max). any existing file"
148 print"with the same name will be scratched."
150 print" ";nf$:input"[145]";nf$:ifnf$=""then68
152 open15,8,15:print#15,"s0:df] "+left$(nf$,8)+"!old":gosub414:ifet=8then68
154 print#15,"r0:df] "+left$(nf$,8)+"!old=df] "+nf$:gosub414:ifet=8then68
156 open5,8,5,"0:df] "+nf$+",s,w":gosub414:ifet=8then68
158 print#5,r;cr$;f;cr$;x:forn=1tof:print#5,f$(n);cr$;l%(n):nextn
159 gosub414:ifet=8then68
160 fori=1tox:print" saving record #";i;"[145][145]"
162 forn=1tof:print#5,rec$(k%(i),n):nextn:nexti:print:gosub414:ifet=8then68
164 fori=1tox:print" saving pointers";i;"[145][145]":print#5,i:nexti
165 print#5,e$:gosub414:ifet=8then68
166 close5:close15:ck=0:goto68
168 rem--load
170 ifck<>0thengosub394
172 clr:gosub16:print"[147] enter name of file to be loaded":inputnf$
173 ifnf$=""then68
174 open15,8,15:open5,8,5,"0:df] "+nf$+",s,r":gosub414:ifet=8then68
175 ifen=62thengosub416:goto68
176 input#5,r,f,x:gosub414:ifet=8then68
177 gosub24:gosub26:forn=1tof:input#5,f$(n),l%(n):nextn:gosub414:ifet=8then68
178 fori=1tox:print" reading record #";i;"[145][145]"
180 forn=1tof:input#5,rec$(i,n):nextn:nexti:print:gosub414:ifet=8then68
182 fori=1tox:print" reading pointers";i;"[145][145]":input#5,k%(i):nexti
184 s=st:ifs<>0then188
186 input#5,e$:gosub414:ifet=8then68
188 close5:close15:goto60
190 rem--view
192 i=1
194 ifi=0then68
196 ifi>xthen68
198 print"[147] record number:"+str$(i)+" file:"+nf$+""
200 forn=1tof:printf$(n)spc(s1-len(f$(n)))" "rec$(k%(i),n):nextn
202 print" n[146]ext, l[146]ast, j[146]ump, f[146]ind, e[146]xit to menu"
204 gosub30:ifa$="n"theni=i+1:goto194
206 ifa$="l"theni=i-1:goto194
208 ifa$="j"then216
210 ifa$="f"then218
212 ifa$="e"then68
214 goto204
216 input" jump to record number";i:goto194
218 print"[147] find records with common items "
220 forn=1tof:print" ";n;"[146] ";f$(n):nextn
222 input" which field is to be searched? 0 [157][157][157][157]";sf:ifsf=0then68
224 ifsf<1orsf>fthenprint"[145][145][145]":goto222
226 print" enter common item[146] ":print" (the entire string is not required)"
228 print"";f$(sf);"[146] ";:inputt$:ift$=d$then68
230 fori=1tox:print" searching record";i;"[145][145]"
232 ift$=left$(rec$(k%(i),sf),len(t$))then236
234 goto240
236 print"[147] record #";i;""
237 forn=1tof:printf$(n)spc(s1-len(f$(n)))" "rec$(k%(i),n):nextn
238 print" n[146]ext record":gosub30
240 nexti:goto68
242 rem--modify
244 print"[147] modify which record? enter #[146] or a[146]ll":inputmr$:ifmr$=d$then68
246 ifmr$="a"thenmr$=d$:goto254
248 i=val(mr$):mr$=d$
250 ifi>xthengosub348:goto244
252 gosub256:goto68
254 fori=1tox:gosub256:print" n[146]ext or e[146]xit":gosub30:ifa$="e"then68
255 nexti:goto68
256 print"[147] to modify record #";i;", make changes"
258 print" as each field is displayed, then return[146]"
260 forn=1tof:printf$(n)":":print" ";rec$(k%(i),n)
261 iflen(rec$(k%(i),n))>36thenprint"[145]";
262 print"[145] ";:inputrec$(k%(i),n)
264 iflen(rec$(k%(i),n))>l%(n)thengosub140:goto260
265 ifrec$(k%(i),n)="="thenrec$(k%(i),n)=rec$(k%(i-1),n)
266 ifrec$(k%(i),n)=""thenrec$(k%(i),n)=">"
268 nextn:ck=1:return
270 rem--delete
272 print"[147] delete which record? enter #[146] or a[146]ll"
274 inputdr$:ifdr$=d$then68
276 ifdr$="a"thendr$=d$:goto282
278 i=val(dr$):dr$=d$:ifi>xthengosub348:goto274
280 gosub284:goto68
282 fori=1tox:gosub284:print" n[146]ext or e[146]xit":gosub30:ifa$="e"then68
283 nexti:goto68
284 print"[147] to delete record number";i;", press"
286 print" shift[146] d[146], press space bar[146] to advance"
288 forn=1tof:printf$(n)spc(s1-len(f$(n)))" "rec$(k%(i),n):nextn
290 gosub30:ifa$="[196]"then294:rem shifted d
292 ck=1:return
294 print"deleting record";i:print"records may now be out of order"
296 forn=1tof:rec$(k%(i),n)=rec$(x,n):rec$(x,n)="":nextn
298 forj=1tox:ifk%(j)=xthenk%(j)=k%(x):k%(x)=0:x=x-1:goto292
300 nextj
302 rem--sort
304 print"[147] sort records in order "
306 for n=1tof:print" ";n;"[146] ";f$(n):nextn
308 input"which field is to be sorted? 0 [157][157][157][157]";sf:ifsf=0then68
310 ifsf>f thenprint"[145][145][145]":goto308
311 input"a[146]scending or d[146]escending? a [157][157][157][157]";a$
312 print" please wait[146]":m=x
314 m=int(m/2):ifm=0thenck=1:goto68
316 j=1:k=x-m
318 i=j
320 l=i+m
322 print" sorting [157][157][157][157][157]";i;"[145]":ifa$<>"a"then325
323 if rec$(k%(i),sf)<=rec$(k%(l),sf) then328
324 goto326
325 if rec$(k%(i),sf)>=rec$(k%(l),sf) then328
326 t%(n)=k%(i):k%(i)=k%(l):k%(l)=t%(n):i=i-m:ifi>0then320
328 j=j+1:ifj>kthen314
330 goto318
332 rem--quit
334 print"[147] [150]you have not saved your changes![158]"
336 print" do you really want to quit? y[146] or n[146]
338 [141]30:[139]a$[178]"y" [167]344
340 [137]68
342 [139]ck[179][177]0[167]334
344 [153]"loaddatafile terminated":[128]
346 [143]--error check
348 [153]" defno such record existssys":[142]
350 [139]r[177]0[167][142]
352 [153]" def no records or files in memory syswait "
353 [129]i[178]1[164]500:[130]i:fl[178]1:[142]
354 [139]x