\begindata{text,538481752}
\textdsversion{12}
\template{default}
\define{global
}


	Ness Calculator

\bigger{\bigger{\bigger{\bigger{\bigger{\bigger{\bigger{
	\bigger{\bigger{\bigger{ \bold{| 0 | }}}}

}}}}}}}

\begindata{lset,538596360}
\V 1
\begindata{lset,538590472}
\V 1
\begindata{lset,538590728}
\V 1
\begindata{cel,538596872}
\V 2
\begindata{value,539103624}
>1
\enddata{value,539103624}
10 539103624 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< allclear
>LINK< 
\begindata{text,538298716}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (C)

\enddata{text,538298716}
\enddata{cel,538596872}
0 0 0 538596872 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,538590728}
\begindata{lset,538597384}
\V 1
\begindata{lset,538597896}
\V 1
\begindata{cel,538599176}
\V 2
\begindata{value,539103752}
>0
\enddata{value,539103752}
10 539103752 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< clearentry
>LINK< EF< raster
\begindata{text,538379164}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (ce)

\enddata{text,538379164}
\enddata{cel,538599176}
0 0 0 538599176 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,538597896}
\begindata{lset,538598408}
\V 1
\begindata{lset,538598664}
\V 1
\begindata{cel,538588936}
\V 2
\begindata{value,539103880}
>2
\enddata{value,539103880}
10 539103880 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< sqrt
>LINK< EF< 
\begindata{text,538491048}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (sqrt)

\enddata{text,538491048}
\enddata{cel,538588936}
0 0 0 538588936 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,538598664}
\begindata{lset,538588424}
\V 1
\begindata{cel,538587912}
\V 2
\begindata{value,539104008}
>0
\enddata{value,539104008}
10 539104008 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< question
>LINK< 
\begindata{text,538405480}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (?)

\enddata{text,538405480}
\enddata{cel,538587912}
0 0 0 538587912 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,538588424}
1 52 0 0 538598664 538588424 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,538598408}
1 67 0 0 538597896 538598408 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,538597384}
1 77 0 0 538590728 538597384 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,538590472}
\begindata{lset,538587400}
\V 1
\begindata{cel,537828872}
\V 2
\begindata{lset,537829128}
\V 1
\begindata{lset,537828360}
\V 1
\begindata{lset,537827592}
\V 1
\begindata{lset,537827848}
\V 1
\begindata{lset,537827080}
\V 1
\begindata{cel,537826312}
\V 2
\begindata{value,539103368}
>4
\enddata{value,539103368}
10 539103368 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< seven
>LINK< LINK< 
\begindata{text,538513528}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (7)

\enddata{text,538513528}
\enddata{cel,537826312}
0 0 0 537826312 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,537827080}
\begindata{lset,538599688}
\V 1
\begindata{lset,538599944}
\V 1
\begindata{cel,538600200}
\V 2
\begindata{value,539103496}
>2
\enddata{value,539103496}
10 539103496 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< eight
>LINK< LINK< 
\begindata{text,538376384}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (8)

\enddata{text,538376384}
\enddata{cel,538600200}
0 0 0 538600200 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,538599944}
\begindata{lset,538600456}
\V 1
\begindata{lset,538600712}
\V 1
\begindata{cel,538600968}
\V 2
\begindata{value,538759048}
>2
\enddata{value,538759048}
10 538759048 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< nine
>LINK< 
\begindata{text,538333940}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (9)

\enddata{text,538333940}
\enddata{cel,538600968}
0 0 0 538600968 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,538600712}
\begindata{lset,538601224}
\V 1
\begindata{cel,538601480}
\V 2
\begindata{value,539103240}
>1
\enddata{value,539103240}
10 539103240 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< divide
>LINK< LINK< 
\begindata{text,539037156}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (/)

\enddata{text,539037156}
\enddata{cel,538601480}
0 0 0 538601480 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,538601224}
1 53 0 0 538600712 538601224 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,538600456}
1 66 0 0 538599944 538600456 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,538599688}
1 77 0 0 537827080 538599688 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,537827848}
\begindata{lset,538601736}
\V 1
\begindata{lset,538601992}
\V 1
\begindata{cel,538602248}
\V 2
\begindata{value,538758792}
>3
\enddata{value,538758792}
10 538758792 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< four
>LINK< 
\begindata{text,538479956}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (4)

