// FS.SR	Format States

get "BRAVO.DF"
get "CHAR.DF"
get "GINN.DF"

// Incoming procedures

external
	[
	getvch
	settabs
	]

// Incoming statics

external
	[
	widthblmin
	widthblave
	heightstd
	rgrgcc
	rgfsfdispl
	rgfsdef
	vrgcc
	vfont
	vxleftmarg
	vxrightmarg
	vheight
	rgccstd
	fontstd
	vrightadjust
	macww
	inheap
	vproc
	vsncompact
	rgdoc
	vdoc
	rgmaccp
	vchremain
	vcp
	vlooksp // **
	vlookcr
	vlooktab
	vlookmarker
	vlooktrailer
	vlookremark
	rgview
	]

// Outgoing procedures

external
	[
	establishww;
	disestablishww;
	getint;
	]

// Outgoing statics

external
	[
	vdevtype
	xleftmargstd
	xrightmargstd
	]

// Local statics

static
	[
	vdevtype
	xleftmargstd
	xrightmargstd
	]

// E S T A B L I S H W W 
//
let establishww(ww, devtype; numargs N) be
[
if N ls 2 then devtype = devalto
vrgcc = rgccstd;
vfont = fontstd;
vrightadjust = false; // ??
vheight = heightstd;
let v = rgview ! (rgdoc ! ww) // ** ...
vlooksp = v & lookspmask
vlookcr = v & lookcrmask
vlooktab = v & looktabmask
vlookmarker = v & lookmarkermask
vlooktrailer = v & looktrailermask
vlookremark = v & lookremarkmask
if devtype eq vdevtype then return
test devtype eq devalto
ifso
	[
	xleftmargstd = altolmarg
	xrightmargstd = altormarg
	widthblmin = widthspmin
	widthblave = widthspave
	settabs(tabchstd)
	]
ifnot 
	[
	if devtype eq devdp then
		[
		xleftmargstd = dplmarg
		xrightmargstd = dprmarg
		widthblmin = dpspmin
		widthblave = dpspave
		settabs(dptabwidth)
		]
	]
vdevtype = devtype
vxleftmarg = xleftmargstd;
vxrightmarg = xrightmargstd;
]
 
and disestablishww() be
[
xleftmargstd = altolmarg
xrightmargstd = altormarg
widthblmin = widthspmin
widthblave = widthspave
settabs(tabchstd)
vdevtype = devalto
vxleftmarg = xleftmargstd;
vxrightmarg = xrightmargstd;
]

// G E T I N T 
//
and getint(doc,radix,digit,pbreak; numargs N) = valof // ** changed
[
if N eq 4 then rv pbreak = -1
if N ls 2 then radix = 10;
vchremain = 0;
vdoc = doc;
let maccp = rgmaccp ! doc;
if vcp eq maccp then resultis 0;
let sum = 0
if N ls 3 then digit = getvch();
while $0 le digit & digit le $9 do
	[
	sum = (sum*radix) + digit-$0;
	if vcp eq maccp then resultis sum;
	digit = getvch( );
	] 
vchremain = 0;
if N eq 4 then rv pbreak = digit;
resultis sum;
]