]> git.saurik.com Git - cycript.git/commitdiff
Added readline history writing and fixed NoRE unary * case.
authorJay Freeman (saurik) <saurik@saurik.com>
Fri, 30 Oct 2009 20:06:34 +0000 (20:06 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Fri, 30 Oct 2009 20:06:34 +0000 (20:06 +0000)
Console.cpp
Cycript.y.in
makefile

index 7f979633511ea6c9e6257af20e116cb6799aa7b1..754422e7fe88b3f40d56cf013176055bb15098dd 100644 (file)
@@ -62,6 +62,7 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <sys/un.h>
+#include <pwd.h>
 
 #include <apr_getopt.h>
 
@@ -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 ?: "<stdin>");
         cy::parser parser(driver);
index 1789d47b7aff735022da699a2e1390b08513df37..9055cb57bce93b38d239d6d7ba50fe6d3ed07d11 100644 (file)
@@ -153,11 +153,14 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
 %token SlashRight "/>"
 %token LeftSlash "</"
 
-%token At "@"
 %token ColonColon "::"
 %token PeriodPeriod ".."
 @end
 
+@begin E4X ObjectiveC
+%token At "@"
+@end
+
 %token Ampersand "&"
 %token AmpersandAmpersand "&&"
 %token AmpersandEqual "&="
@@ -319,6 +322,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
 %type <literal_> ArrayLiteral
 %type <expression_> AssigneeExpression
 %type <expression_> AssigneeExpressionNoBF
+%type <expression_> AssigneeExpressionNoRE
 %type <expression_> AssigneeExpressionNoWC
 %type <expression_> AssignmentExpression
 %type <assignment_> AssignmentExpression_
@@ -343,6 +347,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
 %type <statement_> BreakStatement
 %type <expression_> CallExpression
 %type <expression_> CallExpressionNoBF
+%type <expression_> CallExpressionNoRE
 %type <clause_> CaseBlock
 %type <clause_> CaseClause
 %type <clause_> CaseClausesOpt
@@ -385,7 +390,6 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
 %type <statement_> FunctionBody
 %type <statement_> FunctionDeclaration
 %type <expression_> FunctionExpression
-%type <expression_> FunctionExpression_
 %type <identifier_> Identifier
 %type <identifier_> IdentifierOpt
 %type <comprehension_> IfComprehension
@@ -398,6 +402,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
 %type <statement_> LabelledStatement
 %type <expression_> LeftHandSideExpression
 %type <expression_> LeftHandSideExpressionNoBF
+%type <expression_> LeftHandSideExpressionNoRE
 %type <expression_> LeftHandSideExpressionNoWC
 //%type <statement_> LetStatement
 %type <literal_> Literal
@@ -415,6 +420,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
 %type <expression_> MemberExpression
 %type <expression_> MemberExpression_
 %type <expression_> MemberExpressionNoBF
+%type <expression_> MemberExpressionNoRE
 %type <expression_> MemberExpressionNoWC
 %type <expression_> MultiplicativeExpression
 %type <expression_> MultiplicativeExpressionNoBF
@@ -422,15 +428,18 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
 %type <expression_> NewExpression
 %type <expression_> NewExpression_
 %type <expression_> NewExpressionNoBF
+%type <expression_> NewExpressionNoRE
 %type <expression_> NewExpressionNoWC
 %type <null_> NullLiteral
 %type <literal_> ObjectLiteral
 %type <expression_> PostfixExpression
 %type <expression_> PostfixExpressionNoBF
+%type <expression_> PostfixExpressionNoRE
 %type <expression_> PostfixExpressionNoWC
 %type <expression_> PrimaryExpression
 %type <expression_> PrimaryExpressionNo
 %type <expression_> PrimaryExpressionNoBF
+%type <expression_> PrimaryExpressionNoRE
 %type <expression_> PrimaryExpressionNoWC
 %type <expression_> PrimaryExpressionNoWC_
 @begin E4X
@@ -467,6 +476,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
 %type <expression_> UnaryExpression
 %type <expression_> UnaryExpression_
 %type <expression_> UnaryExpressionNoBF
+%type <expression_> UnaryExpressionNoRE
 %type <expression_> UnaryExpressionNoWC
 %type <declaration_> VariableDeclaration
 %type <declaration_> 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_
index 3e3006d38c48195127a655d8fb0088c213a14a86..18cea089b773917f2b169354a658758961edc79b 100644 (file)
--- 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)