\enddata{text,538479956}
\enddata{cel,538602248}
0 0 0 538602248 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,538601992}
\begindata{lset,538602504}
\V 1
\begindata{lset,538602760}
\V 1
\begindata{cel,538603016}
\V 2
\begindata{value,538758920}
>6
\enddata{value,538758920}
10 538758920 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< five
>LINK< 
\begindata{text,538478320}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (5)

\enddata{text,538478320}
\enddata{cel,538603016}
0 0 0 538603016 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,538602760}
\begindata{lset,538603272}
\V 1
\begindata{lset,539172872}
\V 1
\begindata{cel,539173128}
\V 2
\begindata{value,538758536}
>1
\enddata{value,538758536}
10 538758536 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< six
>LINK< de
\begindata{text,537976672}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (6)

\enddata{text,537976672}
\enddata{cel,539173128}
0 0 0 539173128 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,539172872}
\begindata{lset,539173384}
\V 1
\begindata{cel,539173640}
\V 2
\begindata{value,538758664}
>1
\enddata{value,538758664}
10 538758664 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< times
>LINK< 
\begindata{text,538480756}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (*)

\enddata{text,538480756}
\enddata{cel,539173640}
0 0 0 539173640 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,539173384}
1 53 0 0 539172872 539173384 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,538603272}
1 66 0 0 538602760 538603272 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,538602504}
1 77 0 0 538601992 538602504 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,538601736}
2 49 0 0 537827848 538601736 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,537827592}
\begindata{lset,539173896}
\V 1
\begindata{lset,539174152}
\V 1
\begindata{cel,539174408}
\V 2
\begindata{value,538758280}
>1
\enddata{value,538758280}
10 538758280 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< one
>LINK< 
\begindata{text,538281292}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (1)

\enddata{text,538281292}
\enddata{cel,539174408}
0 0 0 539174408 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,539174152}
\begindata{lset,539174664}
\V 1
\begindata{lset,539174920}
\V 1
\begindata{cel,539175176}
\V 2
\begindata{value,538758408}
>1
\enddata{value,538758408}
10 538758408 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< two
>LINK< 
\begindata{text,538378380}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (2)

\enddata{text,538378380}
\enddata{cel,539175176}
0 0 0 539175176 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,539174920}
\begindata{lset,539175432}
\V 1
\begindata{lset,539175688}
\V 1
\begindata{cel,539175944}
\V 2
\begindata{value,538758024}
>1
\enddata{value,538758024}
10 538758024 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< three
>LINK< LINK< 
\begindata{text,538478196}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (3)

\enddata{text,538478196}
\enddata{cel,539175944}
0 0 0 539175944 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,539175688}
\begindata{lset,539176200}
\V 1
\begindata{cel,539176456}
\V 2
\begindata{value,538758152}
>1
\enddata{value,538758152}
10 538758152 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< minus
>LINK< LINK< 
\begindata{text,538376236}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (-)

\enddata{text,538376236}
\enddata{cel,539176456}
0 0 0 539176456 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,539176200}
1 53 0 0 539175688 539176200 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,539175432}
1 66 0 0 539174920 539175432 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,539174664}
1 77 0 0 539174152 539174664 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,539173896}
2 32 0 0 537827592 539173896 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,537828360}
\begindata{lset,539176712}
\V 1
\begindata{lset,539176968}
\V 1
\begindata{cel,539177224}
\V 2
\begindata{value,538757768}
>2
\enddata{value,538757768}
10 538757768 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< dot
>LINK< 9496032 269495064 0
\begindata{text,538287636}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (.)

\enddata{text,538287636}
\enddata{cel,539177224}
0 0 0 539177224 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,539176968}
\begindata{lset,539177480}
\V 1
\begindata{lset,539177736}
\V 1
\begindata{cel,539177992}
\V 2
\begindata{value,538757896}
>1
\enddata{value,538757896}
10 538757896 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< zero
>LINK< LINK< 
\begindata{text,538378256}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (0)

\enddata{text,538378256}
\enddata{cel,539177992}
0 0 0 539177992 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,539177736}
\begindata{lset,539178248}
\V 1
\begindata{lset,539178504}
\V 1
\begindata{cel,539178760}
\V 2
\begindata{value,538757512}
>1
\enddata{value,538757512}
10 538757512 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< equal
>LINK< LINK< 
\begindata{text,538478072}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (=)

