\begindata{text,268727060}
\textdsversion{12}
\template{default}


	Ness Calculator

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

}}}}}}}

\begindata{lset,269129164}
\V 1
\begindata{lset,269141008}
\V 1
\begindata{lset,269540376}
\V 1
\begindata{cel,269764532}
\V 2
\begindata{value,269763444}
>1
\enddata{value,269763444}
10 269763444 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< allclear
>LINK< 
\begindata{text,269184852}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (C)

\enddata{text,269184852}
\enddata{cel,269764532}
0 0 0 269764532 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,269540376}
\begindata{lset,269420048}
\V 1
\begindata{lset,268708212}
\V 1
\begindata{cel,268695516}
\V 2
\begindata{value,268699972}
>0
\enddata{value,268699972}
10 268699972 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< clearentry
>LINK< EF< raster
\begindata{text,268716184}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (ce)

\enddata{text,268716184}
\enddata{cel,268695516}
0 0 0 268695516 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,268708212}
\begindata{lset,269540172}
\V 1
\begindata{lset,269514552}
\V 1
\begindata{cel,269516924}
\V 2
\begindata{value,269515876}
>2
\enddata{value,269515876}
10 269515876 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< sqrt
>LINK< EF< 
\begindata{text,269505992}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (sqrt)

\enddata{text,269505992}
\enddata{cel,269516924}
0 0 0 269516924 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,269514552}
\begindata{lset,268695312}
\V 1
\begindata{cel,268699856}
\V 2
\begindata{value,268736228}
>0
\enddata{value,268736228}
10 268736228 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< question
>LINK< 
\begindata{text,269794768}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (?)

\enddata{text,269794768}
\enddata{cel,268699856}
0 0 0 268699856 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,268695312}
1 52 0 0 269514552 268695312 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,269540172}
1 67 0 0 268708212 269540172 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,269420048}
1 77 0 0 269540376 269420048 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,269141008}
\begindata{lset,269514348}
\V 1
\begindata{cel,268708096}
\V 2
\begindata{lset,268695108}
\V 1
\begindata{lset,268699652}
\V 1
\begindata{lset,268736024}
\V 1
\begindata{lset,268713204}
\V 1
\begindata{lset,268726176}
\V 1
\begindata{cel,268707388}
\V 2
\begindata{value,268716084}
>4
\enddata{value,268716084}
10 268716084 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< seven
>LINK< LINK< 
\begindata{text,269539948}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (7)

\enddata{text,269539948}
\enddata{cel,268707388}
0 0 0 268707388 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,268726176}
\begindata{lset,268694904}
\V 1
\begindata{lset,268735820}
\V 1
\begindata{cel,268713088}
\V 2
\begindata{value,268726100}
>2
\enddata{value,268726100}
10 268726100 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< eight
>LINK< LINK< 
\begindata{text,269539836}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (8)

\enddata{text,269539836}
\enddata{cel,268713088}
0 0 0 268713088 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,268735820}
\begindata{lset,268694700}
\V 1
\begindata{lset,268712884}
\V 1
\begindata{cel,268725984}
\V 2
\begindata{value,268715984}
>2
\enddata{value,268715984}
10 268715984 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< nine
>LINK< 
\begindata{text,269539724}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (9)

\enddata{text,269539724}
\enddata{cel,268725984}
0 0 0 268725984 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,268712884}
\begindata{lset,268725780}
\V 1
\begindata{cel,268715868}
\V 2
\begindata{value,269794584}
>1
\enddata{value,269794584}
10 269794584 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< divide
>LINK< LINK< 
\begindata{text,269539612}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (/)

\enddata{text,269539612}
\enddata{cel,268715868}
0 0 0 268715868 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,268725780}
1 53 0 0 268712884 268725780 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,268694700}
1 66 0 0 268735820 268694700 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,268694904}
1 77 0 0 268726176 268694904 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,268713204}
\begindata{lset,268715664}
\V 1
\begindata{lset,269794380}
\V 1
\begindata{cel,269539496}
\V 2
\begindata{value,269514096}
>3
\enddata{value,269514096}
10 269514096 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< four
>LINK< 
\begindata{text,268725640}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (4)

\enddata{text,268725640}
\enddata{cel,269539496}
0 0 0 269539496 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,269794380}
\begindata{lset,268715348}
\V 1
\begindata{lset,269794124}
\V 1
\begindata{cel,269539380}
\V 2
\begindata{value,268677864}
>6
\enddata{value,268677864}
10 268677864 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< five
>LINK< 
\begindata{text,269794012}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (5)

\enddata{text,269794012}
\enddata{cel,269539380}
0 0 0 269539380 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,269794124}
\begindata{lset,269793696}
\V 1
\begindata{lset,269793492}
\V 1
\begindata{cel,269793376}
\V 2
\begindata{value,269536016}
>1
\enddata{value,269536016}
10 269536016 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< six
>LINK< de
\begindata{text,269793264}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (6)

