// CheckEndHint.bcpl
// Copyright Xerox Corporation 1979
// Last modified June 25, 1979  10:07 AM by Taft

// Bldr CheckEndHint GP

get "AltoFileSys.d"
get "Streams.d"

external
[
// incoming procedures
SetupReadParam; ReadParam
KsHintLastPageFa; KsBufferAddress; FileLength; GetCurrentFa; OpenFile
Puts; Closes; Wss; Wns; MoveBlock; Free

// incoming statics
dsp; sysZone
]

static [ realDsp; log ]

//----------------------------------------------------------------------------
let CheckEndHint() be
//----------------------------------------------------------------------------
[
log = OpenFile("CheckEndHint.log", ksTypeWriteOnly, charItem)
realDsp = dsp
dsp = lv MyPuts - offset ST.puts/16
SetupReadParam()

   [
   let name = vec 127
   let stream = ReadParam($I, "Filename: ", name, 0, true)
   if stream eq -1 break
   let hintFA = vec lFA
   MoveBlock(hintFA, KsHintLastPageFa(stream), lFA)
   FileLength(stream)
   let realFA = vec lFA
   GetCurrentFa(stream, realFA)
   for i = 0 to lFA-1 do
      if hintFA!i ne realFA!i then
         [
         Wss(dsp, "*nFile ")
         Wss(dsp, name)
         Wss(dsp, " end hint was ")
         PrintFA(hintFA)
         Wss(dsp, ", should be ")
         PrintFA(realFA)
         break
         ]
   // Closes would fix up the incorrect hint!
   Free(sysZone, KsBufferAddress(stream))
   Free(sysZone, stream)
   ] repeat

Closes(log)
dsp = realDsp
]

//----------------------------------------------------------------------------
and PrintFA(fa) be
//----------------------------------------------------------------------------
[
Wss(dsp, "da=")
Wns(dsp, fa>>FA.da, 0, 8)
Wss(dsp, " pn=")
Wns(dsp, fa>>FA.pageNumber, 0, 8)
Wss(dsp, " nc=")
Wns(dsp, fa>>FA.charPos, 0, 8)
]

//----------------------------------------------------------------------------
and MyPuts(stream, char) be [ Puts(realDsp, char); Puts(log, char) ]
//----------------------------------------------------------------------------