\enddata{text,538478072}
\enddata{cel,539178760}
0 0 0 539178760 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,539178504}
\begindata{lset,539179016}
\V 1
\begindata{cel,539179272}
\V 2
\begindata{value,538757640}
>2
\enddata{value,538757640}
10 538757640 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< plus
>LINK< 
\begindata{text,538376112}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (+)

\enddata{text,538376112}
\enddata{cel,539179272}
0 0 0 539179272 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,539179016}
1 53 0 0 539178504 539179016 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,539178248}
1 66 0 0 539177736 539178248 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,539177480}
1 77 0 0 539176968 539177480 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,539176712}
2 25 0 0 537828360 539176712 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,537829128}
0 537829128 0 0 0 0 
>OBJ< lset
>VIEW< lsetview
>REF< lset
>LINK< REF< 
\enddata{cel,537828872}
0 0 0 537828872 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,538587400}
2 80 0 0 538590472 538587400 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,538596360}
\view{lsetview,538596360,597,261,307}


 \
\begindata{ness,538752008}
\origin{00\\11 Oct 1990 at 11:27:40 EDT\\wjh:  Fred Hansen\\00}
\template{default}
\define{fullwidth
menu:[Justify,Full Width]
attr:[LeftMargin LeftMargin Cm -25431]
attr:[RightMargin RightMargin Cm -27743]}
\define{sans
menu:[Font,Sans]
attr:[FontFamily AndySans Int 0]}
-- Calculator


-- This is a five state machine with transitions controlled by d, =, and op 
for

-- digits, equal, and operators, respectively.

--	S0: just after an =

--	S1: after = d

--	S2: after d op*

--	S3: after op d

--	S4: after = op*


marker accum	-- the accumulated result

marker entry	-- the entered or displayed number

marker savedOp	-- the next operation to perform

boolean hadDecimal	-- has a decimal point occurred

integer State	-- 0...4


function display()

	marker s := finish(search(base(currentselection(defaulttext)), " |"))

	replace(extent(s, search(s, "|")), " " ~ entry ~ " |")

end function


function DoArithmetic(left, right)

	-- this routine sets entry to an immutable value

	-- it will be reset to a mutable value when a digit is pressed

	real lv, rv

	if first(left) = "-" then lv := -parsereal(rest(left))

		else lv := parsereal(left) end if

	if first(right) = "-" then rv := -parsereal(rest(right))

		else rv := parsereal(right) end if


	if SavedOp = "+" then

		entry := textimage(lv + rv)

	elif  SavedOp = "-" then

		entry := textimage(lv - rv)

	elif  SavedOp = "*" then

		entry := textimage(lv * rv)

	elif  SavedOp = "/" then

		entry := textimage(lv / rv)

	else

		entry := "0"

	end if

	if last(entry) = "." then 

		entry := extent(entry, start(last(entry))) 

	end if

end function


function allclear()

	entry := copy("0")

	accum := "0"

	savedOp := "+"

	hadDecimal := False

	State := 0

	display()

end function


function digithit(dig)

	if mouseaction = mouseleftup then

		if State = 0 or State = 2 or State = 4 then

			-- first digit of operand

			if dig = "." then entry := copy("0.")

			else entry := copy(dig) end if

			if State = 0 then State := 1

			else State := 3 end if

		elif dig = "." then

			if not hadDecimal then

				entry ~:= dig

				hadDecimal := True

			end if

		else

			entry ~:= dig

		end if

		display()

	end if

end function


function Op(nextoperator)

	if mouseaction /= mouseleftup then

		-- do nothing

	elif State = 3 then

		-- do prior operation

		DoArithmetic(accum, entry)

		display()

		hadDecimal := False

		State := 2

	else

		-- just save the operator for later

		SavedOp := nextoperator

		accum := copy(entry)

		hadDecimal := False

		if State = 1 then State := 2

		elif State = 0 then State := 4

		end if

	end if

end function


function EqualPressed()

	if mouseaction /= mouseleftup then

		exit function 	-- do nothing

	elif State = 0 or State = 1 then

		-- repeat the previous operation

		DoArithmetic(entry, accum)

	elif State = 2 or State = 4 then

		-- this is a unary operation

		accum := copy(entry)

		if SavedOp = "+" then

			-- double the value

			DoArithmetic(entry, entry)

		elif  SavedOp = "-" then

			-- compute negative

			DoArithmetic("0", entry)

		elif  SavedOp = "*" then

			-- square the value

			DoArithmetic(entry, entry)

		elif  SavedOp = "/" then

			-- compute inverse

			DoArithmetic("1", entry)

		else

			entry := copy("0")

		end if

	else

		-- do normal arithmetic

		marker t := accum

		accum := entry

		DoArithmetic(t, entry)

	end if

	display()

	hadDecimal := False

	State := 0

