caryclark@google.com | d312804 | 2012-09-26 13:00:03 +0000 | [diff] [blame] | 1 | #include "SkStream.h" |
| 2 | #include "SkString.h" |
| 3 | #include "SkTDArray.h" |
| 4 | #include <stdio.h> |
| 5 | |
| 6 | static bool replace(const char* fun, const char* dir, const char* filename, const char* marker, |
| 7 | const char* marker2, const char* replace, size_t replaceLen) { |
| 8 | SkString outFileStr(dir); |
| 9 | outFileStr.append(filename); |
| 10 | SkFILEStream opStreamIn(outFileStr.c_str()); |
| 11 | if (!opStreamIn.isValid()) { |
| 12 | SkDebugf("%s couldn't find %s\n", fun, outFileStr.c_str()); |
| 13 | return false; |
| 14 | } |
| 15 | SkTDArray<char> opData; |
| 16 | opData.setCount(opStreamIn.getLength()); |
| 17 | size_t opLen = opData.count(); |
| 18 | opStreamIn.read(opData.begin(), opLen); |
| 19 | opStreamIn.setPath(NULL); |
| 20 | SkFILEWStream opStreamOut(outFileStr.c_str()); |
| 21 | if (!opStreamOut.isValid()) { |
| 22 | SkDebugf("%s couldn't open for writing %s\n", fun, outFileStr.c_str()); |
| 23 | return false; |
| 24 | } |
| 25 | |
| 26 | char* opInsert = strstr(opData.begin(), marker); |
| 27 | if (!opInsert) { |
| 28 | SkDebugf("%s missing marker in %s\n", fun, outFileStr.c_str()); |
caryclark@google.com | beda389 | 2013-02-07 13:13:41 +0000 | [diff] [blame] | 29 | opStreamOut.write(opData.begin(), opLen); |
| 30 | opStreamOut.flush(); |
caryclark@google.com | d312804 | 2012-09-26 13:00:03 +0000 | [diff] [blame] | 31 | return false; |
| 32 | } |
| 33 | const char* opInsertEnd = opInsert + strlen(marker); |
| 34 | if (marker2) { |
| 35 | char* opInsert2 = strstr(opInsert, marker2); |
| 36 | if (!opInsert2) { |
| 37 | SkDebugf("%s missing marker second half in %s\n", fun, outFileStr.c_str()); |
caryclark@google.com | beda389 | 2013-02-07 13:13:41 +0000 | [diff] [blame] | 38 | opStreamOut.write(opData.begin(), opLen); |
| 39 | opStreamOut.flush(); |
caryclark@google.com | d312804 | 2012-09-26 13:00:03 +0000 | [diff] [blame] | 40 | return false; |
| 41 | } |
| 42 | opInsertEnd = opInsert2 + strlen(marker2); |
| 43 | } |
| 44 | opStreamOut.write(opData.begin(), opInsert - opData.begin()); |
| 45 | opStreamOut.write(replace, replaceLen); |
| 46 | opStreamOut.write(opInsertEnd, opLen - (opInsertEnd - opData.begin())); |
| 47 | opStreamOut.flush(); |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | int main (int argc, char * const argv[]) { |
| 52 | if (argc != 2) { |
| 53 | SkDebugf("%s expected filename\n", argv[0]); |
| 54 | return 0; |
| 55 | } |
| 56 | const char* dir = "../../experimental/Intersection/"; |
| 57 | SkString inFileStr; |
| 58 | if (argv[1][0] != '/') { |
| 59 | inFileStr.append(dir); |
| 60 | } |
| 61 | inFileStr.append(argv[1]); |
| 62 | SkFILEStream inFile(inFileStr.c_str()); |
| 63 | if (!inFile.isValid()) { |
| 64 | SkDebugf("%s couldn't find %s\n", argv[0], argv[1]); |
| 65 | return 0; |
| 66 | } |
| 67 | SkTDArray<char> inData; |
| 68 | inData.setCount(inFile.getLength()); |
| 69 | size_t inLen = inData.count(); |
| 70 | inFile.read(inData.begin(), inLen); |
| 71 | inFile.setPath(NULL); |
| 72 | char* insert = strstr(inData.begin(), "\n\n\n"); |
| 73 | if (!insert) { |
| 74 | SkDebugf("%s missing two blank line delimiter in %s\n", argv[0], argv[1]); |
| 75 | return 0; |
| 76 | } |
| 77 | insert += 1; // include first blank line |
| 78 | const char opMarker[] = |
| 79 | "</div>" "\n" |
| 80 | "\n" |
skia.committer@gmail.com | 44d4988 | 2012-09-27 02:01:04 +0000 | [diff] [blame] | 81 | "<script type=\"text/javascript\">" "\n" |
caryclark@google.com | d312804 | 2012-09-26 13:00:03 +0000 | [diff] [blame] | 82 | "\n" |
| 83 | "var testDivs = [" "\n" |
| 84 | ; |
| 85 | if (!replace(argv[0], dir, "op.htm", opMarker, NULL, inData.begin(), |
| 86 | insert - inData.begin())) { |
| 87 | return 0; |
| 88 | } |
| 89 | const char newMarker[] = |
| 90 | "static void (*firstTest)() = " |
| 91 | ; |
skia.committer@gmail.com | 44d4988 | 2012-09-27 02:01:04 +0000 | [diff] [blame] | 92 | const char newMarker2[] = |
caryclark@google.com | d312804 | 2012-09-26 13:00:03 +0000 | [diff] [blame] | 93 | ";" "\n" |
| 94 | "\n" |
| 95 | "static struct {" "\n" |
| 96 | " void (*fun)();" "\n" |
| 97 | " const char* str;" "\n" |
| 98 | "} tests[] = {" "\n" |
| 99 | ; |
| 100 | if (!replace(argv[0], dir, "SimplifyNew_Test.cpp", newMarker, newMarker2, insert + 2, |
| 101 | inLen - (insert - inData.begin()) - 2)) { |
| 102 | return 0; |
| 103 | } |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 104 | const char forceReleaseMarker[] = |
caryclark@google.com | beda389 | 2013-02-07 13:13:41 +0000 | [diff] [blame] | 105 | "#define FORCE_RELEASE 1 // set force release to 1 for multiple thread -- no debugging" |
caryclark@google.com | d312804 | 2012-09-26 13:00:03 +0000 | [diff] [blame] | 106 | ; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 107 | const char forceReleaseReplace[] = |
caryclark@google.com | beda389 | 2013-02-07 13:13:41 +0000 | [diff] [blame] | 108 | "#define FORCE_RELEASE 0 // set force release to 1 for multiple thread -- no debugging" |
caryclark@google.com | d312804 | 2012-09-26 13:00:03 +0000 | [diff] [blame] | 109 | ; |
caryclark@google.com | 1304bb2 | 2013-03-13 20:29:41 +0000 | [diff] [blame] | 110 | if (!replace(argv[0], dir, "DataTypes.h", forceReleaseMarker, NULL, forceReleaseReplace, |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 111 | sizeof(forceReleaseReplace) - 1)) { |
caryclark@google.com | d312804 | 2012-09-26 13:00:03 +0000 | [diff] [blame] | 112 | return 0; |
| 113 | } |
| 114 | return 0; |
| 115 | } |