]> git.saurik.com Git - cycript.git/blobdiff - Console.cpp
Optimized the variable renamer to rename more variables to 'a'.
[cycript.git] / Console.cpp
index 77e9759a7e558e7c50e1164070921e57fecae6bc..65eeb4f08a472db52db8c1d62601b2dcc35c2957 100644 (file)
@@ -1,4 +1,4 @@
-/* Cycript - Remove Execution Server and Disassembler
+/* Cycript - Inlining/Optimizing JavaScript Compiler
  * Copyright (C) 2009  Jay Freeman (saurik)
 */
 
 
 #include "cycript.hpp"
 
+#ifdef CY_EXECUTE
+#include "JavaScript.hpp"
+#endif
+
 #include <cstdio>
 #include <sstream>
 
@@ -66,6 +70,8 @@
 
 #include <apr_getopt.h>
 
+#include <dlfcn.h>
+
 static volatile enum {
     Working,
     Parsing,
@@ -109,7 +115,8 @@ void Setup(CYDriver &driver, cy::parser &parser) {
 void Setup(CYOutput &out, CYDriver &driver) {
     out.pretty_ = pretty_;
 
-    CYContext context(driver.pool_);
+    CYOptions options;
+    CYContext context(driver.pool_, options);
     driver.program_->Replace(context);
 }
 
@@ -174,6 +181,8 @@ void Run(int client, std::string &code, FILE *fout = NULL, bool expand = false)
     Run(client, code.c_str(), code.size(), fout, expand);
 }
 
+int (*append_history$)(int, const char *);
+
 static void Console(apr_pool_t *pool, int client) {
     passwd *passwd;
     if (const char *username = getenv("LOGNAME"))
@@ -222,6 +231,8 @@ static void Console(apr_pool_t *pool, int client) {
         mode_ = Working;
         if (line == NULL)
             break;
+        if (line[0] == '\0')
+            goto read;
 
         if (!extra) {
             extra = true;
@@ -314,7 +325,8 @@ static void Console(apr_pool_t *pool, int client) {
                 code = command;
             else {
                 std::ostringstream str;
-                CYOutput out(str);
+                CYOptions options;
+                CYOutput out(str, options);
                 Setup(out, driver);
                 out << *driver.program_;
                 code = str.str();
@@ -330,8 +342,12 @@ static void Console(apr_pool_t *pool, int client) {
         Run(client, code, fout, expand);
     }
 
-    _syscall(close(_syscall(open(histfile, O_CREAT | O_WRONLY, 0600))));
-    append_history(histlines, histfile);
+    if (append_history$ != NULL) {
+        _syscall(close(_syscall(open(histfile, O_CREAT | O_WRONLY, 0600))));
+        (*append_history$)(histlines, histfile);
+    } else {
+        write_history(histfile);
+    }
 
     fputs("\n", fout);
     fflush(fout);
@@ -360,6 +376,8 @@ int Main(int argc, char const * const argv[], char const * const envp[]) {
     bool tty(isatty(STDIN_FILENO));
     bool compile(false);
 
+    append_history$ = reinterpret_cast<int (*)(int, const char *)>(dlsym(RTLD_DEFAULT, "append_history"));
+
 #ifdef CY_ATTACH
     pid_t pid(_not(pid_t));
 #endif
@@ -585,11 +603,13 @@ int Main(int argc, char const * const argv[], char const * const envp[]) {
             for (CYDriver::Errors::const_iterator i(driver.errors_.begin()); i != driver.errors_.end(); ++i)
                 std::cerr << i->location_.begin << ": " << i->message_ << std::endl;
         } else if (driver.program_ != NULL)
-            if (client != -1)
-                Run(client, start, end - start, stdout);
-            else {
+            if (client != -1) {
+                std::string code(start, end-start);
+                Run(client, code, stdout);
+            } else {
                 std::ostringstream str;
-                CYOutput out(str);
+                CYOptions options;
+                CYOutput out(str, options);
                 Setup(out, driver);
                 out << *driver.program_;
                 std::string code(str.str());
@@ -605,6 +625,7 @@ int Main(int argc, char const * const argv[], char const * const envp[]) {
 
 int main(int argc, char const * const argv[], char const * const envp[]) {
     apr_status_t status(apr_app_initialize(&argc, &argv, &envp));
+
     if (status != APR_SUCCESS) {
         fprintf(stderr, "apr_app_initialize() != APR_SUCCESS\n");
         return 1;