\enddata{text,269793264}
\enddata{cel,269793376}
0 0 0 269793376 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,269793492}
\begindata{lset,269792948}
\V 1
\begindata{cel,269792832}
\V 2
\begindata{value,268725524}
>1
\enddata{value,268725524}
10 268725524 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< times
>LINK< 
\begindata{text,269792660}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (*)

\enddata{text,269792660}
\enddata{cel,269792832}
0 0 0 269792832 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,269792948}
1 53 0 0 269793492 269792948 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,269793696}
1 66 0 0 269794124 269793696 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,268715348}
1 77 0 0 269794380 268715348 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,268715664}
2 49 0 0 268713204 268715664 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,268736024}
\begindata{lset,269792344}
\V 1
\begindata{lset,269792140}
\V 1
\begindata{cel,269792024}
\V 2
\begindata{value,269791948}
>1
\enddata{value,269791948}
10 269791948 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< one
>LINK< 
\begindata{text,269791776}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (1)

\enddata{text,269791776}
\enddata{cel,269792024}
0 0 0 269792024 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,269792140}
\begindata{lset,269791460}
\V 1
\begindata{lset,269791256}
\V 1
\begindata{cel,269791140}
\V 2
\begindata{value,269791064}
>1
\enddata{value,269791064}
10 269791064 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< two
>LINK< 
\begindata{text,269790892}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (2)

\enddata{text,269790892}
\enddata{cel,269791140}
0 0 0 269791140 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,269791256}
\begindata{lset,269790576}
\V 1
\begindata{lset,269790372}
\V 1
\begindata{cel,269790256}
\V 2
\begindata{value,269790180}
>1
\enddata{value,269790180}
10 269790180 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< three
>LINK< LINK< 
\begindata{text,269790008}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (3)

\enddata{text,269790008}
\enddata{cel,269790256}
0 0 0 269790256 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,269790372}
\begindata{lset,269789640}
\V 1
\begindata{cel,269789524}
\V 2
\begindata{value,269789448}
>1
\enddata{value,269789448}
10 269789448 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< minus
>LINK< LINK< 
\begindata{text,269789276}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (-)

\enddata{text,269789276}
\enddata{cel,269789524}
0 0 0 269789524 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,269789640}
1 53 0 0 269790372 269789640 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,269790576}
1 66 0 0 269791256 269790576 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,269791460}
1 77 0 0 269792140 269791460 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,269792344}
2 32 0 0 268736024 269792344 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,268699652}
\begindata{lset,269788908}
\V 1
\begindata{lset,269788704}
\V 1
\begindata{cel,269788588}
\V 2
\begindata{value,269788512}
>2
\enddata{value,269788512}
10 269788512 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< dot
>LINK< 9496032 269495064 0
\begindata{text,269788340}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (.)

\enddata{text,269788340}
\enddata{cel,269788588}
0 0 0 269788588 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,269788704}
\begindata{lset,269787972}
\V 1
\begindata{lset,269787768}
\V 1
\begindata{cel,269787652}
\V 2
\begindata{value,269787576}
>1
\enddata{value,269787576}
10 269787576 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< zero
>LINK< LINK< 
\begindata{text,269787404}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (0)

\enddata{text,269787404}
\enddata{cel,269787652}
0 0 0 269787652 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,269787768}
\begindata{lset,269787036}
\V 1
\begindata{lset,269786832}
\V 1
\begindata{cel,269786716}
\V 2
\begindata{value,269786640}
>1
\enddata{value,269786640}
10 269786640 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< equal
>LINK< LINK< 
\begindata{text,269786468}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (=)

\enddata{text,269786468}
\enddata{cel,269786716}
0 0 0 269786716 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,269786832}
\begindata{lset,269786100}
\V 1
\begindata{cel,269785984}
\V 2
\begindata{value,269785908}
>2
\enddata{value,269785908}
10 269785908 1 0 0 0 
>OBJ< value
>VIEW< buttonV
>REF< plus
>LINK< 
\begindata{text,269785736}
\textdsversion{12}
[long] <bodyfont-size> (22)

[string] <bodyfont> (andysans)

[string] <label> (+)

\enddata{text,269785736}
\enddata{cel,269785984}
0 0 0 269785984 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,269786100}
1 53 0 0 269786832 269786100 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,269787036}
1 66 0 0 269787768 269787036 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,269787972}
1 77 0 0 269788704 269787972 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,269788908}
2 25 0 0 268699652 269788908 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,268695108}
0 268695108 0 0 0 0 
>OBJ< lset
>VIEW< lsetview
>REF< lset
>LINK< REF< 
\enddata{cel,268708096}
0 0 0 268708096 0 0 0
>OBJ< cel
>VIEW< celview
>REF< 
\enddata{lset,269514348}
2 80 0 0 269141008 269514348 0
>OBJ< 
>VIEW< 
>REF< 
\enddata{lset,269129164}
\view{lsetview,269129164,2,261,307}


 \
\begindata{ness,269785312}
\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,269785312}
\view{nessview,269785312,3,0,589}




\enddata{text,268727060}
