From 2916a2acd45a0d828c550be3f31e61022974cf18 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sat, 20 Feb 2010 22:41:27 -0800 Subject: [PATCH] Remove '--' from command line parsing --- AUTHORS | 1 + src/node.cc | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/AUTHORS b/AUTHORS index e50a138..bdf4b8a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -51,3 +51,4 @@ Michael Stillwell Yuichiro MASUI Mark Hansen Zoran Tomicic +Jeremy Ashkenas diff --git a/src/node.cc b/src/node.cc index d63ec6c..648c4d1 100644 --- a/src/node.cc +++ b/src/node.cc @@ -60,7 +60,7 @@ static Persistent listeners_symbol; static Persistent uncaught_exception_symbol; static Persistent emit_symbol; -static int dash_dash_index = 0; +static int option_end_index = 0; static bool use_debug_agent = false; @@ -951,9 +951,9 @@ static void Load(int argc, char *argv[]) { // process.argv int i, j; - Local arguments = Array::New(argc - dash_dash_index + 1); + Local arguments = Array::New(argc - option_end_index + 1); arguments->Set(Integer::New(0), String::New(argv[0])); - for (j = 1, i = dash_dash_index + 1; i < argc; j++, i++) { + for (j = 1, i = option_end_index + 1; i < argc; j++, i++) { Local arg = String::New(argv[i]); arguments->Set(Integer::New(j), arg); } @@ -1078,7 +1078,7 @@ static void Load(int argc, char *argv[]) { } static void PrintHelp() { - printf("Usage: node [options] [--] script.js [arguments] \n" + printf("Usage: node [options] script.js [arguments] \n" " -v, --version print node's version\n" " --debug enable remote debugging\n" // TODO specify port " --cflags print pre-processor and compiler flags\n" @@ -1092,13 +1092,10 @@ static void ParseArgs(int *argc, char **argv) { // TODO use parse opts for (int i = 1; i < *argc; i++) { const char *arg = argv[i]; - if (strcmp(arg, "--") == 0) { - dash_dash_index = i; - break; - } else if (strcmp(arg, "--debug") == 0) { + if (strcmp(arg, "--debug") == 0) { argv[i] = reinterpret_cast(""); use_debug_agent = true; - dash_dash_index = i; + option_end_index = i; } else if (strcmp(arg, "--version") == 0 || strcmp(arg, "-v") == 0) { printf("%s\n", NODE_VERSION); exit(0); @@ -1110,7 +1107,10 @@ static void ParseArgs(int *argc, char **argv) { exit(0); } else if (strcmp(arg, "--v8-options") == 0) { argv[i] = reinterpret_cast("--help"); - dash_dash_index = i+1; + option_end_index = i+1; + } else if (argv[i][0] != '-') { + option_end_index = i-1; + break; } } } @@ -1121,9 +1121,9 @@ static void ParseArgs(int *argc, char **argv) { int main(int argc, char *argv[]) { // Parse a few arguments which are specific to Node. node::ParseArgs(&argc, argv); - // Parse the rest of the args (up to the 'dash_dash_index' (where '--' was + // Parse the rest of the args (up to the 'option_end_index' (where '--' was // in the command line)) - V8::SetFlagsFromCommandLine(&node::dash_dash_index, argv, false); + V8::SetFlagsFromCommandLine(&node::option_end_index, argv, false); // Error out if we don't have a script argument. if (argc < 2) { @@ -1144,7 +1144,7 @@ int main(int argc, char *argv[]) { // watchers. In this way it can check if the 'tick' has other pending // watchers by using ev_pending_count() - if it ran with lower priority // then the other watchers might run before it - not giving us good idea - // of loop idleness. + // of loop idleness. ev_set_priority(&node::gc_timer, EV_MAXPRI); ev_timer_start(EV_DEFAULT_UC_ &node::gc_timer); ev_unref(EV_DEFAULT_UC); -- 2.7.4