1 REMark replace_bas (c) Timo Salmi
2 REMark Thu 1992 Oct 22 07:00:43
3 REMark version 1.1
4 :
100 CLEAR:kokoaika=DATE:mp=37:bon=1
110 DIM ohj$(7),tpvm$(8),ots$(mp)
120 ohj$="REPLACE":tpvm$="07.08.86"
130 ots$="Change strings in ASCII-file"
150 p_isotsake(ohj$),(tpvm$),(ots$)
160 p_ikkunat
180 REPeat runko
200 pmax%=20
210 DIM f$(mp)
220 DIM f1$(mp)
230 DIM f2$(mp)
240 DIM a$(pmax%)
250 DIM b$(pmax%)
260 DIM m$(1)
270 DIM apu$(pmax%)
290 CLS
310 rv%=1:f1$=f_mista$
320 f2$=f1$&"_tmp"
350 rv%=rv%+2:jemma%=rv%
360 REPeat kysy
370 rv%=jemma%:a$=f_mika$
380 rv%=rv%+1:b$=f_milla$
390 IF b$<>"" THEN EXIT kysy
400 END REPeat kysy
420 rv%=rv%+1:ero%=f_erota
440 rv%=rv%+2:IF NOT f_vahvistus THEN GO TO 360
460 OPEN_IN#5,f1$
470 u%=6
480 DELETE f2$:OPEN_NEW#u%,f2$
500 PAPER 2:INK 7
510 rv%=rv%+2
520 AT rv%,0:PRINT"REPLACED:"
530 STRIP 7:INK 0
540 pit%=LEN(a$)
550 j%=1:sama%=0:lask%=0:tab%=9
560 AT rv%,tab%:PRINT lask%
580 REPeat lue
590 IF EOF(#5) THEN EXIT lue
600 m$=INKEY$(#5,-1)
610 IF ero% THEN 
620 IF m$<>a$(1):PRINT#u%,m$;:NEXT lue:END IF 
630 ELSE 
640 IF NOT m$==a$(1):PRINT#u%,m$;:NEXT lue:END IF 
650 END IF 
660 apu$=m$:sama%=1
670 IF j%=pit% THEN 
680 PRINT#u%,b$;
690 lask%=lask%+1:AT rv%,tab%:PRINT lask%
700 j%=1:sama%=0:NEXT lue
710 ELSE 
720 IF EOF(#5) THEN EXIT lue
730 m$=INKEY$(#5,-1):apu$=apu$&m$
740 IF (ero% AND m$<>a$(j%+1)) OR (NOT ero% AND NOT          m$==a$(j%+1)) THEN 
750 PRINT#u%,apu$(1 TO j%);
760 j%=1:sama%=0:GO TO 610
770 ELSE 
780 j%=j%+1:GO TO 670
790 END IF 
800 END IF 
810 END REPeat lue
830 IF sama% THEN PRINT#u%,apu$(1 TO j%);
850 CLOSE#5:CLOSE#u%
870 PAPER 2:INK 7:AT rv%+2,0:PRINT"READY, CREATED"!f2$
880 IF NOT f_vielako THEN 
890 CLS#0:AT rv%+4,0:p_valmis(1):STOP
900 END IF 
920 END REPeat runko
2000 DEFine FuNction f_mista$
2010 LOCal f$(mp),kysy
2020 REPeat kysy
2030 AT rv%,0:PAPER 2:INK 7:CLS 3
2040 PRINT"SOURCE FILE?";
2050 AT rv%,13:clb=KEYROW(0):INPUT f$:CLS 2
2060 IF NOT f_nimtark((f$)) THEN NEXT kysy
2070 IF f_onkof((f$)) THEN RETurn f$
2080 p_beep1:STRIP 6:INK 1:PRINT f$!;
2090 INK 2:PRINT"FILE NOT FOUND"
2100 END REPeat kysy
2110 END DEFine f_mista$
3000 DEFine FuNction f_mika$
3010 LOCal ml$(pmax%+1),kysy
3020 REPeat kysy
3030 AT rv%,0:PAPER 2:INK 7:CLS 3
3040 PRINT"REPLACE STRING?";
3050 AT rv%,16:clb=KEYROW(0):INPUT ml$:CLS 2
3060 IF ml$="" THEN 
3070 p_beep1:STRIP 6:INK 2:PRINT"NO STRING"
3080 NEXT kysy
3090 END IF 
3100 IF LEN(ml$)>pmax% THEN 
3110 p_beep1:STRIP 6:INK 2
3120 PRINT"MAXIMUM LENGTH"!pmax%!"BYTES"
3130 NEXT kysy
3140 END IF 
3150 RETurn ml$
3160 END REPeat kysy
3170 END DEFine f_mika$
3190 DEFine FuNction f_milla$
3200 LOCal ml$(pmax%)
3210 AT rv%,0:PAPER 2:INK 7:CLS 3
3220 PRINT"WITH    STRING?";
3230 AT rv%,16:clb=KEYROW(0):INPUT ml$:CLS 2
3240 IF LEN(ml$)<>LEN(a$) THEN 
3250 p_beep1:STRIP 6:INK 2
3260 PRINT"LENGTHS DO NOT AGREE"
3270 RETurn ""
3280 END IF 
3290 RETurn ml$
3300 END DEFine f_milla$
3320 DEFine FuNction f_erota
3330 LOCal vl$(2),kysy
3340 REPeat kysy
3350 AT rv%,0:PAPER 2:INK 7:CLS 3
3360 PRINT"IGNORE UPPER/LOWER CASE (Y/N)? Y"
3370 AT rv%,31:clb=KEYROW(0):INPUT vl$:CLS 2
3380 IF vl$="" THEN vl$="y"
3390 IF vl$=="n" THEN RETurn 1
3400 IF vl$=="y" THEN RETurn 0
3410 p_beep1
3420 END REPeat kysy
3430 END DEFine f_erota
3450 DEFine FuNction f_vahvistus
3460 LOCal vl$(2),kysy
3470 REPeat kysy
3480 AT rv%,0:PAPER 2:INK 7:CLS 3
3490 PRINT"SATISFIED? (Y/N)?"
3500 AT rv%,18:clb=KEYROW(0):INPUT vl$:CLS 2
3510 IF vl$=="n" THEN RETurn 0
3520 IF vl$=="y" THEN RETurn 1
3530 p_beep1
3540 END REPeat kysy
3550 END DEFine f_vahvistus
17000 DEFine PROCedure p_ikkunat
17010 LOCal levl%,al%
17020 levl%=448
17030 al%=INT((512-levl%)/2)
17040 WINDOW#1,levl%,180,al%, 48
17050 WINDOW#0,levl%, 28,al%,228
17060 PAPER#1,2:CSIZE#1,2,0:CLS#1
17070 PAPER#0,0:CSIZE#0,2,0:CLS#0
17080 END DEFine p_ikkunat
19000 DEFine PROCedure p_beep1
19010 IF bon:BEEP 4000,70:END IF 
19020 END DEFine p_beep1
20000 DEFine PROCedure p_isotsake(ohj$,tpvm$,ots$)
20010 LOCal il1%,il2%,chl%,levl%,al%
20020 MODE 8:chl%=5:levl%=448
20030 WINDOW 512,256,0,0:PAPER 0:CLS
20040 OPEN#chl%,con_
20050 al%=INT((512-levl%)/2)
20060 WINDOW#chl%,levl%,32,al%,16
20070 PAPER#chl%,0:CLS#chl%
20080 BORDER#chl%,1,7:CSIZE#chl%,3,1
20090 CURSOR#chl%,5,0
20100 INK#chl%,6:PRINT#chl%,ohj$
20110 il2%=levl%-16*LEN(tpvm$)-4
20120 il1%=(il2%+16*LEN(ohj$)-155)/2
20130 INK#chl%,4:CURSOR#chl%,il1%,0
20140 PRINT#chl%,"Timo Salmi"
20150 INK#chl%,2:CURSOR#chl%,il2%,0
20160 PRINT#chl%,tpvm$:CLOSE#chl%
20170 OPEN#chl%,con_
20180 WINDOW#chl%,levl%-4,10,al%+2,37
20190 PAPER#chl%,0:CLS#chl%:CSIZE#chl%,2,0:INK#chl%,5
20200 CURSOR#chl%,5,0:PRINT#chl%,ots$:CLOSE#chl%
20210 END DEFine p_isotsake
27000 DEFine FuNction f_nimtark(f$)
27010 LOCal pl%,dl$(5),ml$(8)
27020 pl%=LEN(f$):IF pl%<5:p_mdvherja:RETurn 0:END IF 
27030 dl$=f$(1 TO 3)
27040 IF NOT(dl$=="mdv" OR dl$=="fdk" OR dl$=="flp" OR        dl$=="ram"):p_mdvherja:RETurn 0:END IF 
27050 IF f$(5)<>"_":p_mdvherja:RETurn 0:END IF 
27060 ml$="1234"
27070 IF dl$=="mdv" OR dl$=="ram" THEN ml$="12345678"
27080 IF NOT f$(4)INSTR ml$:p_mdvherja:RETurn 0:END IF 
27090 IF pl%<6 THEN 
27100 p_beep1:STRIP 6:INK 2:PRINT"MISSING FILENAME"
27110 RETurn 0
27120 END IF 
27130 RETurn 1
27140 END DEFine f_nimtark
27160 DEFine PROCedure p_mdvherja
27170 STRIP 6:INK 2:p_beep1
27180 PRINT"MISSING OR UNKNOWN DEVICENAME"
27190 RETurn 
27200 END DEFine p_mdvherja
27500 DEFine FuNction f_onkof(f$)
27510 LOCal hl$(17),al$(37),fbl$(37),etsi,fon
27520 IF LEN(f$)<5 THEN RETurn 0
27530 hl$=f$(1 TO 5)&"tilaphak_tmp"
27540 DELETE hl$:OPEN_NEW#6,hl$:DIR#6,f$(1 TO 5)
27550 CLOSE#6:OPEN_IN#5,hl$:INPUT#5,al$,al$
27560 fbl$="":IF LEN(f$)>5 THEN fbl$=f$(6 TO)
27570 REPeat etsi
27580 IF EOF(#5):fon=0:EXIT etsi:END IF 
27590 INPUT#5,al$
27600 IF fbl$==al$:fon=1:EXIT etsi:END IF 
27610 END REPeat etsi
27620 CLOSE#5:DELETE hl$:RETurn fon
27630 END DEFine f_onkof
30000 DEFine PROCedure p_valmis(ch%)
30010 LOCal tl,ml,sl
30020 PRINT#ch%,"Elapsed time";
30030 sl=DATE-kokoaika
30040 tl=INT(sl/3600):sl=sl-tl*3600
30050 ml=INT(sl/60):sl=sl-60*ml
30060 IF tl>0 THEN PRINT#ch%,!tl!"h";
30070 IF ml>0 OR tl>0 THEN PRINT#ch%,!ml!"min";
30080 PRINT#ch%,!sl!"sec"
30090 END DEFine p_valmis
30500 DEFine FuNction f_vielako
30510 LOCal key,cl,loop
30520 cl=0:PAPER#cl,0:CLS#cl
30530 PRINT#cl,"AGAIN: F3, EXIT: ESC";
30540 clb=KEYROW(0)
30550 REPeat loop
30560 key=CODE(INKEY$(-1))
30570 IF key=240:PAPER#cl,0:CLS#cl:RETurn 1:END IF 
30580 IF key=27:RETurn 0:END IF 
30590 END REPeat loop
30600 END DEFine f_vielako
31000 DEFine PROCedure reset(i)
31010 LOCal il:MODE i
31020 FOR il=1,2:OPEN#il,con_:END FOR il
31030 WINDOW 512,256,0,0:PAPER 0:CLS
31040 WINDOW#0,448,40-(i=4),32,216+(i=4)
31050 WINDOW#2,448,200,32,16:PAPER#2,1:INK#2,7
31060 WINDOW 448+8*(i=4),200+2*(i=4),32-4*(i=4),16-(i=4)
31070 PAPER 2*(i=8):BORDER (i=4),4*(i=4)
31080 FOR il=0,1,2:CSIZE#il,(i=4)+2*(i=8),0:END FOR il
31090 PAPER#0,0:INK#0,7-3*(i=0):INK 7:CLS
31100 SCALE 100,0,0:FILL 0
31110 END DEFine reset
31130 PAPER 0:BORDER 1,4
31140 FOR il=0,1,2:CSIZE#il,1,0:END FOR il
31150 END IF 
31160 PAPER#0,0:INK#0,7:INK 7:CLS
31170 SCALE 100,0,0:FILL 0
31180 END DEFine reset
31990 STOP
32000 vsave 1:STOP
32010 vsave 2:STOP
32020 vsave 3:STOP
32030 vsave 4:STOP
32040 vsave 5:STOP
32050 vsave 6:STOP
32060 DEFine PROCedure vsave(dr)
32070 LOCal avl$(42),bvl$(42),dvl$(6,5):avl$="replace_bas"
32080 bvl$=DATE$:bvl$=bvl$(1 TO 4)
32090 IF bvl$<>1992 THEN 
32100 PRINT#0,DAY$!DATE$!"Not saved, set SDATE"
32110 BEEP 4000,12:STOP:END IF 
32120  ver1%=1:ver2%=1
32130 dvl$(1)="mdv1_":dvl$(2)="mdv2_"
32140 dvl$(3)="fdk1_":dvl$(4)="fdk2_"
32150 dvl$(5)="ram1_":dvl$(6)="ram2_"
32160 bvl$=dvl$(dr)&avl$
32170 DELETE bvl$:OPEN_NEW#3,bvl$:ver%=ver2%+1
32180 PRINT#3,"1 REMark ";avl$!"(c) Timo Salmi"
32190 PRINT#3,"2 REMark ";DAY$!DATE$
32200 PRINT#3,"3 REMark version"!ver1%;".";ver%
32210 PRINT#3,"4 :"
32220 LIST#3,100 TO 32110
32230 PRINT#3,"32120  ver1%=";ver1%;":ver2%=";ver%
32240 LIST#3,32130 TO:CLOSE#3
32250 PRINT#0,"Saved"!bvl$!"version"!ver1%;".";ver%
32260 END DEFine vsave
