Index: src/d8.cc |
=================================================================== |
--- src/d8.cc (revision 1260) |
+++ src/d8.cc (working copy) |
@@ -419,6 +419,27 @@ |
} |
+static char* ReadToken(const char* data, char token) { |
+ char* next = ::strchr(data, token); |
+ if (next != NULL) { |
+ *next = '\0'; |
+ return (next + 1); |
+ } |
+ |
+ return NULL; |
+} |
+ |
+ |
+static char* ReadLine(const char* data) { |
+ return ReadToken(data, '\n'); |
+} |
+ |
+ |
+static char* ReadWord(const char* data) { |
+ return ReadToken(data, ' '); |
+} |
+ |
+ |
// Reads a file into a v8 string. |
Handle<String> Shell::ReadFile(const char* name) { |
int size = 0; |
@@ -473,27 +494,42 @@ |
global_template->Set(String::New("version"), |
FunctionTemplate::New(Shell::Version)); |
- Persistent<Context> thread_context = Context::New(NULL, global_template); |
- thread_context->SetSecurityToken(Undefined()); |
- |
- Context::Scope context_scope(thread_context); |
- |
char* ptr = const_cast<char*>(files_.start()); |
while ((ptr != NULL) && (*ptr != '\0')) { |
// For each newline-separated line. |
- char *filename = ptr; |
- char* next = ::strchr(ptr, '\n'); |
- if (next != NULL) { |
- *next = '\0'; |
- ptr = (next + 1); |
- } else { |
- ptr = NULL; |
+ char* next_line = ReadLine(ptr); |
+ |
+ if (*ptr == '#') { |
+ // Skip comment lines. |
+ ptr = next_line; |
+ continue; |
} |
- Handle<String> str = Shell::ReadFile(filename); |
- Shell::ExecuteString(str, String::New(filename), false, false); |
+ |
+ Persistent<Context> thread_context = Context::New(NULL, global_template); |
+ thread_context->SetSecurityToken(Undefined()); |
+ Context::Scope context_scope(thread_context); |
+ |
+ while ((ptr != NULL) && (*ptr != '\0')) { |
+ char* filename = ptr; |
+ ptr = ReadWord(ptr); |
+ |
+ // Skip empty strings. |
+ if (strlen(filename) == 0) { |
+ break; |
+ } |
+ |
+ Handle<String> str = Shell::ReadFile(filename); |
+ if (str.IsEmpty()) { |
+ printf("WARNING: %s not found\n", filename); |
+ break; |
+ } |
+ |
+ Shell::ExecuteString(str, String::New(filename), false, false); |
+ } |
+ |
+ thread_context.Dispose(); |
+ ptr = next_line; |
} |
- |
- thread_context.Dispose(); |
} |