/* Cycript - Optimizing JavaScript Compiler/Runtime
- * Copyright (C) 2009-2014 Jay Freeman (saurik)
+ * Copyright (C) 2009-2015 Jay Freeman (saurik)
*/
/* GNU Affero General Public License, Version 3 {{{ */
case Parsing:
longjmp(ctrlc_, 1);
case Running:
- throw "*** Ctrl-C";
+ CYCancel();
+ return;
case Sending:
return;
case Waiting:
CYOptions options;
CYContext context(options);
- CYStatement *statement(driver.program_->statements_);
+ CYStatement *statement(driver.program_->code_);
_assert(statement != NULL);
_assert(statement->next_ == NULL);
- CYExpress *express(dynamic_cast<CYExpress *>(driver.program_->statements_));
+ CYExpress *express(dynamic_cast<CYExpress *>(driver.program_->code_));
_assert(express != NULL);
- return express->expression_;
+ CYParenthetical *parenthetical(dynamic_cast<CYParenthetical *>(express->expression_));
+ _assert(parenthetical != NULL);
+
+ return parenthetical->expression_;
}
static int client_;
driver.program_->Replace(context);
- std::ostringstream str;
+ std::stringbuf str;
CYOutput out(str, options);
out << *driver.program_;
// need char *, not const char *
static char name_[] = "cycript";
-static char break_[] = " \t\n\"\\'`@$><=;|&{(" ")}" ".:[]";
+static char break_[] = " \t\n\"\\'`@><=;|&{(" ")}" ".:[]";
class History {
private:
}
void operator +=(const std::string &command) {
- add_history(command_.c_str());
+ add_history(command.c_str());
++histlines_;
}
};
static void Console(CYOptions &options) {
- CYPool pool;
-
- passwd *passwd;
- if (const char *username = getenv("LOGNAME"))
- passwd = getpwnam(username);
- else
- passwd = getpwuid(getuid());
+ std::string basedir;
+ if (const char *home = getenv("HOME"))
+ basedir = home;
+ else {
+ passwd *passwd;
+ if (const char *username = getenv("LOGNAME"))
+ passwd = getpwnam(username);
+ else
+ passwd = getpwuid(getuid());
+ basedir = passwd->pw_dir;
+ }
- std::string basedir(passwd->pw_dir);
basedir += "/.cycript";
mkdir(basedir.c_str(), 0700);
}
command_ += line;
+ command_ += "\n";
char *begin(line), *end(line + strlen(line));
while (char *nl = reinterpret_cast<char *>(memchr(begin, '\n', end - begin))) {
if (parser.parse() != 0 || !driver.errors_.empty()) {
for (CYDriver::Errors::const_iterator error(driver.errors_.begin()); error != driver.errors_.end(); ++error) {
- cy::position begin(error->location_.begin);
- if (begin.line != lines.size() || begin.column < lines.back().size() || error->warning_) {
- cy::position end(error->location_.end);
+ CYPosition begin(error->location_.begin);
+ if (begin.line != lines.size() + 1 || error->warning_) {
+ CYPosition end(error->location_.end);
if (begin.line != lines.size()) {
std::cerr << " | ";
std::cerr << " | ";
std::cerr << error->message_ << std::endl;
- history += command_;
+ history += command_.substr(0, command_.size() - 1);
goto restart;
}
}
driver.errors_.clear();
- command_ += '\n';
prompt = "cy> ";
goto read;
}
if (driver.program_ == NULL)
goto restart;
- std::ostringstream str;
+ std::stringbuf str;
CYOutput out(str, options);
Setup(out, driver, options, lower);
out << *driver.program_;
code = str.str();
}
- history += command_;
+ history += command_.substr(0, command_.size() - 1);
if (debug) {
std::cout << "cy= ";
}
}
-void InjectLibrary(pid_t pid);
+void InjectLibrary(pid_t, int, const char *const []);
int Main(int argc, char * const argv[], char const * const envp[]) {
bool tty(isatty(STDIN_FILENO));
// XXX: arg needs to be escaped in some horrendous way of doom
// XXX: this is a memory leak now because I just don't care enough
char *command;
- asprintf(&command, "ps axc|sed -e '/^ *[0-9]/{s/^ *\\([0-9]*\\)\\( *[^ ]*\\)\\{3\\} *-*\\([^ ]*\\)/\\3 \\1/;/^%s /{s/^[^ ]* //;q;};};d'", optarg);
+ int writ(asprintf(&command, "ps axc|sed -e '/^ *[0-9]/{s/^ *\\([0-9]*\\)\\( *[^ ]*\\)\\{3\\} *-*\\([^ ]*\\)/\\3 \\1/;/^%s /{s/^[^ ]* //;q;};};d'", optarg));
+ _assert(writ != -1);
if (FILE *pids = popen(command, "r")) {
char value[32];
memset(&address, 0, sizeof(address));
address.sun_family = AF_UNIX;
- sprintf(address.sun_path, "/tmp/.s.cy.%u", getpid());
+ const char *tmp;
+#if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__))
+ tmp = "/Library/Caches";
+#else
+ tmp = "/tmp";
+#endif
+
+ sprintf(address.sun_path, "%s/.s.cy.%u", tmp, getpid());
unlink(address.sun_path);
struct File {
_syscall(chmod(address.sun_path, 0777));
_syscall(listen(server, 1));
- InjectLibrary(pid);
+ const char *const argv[] = {address.sun_path, NULL};
+ InjectLibrary(pid, 1, argv);
client_ = _syscall(accept(server, NULL, NULL));
}
#else
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) {
- std::ostringstream str;
+ std::stringbuf str;
CYOutput out(str, options);
Setup(out, driver, options, true);
out << *driver.program_;