0
@@ -33,181 +33,230 @@ the browser to the URL.
0
)abbrev package AXSERV AxiomServer
0
AxiomServer: public == private where
0
- axServer: (Integer, SExpression->Void) -> Void
0
- multiServ: SExpression -> Void
0
- fileserver: SExpression -> Void
0
- axget: SExpression -> Void
0
- axpost: SExpression -> Void
0
+ axServer: (Integer, SExpression->Void) -> Void
0
+ multiServ: SExpression -> Void
0
+ getFile: (SExpression,String) -> Void
0
+ getCommand: (SExpression,String) -> Void
0
+ lastStep: () -> String
0
+ lastType: () -> String
0
+ formatMessages: String -> String
0
+ getContentType: String -> String
0
- getFile: (SExpression,String) -> Void
0
- getCommand: (SExpression,String) -> Void
0
- lastStep: () -> String
0
- lastType: () -> String
0
- formatMessages: String -> String
0
- formatMessages1: String -> String
0
+ axServer(port:Integer,serverfunc:SExpression->Void):Void ==
0
+ WriteLine("socketServer")$Lisp
0
+ s := SiSock(port,serverfunc)$Lisp
0
+ -- To listen for just one connection and then close the socket
0
+ if not null?(SiListen(s)$Lisp)$SExpression then
0
- axServer(port:Integer,serverfunc:SExpression->Void):Void ==
0
- WriteLine("socketServer")$Lisp
0
- s := SiSock(port,serverfunc)$Lisp
0
- -- To listen for just one connection and then close the socket
0
- if not null?(SiListen(s)$Lisp)$SExpression then
0
+ multiServ(s:SExpression):Void ==
0
+ WriteLine("multiServ begin")$Lisp
0
+ -- read in the http headers
0
+ char := STRING(READ_-CHAR_-NO_-HANG(s,NIL$Lisp,'EOF)$Lisp)$Lisp)_
0
+ headers := concat [headers,char]
0
+ WriteLine(headers)$Lisp
0
+ StringMatch("([^ ]*)", headers)$Lisp
0
+ u:UniversalSegment(Integer)
0
+ u := segment(MatchBeginning(1)$Lisp+1,_
0
+ MatchEnd(1)$Lisp)$UniversalSegment(Integer)
0
+ reqtype:String := headers.u
0
+ WriteLine$Lisp concat ["request type: ",reqtype]
0
+ if reqtype = "GET" then
0
+ StringMatch("GET ([^ ]*)",headers)$Lisp
0
+ u:UniversalSegment(Integer)
0
+ u := segment(MatchBeginning(1)$Lisp+1,_
0
+ MatchEnd(1)$Lisp)$UniversalSegment(Integer)
0
+ if reqtype = "POST" then
0
+ StringMatch("command=(.*)$",headers)$Lisp
0
+ u:UniversalSegment(Integer)
0
+ u := segment(MatchBeginning(1)$Lisp+1,_
0
+ MatchEnd(1)$Lisp)$UniversalSegment(Integer)
0
+ getCommand(s,headers.u)
0
+ WriteLine("multiServ end")$Lisp
0
- multiServ(s:SExpression):Void ==
0
- WriteLine("multiServ")$Lisp
0
- -- read in the http headers
0
- STRING(READ_-CHAR_-NO_-HANG(s,NIL$Lisp,'EOF)$Lisp)$Lisp) ^= "EOF"_
0
- headers := concat [headers,char]
0
- StringMatch("([^ ]*)", headers)$Lisp
0
- u:UniversalSegment(Integer)
0
- u := segment(MatchBeginning(1)$Lisp+1,_
0
- MatchEnd(1)$Lisp)$UniversalSegment(Integer)
0
- reqtype:String := headers.u
0
- sayTeX$Lisp concat ["request type: ",reqtype]
0
- if reqtype = "GET" then
0
- StringMatch("GET ([^ ]*)",headers)$Lisp
0
- u:UniversalSegment(Integer)
0
- u := segment(MatchBeginning(1)$Lisp+1,_
0
- MatchEnd(1)$Lisp)$UniversalSegment(Integer)
0
- if reqtype = "POST" then
0
- StringMatch("command=(.*)$",headers)$Lisp
0
- u:UniversalSegment(Integer)
0
- u := segment(MatchBeginning(1)$Lisp+1,_
0
- MatchEnd(1)$Lisp)$UniversalSegment(Integer)
0
- getCommand(s,headers.u)
0
+ getFile(s:SExpression,pathvar:String):Void ==
0
+ WriteLine("getFile begin")$Lisp
0
+ if not null? PATHNAME_-NAME(PATHNAME(pathvar)$Lisp)$Lisp then
0
+ contentType:String := "application/xhtml+xml"
0
+ q := Open(pathvar)$Lisp
0
+ q := MAKE_-STRING_-INPUT_-STREAM("File doesn't exist")$Lisp
0
+ WriteLine("File does not exist.")$Lisp
0
+ q:=MAKE_-STRING_-INPUT_-STREAM("Problem with file path")$Lisp
0
+ WriteLine("begin reading file")$Lisp
0
+ r := MAKE_-STRING_-OUTPUT_-STREAM()$Lisp
0
+ SiCopyStream(q,r)$Lisp
0
+ filestream:String := GET_-OUTPUT_-STREAM_-STRING(r)$Lisp
0
+ filelength:String := string(#filestream)
0
+ WriteLine("end reading file")$Lisp
0
+ file := concat ["Content-Length: ",filelength,_
0
+ STRING(NewLine$Lisp)$Lisp,STRING(NewLine$Lisp)$Lisp,file]
0
+ file := concat ["Connection: close",STRING(NewLine$Lisp)$Lisp,file]
0
+ file := concat ["Content-Type: ",contentType,_
0
+ STRING(NewLine$Lisp)$Lisp,file]
0
+ file := concat ["HTTP/1.1 200 OK",STRING(NewLine$Lisp)$Lisp,file]
0
+ file := concat [file,filestream]
0
+ f:=MAKE_-STRING_-INPUT_-STREAM(file)$Lisp
0
+ SiCopyStream(f,s)$Lisp
0
+ WriteLine("getFile end")$Lisp
0
- getFile(s:SExpression,pathvar:String):Void ==
0
- WriteLine("getFile")$Lisp
0
- if not null? PATHNAME_-NAME(PATHNAME(pathvar)$Lisp)$Lisp then
0
- -- display contents of file
0
- q:=MAKE_-STRING_-INPUT_-STREAM("Problem with file path")$Lisp
0
- while (line :=STRING(READ_-LINE(q,NIL$Lisp,'EOF)$Lisp)$Lisp) ^= "EOF" _
0
- file := concat [file,line,STRING(NewLine$Lisp)$Lisp]
0
- ["Content-Length: ",string(#file),STRING(NewLine$Lisp)$Lisp,_
0
- STRING(NewLine$Lisp)$Lisp,file]
0
- file := concat ["Connection: close",STRING(NewLine$Lisp)$Lisp,file]
0
- ["Content-Type: application/xhtml+xml",STRING(NewLine$Lisp)$Lisp,file]
0
- file := concat ["HTTP/1.1 200 OK",STRING(NewLine$Lisp)$Lisp,file]
0
- f:=MAKE_-STRING_-INPUT_-STREAM(file)$Lisp
0
- SiCopyStream(f,s)$Lisp
0
- getCommand(s:SExpression,command:String):Void ==
0
- WriteLine$Lisp concat ["getCommand: ",command]
0
- SETQ(tmpmathml$Lisp, MAKE_-STRING_-OUTPUT_-STREAM()$Lisp)$Lisp
0
- SETQ(tmpalgebra$Lisp, MAKE_-STRING_-OUTPUT_-STREAM()$Lisp)$Lisp
0
- SETQ(savemathml$Lisp, _$texOutputStream$Lisp)$Lisp
0
- SETQ(savealgebra$Lisp, _$algebraOutputStream$Lisp)$Lisp
0
- SETQ(_$texOutputStream$Lisp,tmpmathml$Lisp)$Lisp
0
- SETQ(_$algebraOutputStream$Lisp,tmpalgebra$Lisp)$Lisp
0
+ getCommand(s:SExpression,command:String):Void ==
0
+ WriteLine$Lisp concat ["getCommand: ",command]
0
+ SETQ(tmpmathml$Lisp, MAKE_-STRING_-OUTPUT_-STREAM()$Lisp)$Lisp
0
+ SETQ(tmpalgebra$Lisp, MAKE_-STRING_-OUTPUT_-STREAM()$Lisp)$Lisp
0
+ SETQ(savemathml$Lisp, _$texOutputStream$Lisp)$Lisp
0
+ SETQ(savealgebra$Lisp, _$algebraOutputStream$Lisp)$Lisp
0
+ SETQ(_$texOutputStream$Lisp,tmpmathml$Lisp)$Lisp
0
+ SETQ(_$algebraOutputStream$Lisp,tmpalgebra$Lisp)$Lisp
0
-- parseAndInterpret$Lisp command
0
-- parseAndEvalStr$Lisp command
0
-- The previous two commands don't exit nicely when a syntactically
0
--- incorrect command is given to them.
They somehow need to be wrapped
0
+-- incorrect command is given to them.
They somehow need to be wrapped
0
-- in CATCH statements but I haven't figured out how to do this.
0
--- parseAndEvalToStringEqNum uses the following CATCH statements to
0
--- call parseAndEvalStr but when I try these they don't work. I get a
0
--- "NIL is not a valid identifier to use in AXIOM" message.
0
--- Using parseAndEvalToStringEqNum works and doesn't crash on a syntax error.
0
+-- parseAndEvalToStringEqNum uses the following CATCH statements to call
0
+-- parseAndEvalStr but when I try these they don't work. I get a
0
+-- "NIL is not a valid identifier to use in AXIOM" message. Using
0
+-- parseAndEvalToStringEqNum works and doesn't crash on a syntax error.
0
-- v := CATCH('SPAD__READER, _
0
-
CATCH('top__level, parseAndEvalStr$Lisp command)$Lisp)$Lisp
0
+
-- CATCH('top__level, parseAndEvalStr$Lisp command)$Lisp)$Lisp
0
-- v = 'restart => ['"error"]
0
- ans := string parseAndEvalToStringEqNum$Lisp command
0
- SETQ(resultmathml$Lisp,_
0
+ ans := string parseAndEvalToStringEqNum$Lisp command
0
+ SETQ(resultmathml$Lisp,_
0
GET_-OUTPUT_-STREAM_-STRING(_$texOutputStream$Lisp)$Lisp)$Lisp
0
-
SETQ(resultalgebra$Lisp,_
0
+
SETQ(resultalgebra$Lisp,_
0
GET_-OUTPUT_-STREAM_-STRING(_$algebraOutputStream$Lisp)$Lisp)$Lisp
0
- SETQ(_$texOutputStream$Lisp,savemathml$Lisp)$Lisp
0
- SETQ(_$algebraOutputStream$Lisp,savealgebra$Lisp)$Lisp
0
- CLOSE(tmpmathml$Lisp)$Lisp
0
- CLOSE(tmpalgebra$Lisp)$Lisp
0
- -- Since strings returned from axiom are going to be displayed in html
0
- -- I should really check for the characters &,<,> and replace them with
0
- -- At present I only check for ampersands in formatMessages.
0
- mathml:String := string(resultmathml$Lisp)
0
- algebra:String := string(resultalgebra$Lisp)
0
- algebra := formatMessages(algebra)
0
- -- At this point mathml contains the mathml for the output but does
0
- -- not include step number or type information. We should also save
0
- -- the command. I get the type and step number from the
0
- -- $internalHistoryTable
0
- axans:String := concat
0
- "<div class=_"stepnum_"> (", lastStep(), _
0
- ") -> ", command, "</div>" _
0
- "<div class=_"algebra_">", algebra, "</div>" _
0
- "<div id=_"answer_" class=_"mathml_">", mathml , "</div>" _
0
- "<div class=_"type_">Type: ",lastType(),"</div>"_
0
- WriteLine$Lisp concat ["mathml answer: ",mathml]
0
- WriteLine$Lisp concat ["algebra answer: ",algebra]
0
- q:=MAKE_-STRING_-INPUT_-STREAM(axans)$Lisp
0
- SiCopyStream(q,s)$Lisp
0
+ SETQ(_$texOutputStream$Lisp,savemathml$Lisp)$Lisp
0
+ SETQ(_$algebraOutputStream$Lisp,savealgebra$Lisp)$Lisp
0
+ CLOSE(tmpmathml$Lisp)$Lisp
0
+ CLOSE(tmpalgebra$Lisp)$Lisp
0
+ -- Since strings returned from axiom are going to be
0
+ -- displayed in html I
0
+ -- should really check for the characters &,<,> and
0
+ -- &,<,>. At present I only check for ampersands in
0
+ -- formatMessages. MathML should already be valid xml.
0
+ mathml:String := string(resultmathml$Lisp)
0
+ algebra:String := string(resultalgebra$Lisp)
0
+ algebra := formatMessages(algebra)
0
+ -- At this point mathml contains the mathml for the
0
+ -- output but does not
0
+ -- include step number or type information.
0
+ -- We should also save the command.
0
+ -- I get the type and step number from the $internalHistoryTable
0
+ axans:String := concat _
0
+ ["<div><div class=_"command_">(",lastStep(),") -> ",_
0
+ command,"</div><div class=_"algebra_">",_
0
+ algebra,"</div><div class=_"mathml_">",_
0
+ mathml,"</div><div class=_"type_">Type: ",_
0
+ lastType(),"</div></div>"]
0
+ WriteLine$Lisp concat ["mathml answer: ",mathml]
0
+ WriteLine$Lisp concat ["algebra answer: ",algebra]
0
+ q:=MAKE_-STRING_-INPUT_-STREAM(axans)$Lisp
0
+ SiCopyStream(q,s)$Lisp
0
-- The last history entry is the first item in the
0
--- $internalHistoryTable list so car(_$internalHistoryTable$Lisp)
0
--- selects it. Here's an example:
0
+-- $internalHistoryTable list so
0
+-- car(_$internalHistoryTable$Lisp) selects it. Here's an example:
0
-- (3 (x+y)**3 (% (value (Polynomial (Integer)) WRAPPED 1 y
0
--- (3 0 . 1) (2 1 x (1 0 . 3)) (1 1 x (2 0 . 3)) (0 1 x (3 0 . 1)))))
0
--- This corresponds to the input "(x+y)**3" being issued as the third
0
--- command after starting axiom.
0
--- The following line selects the type information.
0
- string cadr(cadar(cddar(_$internalHistoryTable$Lisp)$Lisp)$Lisp)$Lisp
0
+-- (3 0 . 1) (2 1 x (1 0 . 3)) (1 1 x (2 0 . 3)) (0 1 x (3 0 . 1)))))
0
+-- This corresponds to the input "(x+y)**3" being issued
0
+-- as the third command after
0
+-- starting axiom. The following line selects the type information.
0
+ string cadr(cadar(cddar(_$internalHistoryTable$Lisp)$Lisp)$Lisp)$Lisp
0
+ string car(car(_$internalHistoryTable$Lisp)$Lisp)$Lisp
0
+ formatMessages(str:String):String ==
0
+ WriteLine("formatMessages")$Lisp
0
+ -- I need to replace any ampersands with & and may also need to
0
+ -- replace < and > with < and >
0
+ strlist := split(str,char "&")
0
+ -- oops, if & is the last character in the string this method
0
+ -- will eliminate it. Need to redo this.
0
+ for s in strlist repeat
0
+ str := concat [str,s,"&"]
0
+ strlen:Integer := #str
0
+ str := str.(1..(#str - 5))
0
+ -- Here I split the string into lines and put each line in a "div".
0
+ strlist := split(str, char string NewlineChar$Lisp)
0
+ WriteLine("formatMessages1")$Lisp
0
+ WriteLine(concat strlist)$Lisp
0
+ for s in strlist repeat
0
+ str := concat [str,"<div>",s,"</div>"]
0
- string caar(_$internalHistoryTable$Lisp)$Lisp
0
+ getContentType(pathvar:String):String ==
0
+ WriteLine("getContentType begin")$Lisp
0
+ -- set default content type
0
+ contentType:String := "text/plain"
0
+ -- need to test for successful match?
0
+ StringMatch(".*\.(.*)$", pathvar)$Lisp
0
+ u:UniversalSegment(Integer)
0
+ u := segment(MatchBeginning(1)$Lisp+1,_
0
+ MatchEnd(1)$Lisp)$UniversalSegment(Integer)
0
+ extension:String := pathvar.u
0
+ WriteLine$Lisp concat ["file extension: ",extension]
0
+ -- test for extensions: html, htm, xml, xhtml, js, css, png, jpg, jpeg
0
+ if extension = "html" then
0
+ contentType:String := "text/html"
0
+ else if extension = "htm" then
0
+ contentType:String := "text/html"
0
+ else if extension = "xml" then
0
+ contentType:String := "text/xml"
0
+ else if extension = "xhtml" then
0
+ contentType:String := "application/xhtml+xml"
0
+ else if extension = "js" then
0
+ contentType:String := "text/javascript"
0
+ else if extension = "css" then
0
+ contentType:String := "text/css"
0
+ else if extension = "png" then
0
+ contentType:String := "image/png"
0
+ else if extension = "jpg" then
0
+ contentType:String := "image/jpeg"
0
+ else if extension = "jpeg" then
0
+ contentType:String := "image/jpeg"
0
+ WriteLine$Lisp concat ["Content-Type: ",contentType]
0
+ WriteLine("getContentType end")$Lisp
0
- formatMessages(str:String):String ==
0
- WriteLine("formatMessages")$Lisp
0
- -- I need to replace any ampersands with & and may also need to
0
- -- replace < and > with < and >
0
- strlist := split(str,char "&")
0
- for s in strlist repeat
0
- str := concat [str,s,"&"]
0
- strlen:Integer := #str
0
- str := str.(1..(#str - 5))
0
- -- Here I split the string into lines and put each line in a "div".
0
- strlist := split(str, char string NewlineChar$Lisp)
0
- WriteLine("formatMessages1")$Lisp
0
- WriteLine(concat strlist)$Lisp
0
- for s in strlist repeat
0
- str := concat [str,"<div>",s,"</div>"]
0
@@ -229,9 +278,9 @@ AxiomServer: public == private where
0
-- the documentation and/or other materials provided with the
0
--- - Neither the name of Arthur C. Ralfs nor the
0
--- names of its contributors may be used to endorse or promote products
0
--- derived from this software without specific prior written permission.
0
+-- - The name of Arthur C. Ralfs may not be used to endorse or promote
0
+-- products derived from this software without specific prior written
0
--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
0
--IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
Comments
No one has commented yet.