]> git.saurik.com Git - cycript.git/commitdiff
Added -p <name> and updated todo.
authorJay Freeman (saurik) <saurik@saurik.com>
Fri, 30 Oct 2009 23:11:53 +0000 (23:11 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Fri, 30 Oct 2009 23:11:53 +0000 (23:11 +0000)
Console.cpp
makefile
todo.txt

index 754422e7fe88b3f40d56cf013176055bb15098dd..ef3de637a7e63dee7342635ce3495da05fc7dae5 100644 (file)
@@ -388,7 +388,7 @@ int main(int argc, char const * const argv[], char const * const envp[]) {
                 fprintf(stderr,
                     "usage: cycript [-c]"
 #ifdef CY_ATTACH
-                    " [-p <pid>]"
+                    " [-p <pid|name>]"
 #endif
                     " [<script> [<arg>...]]\n"
                 );
@@ -428,10 +428,51 @@ int main(int argc, char const * const argv[], char const * const envp[]) {
             case 'p': {
                 size_t size(strlen(arg));
                 char *end;
+
                 pid = strtoul(arg, &end, 0);
                 if (arg + size != end) {
-                    fprintf(stderr, "invalid pid for -p\n");
-                    return 1;
+                    // XXX: arg needs to be escaped in some horrendous way of doom
+                    const char *command(apr_psprintf(pool, "ps axc|sed -e '/^ *[0-9]/{s/^ *\\([0-9]*\\)\\( *[^ ]*\\)\\{3\\} *-*\\([^ ]*\\)/\\3 \\1/;/^%s /{s/^[^ ]* //;q;};};d'", arg));
+
+                    if (FILE *pids = popen(command, "r")) {
+                        char value[32];
+                        size = 0;
+
+                        for (;;) {
+                            size_t read(fread(value + size, 1, sizeof(value) - size, pids));
+                            if (read == 0)
+                                break;
+                            else {
+                                size += read;
+                                if (size == sizeof(value)) {
+                                    pid = _not(pid_t);
+                                    goto pclose;
+                                }
+                            }
+                        }
+
+                      size:
+                        if (size == 0)
+                            goto pclose;
+                        if (value[size - 1] == '\n') {
+                            --size;
+                            goto size;
+                        }
+
+                        value[size] = '\0';
+                        size = strlen(value);
+                        pid = strtoul(value, &end, 0);
+                        if (value + size != end)
+                            pid = _not(pid_t);
+
+                      pclose:
+                        _syscall(pclose(pids));
+                    }
+
+                    if (pid == _not(pid_t)) {
+                        fprintf(stderr, "invalid pid for -p\n");
+                        return 1;
+                    }
                 }
             } break;
 #endif
index 18cea089b773917f2b169354a658758961edc79b..fb9a6c8c49538b474bcc0384fc59ad15a15b0439 100644 (file)
--- a/makefile
+++ b/makefile
@@ -45,8 +45,8 @@ ifneq ($(shell which gnustep-config 2>/dev/null),)
 endif
 endif
 
-flags += -g3 -O0 -DYYDEBUG=1
-#flags += -g0 -O3
+#flags += -g3 -O0 -DYYDEBUG=1
+flags += -g0 -O3
 flags += -Wall -Werror -Wno-parentheses #-Wno-unused
 flags += -fPIC -fno-common
 flags += -I. -I$(shell apr-1-config --includedir)
index be2776aa0a1173fa49f135880fe983e20376eb33..e6a54bc04ba80e8159f1982e79936a9eaa74f2d1 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -1,10 +1,8 @@
 unicode identifier support (native and \u)
-object literal compilation should use numerify strings
 support unions (right now 0-1 fields parsed as struct)
 \\\n escapes in strings aren't handled in the console
 look into what String is, and whether to bridge it
 the console frontend's error handling, well, doesn't
-setup a default hook mechanism for ffi_call passthrough
 some JS callbacks don't use exception pointers at all...
 a newline needs to not be allowed after a unary *
 finish implementing default xml namespace statement