header and post request in variables, other tweaks

cvs
Slava Pestov 2004-08-18 00:44:57 +00:00
parent 86c5f5956c
commit 5c00ef85dd
17 changed files with 138 additions and 82 deletions

View File

@ -1,5 +1,5 @@
CC = gcc34
CFLAGS = -Os -march=pentium4 -Wall -Wno-long-long -fomit-frame-pointer
CC = gcc
CFLAGS = -g # -Os -march=pentium4 -Wall -Wno-long-long -fomit-frame-pointer
LIBS = -lm
STRIP = strip
@ -16,7 +16,7 @@ OBJS = native/arithmetic.o native/array.o native/bignum.o \
f: $(OBJS)
$(CC) $(LIBS) -o $@ $(OBJS)
$(STRIP) $@
# $(STRIP) $@
clean:
rm -f $(OBJS)

View File

@ -40,6 +40,8 @@
+ listener/plugin:
- completion: don't show automatically
- debug sidekick
- completion in the listener
- special completion for USE:/IN:
- fedit broken with listener

View File

@ -9,14 +9,14 @@
if(sel == null)
view.toolkit.beep();
else
factor.jedit.FactorPlugin.eval(view,sel);
factorEval(view,sel);
</CODE>
</ACTION>
<ACTION NAME="factor-run-file">
<CODE>
buffer.save(view,null);
VFSManager.waitForRequests();
factor.jedit.FactorPlugin.eval(view,
factorEval(view,
"\""
+ MiscUtilities.charsToEscapes(buffer.path)
+ "\" run-file");
@ -26,7 +26,7 @@
<CODE>
if(textArea.selectionCount == 0)
textArea.selectWord();
factor.jedit.FactorPlugin.eval(view,
factorEval(view,
"\""
+ MiscUtilities.charsToEscapes(
textArea.selectedText)
@ -35,40 +35,28 @@
</ACTION>
<ACTION NAME="factor-see">
<CODE>
data = sidekick.SideKickParsedData.getParsedData(view);
if(data instanceof factor.jedit.FactorParsedData)
{
if(textArea.selectionCount == 0)
textArea.selectWord();
factor.jedit.FactorPlugin.eval(view,
"\""
+ MiscUtilities.charsToEscapes(
textArea.selectedText)
+ "\" "
+ factor.FactorReader.unparseObject(data.use)
+ " search see");
}
else
view.toolkit.beep();
factorWordOperation(view,"see");
</CODE>
</ACTION>
<ACTION NAME="factor-edit">
<CODE>
factorWordOperation(view,"USE: jedit jedit");
</CODE>
</ACTION>
<ACTION NAME="factor-usages">
<CODE>
data = sidekick.SideKickParsedData.getParsedData(view);
if(data instanceof factor.jedit.FactorParsedData)
{
if(textArea.selectionCount == 0)
textArea.selectWord();
factor.jedit.FactorPlugin.eval(view,
"\""
+ MiscUtilities.charsToEscapes(
textArea.selectedText)
+ "\" "
+ factor.FactorReader.unparseObject(data.use)
+ " search usages.");
}
factorWordOperation(view,"usages.");
</CODE>
</ACTION>
<ACTION NAME="factor-balance">
<CODE>
if(textArea.selectedText == null)
textArea.toolkit.beep();
else
view.toolkit.beep();
{
factorEval(view,
"[ " + textArea.selectedText + " ] balance");
}
</CODE>
</ACTION>
</ACTIONS>

View File

@ -47,6 +47,7 @@
<include name="factor/*.class"/>
<include name="factor/**/*.class"/>
<include name="factor/**/*.props"/>
<include name="factor/**/*.bsh"/>
<include name="*.xml"/>
<include name="library/**/*.factor"/>
<include name="org/**/*.class"/>

View File

@ -77,23 +77,22 @@ public class FactorCompletion extends SideKickCompletion
}
public boolean handleKeystroke(int selectedIndex, char keyChar)
{
if(keyChar == '\t')
insert(selectedIndex);
else
{
Macros.Recorder recorder = view.getMacroRecorder();
boolean ws = (ReadTable.DEFAULT_READTABLE
.getCharacterType(keyChar)
== ReadTable.WHITESPACE);
if(ws)
insert(selectedIndex);
if(keyChar != '\n')
{
if(recorder != null)
recorder.recordInput(1,keyChar,false);
textArea.userInput(keyChar);
}
boolean ws = (ReadTable.DEFAULT_READTABLE
.getCharacterType(keyChar)
== ReadTable.WHITESPACE);
return !ws;
}

View File

@ -31,6 +31,7 @@ package factor.jedit;
import factor.listener.FactorListenerPanel;
import factor.FactorInterpreter;
import java.io.InputStreamReader;
import org.gjt.sp.jedit.gui.*;
import org.gjt.sp.jedit.*;
@ -43,7 +44,9 @@ public class FactorPlugin extends EditPlugin
//{{{ start() method
public void start()
{
/* Macros.registerHandler(new FactorMacroHandler()); */
String path = "/factor/jedit/factor.bsh";
BeanShell.runScript(null,path,new InputStreamReader(
getClass().getResourceAsStream(path)),false);
} //}}}
//{{{ getInterpreter() method

View File

@ -16,15 +16,19 @@ plugin.factor.jedit.FactorPlugin.menu=factor \
factor-run-file \
factor-eval-selection \
factor-apropos \
factor-edit \
factor-see \
factor-usages
factor-usages \
factor-balance
factor.label=Factor Listener
factor-run-file.label=Run current file
factor-eval-selection.label=Evaluate selection
factor-apropos.label=Apropos at caret
factor-see.label=See word at caret
factor-edit.label=Edit word at caret
factor-usages.label=Word usages at caret
factor-balance.label=Balance selection
factor.title=Factor

View File

@ -158,6 +158,13 @@ public class FactorSideKickParser extends SideKickParser
return true;
} //}}}
//{{{ isWhitespace() method
private boolean isWhitespace(char ch)
{
return (ReadTable.DEFAULT_READTABLE.getCharacterType(ch)
== ReadTable.WHITESPACE);
} //}}}
//{{{ complete() method
/**
* Returns completions suitable for insertion at the specified position.
@ -182,12 +189,20 @@ public class FactorSideKickParser extends SideKickParser
int lineStart = buffer.getLineStartOffset(caretLine);
String text = buffer.getText(lineStart,caret - lineStart);
/* Don't complete in the middle of a word */
int lineEnd = buffer.getLineEndOffset(caretLine) - 1;
if(caret != lineEnd)
{
String end = buffer.getText(caret,lineEnd - caret);
if(!isWhitespace(end.charAt(0)))
return null;
}
int wordStart = 0;
for(int i = text.length() - 1; i >= 0; i--)
{
char ch = text.charAt(i);
if(ReadTable.DEFAULT_READTABLE.getCharacterType(ch)
== ReadTable.WHITESPACE)
if(isWhitespace(ch))
{
wordStart = i + 1;
break;
@ -195,6 +210,11 @@ public class FactorSideKickParser extends SideKickParser
}
String word = text.substring(wordStart);
/* Don't complete empty string */
if(word.length() == 0)
return null;
List completions = getCompletions(data.use,word);
if(completions.size() == 0)

View File

@ -67,5 +67,20 @@ USE: url-encoding
: content-length ( alist -- length )
"Content-Length" swap assoc dec> ;
: read-post-request ( -- string )
read-header content-length dup [ read# url-decode ] when ;
: read-post-request ( header -- string )
content-length dup [ read# url-decode ] when ;
: log-user-agent ( alist -- )
"User-Agent" swap assoc* [
unswons <% % ": " % % %> log
] when* ;
: with-request ( method quot -- )
[
read-header "header" set
"header" get log-user-agent
swap "post" = [
"header" get read-post-request "response" set
] when
call
] with-scope ;

View File

@ -42,6 +42,14 @@ USE: strings
USE: httpd-responder
USE: url-encoding
: httpd-log-stream ( -- stream )
#! Set httpd-log-file to save httpd log to a file.
"httpd-log-file" get dup [
<filecr>
] [
drop "stdio" get
] ifte ;
: bad-request ( -- )
"400 Bad request" httpd-error ;
@ -97,11 +105,12 @@ USE: url-encoding
dup accept httpd-client
] while ;
: httpd ( port -- )
[
: (httpd) ( port -- )
<server> [
httpd-loop
] [
swap fclose clear-quit-flag rethrow
] catch
] with-logging ;
] catch ;
: httpd ( port -- )
[ httpd-log-stream "log" set (httpd) ] with-scope ;

View File

@ -28,6 +28,7 @@
IN: httpd-responder
USE: combinators
USE: kernel
USE: lists
USE: logging
USE: namespaces
@ -40,10 +41,12 @@ USE: httpd
: <responder> ( -- responder )
<namespace> [
( url -- )
[
drop "GET method not implemented" httpd-error
] "get" set
( url -- )
[
drop "POST method not implemented" httpd-error
] "post" set
@ -62,7 +65,9 @@ USE: httpd
dup f-or-"" [ drop "default-argument" get ] when ;
: call-responder ( method argument responder -- )
[ responder-argument swap get call ] bind ;
[
over [ responder-argument swap get call ] with-request
] bind ;
: no-such-responder ( name -- )
"404 no such responder: " swap cat2 httpd-error ;

View File

@ -114,7 +114,8 @@ USE: httpd-responder
"wiki" get [ put ] bind ;
: wiki-post-responder ( argument -- )
read-post-request dup [
#! Handle a page edit.
"response" get dup [
"text=" str-head? dup [
2dup set-wiki-page serve-existing-page
] [

View File

@ -48,3 +48,6 @@ USE: unparser
: with-logging ( quot -- )
[ "stdio" get "log" set call ] with-scope ;
: with-log-file ( file quot -- )
[ swap <filecr> "log" set call ] with-scope ;

View File

@ -37,10 +37,15 @@ USE: strings
: stdout 1 getenv ;
: stderr 2 getenv ;
: yield ( -- )
next-io-task dup [
call
] [
drop yield
] ifte ;
: flush-fd ( port -- )
[
swap add-write-io-task next-io-task call
] callcc0 drop ;
[ swap add-write-io-task yield ] callcc0 drop ;
: wait-to-write ( len port -- )
tuck can-write? [ drop ] [ flush-fd ] ifte ;
@ -51,9 +56,7 @@ USE: strings
over wait-to-write write-fd-8 ;
: fill-fd ( port -- )
[
swap add-read-line-io-task next-io-task call
] callcc0 drop ;
[ swap add-read-line-io-task yield ] callcc0 drop ;
: wait-to-read-line ( port -- )
dup can-read-line? [ drop ] [ fill-fd ] ifte ;
@ -62,9 +65,7 @@ USE: strings
dup wait-to-read-line read-line-fd-8 dup [ sbuf>str ] when ;
: wait-to-accept ( socket -- )
[
swap add-accept-io-task next-io-task call
] callcc0 drop ;
[ swap add-accept-io-task yield ] callcc0 drop ;
: blocking-accept ( socket -- host port in out )
dup wait-to-accept accept-fd ;

View File

@ -224,14 +224,21 @@ CELL next_io_task(void)
CELL callback;
fd_set except_fd_set;
int i;
FD_ZERO(&except_fd_set);
if(!reading && !writing)
critical_error("next_io_task() called with no IO tasks",0);
select(read_fd_count > write_fd_count
? read_fd_count : write_fd_count,
(reading ? &read_fd_set : NULL),
(writing ? &write_fd_set : NULL),
NULL,NULL);
select(read_fd_count > write_fd_count ? read_fd_count : write_fd_count,
&read_fd_set,&write_fd_set,&except_fd_set,NULL);
for(i = 0; i < 100; i++)
{
if(FD_ISSET(i,&except_fd_set))
exit(1);
}
callback = perform_io_tasks(&read_fd_set,read_fd_count,read_io_tasks);
if(callback != F)
@ -242,15 +249,7 @@ CELL next_io_task(void)
void primitive_next_io_task(void)
{
CELL callback;
for(;;)
{
callback = next_io_task();
if(callback != F)
break;
}
dpush(callback);
dpush(next_io_task());
}
void collect_io_tasks(void)

View File

@ -14,6 +14,7 @@ void init_signals(void)
sigaction(SIGFPE,&custom_sigaction,NULL);
sigaction(SIGBUS,&custom_sigaction,NULL);
sigaction(SIGSEGV,&custom_sigaction,NULL);
sigaction(SIGPIPE,&custom_sigaction,NULL);
}
void clear_environment(void)

View File

@ -48,6 +48,8 @@ CELL accept_connection(PORT* p)
struct sockaddr_in clientname;
size_t size = sizeof(clientname);
int oobinline = 1;
int new = accept(p->fd,(struct sockaddr *)&clientname,&size);
if(new < 0)
{
@ -57,6 +59,9 @@ CELL accept_connection(PORT* p)
io_error(NULL,__FUNCTION__);
}
/* if(setsockopt(new,SOL_SOCKET,SO_OOBINLINE,&oobinline,sizeof(int)) < 0)
io_error(NULL,__FUNCTION__); */
p->client_host = tag_object(from_c_string(inet_ntoa(
clientname.sin_addr)));
p->client_port = tag_fixnum(ntohs(clientname.sin_port));