// L F I N I T
// Finds length of fonts and stashes length in FDH

// Last modified October 25, 1979 3:24 PM by Taft

get "bravo1.df"
get "altofilesys.d"
get "st.df"
get "font.df"
get "dir.df"

// incoming procedures

external
[
FindFptr
movec
move
array1
array
sbwsize
InitNmd
RealDA
ReadVec
errhlta
stcopy
stnum
stappend
errhlt
stcompare
FindCfc
ugt
]

// outgoing procedures

external
[
FddlMaxInit
]

// incoming statics

external
[
cfaSysDirEnd
//
llnmd
mpfunfd
mpCrockLrec2
vfddfirst
]

// local manifests

manifest
[
lrec2nil = 0
]

static [
llnmd
]

// - =- =- =- =- =- =- =- =- =- =
let FddlMaxInit() = valof
// - =- =- =- =- =- =- =- =- =- =

[
let fun = nil
let fa = nil
let fd = nil
let fdh = nil
let tnmd = nil
let lf = vec 1
let cfa = vec lCFA

makellnmd()
FindFptr(cfaSysDirEnd, llnmd, 0, -1)

// init FDH lengths to lrec2nil = 0

for fun = 0 to maxfun-1 do
[
fd = mpfunfd ! fun
if fd eq fdnil then loop
fdh = lv(fd>>FD.fdh)
movec(lv(fdh>>FDH.ampFaLrec2), lv(fdh>>FDH.ampFaLrec2) + 3, lrec2nil)
]

// read 1st page of each font (if cver gr 0) - word 0 is lrec2l
tnmd = rv llnmd
fun = 0
fa = 0
for fun = 0 to maxfun-1 do
[
if mpfunfd ! fun eq fdnil then loop
for fa = 0 to 3 do
[
if tnmd>>NMD.cver ne 0 then
[
makecfa2(cfa, lv(tnmd>>NMD.afptr))
ReadVec(cfa, 1, lf)
fd = mpfunfd ! fun
fdh = lv(fd>>FD.fdh)
(lv(fdh>>FDH.ampFaLrec2)) ! fa = rv lf
]
tnmd = tnmd>>NMD.next
]
]
for t = 0 to 2 do
[
if tnmd>>NMD.cver ne 0 then
[
makecfa2(cfa, lv(tnmd>>NMD.afptr))
ReadVec(cfa, 1, lf)
mpCrockLrec2 ! t = @lf
]
tnmd = tnmd>>NMD.next
]
let fdd = vfddfirst
let tlfileMax = 0;
let tfddlMax = 0;
while fdd ne 0 do
[
if tnmd>>NMD.cver ne 0 then
[
move(lv tnmd >> NMD.afptr, lv fdd >> FDD.aFptr, lFP)
let dblL = vec 2
FindCfc(lv fdd >> FDD.aFptr, dblL)
fdd >> FDD.lfile = (dblL ! 1) rshift 1
if ugt(fdd>>FDD.lfile, tlfileMax) then
[ tlfileMax = fdd>>FDD.lfile;
tfddlMax = fdd;
]
]
fdd = fdd >> FDD.fddnext
tnmd = tnmd>>NMD.next
]
unless tnmd eq 0 then errhlt("n0")
// if tfddlMax eq 0 then errhlt("fdm");
resultis tfddlMax;
]

// - =- =- =- =- =- =- =- =- =- =
and makellnmd() be
// =-- =- =- =- =- =- =- =- =- =-

[
let oldnmd = array1(1, 0)
let newnmd = oldnmd
let funfa =nil
let fun =nil
let fa =nil
let lNMD = nil
let sbfile = vec maxLengthFnInWords

llnmd = oldnmd

for fun = 0 to maxfun-1 do
[
if mpfunfd ! fun eq fdnil then loop
for fa = 0 to 3 do
[
CreateSbEff(sbfile, fun, fa)
oldnmd = NmdAdd(sbfile, oldnmd, array)
]
]
oldnmd = NmdAdd("HELVETICA10B.EP", oldnmd, array)
oldnmd = NmdAdd("BORDER20.EP", oldnmd, array)
oldnmd = NmdAdd("KEYHOLE20.EP", oldnmd, array)
let fdd = vfddfirst
while fdd ne 0 do
[
CreateSbAl(sbfile, fdd)
oldnmd = NmdAdd(sbfile, oldnmd, array)
fdd = fdd >> FDD.fddnext
]
]

// A D D N M D
//
and NmdAdd(sbFile, nmdPrev, alloc) = valof
[
let lNMD = ovhNmd + sbwsize(sbFile) + 1
let newnmd = array(lNMD)
nmdPrev>>NMD.next = newnmd
InitNmd(newnmd, lNMD, sbFile, vcNewest)
resultis newnmd
]

// - =- =- =- =- =- =- =- =- =- =
and makecfa2(cfa, fp) be
// - =-- =- =- =- =- =- =- =- = =

[
move(fp, lv(cfa>>CFA.fp), lFP)
cfa>>CFA.fa.da = RealDA(fp>>FP.leaderVirtualDa)
cfa>>CFA.fa.pageNumber = 0
cfa>>CFA.fa.charPos = 0
]

// C R E A T E S B E F F
// duplicate of proc in doculist.sr
//
and CreateSbEff(sbdest, fun, fa) be
[
let fd = mpfunfd ! fun;
let fdh = lv(fd >> FD.fdh);
test fun ge maxfun ifso
[
let tsb = nil
switchon fun into
[
case maxfun:
tsb = "HELVETICA10B.EP";
endcase
case maxfun+1:
tsb = "BORDER20.EP";
endcase
case maxfun+2:
tsb = "KEYHOLE20.EP";
endcase
default:
errhlta(180);
]
stcopy(sbdest, tsb)
]
ifnot[
stcopy(sbdest, lv(fdh >> FDH.rvsbname));
let tsbnum = vec 10;
tsbnum ! 0 = 0;
stnum(tsbnum, fdh >> FDH.height, 10, 0, false, false, false);
stappend(sbdest, tsbnum);
if fa ne 0 then
[
let tsb = selecton fa into
[
case 1:
"I"
case 2:
"B"
case 3:
"BI"
]
stappend(sbdest, tsb);
]
stappend(sbdest, ".EP");
]
]

// C R E A T E S B A L
//
and CreateSbAl(sbDest, fdd) be
[
let tsb1 = vec 10;
stnum(tsb1, fdd >> FDD.height, 10, 0);
stcopy(sbDest, lv(fdd >> FDD.rvsbname));
stappend(sbDest, tsb1);
stappend(sbDest, ".AL");
]