X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/0c862573814a40ff60bc3bac0c0effd3dfe84b20..db5e284073ce1f951343c5825a7e4d64d159582b:/Application.mm diff --git a/Application.mm b/Application.mm index 7e3afdb..106c7dd 100644 --- a/Application.mm +++ b/Application.mm @@ -1,63 +1,7 @@ -#include -#include +#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -#define _trace() do { \ - CFLog(kCFLogLevelNotice, CFSTR("_trace(%u)"), __LINE__); \ -} while (false) - -JSContextRef JSGetContext(void); -void CYThrow(JSContextRef context, id error, JSValueRef *exception); -CFStringRef JSValueToJSONCopy(JSContextRef context, JSValueRef value); +int CYConsole(FILE *in, FILE *out, FILE *err); int main() { - for (;;) { - NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); - - std::cout << ">>> " << std::flush; - - std::string line; - if (!std::getline(std::cin, line)) - break; - - JSStringRef script(JSStringCreateWithUTF8CString(line.c_str())); - - JSContextRef context(JSGetContext()); - - JSValueRef exception(NULL); - JSValueRef result(JSEvaluateScript(context, script, NULL, NULL, 0, &exception)); - JSStringRelease(script); - - if (exception != NULL) - result = exception; - - if (!JSValueIsUndefined(context, result)) { - CFStringRef json; - - @try { json: - json = JSValueToJSONCopy(context, result); - } @catch (id error) { - CYThrow(context, error, &result); - goto json; - } - - std::cout << [reinterpret_cast(json) UTF8String] << std::endl; - CFRelease(json); - } - - [pool release]; - } - - return 0; + return CYConsole(stdin, stdout, stderr); }