X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/9567837688897dd742899612a9701fc590f54326..2385c806df15d62fc4ec2cac7913a975e3bafa13:/Console.cpp diff --git a/Console.cpp b/Console.cpp index 77e9759..719e6f0 100644 --- a/Console.cpp +++ b/Console.cpp @@ -1,4 +1,4 @@ -/* Cycript - Remove Execution Server and Disassembler +/* Cycript - Inlining/Optimizing JavaScript Compiler * Copyright (C) 2009 Jay Freeman (saurik) */ @@ -66,6 +66,8 @@ #include +#include + static volatile enum { Working, Parsing, @@ -174,6 +176,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 +226,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; @@ -326,12 +332,17 @@ static void Console(apr_pool_t *pool, int client) { if (debug) std::cout << code << std::endl; + code = "with(Cycript.all){" + code + "}"; 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 +371,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(dlsym(RTLD_DEFAULT, "append_history")); + #ifdef CY_ATTACH pid_t pid(_not(pid_t)); #endif @@ -605,6 +618,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;