| 5 | #include <string.h> |
| 6 | |
| 7 | int main(int argc, const char** argv) { |
| 8 | |
| 9 | if (argc < 3) { |
| 10 | printf("Searches within a NanoLog decompressed file for a leading\r\n" |
| 11 | "string and then aggregates the element after the string\r\n" |
| 12 | "for a min/max/mean as an int. An example would be\r\n" |
| 13 | "aggregating on \"Hello World # 10\", the invocation is:\r\n" |
| 14 | " %s \"Hello World # \" <logFile>\r\n\r\n", argv[0]); |
| 15 | return 1; |
| 16 | } |
| 17 | |
| 18 | const char *searchString = argv[1]; |
| 19 | const char *filename = argv[2]; |
| 20 | |
| 21 | std::ifstream in(filename, std::ifstream::in); |
| 22 | if (!in.is_open() || !in.good()) { |
| 23 | printf("Unable to open file: %s\r\n", filename); |
| 24 | exit(-1); |
| 25 | } |
| 26 | |
| 27 | long min, max, total, count; |
| 28 | min = max = total = count = 0; |
| 29 | |
| 30 | char line[1024]; |
| 31 | while (!in.eof() && in.good()) { |
| 32 | in.getline(line, sizeof(line)); |
| 33 | |
| 34 | if (in.eof()) |
| 35 | break; |
| 36 | |
| 37 | if (in.fail()) { |
| 38 | printf("Failed to read a line... Perhaps the buffer isn't large" |
| 39 | " enough at %lu bytes\r\n", sizeof(line)); |
| 40 | exit(1); |
| 41 | } |
| 42 | |
| 43 | char *pos = strstr(line, searchString); |
| 44 | |
| 45 | // Didn't match |
| 46 | if (pos == nullptr) |
| 47 | continue; |
| 48 | |
| 49 | // Move the string to the right place |
| 50 | pos += strlen(searchString); |
| 51 | long num = atol(pos); |
| 52 | |
| 53 | if (count) { |
| 54 | if (min > num) min = num; |
| 55 | if (max < num) max = num; |
| 56 | total += num; |
| 57 | ++count; |
| 58 | } else { |
| 59 | total = min = max = num; |
| 60 | count = 1; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 |
nothing calls this directly
no outgoing calls
no test coverage detected