Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 return ThrowException(String::New("Error loading file")); | 219 return ThrowException(String::New("Error loading file")); |
| 220 } | 220 } |
| 221 return source; | 221 return source; |
| 222 } | 222 } |
| 223 | 223 |
| 224 | 224 |
| 225 Handle<Value> Shell::ReadLine(const Arguments& args) { | 225 Handle<Value> Shell::ReadLine(const Arguments& args) { |
| 226 static const int kBufferSize = 256; | 226 static const int kBufferSize = 256; |
| 227 char buffer[kBufferSize]; | 227 char buffer[kBufferSize]; |
| 228 Handle<String> accumulator = String::New(""); | 228 Handle<String> accumulator = String::New(""); |
| 229 bool linebreak; | |
| 230 int length; | 229 int length; |
| 231 do { // Repeat if the line ends with an escape '\'. | 230 while (true) { |
| 232 // fgets got an error. Just give up. | 231 // Continue reading if the line ends with an escape '\\' or the line has |
| 232 // not been fully read into the buffer yet (does not end with '\n'). | |
| 233 // If fgets gets an error. Just give up. | |
| 233 if (fgets(buffer, kBufferSize, stdin) == NULL) return Null(); | 234 if (fgets(buffer, kBufferSize, stdin) == NULL) return Null(); |
| 234 length = static_cast<int>(strlen(buffer)); | 235 length = static_cast<int>(strlen(buffer)); |
|
Sven Panne
2011/08/01 11:25:06
Using size_t for length gets rid of the cast. Furt
| |
| 235 linebreak = (length > 1 && buffer[length-2] == '\\'); | 236 if (length == 0) return accumulator; |
|
Sven Panne
2011/08/01 11:25:06
In general, a simple if-then-else cascade is easie
| |
| 236 if (linebreak) buffer[length-2] = '\n'; | 237 if (buffer[length-1] == '\n') { |
| 237 accumulator = String::Concat(accumulator, String::New(buffer, length-1)); | 238 length--; |
| 238 } while (linebreak); | 239 if (length == 0 || buffer[length-1] != '\\') { |
| 239 return accumulator; | 240 return String::Concat(accumulator, String::New(buffer, length)); |
| 241 } | |
| 242 buffer[length-1] = '\n'; | |
| 243 } | |
| 244 accumulator = String::Concat(accumulator, String::New(buffer, length)); | |
| 245 } | |
| 240 } | 246 } |
| 241 | 247 |
| 242 | 248 |
| 243 Handle<Value> Shell::Load(const Arguments& args) { | 249 Handle<Value> Shell::Load(const Arguments& args) { |
| 244 for (int i = 0; i < args.Length(); i++) { | 250 for (int i = 0; i < args.Length(); i++) { |
| 245 HandleScope handle_scope; | 251 HandleScope handle_scope; |
| 246 String::Utf8Value file(args[i]); | 252 String::Utf8Value file(args[i]); |
| 247 if (*file == NULL) { | 253 if (*file == NULL) { |
| 248 return ThrowException(String::New("Error loading file")); | 254 return ThrowException(String::New("Error loading file")); |
| 249 } | 255 } |
| (...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1284 } | 1290 } |
| 1285 | 1291 |
| 1286 } // namespace v8 | 1292 } // namespace v8 |
| 1287 | 1293 |
| 1288 | 1294 |
| 1289 #ifndef GOOGLE3 | 1295 #ifndef GOOGLE3 |
| 1290 int main(int argc, char* argv[]) { | 1296 int main(int argc, char* argv[]) { |
| 1291 return v8::Shell::Main(argc, argv); | 1297 return v8::Shell::Main(argc, argv); |
| 1292 } | 1298 } |
| 1293 #endif | 1299 #endif |
| OLD | NEW |