end function 


--	S0: just after an =  : take sqrt of entry

--	S1: after = d    :  take sqrt of entry

--	S2: after d op*  : ignore op, take sqrt of entry

--	S3: after op d :  apply op, then take sqrt of entry

--	S4: after = op*  : take sqrt of entry

extend "sqrt"

	on mouse "any"

		if mouseaction /= mouseleftup then

			exit function

		end if

		if State = 3 then 

			-- perform operation

			marker t := accum

			accum := entry

			DoArithmetic(t, entry)

		end if

		if first(entry) = "-" then 

			entry := "nan"

		else 

			entry := textimage(sqrt(parsereal(entry)))

		end if

		display()

		hadDecimal := False

		State := 0

	end mouse

end extend


extend "question"	

	on mouse "any"

		if mouseaction = mouseleftup then

			marker m

			m := AskUser("How are you? ", "")

			if m /= "CANCEL" then

				TellUser("Good, I am " ~ m ~ ", too")

			end if

		end if

	end mouse

end extend


extend "dot"	-- calculator cell to the right of zero

	on mouse "any"

		digithit(".")

	end mouse

end extend


extend "allclear"

	on mouse "any"

		if mouseaction = mouseleftup then

			allclear()

		end if

	end mouse

end extend

extend "clearentry"

	on mouse "any"

		if mouseaction = mouseleftup then

			entry := copy("0")

			hadDecimal := False

			display()

		end if

	end mouse

end extend

extend "equal"

	on mouse "any"

		EqualPressed()

	end mouse

end extend

extend "plus"

	on mouse "any"

		Op("+")

	end mouse

end extend

extend "minus"

	on mouse "any"

		Op("-")

	end mouse

end extend

extend "times"

	on mouse "any"

		Op("*")

	end mouse

end extend

extend "divide"

	on mouse "any"

		Op("/")

	end mouse

end extend

extend "one"

	on mouse "any"

		digithit("1")

	end mouse

end extend

extend "two"

	on mouse "any"

		digithit("2")

	end mouse

end extend

extend "three"

	on mouse "any"

		digithit("3")

	end mouse

end extend

extend "four"

	on mouse "any"

		digithit("4")

	end mouse

end extend

extend "five"

	on mouse "any"

		digithit("5")

	end mouse

end extend

extend "six"

	on mouse "any"

		digithit("6")

	end mouse

end extend

extend "seven"

	on mouse "any"

		digithit("7")

	end mouse

end extend

extend "eight"

	on mouse "any"

		digithit("8")

	end mouse

end extend

extend "nine"

	on mouse "any"

		digithit("9")

	end mouse

end extend

extend "zero"

	on mouse "any"

		digithit("0")

	end mouse

end extend



function main()

	allclear()

end function


integer function initkludge()

	if isreadonly(currentselection(defaulttext)) then

		textview_toggle_read_only(defaulttext)

	end if

	allclear()

	return 0

end function


integer kludge := initkludge()

\enddata{ness,538752008}
\view{nessview,538752008,598,0,589}





\begindata{bp,537558784}
\enddata{bp,537558784}
\view{bpv,537558784,600,0,0}
Copyright 1992 Carnegie Mellon University and IBM.  All rights reserved.

\smaller{\smaller{$Disclaimer: 

Permission to use, copy, modify, and distribute this software and its 

documentation for any purpose is hereby granted without fee, 

provided that the above copyright notice appear in all copies and that 

both that copyright notice, this permission notice, and the following 

disclaimer appear in supporting documentation, and that the names of 

IBM, Carnegie Mellon University, and other copyright holders, not be 

used in advertising or publicity pertaining to distribution of the software 

without specific, written prior permission.



IBM, CARNEGIE MELLON UNIVERSITY, AND THE OTHER COPYRIGHT HOLDERS 

DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 

ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT 

SHALL IBM, CARNEGIE MELLON UNIVERSITY, OR ANY OTHER COPYRIGHT HOLDER 

BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY 

DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 

WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 

ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 

OF THIS SOFTWARE.

 $

}}\enddata{text,538481752}
