| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 fprintf(stdout, "%s", prompt); | 122 fprintf(stdout, "%s", prompt); |
| 123 fflush(stdout); | 123 fflush(stdout); |
| 124 while (keep_going) { | 124 while (keep_going) { |
| 125 if (fgets(line_buf, sizeof(line_buf), stdin) == NULL) { | 125 if (fgets(line_buf, sizeof(line_buf), stdin) == NULL) { |
| 126 // fgets got an error. Just give up. | 126 // fgets got an error. Just give up. |
| 127 if (result != NULL) { | 127 if (result != NULL) { |
| 128 DeleteArray(result); | 128 DeleteArray(result); |
| 129 } | 129 } |
| 130 return NULL; | 130 return NULL; |
| 131 } | 131 } |
| 132 int len = strlen(line_buf); | 132 int len = StrLength(line_buf); |
| 133 if (len > 1 && | 133 if (len > 1 && |
| 134 line_buf[len - 2] == '\\' && | 134 line_buf[len - 2] == '\\' && |
| 135 line_buf[len - 1] == '\n') { | 135 line_buf[len - 1] == '\n') { |
| 136 // When we read a line that ends with a "\" we remove the escape and | 136 // When we read a line that ends with a "\" we remove the escape and |
| 137 // append the remainder. | 137 // append the remainder. |
| 138 line_buf[len - 2] = '\n'; | 138 line_buf[len - 2] = '\n'; |
| 139 line_buf[len - 1] = 0; | 139 line_buf[len - 1] = 0; |
| 140 len -= 1; | 140 len -= 1; |
| 141 } else if ((len > 0) && (line_buf[len - 1] == '\n')) { | 141 } else if ((len > 0) && (line_buf[len - 1] == '\n')) { |
| 142 // Since we read a new line we are done reading the line. This | 142 // Since we read a new line we are done reading the line. This |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 177 } |
| 178 return NULL; | 178 return NULL; |
| 179 } | 179 } |
| 180 | 180 |
| 181 // Get the size of the file and rewind it. | 181 // Get the size of the file and rewind it. |
| 182 *size = ftell(file); | 182 *size = ftell(file); |
| 183 rewind(file); | 183 rewind(file); |
| 184 | 184 |
| 185 char* result = NewArray<char>(*size + extra_space); | 185 char* result = NewArray<char>(*size + extra_space); |
| 186 for (int i = 0; i < *size;) { | 186 for (int i = 0; i < *size;) { |
| 187 int read = fread(&result[i], 1, *size - i, file); | 187 int read = static_cast<int>(fread(&result[i], 1, *size - i, file)); |
| 188 if (read <= 0) { | 188 if (read <= 0) { |
| 189 fclose(file); | 189 fclose(file); |
| 190 DeleteArray(result); | 190 DeleteArray(result); |
| 191 return NULL; | 191 return NULL; |
| 192 } | 192 } |
| 193 i += read; | 193 i += read; |
| 194 } | 194 } |
| 195 fclose(file); | 195 fclose(file); |
| 196 return result; | 196 return result; |
| 197 } | 197 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 214 } | 214 } |
| 215 result[size] = '\0'; | 215 result[size] = '\0'; |
| 216 *exists = true; | 216 *exists = true; |
| 217 return Vector<const char>(result, size); | 217 return Vector<const char>(result, size); |
| 218 } | 218 } |
| 219 | 219 |
| 220 | 220 |
| 221 int WriteCharsToFile(const char* str, int size, FILE* f) { | 221 int WriteCharsToFile(const char* str, int size, FILE* f) { |
| 222 int total = 0; | 222 int total = 0; |
| 223 while (total < size) { | 223 while (total < size) { |
| 224 int write = fwrite(str, 1, size - total, f); | 224 int write = static_cast<int>(fwrite(str, 1, size - total, f)); |
| 225 if (write == 0) { | 225 if (write == 0) { |
| 226 return total; | 226 return total; |
| 227 } | 227 } |
| 228 total += write; | 228 total += write; |
| 229 str += write; | 229 str += write; |
| 230 } | 230 } |
| 231 return total; | 231 return total; |
| 232 } | 232 } |
| 233 | 233 |
| 234 | 234 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 258 } | 258 } |
| 259 | 259 |
| 260 | 260 |
| 261 StringBuilder::StringBuilder(int size) { | 261 StringBuilder::StringBuilder(int size) { |
| 262 buffer_ = Vector<char>::New(size); | 262 buffer_ = Vector<char>::New(size); |
| 263 position_ = 0; | 263 position_ = 0; |
| 264 } | 264 } |
| 265 | 265 |
| 266 | 266 |
| 267 void StringBuilder::AddString(const char* s) { | 267 void StringBuilder::AddString(const char* s) { |
| 268 AddSubstring(s, strlen(s)); | 268 AddSubstring(s, StrLength(s)); |
| 269 } | 269 } |
| 270 | 270 |
| 271 | 271 |
| 272 void StringBuilder::AddSubstring(const char* s, int n) { | 272 void StringBuilder::AddSubstring(const char* s, int n) { |
| 273 ASSERT(!is_finalized() && position_ + n < buffer_.length()); | 273 ASSERT(!is_finalized() && position_ + n < buffer_.length()); |
| 274 ASSERT(static_cast<size_t>(n) <= strlen(s)); | 274 ASSERT(static_cast<size_t>(n) <= strlen(s)); |
| 275 memcpy(&buffer_[position_], s, n * kCharSize); | 275 memcpy(&buffer_[position_], s, n * kCharSize); |
| 276 position_ += n; | 276 position_ += n; |
| 277 } | 277 } |
| 278 | 278 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 303 buffer_[position_] = '\0'; | 303 buffer_[position_] = '\0'; |
| 304 // Make sure nobody managed to add a 0-character to the | 304 // Make sure nobody managed to add a 0-character to the |
| 305 // buffer while building the string. | 305 // buffer while building the string. |
| 306 ASSERT(strlen(buffer_.start()) == static_cast<size_t>(position_)); | 306 ASSERT(strlen(buffer_.start()) == static_cast<size_t>(position_)); |
| 307 position_ = -1; | 307 position_ = -1; |
| 308 ASSERT(is_finalized()); | 308 ASSERT(is_finalized()); |
| 309 return buffer_.start(); | 309 return buffer_.start(); |
| 310 } | 310 } |
| 311 | 311 |
| 312 } } // namespace v8::internal | 312 } } // namespace v8::internal |
| OLD | NEW |