// formats.sr // Last modified November 26, 1979 2:31 PM by Taft get "BRAVO1.DF" get "FORMAT.DF" get "CHAR.DF" get "MSG.DF" get "DISPLAY.DF" // Incoming procedures external [ errhlta errhlt movec mapcp establishfun makefmsg establishofset ldToSgTop maxBlBlNew ult widthvis XtbFromDxtb XtbFromTc umin umax divmod mult max min ] // Incoming statics external [ mpWwWwd vofsetPrev vofset vcp vheighth vheightd vmapstatus vchremain vsgd vsgh rgmaccp parsacred vcuripar vlb vpw vlook1 vlook2 vfa vfun vfwheel vblh vbld vchfrremain vfOldtab vdxtb ttblsacred vdxtbStd fontvis vheightVis vblVis dcpendofdoc ] // Outgoing procedures external [ format; ] // Outgoing statics external [ fmsg; msgtbl; rgxw; rgfinfo; vmaccr; vww; vxd; vxdlast; vxdfirst; vxdwidth; vcplast; vxrightmarg; vxleftmarg; vcpatxdl; vcpatxdr; vcpfirst; char; vdl; vxfirst; vxlast; vfsspec; vrgcc1; vrgcc2; vxafirst; vdxdleft; vdxdright; vnwrds; vtl; vld; fvbuf; fvis; fext; vfchoflow vYdofDl ] // Local statics static [ fmsg; msgtbl; rgxw; rgfinfo; vmaccr; vww; vxd; vxdlast; vxdfirst; vxdwidth; vcplast; vxrightmarg; vxleftmarg; vcpatxdl; vcpatxdr; vcpfirst; char; vdl; vxfirst; vxlast; vfsspec; vrgcc1; vrgcc2; vxafirst; vdxdleft; vdxdright; vnwrds; vtl; vld; fvbuf; fvis; fext; vfchoflow vYdofDl cr x1 x2 crBl ccrBl // crVanRun x1Brk x2Brk crBlBrk ccrBlBrk ] // local manifests manifest [ bnbTab = 0 bnbNonbreak = 1 bnbBreak = 2 crNil = #377; ] // F O R M A T // catalogue no. = 111 let format(ww, cp, mode, dld; numargs na) be [ if (mode eq 0) & (na ls 4) then errhlta(190); vww = ww; let wwd = mpWwWwd ! ww; let doc = wwd>>WWD.doc; cr = 0; crBl = crNil; ccrBl = 0; vcp = cp; let crVanRun = crNil; let dcpVanRun = 0; let crBrk = crNil; let cpBrk = nil; let crVanRunBrk = crNil; let dcpVanRunBrk = 0; let ch = nil; let dx1 = nil; let cc = nil; let bnbCurrent = nil; let bnbPrev = bnbNonbreak; let fFirstcall = true; let tlook1 = nil; let tfinfo = nil; let tfinfobase = nil; let inword = nil; let inwordlast = #377; let fJustify = nil; let fHd = wwd>>WWD.fHd ne 0 & mode ne modehc; let tfun = -1; let tfa = -1; let fRbrk = false; let ofset = 0; let fBlacktab = false // let fCase = nil // let fUpper = nil let dxBmOflow = 0 let x1Lim = nil; let cpLim = rgmaccp ! doc - (mode eq modehc ? dcpendofdoc, 0); vofset = 0; vheighth = -1; vheightd = -1; vmapstatus = statusblind; vchremain = 0; fext = false; fvis = false; fvbuf = false; movec(vsgd, vsgd+sgl-1, 0) movec(vsgh, vsgh+sgl-1, 0) fmsg = msgtbl; fmsg>>FMSG.look1 = -1; fmsg>>FMSG.look2 = -1; vfchoflow = false if mode eq modex then movec(rgfinfo, rgfinfo+maxcharperline-1, 0); [ unless vchremain do [ startmap: unless ult(vcp, cpLim) then [ fRbrk = true; break; ]; test fFirstcall ifso [ mapcp(doc, vcp, parneeded); vfsspec = parsacred>>PAR.spec; vxleftmarg = parsacred>>PAR.xleftmarg; vxrightmarg = parsacred>>PAR.xrightmarg; vld = vfsspec<>IPAR.cpfirst eq vcp ifso [ vxfirst = parsacred>>PAR.xleftmargf; vld = vld + vfsspec<>lh, vpw>>rh))<>SG.ldTop = max(0, vld+vofsetPrev); vofsetPrev= 0; // vofsetPrev= min offset of previous line vsgd>>SG.ldTop = vld; fJustify = vfsspec<>FMSG.look1) % (vlook2 ne fmsg>>FMSG.look2) then [ let fUpdateSg = false fFirstcall = false; // fCase = tlook1<>lh; vlb = false; ] ifnot [ ch = vpw>>rh; vlb = true; vpw = vpw+1; ]; // if fCase then // test fUpper ifso // if ch ge $a & ch le $z then // ch = ch - #40 // ifnot if ch ge $A & ch le $Z then // ch = ch + #40; vchremain = vchremain-1; [ cc = vrgcc1 ! ch; bnbCurrent = (cc<>SG.blmax; dld>>DLD.dYdBm = ((vsgd>>SG.topmax+vbld) + 1) & (-2); let xdhd = wwd>>WWD.xdUd-xaudleft; vxafirst = max(vxdfirst-xdhd, xaudleft); let xalast = min(vxdlast-xdhd, xaudright); vdxdleft = max(0, wwd>>WWD.xdUd-vxdfirst); vdxdright = max(0, vxdlast-xdhd-xaudright); if fBlacktab & vdxdright eq 0 then [ xalast = xalast + widthvis(chlf) rshift 5; rgfinfo ! vmaccr = #21000 + chlf; // ibv, visible rgxw ! vmaccr = 0; vmaccr = vmaccr + 1; ]; dld>>DLD.nwrds = xalast gr vxafirst ? (((xalast+max(dxdBitmap, dxaleft)+max(dxdBitmap, dxaright)-(vxafirst & #177760)+31) rshift 5) lshift 1), 2; dld>>DLD.ld = ((vsgd>>SG.ldTop) + 1) & (-2); dld>>DLD.cpLast = vcplast; dld>>DLD.xdFirst = vxdfirst; dld>>DLD.xdLast = vxdlast; ]; vheighth = vsgh>>SG.topmax+vsgh>>SG.blmax; vblh = vsgh>>SG.blmax; vtl>>TL.ww = ww; vtl>>TL.cpfirst = cp; vtl>>TL.cplast = vcplast; vtl>>TL.maccr = vmaccr; vtl>>TL.mode = mode; rgfinfo ! vmaccr = finfoterm; ] // A D J U S T X and AdjustX(mode, fJustify, crAdjust, xTarget, fMax) be [ let crSep = cr; let x2Sep = x2; let tdxBl = widthblave - widthblmin; while crSep gr (crAdjust eq crNil ? 0, crAdjust + 1) do [ crSep = crSep - 1; // if crSep eq crVanRun then // loop; let finfo = rgfinfo ! crSep; unless finfo<