home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
MBUG
/
MBUG055.ARC
/
PHONE.BAS
< prev
next >
Wrap
BASIC Source File
|
1979-12-31
|
10KB
|
293 lines
10 REM ****************************************************
15 REM *** ***
20 REM *** INDEXED TELEPHONE FILE ***
25 REM *** ***
30 REM *** WRITTEN IN MBASIC 5.2 ***
40 REM *** BY LES BELL, 6/15/82 ***
45 REM *** ***
50 REM *** DOWNLOADED TO KAYPRO, 7/20/83 FROM MICC ***
60 REM *** PERSEVERED WITH BY ALL WHO CAME IN CONTACT ***
65 REM *** ***
70 REM *** DEBUGGED & MODIFIED BY TODD WRIGHT ***
71 REM *** (NO APPLAUSE PLEASE) ***
75 REM *** ***
80 REM *** UPLOADED BACK TO MICC 07/24/83 ***
85 REM *** ***
90 REM ****************************************************
100 :
110 REM INITIALIZATION SECTION
120 :
130 DEFINT I - N
140 DEF FNGXY$(X,Y)=CHR$(27)+"="+CHR$(Y+31)+CHR$(X+31)
150 DEF FNHT$(A$)=CHR$(27)+")"+A$+CHR$(27)+"("
160 DEF FNLN$(L)=STRING$(L,95)
170 HOME$=CHR$(11)
180 CLS$=CHR$(12)
190 DIM N$(256), K(256)
200 TL%=300: ' TIME DELAY
210 PRINT CLS$
220 INPUT "Telephone directory file";F$
230 IF F$="" THEN F$="TEST"
240 :
250 REM *** READ INDEX FILE ***
260 :
270 ON ERROR GOTO 540
280 OPEN "I",#1,F$+".IND"
290 N=1
300 IF EOF(1) THEN CLOSE 1: GOTO 330
310 INPUT#1,N$(N),K(N)
320 N = N + 1: GOTO 300
330 PRINT: PRINT: PRINT N-1;"Records in file"
340 OPEN "R",#2,F$+".TDR"
350 FIELD #2,20 AS FM$,20 AS FC$,30 AS FA1$,20 AS FA2$,4 AS FPC$,15 AS FTEL$,19 AS FCT$
360 :
370 REM *** DISPLAY MENU ***
380 :
390 PRINT CLS$
400 PRINT "1 - Add name"
410 PRINT "2 - Delete name"
420 PRINT "3 - Find name"
430 PRINT "4 - Find comment"
440 PRINT "5 - List file to Video"
450 PRINT "6 - List file to Printer"
460 PRINT "7 - Quit and return to CP/M"
470 PRINT: PRINT "Enter choice:";
480 A$ = INKEY$
490 WHILE A$<"1" OR A$ > "7"
500 A$ = INKEY$
510 WEND
520 ON ASC(A$)-48 GOTO 690,1780,1280,2350,1080,2580,600
530 :
540 IF ERR=53 THEN CLOSE: PRINT "File does not exist - creating one.": N=1: RESUME 340
550 PRINT "Error";ERR;"in line";ERL: STOP
560 :
570 REM *** EXIT TO CP/M ***
580 :
590 REM WRITE INDEX FILE
600 GOSUB 1630: GOSUB 2150: REM SORT INDICES AND PACK FILE
610 OPEN "O",#1,F$+".IND"
620 FOR I=1 TO N-1: IF K(I) = 0 THEN 640
630 WRITE#1,N$(I),K(I)
640 NEXT I
650 PRINT CLS$: CLOSE:PRINT"Going back to CP/M.... Goodbye, Have a nice day....":SYSTEM
660 :
670 REM *** ROUTINE TO ADD A NAME TO FILE ***
680 :
690 IF DELFLG = 1 THEN GOSUB 1630: GOSUB 2150
700 PRINT CLS$;"Add name to file ":FOR I=1 TO TL%: NEXT I
710 PRINT CLS$
720 PRINT FNGXY$(1,3);FNHT$("Surname : ");FNLN$(20)
730 PRINT FNHT$("First Name : ");FNLN$(20)
740 PRINT FNHT$("Street : ");FNLN$(30)
750 PRINT FNHT$("Town/City : ");FNLN$(20)
760 PRINT FNHT$("Postcode : ");FNLN$(4)
770 PRINT FNHT$("Telephone : ");FNLN$(15)
780 PRINT FNHT$("Comment : ");FNLN$(19)
790 PRINT FNGXY$(13,3);:INPUT N$
800 IF N$ = "" THEN GOTO 390
810 PRINT FNGXY$(13,3);": ";N$;SPACE$(20-LEN(N$))
820 PRINT FNGXY$(13,4);:INPUT C$
830 PRINT FNGXY$(13,4);": ";C$;SPACE$(20-LEN(C$))
840 PRINT FNGXY$(13,5);:INPUT A1$
850 PRINT FNGXY$(13,5);": ";A1$;SPACE$(30-LEN(A1$))
860 PRINT FNGXY$(13,6);:INPUT A2$
870 PRINT FNGXY$(13,6);": ";A2$;SPACE$(20-LEN(A2$))
880 PRINT FNGXY$(13,7);:INPUT PC$
890 PRINT FNGXY$(13,7);": ";PC$;SPACE$(16)
900 PRINT FNGXY$(13,8);:INPUT TEL$
910 PRINT FNGXY$(13,8);": ";TEL$;SPACE$(15-LEN(TEL$))
920 PRINT FNGXY$(13,9);:INPUT CT$
930 PRINT FNGXY$(13,9);": ";CT$;SPACE$(19-LEN(CT$))
940 REM *** WRITE RECORD TO DISK ***
950 LSET FM$ = N$
960 LSET FC$ = C$
970 LSET FA1$ = A1$
980 LSET FA2$ = A2$
990 LSET FPC$ = PC$
1000 LSET FTEL$ = TEL$
1010 LSET FCT$ = CT$
1020 PUT #2,N
1030 N$(N) = N$: K(N) = N
1040 N = N + 1
1050 GOTO 690
1060 :
1070 REM *** LIST FILE TO CON: ***
1080 FOR I = 1 TO N-1
1090 IF K(I) = 0 THEN 1250
1100 GET #2,K(I)
1110 PRINT CLS$;I
1120 PRINT FNGXY$(1,3);FNHT$("Surname : ");FM$
1130 PRINT FNHT$("First Name : ");FC$
1140 PRINT FNHT$("Street : ");FA1$
1150 PRINT FNHT$("Town/City : ");FA2$
1160 PRINT FNHT$("Postcode : ");FPC$
1170 PRINT FNHT$("Telephone : ");FTEL$
1180 PRINT FNHT$("Comment : ");FCT$
1190 PRINT FNGXY$(40,24);: PRINT "Hit space bar to hold, ESC to quit";
1200 FOR J=1 TO TL%
1210 A$=INKEY$: IF LEN(A$) = 0 THEN 1240
1220 IF A$ = " " THEN J = 1
1230 IF A$ = CHR$(27) THEN 390
1240 NEXT J
1250 NEXT I
1260 GOTO 390
1270 :
1280 REM *** ROUTINE TO FIND NAME ***
1290 :
1300 PRINT CLS$;"Search file for name"
1310 PRINT FNGXY$(1,5);:INPUT "Name to find";N$
1320 REM *** BINARY SEARCH ON N$(N) ***
1330 L = 1: U = N - 1: 'SET UPPER AND LOWER BOUNDARIES
1340 IF U < L THEN 1540
1350 I = (U + L) \ 2
1360 IF N$ < N$(I) THEN U = I - 1: GOTO 1340
1370 IF N$ > N$(I) THEN L = I + 1: GOTO 1340
1380 GET #2,K(I)
1390 PRINT FNGXY$(1,3);FNHT$("Surname : ");FM$
1400 PRINT FNHT$("First Name : ");FC$
1410 PRINT FNHT$("Street : ");FA1$
1420 PRINT FNHT$("Town/City : ");FA2$
1430 PRINT FNHT$("Postcode : ");FPC$
1440 PRINT FNHT$("Telephone : ");FTEL$
1450 PRINT FNHT$("Comment : ");FCT$
1460 PRINT FNGXY$(40,24);"Hit space to continue, ESC to quit";
1470 A$ = INKEY$
1480 WHILE A$ <> " " AND A$ <> CHR$(27)
1490 A$ = INKEY$
1500 WEND
1510 IF A$ = " " THEN I = I + 1:IF I < N THEN 1380
1520 GOTO 390
1530 :
1540 REM *** UNSUCCESSFUL ***
1550 :
1560 PRINT CLS$;"Not found";
1570 FOR I = 1 TO TL%:NEXT I
1580 GOTO 390
1590 REM *** SORT INDEX ARRAY ***
1600 :
1610 GOSUB 1630:GOSUB 2150: GOTO 390
1620 REM *** SORT SUBROUTINE ***
1630 PRINT CLS$;"Sorting index. Please wait"
1640 M = (N-1)/2
1650 L = N - M - 1
1660 FOR J = 1 TO L
1670 FOR I = J TO 1 STEP -M
1680 IF N$(I) > N$(I+1) THEN SWAP N$(I), N$(I+1): SWAP K(I), K(I+1)
1690 PRINT ".";
1700 NEXT I
1710 NEXT J
1720 M = M \ 2
1730 IF M <> 0 THEN 1650
1740 RETURN
1750 :
1760 REM *** ROUTINE TO DELETE NAME FROM FILE ***
1770 :
1780 PRINT CLS$;"Delete name from file"
1790 PRINT FNGXY$(1,5);:INPUT "Name to delete";N$
1800 IF N$=CHR$(13) THEN 390
1810 REM *** BINARY SEARCH ON N$(N) ***
1820 L = 1: U = N - 1: 'SET UPPER AND LOWER BOUNDARIES
1830 IF U < L THEN 1540
1840 I = (U + L) \ 2
1850 IF N$ < N$(I) THEN U = I - 1: GOTO 1830
1860 IF N$ > N$(I) THEN L = I + 1: GOTO 1830
1870 IF K(I)=0 THEN 1780
1880 GET #2,K(I)
1890 IF LEFT$(FM$,1) = ";" THEN K=K+1:GOTO 1290
1900 IF LEFT$(FM$,1)=" " THEN PRINT CLS$;"Not found":FOR J = 1 TO TL%:NEXT J:GOTO 390
1910 PRINT CLS$
1920 PRINT FNGXY$(1,3);FNHT$("Surname : ");FM$
1930 PRINT FNHT$("First Name : ");FC$
1940 PRINT FNHT$("Street : ");FA1$
1950 PRINT FNHT$("Town/City : ");FA2$
1960 PRINT FNHT$("Postcode : ");FPC$
1970 PRINT FNHT$("Telephone : ");FTEL$
1980 PRINT FNHT$("Comment : ");FCT$
1990 PRINT FNGXY$(40,24);"Delete (Y/N/ <S>EARCH FOR NEW NAME>)";
2000 GOSUB 2070
2010 IF A$="S" THEN 1780
2020 IF A$ <> "Y" AND A$ <> "y" THEN I = I + 1:GOTO 1870
2030 K(I) = 0: DELFLG = 1
2040 GOTO 390
2050 :
2060 REM *** SUBROUTINE TO RETURN Y/N RESPONSE IN A$ ***
2070 A$ = INKEY$
2080 WHILE A$ <> "Y" AND A$ <> "N" AND A$ <> "S"
2090 A$ = INKEY$
2100 WEND
2110 RETURN
2120 :
2130 REM *** PACK RANDOM FILE ***
2140 :
2150 PRINT CLS$;"Packing data file.";
2160 D = 0
2170 FOR S = 1 TO LOF(2)
2180 T$=SPACE$(20)
2190 GET#2,S
2200 N$ = FM$
2210 L=1: U=N-1
2220 IF U<L THEN 2300
2230 I = (U + L) \ 2
2240 LSET T$ = N$(I)
2250 IF N$ < T$ THEN U = I - 1: GOTO 2220
2260 IF N$ > T$ THEN L = I + 1: GOTO 2220
2270 IF K(I) = 0 THEN 2300
2280 D = D + 1
2290 PUT#2,D:K(I) = D:PRINT ".";
2300 NEXT S
2310 DELFLG = 0
2320 RETURN
2330 REM *** FIND COMMENT ***
2340 :
2350 PRINT CLS$; "Find comment"
2360 PRINT FNGXY$(1,5);:INPUT "Comment to search for";CT$
2370 FOR I=1 TO LOF(2)
2380 IF K(I) = 0 THEN 2550
2390 GET #2,K(I)
2400 IF LEFT$(FCT$,LEN(CT$)) <> CT$ THEN 2550
2410 PRINT CLS$;
2420 PRINT FNGXY$(1,3);FNHT$("Surname : ");FM$
2430 PRINT FNHT$("First Name : ");FC$
2440 PRINT FNHT$("Street : ");FA1$
2450 PRINT FNHT$("Town/City : ");FA2$
2460 PRINT FNHT$("Postcode : ");FPC$
2470 PRINT FNHT$("Telephone : ");FTEL$
2480 PRINT FNHT$("Comment : ");FCT$
2490 PRINT FNGXY$(40,24);: PRINT "Hit space bar to hold, ESC to quit";
2500 FOR J=1 TO TL%
2510 A$=INKEY$: IF LEN(A$) = 0 THEN 2540
2520 IF A$ = " " THEN J = 1
2530 IF A$ = CHR$(27) THEN 390
2540 NEXT J
2550 NEXT I
2560 GOTO 390
2570 :
2580 REM *** LIST FILE TO PRINTER ***
2590 :
2600 X=132
2610 PRINT CLS$;"IS PRINTER IN 132 COLUMN MODE (Y/N)";:INPUT PR$
2620 IF PR$="N" THEN PRINT"PRINTER ASSUMED 80 COLUMN MODE":X=80
2630 FOR J = 1 TO TL%:NEXT J
2640 LA=(X/2)-(LEN(F$)+6)
2650 WIDTH LPRINT X
2660 LPRINT STRING$(LA,32);"UPDATED ";F$;" LISTING"
2670 LPRINT : LPRINT
2680 FOR J = 1 TO N - 1
2690 IF K(J)=0 THEN 2800
2700 GET #2,K(J)
2710 PRINT CLS$;"Printing File ";J;" to Paper.... "
2720 SP=(20-LEN(FM$)):LPRINT FM$;STRING$(SP,32);
2730 SP=(20-LEN(FC$)):LPRINT FC$;STRING$(SP,32);
2740 SP=(30-LEN(FA1$)):LPRINT FA1$;STRING$(SP,32);
2750 SP=(20-LEN(FA2$)):LPRINT FA2$;STRING$(SP,32);
2760 SP=(6-LEN(FPC$)):LPRINT FPC$;STRING$(SP,32);
2770 SP=(16-LEN(FTEL$)):LPRINT FTEL$;STRING$(SP,32);
2780 SP=(20-LEN(FCT$)):LPRINT FCT$;STRING$(SP,32)
2790 LPRINT
2800 NEXT J
2810 GOTO 390
L$)):LPRINT FTEL$;STRING$(SP,32);
2780 SP=(20-LEN(FCT$)):LPRINT FCT$;STRING$(SP,32)
2790 LPRINT
2800 NEXT J
28