From b15898455c67b0ec79886a244d436ea1097552b8 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Fri, 30 Oct 2009 20:06:34 +0000 Subject: [PATCH] Added readline history writing and fixed NoRE unary * case. --- Console.cpp | 24 ++++++++++++++++-- Cycript.y.in | 72 ++++++++++++++++++++++++++++++++++++++++++++-------- makefile | 2 +- 3 files changed, 85 insertions(+), 13 deletions(-) diff --git a/Console.cpp b/Console.cpp index 7f97963..754422e 100644 --- a/Console.cpp +++ b/Console.cpp @@ -62,6 +62,7 @@ #include #include #include +#include #include @@ -173,7 +174,20 @@ void Run(int socket, std::string &code, FILE *fout = NULL, bool expand = false) Run(socket, code.c_str(), code.size(), fout, expand); } -static void Console(int socket) { +static void Console(apr_pool_t *pool, int socket) { + passwd *passwd; + if (const char *username = getenv("LOGNAME")) + passwd = getpwnam(username); + else + passwd = getpwuid(getuid()); + + const char *basedir(apr_psprintf(pool, "%s/.cycript", passwd->pw_dir)); + const char *histfile(apr_psprintf(pool, "%s/history", basedir)); + size_t histlines(0); + + mkdir(basedir, 0700); + read_history(histfile); + bool bypass(false); bool debug(false); bool expand(false); @@ -227,6 +241,7 @@ static void Console(int socket) { fflush(fout); } add_history(line); + ++histlines; goto restart; } } @@ -280,6 +295,7 @@ static void Console(int socket) { std::cerr << error->message_ << std::endl; add_history(command.c_str()); + ++histlines; goto restart; } } @@ -306,6 +322,7 @@ static void Console(int socket) { } add_history(command.c_str()); + ++histlines; if (debug) std::cout << code << std::endl; @@ -313,6 +330,9 @@ static void Console(int socket) { Run(socket, code, fout, expand); } + _syscall(close(_syscall(open(histfile, O_CREAT | O_WRONLY, 0600)))); + append_history(histlines, histfile); + fputs("\n", fout); fflush(fout); } @@ -476,7 +496,7 @@ int main(int argc, char const * const argv[], char const * const envp[]) { #endif if (script == NULL && tty) - Console(socket); + Console(pool, socket); else { CYDriver driver(script ?: ""); cy::parser parser(driver); diff --git a/Cycript.y.in b/Cycript.y.in index 1789d47..9055cb5 100644 --- a/Cycript.y.in +++ b/Cycript.y.in @@ -153,11 +153,14 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %token SlashRight "/>" %token LeftSlash " ArrayLiteral %type AssigneeExpression %type AssigneeExpressionNoBF +%type AssigneeExpressionNoRE %type AssigneeExpressionNoWC %type AssignmentExpression %type AssignmentExpression_ @@ -343,6 +347,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type BreakStatement %type CallExpression %type CallExpressionNoBF +%type CallExpressionNoRE %type CaseBlock %type CaseClause %type CaseClausesOpt @@ -385,7 +390,6 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type FunctionBody %type FunctionDeclaration %type FunctionExpression -%type FunctionExpression_ %type Identifier %type IdentifierOpt %type IfComprehension @@ -398,6 +402,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type LabelledStatement %type LeftHandSideExpression %type LeftHandSideExpressionNoBF +%type LeftHandSideExpressionNoRE %type LeftHandSideExpressionNoWC //%type LetStatement %type Literal @@ -415,6 +420,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type MemberExpression %type MemberExpression_ %type MemberExpressionNoBF +%type MemberExpressionNoRE %type MemberExpressionNoWC %type MultiplicativeExpression %type MultiplicativeExpressionNoBF @@ -422,15 +428,18 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type NewExpression %type NewExpression_ %type NewExpressionNoBF +%type NewExpressionNoRE %type NewExpressionNoWC %type NullLiteral %type ObjectLiteral %type PostfixExpression %type PostfixExpressionNoBF +%type PostfixExpressionNoRE %type PostfixExpressionNoWC %type PrimaryExpression %type PrimaryExpressionNo %type PrimaryExpressionNoBF +%type PrimaryExpressionNoRE %type PrimaryExpressionNoWC %type PrimaryExpressionNoWC_ @begin E4X @@ -467,6 +476,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type UnaryExpression %type UnaryExpression_ %type UnaryExpressionNoBF +%type UnaryExpressionNoRE %type UnaryExpressionNoWC %type VariableDeclaration %type VariableDeclarationNoIn @@ -716,6 +726,13 @@ PrimaryExpressionNoBF @end ; +PrimaryExpressionNoRE + : PrimaryExpressionNoWC_ { $$ = $1; } +@begin E4X + | PrimaryExpressionWC { $$ = $1; } +@end + ; + PrimaryExpressionNoWC_ : PrimaryExpressionBF { $$ = $1; } | PrimaryExpressionNo { $$ = $1; } @@ -803,7 +820,7 @@ MemberAccess MemberExpression : PrimaryExpression { $$ = $1; } - | FunctionExpression { $$ = $1; } + | LexSetRegExp FunctionExpression { $$ = $2; } | MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; } | LexSetRegExp MemberExpression_ { $$ = $2; } ; @@ -814,9 +831,16 @@ MemberExpressionNoBF | MemberExpression_ { $$ = $1; } ; +MemberExpressionNoRE + : PrimaryExpressionNoRE { $$ = $1; } + | FunctionExpression { $$ = $1; } + | MemberExpressionNoRE MemberAccess { $2->SetLeft($1); $$ = $2; } + | MemberExpression_ { $$ = $1; } + ; + MemberExpressionNoWC : PrimaryExpression { $$ = $1; } - | FunctionExpression { $$ = $1; } + | LexSetRegExp FunctionExpression { $$ = $2; } | MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; } | LexSetRegExp MemberExpression_ { $$ = $2; } ; @@ -835,6 +859,11 @@ NewExpressionNoBF | NewExpression_ { $$ = $1; } ; +NewExpressionNoRE + : MemberExpressionNoRE { $$ = $1; } + | NewExpression_ { $$ = $1; } + ; + NewExpressionNoWC : MemberExpressionNoWC { $$ = $1; } | LexSetRegExp NewExpression_ { $$ = $2; } @@ -852,6 +881,12 @@ CallExpressionNoBF | CallExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; } ; +CallExpressionNoRE + : PrimaryExpressionNoRE Arguments { $$ = new(driver.pool_) CYCall($1, $2); } + | CallExpressionNoRE Arguments { $$ = new(driver.pool_) CYCall($1, $2); } + | CallExpressionNoRE MemberAccess { $2->SetLeft($1); $$ = $2; } + ; + ArgumentList_ : "," ArgumentList { $$ = $2; } | { $$ = NULL; } @@ -880,6 +915,11 @@ LeftHandSideExpressionNoBF | CallExpressionNoBF { $$ = $1; } ; +LeftHandSideExpressionNoRE + : NewExpressionNoRE { $$ = $1; } + | CallExpressionNoRE { $$ = $1; } + ; + LeftHandSideExpressionNoWC : NewExpressionNoWC { $$ = $1; } | CallExpression { $$ = $1; } @@ -898,6 +938,12 @@ PostfixExpressionNoBF | LeftHandSideExpressionNoBF "--" { $$ = new(driver.pool_) CYPostDecrement($1); } ; +PostfixExpressionNoRE + : AssigneeExpressionNoRE { $$ = $1; } + | LeftHandSideExpressionNoRE "++" { $$ = new(driver.pool_) CYPostIncrement($1); } + | LeftHandSideExpressionNoRE "--" { $$ = new(driver.pool_) CYPostDecrement($1); } + ; + PostfixExpressionNoWC : AssigneeExpressionNoWC { $$ = $1; } | LeftHandSideExpression "++" { $$ = new(driver.pool_) CYPostIncrement($1); } @@ -929,6 +975,11 @@ UnaryExpressionNoBF | UnaryExpression_ { $$ = $1; } ; +UnaryExpressionNoRE + : PostfixExpressionNoRE { $$ = $1; } + | UnaryExpression_ { $$ = $1; } + ; + UnaryExpressionNoWC : PostfixExpressionNoWC { $$ = $1; } | LexSetRegExp UnaryExpression_ { $$ = $2; } @@ -1213,6 +1264,11 @@ AssigneeExpressionNoBF | UnaryAssigneeExpression { $$ = $1; } ; +AssigneeExpressionNoRE + : LeftHandSideExpressionNoRE { $$ = $1; } + | UnaryAssigneeExpression { $$ = $1; } + ; + AssigneeExpressionNoWC : LeftHandSideExpressionNoWC { $$ = $1; } | LexSetRegExp UnaryAssigneeExpression { $$ = $2; } @@ -1507,12 +1563,8 @@ FunctionDeclaration : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionStatement($2, $4, $7); } ; -FunctionExpression_ - : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionExpression($2, $4, $7); } - ; - FunctionExpression - : LexSetRegExp FunctionExpression_ { $$ = $2; } + : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionExpression($2, $4, $7); } ; FormalParameterList_ @@ -1678,7 +1730,7 @@ PrimaryExpressionNo @begin C /* Cycript (C): Pointer Indirection/Addressing {{{ */ UnaryAssigneeExpression - : "*" UnaryExpression { $$ = new(driver.pool_) CYIndirect($2); } + : "*" UnaryExpressionNoRE { $$ = new(driver.pool_) CYIndirect($2); } ; UnaryExpression_ diff --git a/makefile b/makefile index 3e3006d..18cea08 100644 --- a/makefile +++ b/makefile @@ -26,7 +26,7 @@ code += Cycript.tab.o lex.cy.o code += Network.o Parser.o code += JavaScriptCore.o Library.o -filters := C E4X +filters := C #E4X ldid := true dll := so apr := $(shell apr-1-config --link-ld) -- 2.47.2