REM *** MBASEFM 3.0 ***  MAG/base FILE MANANGEMENT FUNCTIONS 
REM
REM CB80 VERSION - REAL RECORD NUMBERS ARE ONLY DIFFERENCE
REM			(ALSO SEE FN.SKFDF$)
REM
REM WRITTEN: 11/29/79  UPDATED: 05/02/82 FROM 05/17/81 VERSION
REM
REM PROPRIETARY SOFTWARE OF:
REM  MICRO APPLICATIONS GROUP
REM  20201 SHERMAN WAY, SUITE 205
REM  CANOGA PARK, CA 91306
REM
REM  (C) COPYRIGHT MAG 1979 ALL RIGHTS RESERVED
REM
%NOLIST
REM
REM	OPEN FILE DEFINITION FILE
REM
	DEF FN.OOFDF$
	OPEN SYSDRIVE$+":MBASEFDF.I01" RECL 256 AS 18	
	OPEN SYSDRIVE$+":MBASEFDF.DAT" RECL 200 AS 19
	FX.FDFOPEN$=""
	RETURN
	FEND

REM
REM	MAGSAM OPEN FUNCTION - FILE DEFINITION FILE
REM
	DEF FN.FDFOPEN$
	MAGSAM(1)=18:MAGSAM(2)=19:MAGSAM(3)=20:MAGSAM(4)=4
	MAGSAM$(1)="OO":MAGSAM$(3)="":MAGSAM$(6)="B"
	FI.DUM$=FN.MAGSAM$
	FX.FDFOPEN$="OO"
	RETURN
	FEND

REM
REM	CLOSE FILE DEFINITION FILE
REM
	DEF FN.CLFDF$
	CLOSE 18, 19
	FX.FDFOPEN$=""
	RETURN
	FEND

REM
REM	READ FILE DEFINITION HEADER
REM
	DEF FN.RDFHR$
	READ # 19, 1; \ 
%INCLUDE MBASEFHR
	RETURN
	FEND

REM
REM	READ FILE DEFINITION RECORD
REM
	DEF FN.RDFLR$(FP.RECNO%)
	READ # 19, FP.RECNO%; \ 
%INCLUDE MBASEFLR
	RETURN
	FEND

REM
REM	READ KEY (SK) - FILE DEFINITION RECORD
REM
	DEF FN.SKFDF$(FP.FILNO%,FP.MODE$)
	IF FX.FDFOPEN$<>"OO" THEN FI.DUM$=FN.FDFOPEN$
	MAGSAM(1)=18:MAGSAM(2)=19:MAGSAM(3)=20:MAGSAM(4)=4
	MAGSAM$(3)="":MAGSAM$(6)="B": REM NON-DUP, BUFFERED
	IF FP.MODE$="N" THEN \
	   MAGSAM$(1)="SN" \
		ELSE \
	   MAGSAM$(1)="SK": \
	   MAGSAM$(2)=RIGHT$("0000"+STR$(FP.FILNO%),4)
	FI.DUM$=FN.MAGSAM$: REM GET FILE DEF REC # FROM MAGSAM INDEX
	IF MAGSAM(8)<>0 THEN \
	   FN.SKFDF$=STR$(MAGSAM(8)): \	
	   RETURN
	FN.SKFDF$=""
	FI.RECNO%=MAGSAM(9): REM (CB80)
	FI.DUM$=FN.RDFLR$(FI.RECNO%): REM READ FILE DEF REC (CB80)
	RETURN
	FEND

REM
REM	READ FIELD DEFINITION RECORD
REM
	DEF FN.RDFDR$(FP.RECNO%)
	READ # 19, FP.RECNO%; \
%INCLUDE MBASEFDR
	RETURN
	FEND

REM
REM	READ KEY DEFINITION RECORD
REM
	DEF FN.RDKDR$(FP.RECNO%)
	READ # 19, FP.RECNO%; \
%INCLUDE MBASEKDR
	RETURN
	FEND

REM
REM	INITIALIZE FILE DEFINITION HEADER
REM
	DEF FN.INITFHR$	
	FHR.RTYP$="FHR"	
	FHR.FILS%=0	
	FHR.RECS%=1
	RETURN
	FEND

