| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BIN_PROCESS_SCRIPT_H_ | 5 #ifndef BIN_PROCESS_SCRIPT_H_ |
| 6 #define BIN_PROCESS_SCRIPT_H_ | 6 #define BIN_PROCESS_SCRIPT_H_ |
| 7 | 7 |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| 11 | 11 |
| 12 class CommandLineOptions { | 12 class CommandLineOptions { |
| 13 public: | 13 public: |
| 14 explicit CommandLineOptions(int max_count) | 14 explicit CommandLineOptions(int max_count) |
| 15 : count_(0), max_count_(max_count), arguments_(NULL) { | 15 : count_(0), max_count_(max_count), arguments_(NULL) { |
| 16 static const int kWordSize = sizeof(intptr_t); | 16 static const int kWordSize = sizeof(intptr_t); |
| 17 arguments_ = reinterpret_cast<char **>(malloc(max_count * kWordSize)); | 17 arguments_ = reinterpret_cast<const char **>(malloc(max_count * kWordSize)); |
| 18 if (arguments_ == NULL) { | 18 if (arguments_ == NULL) { |
| 19 max_count_ = 0; | 19 max_count_ = 0; |
| 20 } | 20 } |
| 21 } | 21 } |
| 22 ~CommandLineOptions() { | 22 ~CommandLineOptions() { |
| 23 free(arguments_); | 23 free(arguments_); |
| 24 count_ = 0; | 24 count_ = 0; |
| 25 max_count_ = 0; | 25 max_count_ = 0; |
| 26 arguments_ = NULL; | 26 arguments_ = NULL; |
| 27 } | 27 } |
| 28 | 28 |
| 29 int count() const { return count_; } | 29 int count() const { return count_; } |
| 30 char** arguments() const { return arguments_; } | 30 const char** arguments() const { return arguments_; } |
| 31 | 31 |
| 32 char* GetArgument(int index) const { | 32 const char* GetArgument(int index) const { |
| 33 return (index >= 0 && index < count_) ? arguments_[index] : NULL; | 33 return (index >= 0 && index < count_) ? arguments_[index] : NULL; |
| 34 } | 34 } |
| 35 void AddArgument(char* argument) { | 35 void AddArgument(const char* argument) { |
| 36 if (count_ < max_count_) { | 36 if (count_ < max_count_) { |
| 37 arguments_[count_] = argument; | 37 arguments_[count_] = argument; |
| 38 count_ += 1; | 38 count_ += 1; |
| 39 } else { | 39 } else { |
| 40 abort(); // We should never get into this situation. | 40 abort(); // We should never get into this situation. |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 44 void operator delete(void* pointer) { abort(); } | 44 void operator delete(void* pointer) { abort(); } |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 void* operator new(size_t size); | 47 void* operator new(size_t size); |
| 48 CommandLineOptions(const CommandLineOptions&); | 48 CommandLineOptions(const CommandLineOptions&); |
| 49 void operator=(const CommandLineOptions&); | 49 void operator=(const CommandLineOptions&); |
| 50 | 50 |
| 51 int count_; | 51 int count_; |
| 52 int max_count_; | 52 int max_count_; |
| 53 char** arguments_; | 53 const char** arguments_; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 | 56 |
| 57 extern Dart_Handle ReadStringFromFile(const char* filename); |
| 57 extern Dart_Handle LoadScript(const char* script_name); | 58 extern Dart_Handle LoadScript(const char* script_name); |
| 58 extern Dart_Handle LoadSnapshotCreationScript(const char* script_name); | |
| 59 | 59 |
| 60 #endif // BIN_PROCESS_SCRIPT_H_ | 60 #endif // BIN_PROCESS_SCRIPT_H_ |
| OLD | NEW |