home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nibble Magazine
/
nib31a.dsk
/
JUNE.1987
/
RECORD.KEEPER.bas
< prev
next >
Wrap
BASIC Source File
|
2023-02-26
|
7KB
|
158 lines
10 REM **********************
20 REM * RECORD.KEEPER *
30 REM * A SPARSE FILE DEMO *
40 REM * BY SANDY MOSSBERG *
50 REM * COPYRIGHT (C) 1987 *
60 REM * BY MICROSPARC, INC *
70 REM * CONCORD, MA 01742 *
80 REM **********************
90 REM
100 REM ======================
110 REM INITIALIZE VARIABLES
120 REM ======================
130 LOMEM: PEEK(105) + PEEK(106) *256 +256: REM Increase LOMEM by 256 bytes before variables are defined
140 BUF = PEEK(105) + PEEK(106) *256 -256: REM Use liberated space as buffer
150 D$ = CHR$(4):B$ = CHR$(7)
160 F$ = "RK.DATA":L$ = ",L256":L = 255
170 BIVERS = 49149:COL80 = 49183
180 IF NOT PEEK(BIVERS) THEN PRINT B$: PRINT "BASIC.SYSTEM VERSION 1.0 NOT ACCEPTABLE": END : REM Abort if BI v1.0 installed
190 PRINT D$"PREFIX": INPUT PFX$: REM Get prefix
200 PN$ = PFX$ +F$: REM Set full pathname of data file
210 REM ==================
220 REM VERIFY DATA FILE
230 REM ==================
240 ONERR GOTO 1510: REM Enable ONERR flag
250 PRINT D$"BLOAD"PN$",TTXT,A"BUF",L256": REM Check status of RK.DATA file
260 FLAG = 1: REM If above command not trapped, file may be accessed
270 POKE 216,0: REM Disable ONERR flag
280 REM ==========
290 REM SET DATE
300 REM ==========
310 HOME
320 INPUT "Enter Date (DA-MON-YR): ";DA$
330 IF DA$ = "" THEN DA$ = "NO DATE": GOTO 400
340 DL = LEN(DA$)
350 IF DL <7 OR DL >9 THEN 310
360 IF MID$ (DA$,DL -2,1) < >"-" OR MID$ (DA$,DL -6,1) < >"-" THEN 310
370 REM ======
380 REM MENU
390 REM ======
400 HOME
410 PRINT "-------------"
420 PRINT "RECORD KEEPER"
430 PRINT "-------------"
440 PRINT " 1. Enter New Record"
450 PRINT " 2. View Record"
460 PRINT " 3. View Record Usage"
470 PRINT " 4. Delete Record"
480 PRINT " 5. Catalog Disk"
490 PRINT " 6. Quit"
500 PRINT : PRINT "Selection: ";
510 GET A$:A = VAL(A$)
520 IF A <1 OR A >6 THEN 510
530 PRINT A
540 ON A GOTO 590,790,940,1110,1280
550 END
560 REM ==================
570 REM ENTER NEW RECORD
580 REM ==================
590 IF NOT FLAG THEN GOSUB 1430: GOTO 610: REM Filter out empty file
600 PRINT D$"BLOAD"PN$",TTXT,A"BUF",L256": REM Load record map into buffer
610 GOSUB 1350: REM Get record number
620 IF NOT PEEK(BUF +R) THEN 650: REM If record not filled, proceed
630 PRINT B$: PRINT "THIS RECORD ALREADY FILLED"
640 GOSUB 1410: GOTO 400
650 PRINT D$"OPEN"PN$;L$
660 PRINT D$"WRITE"PN$",R"R
670 PRINT "RECORD "R: REM Save record number data
680 PRINT DA$: REM Save date data
690 PRINT D$"CLOSE"
700 FLAG = 1: REM Enable file access flag
710 RF = PEEK(BUF) +1
720 POKE BUF,RF: REM Increment count of filled records
730 POKE BUF +R,1: REM Mark record filled in buffer image of record map
740 PRINT D$"BSAVE"PN$",TTXT,A"BUF",L256"",B0": REM Save record map back to disk
750 GOSUB 1390: GOTO 400
760 REM =============
770 REM VIEW RECORD
780 REM =============
790 IF NOT FLAG THEN PRINT B$: PRINT "NO RECORDS ENTERED": GOSUB 1410: GOTO 400: REM Check file access
800 PRINT D$"BLOAD"PN$",TTXT,A"BUF",L256": REM Load record map into buffer
810 GOSUB 1350: REM Get record number
820 IF PEEK(BUF +R) THEN 850: REM If record filled, proceed
830 PRINT B$: PRINT "THIS RECORD EMPTY"
840 GOSUB 1410: GOTO 400
850 PRINT D$"OPEN"PN$;L$
860 PRINT D$"READ"PN$",R"R
870 INPUT A$: INPUT A1$
880 PRINT D$"CLOSE"
890 PRINT : PRINT " "A$: PRINT " "A1$
900 GOSUB 1410: GOTO 400
910 REM ===================
920 REM VIEW RECORD USAGE
930 REM ===================
940 IF NOT FLAG THEN 790: REM Check file access
950 PRINT D$"BLOAD"PN$",TTXT,A"BUF",L256": REM Load record map into buffer
960 PRINT : PRINT "Records Containing Data:": PRINT
970 CW = 78: IF PEEK(COL80) <128 THEN CW = 38: REM Set column width for display
980 J = 3: REM Start at column 3
990 FOR I = 1 TO L: REM Search entire record map
1000 IF NOT PEEK(I +BUF) THEN 1050: REM Skip empty record
1010 A$ = STR$(I)
1020 HTAB (J - LEN(A$) +1): PRINT I;: REM Format and print filled record number
1030 J = J +5: REM Tab to next display column
1040 IF J >CW THEN J = 3: PRINT : REM If end of line, set next line
1050 NEXT I
1060 RF = PEEK(BUF): REM Get number of used records
1070 PRINT : GOSUB 1390: GOTO 400
1080 REM ===============
1090 REM DELETE RECORD
1100 REM ===============
1110 IF NOT FLAG THEN 790: REM Check file access
1120 PRINT D$"BLOAD"PN$",TTXT,A"BUF",L256": REM Load record map into buffer
1130 GOSUB 1350: REM Get record number
1140 IF PEEK(BUF +R) THEN 1170: REM If record filled, proceed
1150 PRINT B$: PRINT "THIS RECORD EMPTY"
1160 GOSUB 1410: GOTO 400
1170 POKE BUF +R,0: REM Mark record used in buffer image of record map
1180 RF = PEEK(BUF) -1
1190 POKE BUF,RF: REM Decrement count of filled records
1200 PRINT D$"BSAVE"PN$",TTXT,A"BUF",L256"",B0": REM Save record map back to disk
1210 GOSUB 1430: REM Convert buffer to empty record
1220 B = (L +1) *R: REM Set absolute record offset
1230 PRINT D$"BSAVE"PN$",TTXT,A"BUF",L256"",B"B: REM Save empty record back to disk
1240 GOSUB 1390: GOTO 400
1250 REM ==============
1260 REM CATALOG DISK
1270 REM ==============
1280 HOME
1290 IF PEEK(COL80) <128 THEN PRINT D$"CAT"PFX$: GOTO 1310
1300 PRINT D$"CATALOG"PFX$
1310 GOSUB 1410: GOTO 400
1320 REM =============
1330 REM SUBROUTINES
1340 REM =============
1350 VTAB 14: CALL -958: INPUT "ENTER RECORD NUMBER: ";R$:R = VAL(R$): REM Enter record number
1360 IF R$ = "" THEN POP : GOTO 400: REM If RETURN pressed, go to menu
1370 IF R < > INT(R) OR R <1 OR R >L THEN 1350
1380 RETURN
1390 PRINT : PRINT " RECORDS USED : "RF: REM Print number of filled and empty records
1400 PRINT " RECORDS EMPTY: "L -RF
1410 PRINT : PRINT "Press Any Key ";: GET A$: REM Pause
1420 RETURN
1430 FOR I = BUF TO BUF +255: REM Fill buffer with zeroes
1440 POKE I,0: NEXT I
1450 RETURN
1460 PRINT B$: PRINT "NO RECORDS ENTERED": GOSUB 1300
1470 RETURN
1480 REM ===============
1490 REM ERROR HANDLER
1500 REM ===============
1510 POKE 216,0: REM Disable ONERR flag
1520 ERR = PEEK(222): REM Get error code
1530 IF ERR <5 AND ERR >7 THEN RESUME : REM Report fatal error and abort program
1540 CALL -3288: REM Clean up stack
1550 IF ERR = 5 THEN 310: REM END OF DATA error means empty file exists
1560 PRINT D$"OPEN"PN$;L$: REM PATH NOT FOUND error means RK.DATA must be created
1570 PRINT D$"CLOSE"
1580 GOTO 310