REM	
REM	INITIALIZE FILE DEFINITION RECORD
REM
	DEF FN.INITFLR$
	FLR.RTYP$="FLR"	
	FLR.NO%=0
	FLR.ID$=""
	FLR.DESC$=""
	FLR.DRIVE$=""
	FLR.FLDS%=0
	FLR.KEYS%=0
	FLR.LNKS%=0
	FLR.RECL%=0
	FLR.PRECL%=0
	FLR.INDEX%=0
	FLR.INCR%=0
	FLR.MODE$=""
	RETURN
	FEND

REM
REM	INITIALIZE FIELD DEFINITION RECORD
REM
	DEF FN.INITFDR$
	FDR.RTYP$="FDR"
	FDR.NO%=0
	FDR.ID$=""
	FDR.DESC$=""
	FDR.TYPE$=""
	FDR.MINL%=0
	FDR.MAXL%=0
	FDR.DEC%=0
	FDR.MINV=0.
	FDR.MAXV=0.
	FDR.KEY%=0
	FDR.LINK%=0
	RETURN
	FEND


REM
REM	PUT FILE DEFINITION RECORD
REM
	DEF FN.PTFLR$(FP.RECNO%)
	PRINT # 19, FP.RECNO%; \
%INCLUDE MBASEFLR
	RETURN
	FEND


REM
REM	INITIALIZE KEY DEFINITION RECORD
REM
	DEF FN.INITKDR$
	KDR.RTYP$="KDR"	
	KDR.NO%=0
	KDR.DESC$=""
	KDR.TYPE$=""
	IF FI.KDRFLG$="" THEN GOTO .40100
	   FOR FI.I%=1 TO 10
		KDR.FLD%(FI.I%)=0
		KDR.LEN%(FI.I%)=0
		KDR.FTP$(FI.I%)=""
		IF FI.DESC%>=FI.I% THEN FLD.DESC$(FI.I%)=""
	   NEXT FI.I%
.40100	FI.KDRFLG$="Y"
	DIM KDR.FLD%(10)
	DIM KDR.LEN%(10)
	DIM KDR.FTP$(10)
	DIM FLD.DESC$(10)
	FI.DESC%=10
	RETURN
	FEND

REM
REM	DIMENSION FIELD CHARACTERISTICS
REM
	DEF FN.DIMFLD$(FP.FLDS%)
	IF FI.FLDS%=0 THEN GOTO .40200
	   FOR FI.I%=1 TO FI.FLDS%
		FLD.NO%(FI.I%)=0
		FLD.ID$(FI.I%)=""
		FLD.DESC$(FI.I%)=""
		FLD.TYPE$(FI.I%)=""
		FLD.MINL%(FI.I%)=0
		FLD.MAXL%(FI.I%)=0
		FLD.DEC%(FI.I%)=0
		FLD.MINV(FI.I%)=0.
		FLD.MAXV(FI.I%)=0.
		FLD.KEY%(FI.I%)=0
		FLD.LINK%(FI.I%)=0
		FLD.VAL$(FI.I%)=""
	   NEXT FI.I%
	IF FI.DESC%<=FI.FLDS% THEN GOTO .40200
	   FOR FI.I%=FI.FLDS%+1 TO FI.DESC%
		FLD.DESC$(FI.I%)=""
	   NEXT FI.I%
.40200	FI.FLDS%=FP.FLDS%
	FI.DESC%=FP.FLDS%
	DIM FLD.NO%(FP.FLDS%),FLD.ID$(FP.FLDS%),FLD.DESC$(FP.FLDS%)
	DIM FLD.TYPE$(FP.FLDS%),FLD.MINL%(FP.FLDS%),FLD.MAXL%(FP.FLDS%)
	DIM FLD.DEC%(FP.FLDS%),FLD.MINV(FP.FLDS%),FLD.MAXV(FP.FLDS%)
	DIM FLD.KEY%(FP.FLDS%),FLD.LINK%(FP.FLDS%)
	DIM FLD.VAL$(FP.FLDS%)
	RETURN
	FEND

%LIST
