frink.fsp - Frink Server Pages highlighter
[Try frink.fsp]
<%@ persistent="true" %>
<%
use ../
HTMLUtils.frink
use ../
hints.frink
fromValRestore = ""
toValRestore = ""
if (hideHelp or isVariableDefined["keep"])
{
fromValRestore = HTMLEncodeQuoted[fromVal]
toValRestore = HTMLEncodeQuoted[toVal]
} %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML LANG="en">
<HEAD>
<TITLE>Frink Web-based Interface</TITLE>
<META HTTP-EQUIV="Default-Style" CONTENT="APE Airy">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<META NAME="viewport" CONTENT="width=device-width, initial-scale=1.0">
<LINK REL="StyleSheet" HREF="/frinkdocs/apeairy.css" TYPE="text/css"
TITLE="APE Airy">
<LINK REL="Alternate StyleSheet" HREF="/frinkdocs/spaceship.css"
TYPE="text/css" TITLE="Spaceship">
<LINK REL="Alternate StyleSheet" HREF="/frinkdocs/style.css" TYPE="text/css"
TITLE="APE Classic">
<LINK REL="Alternate StyleSheet" HREF="/frinkdocs/style2.css" TYPE="text/css"
TITLE="Compact">
<LINK REL="icon" HREF="/images/futureboyicon.png" TYPE="image/png">
<LINK REL="canonical" HREF="https://frinklang.org/fsp/frink.fsp">
</HEAD>
<% focusOn=lookup ? "f2.lookup" : "f1.fromVal" %>
<BODY onLoad="document.$focusOn
.focus()">
<H1>Frink Web-based Interface</H1>
<P CLASS="CENTER">
<A HREF="/frinkdocs/">Frink Documentation</A> *
<A HREF="/frinkdocs/whatsnew.html">What's New</A> *
<A HREF="/frinkdocs/faq.html">FAQ</A> *
<A HREF="/frinkdocs/index.html#JavaWebStart">Download Frink</A> *
<A HREF="/frinkdocs/FrinkApplet.html">Frink Applet</A> *
<A
HREF="/frinkdocs/fspdocs.html">Frink Server Pages Docs</A> *
<A HREF="samples.fsp">Sample Programs</A> *
<A HREF="mailto:eliasen@mindspring.com">Contact Alan Eliasen</A> *
<A HREF="/frinkdocs/android.html">Frink on Android</A> *
<A HREF="/frinkdocs/donate.html">Donate</A>
</P>
<A NAME="calc"></A>
<FORM ACTION="frink.fsp#calc" METHOD="GET" NAME="f1">
<% if isVariableDefined["keep"]
println[""" <INPUT TYPE="HIDDEN" NAME="keep" VALUE="1">"""]
%>
<TABLE CLASS="back">
<TR><TD CLASS="noborder">
<LABEL FOR="fromVal">From:</LABEL>
<TD CLASS="noborder"><INPUT TYPE="TEXT" NAME="fromVal" VALUE="$fromValRestore
"
ID="fromVal" SIZE=50 autocapitalize="none" autocorrect="none"
STYLE="width:100%">
<TR><TD CLASS="noborder"><LABEL FOR="toVal">To:</LABEL>
<TD CLASS="noborder"><INPUT TYPE="TEXT" NAME="toVal" VALUE="$toValRestore
" ID="toVal"
SIZE=50 autocapitalize="none" autocorrect="none"
STYLE="width:100%">
<TR><TD COLSPAN="2" CLASS="noborder"><INPUT TYPE="SUBMIT" VALUE="Calculate">
</TABLE>
</FORM>
<%
prog = undef
if fromVal
{
println["<TABLE BORDER=\"0\">"]
println["<TR><TD VALIGN=\"top\" CLASS=\"noborder\"><B>From:</B><TD CLASS=\"noborderlit\">" + HTMLEncode[fromVal]]
if (toVal)
{
println["<TR><TD CLASS=\"noborder\"><B>To:</B><TD CLASS=\"noborderlit\">" + HTMLEncode[toVal]]
prog = "$fromVal
-> $toVal
"
} else
prog = fromVal
println["<TR><TD VALIGN=TOP CLASS=\"noborder\"><B>Result:</B><TD CLASS=\"noborderlit\">"]
result = undef
// Evaluate and throw exceptions. This may print output that we
// want to format so we turn on HTML encoding.
// THINK ABOUT:
// Unfortunately, we can't do this in a try/catch block because
// the try block creates a new ContextFrame which means that
// any variables we set disappear at the end of the ContextFrame
// and we can't do persistent calculations.
// try
// {
setHTMLEncode[true]
result = eval[prog, true]
// }
// finally
// {
setHTMLEncode[false]
// }
result = "$result
" // Coerce to string in all cases.
result = HTMLEncode[result]
result =~ %s/(\n\r?|\r\n?)/<BR>\n/g
// Highlight undefined symbols
result =~ %s/((\w+)\s*\(undefined symbol\))/<SPAN class="warning">$1<\/SPAN>/ig
println["<A NAME=results>$result
</A>"]
println["</TABLE>"]
}
if prog
{
toVal = toVal ? toVal : ""
fromVal = fromVal ? fromVal : ""
result = result ? result : ""
println[getHints[prog, fromVal, toVal, result]]
}
%>
<P>
<A NAME="lookup"></A>
<FORM ACTION="frink.fsp#lookup" METHOD="GET" NAME="f2">
<TABLE CLASS="back">
<TR><TD CLASS="noborder">
<LABEL FOR="lookup">Lookup:</LABEL>
<INPUT TYPE="TEXT" NAME="lookup" SIZE=20 ID="lookup" autocapitalize="none"
autocorrect="none">
<INPUT TYPE="CHECKBOX" NAME="exactMatch" ID="exactMatch"><LABEL FOR="exactMatch">Exact match only</LABEL>
<TR><TD CLASS="noborder">
<INPUT TYPE="SUBMIT" VALUE="Lookup">
</TABLE>
<HR>
<%
// Look up word
if lookup
{
if (lookup =~ %r/\S+\s+\S+/)
println["<P CLASS=\"warning\"><B>Please enter only one word (or part of a word) into the lookup field.<BR>\nFor example, if you want to find out what Frink knows about the earth, enter \"earth\" in the lookup box. To find out what different types of cubits have been used around the world, enter \"cubit\" in the lookup box.</B></P>"]
if (exactMatch)
pat = regex["^$lookup
\b"]
else
pat = regex["$lookup
","i"]
for [line] lines["file:///$FSPRoot
/../../data/units.txt"]
{
if (line =~ pat)
{
line = HTMLEncode[line]
line =~ %s/^([^ \/]+)/<B>$1<\/B>/ // Put unit name in bold
line =~ %s/\/\/\s*(.*)/ <I>[$1]<\/I>/
println["$line
<BR>"]
}
}
}
%>
<P>
<% if showHelp
hideOn = false
if hideHelp || hideOn
{
hideOn = true
%>
<INPUT TYPE="Submit" NAME="showHelp" VALUE="Show Help">
<% } else
{ %>
<INPUT TYPE="Submit" NAME="hideHelp" VALUE="Hide 'help' information below">
<% } %>
</P>
</FORM>
<% if ! hideOn
{
%>
<DIV CLASS="back">
<P>
If you don't know what this page is for, please look at the <A HREF="/frinkdocs/">Frink documentation</A> and some <A HREF="/frinkdocs/#SampleCalculations">sample calculations</A> first.
</P>
<P>
In this web interface, you can enter any arbitrarily complex Frink
expression (see the <A HREF="/frinkdocs/">documentation</A>) in the "From:"
box and click "Calculate". If you also enter a value in the "To:" box, it
is treated as the right-hand side of a conversion expression (that is, to
the right of the conversion operator <CODE>-></CODE> )
</P>
<P>
Thus, to convert 10 meters to feet, you can enter
<CODE CLASS="input">10 meters</CODE> in the "From" box and
<CODE CLASS="input">feet</CODE> in the "To" box, or, equivalently, type
<CODE CLASS="input">10 meters -> feet</CODE> in the
"From" box and leave the "To" box empty. It does exactly the same thing.
</P>
<P>
Didn't find the unit you were looking for? Got "undefined symbol" or other
errors? Try reading the <A HREF="/frinkdocs/faq.html">FAQ</A> for common
issues. Frink is case-sensitive. To find the name Frink uses for an
obscure unit, type part or all of the word in the "Lookup" box (in upper-
<EM>or</EM> lower-case; the lookup is not case-sensitive) and click the
"Lookup" button, or, better yet, if you're, say, looking for information
about the moon, type <CODE CLASS="input">??moon</CODE> in the "From:" box
and click the "Calculate" button. See the <A
HREF="/frinkdocs/index.html#IntegratedHelp">Integrated Help</A> section of
the documentation for more ways to look up units.
</P>
<P>
<I>Note:</I> You can now set variables in this interface that will last for
the duration of your session.
<P>
<P>
This is powered by <A HREF="/frinkdocs/fspdocs.html">Frink Server
Pages.</A> Can your browser handle Java 1.3.1 or later? Try the
<A HREF="/frinkdocs/FrinkApplet.html">applet-based Frink interface</A> or
<A HREF="/frinkdocs/index.html#JavaWebStart">Download Frink</A> onto
your own computer.
</P>
<P>
Back to <A HREF="/frinkdocs/fspdocs.html">Frink Server Pages
documentation.</A>
</P>
</DIV>
<% } // end "if hide %>
<P>
Please report any comments, questions, suggestions, or errors to
<A HREF="mailto:eliasen@mindspring.com">Alan Eliasen</A>.
</P>
</BODY>
</HTML>
[Try frink.fsp]
Alan Eliasen was born
20203 days, 10 hours, 40 minutes ago.
Back to Frink Server Pages
documentation.