OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <limits.h> | 5 #include <limits.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <iostream> | 7 #include <iostream> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 const char kEndSwitch[] = "end"; | 23 const char kEndSwitch[] = "end"; |
24 const char kEndSwitchHelp[] = | 24 const char kEndSwitchHelp[] = |
25 "output messages before |m|th message in file (exclusive)."; | 25 "output messages before |m|th message in file (exclusive)."; |
26 | 26 |
27 const char kHelpSwitch[] = "help"; | 27 const char kHelpSwitch[] = "help"; |
28 const char kHelpSwitchHelp[] = | 28 const char kHelpSwitchHelp[] = |
29 "display this message."; | 29 "display this message."; |
30 | 30 |
31 const char kInSwitch[] = "in"; | 31 const char kInSwitch[] = "in"; |
32 const char kInSwitchHelp[] = | 32 const char kInSwitchHelp[] = |
33 "output only the messages in the specified list."; | 33 "output only the messages at the specified positions in the file."; |
34 | 34 |
35 const char kInvertSwitch[] = "invert"; | 35 const char kInvertSwitch[] = "invert"; |
36 const char kInvertSwitchHelp[] = | 36 const char kInvertSwitchHelp[] = |
37 "output messages NOT meeting above criteria."; | 37 "output messages NOT meeting above criteria."; |
38 | 38 |
39 const char kRegexpSwitch[] = "regexp"; | 39 const char kRegexpSwitch[] = "regexp"; |
40 const char kRegexpSwitchHelp[] = | 40 const char kRegexpSwitchHelp[] = |
41 "output messages matching regular expression |x|."; | 41 "output messages matching regular expression |x|."; |
42 | 42 |
43 const char kStartSwitch[] = "start"; | 43 const char kStartSwitch[] = "start"; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 start_index = static_cast<size_t>(temp); | 95 start_index = static_cast<size_t>(temp); |
96 } | 96 } |
97 | 97 |
98 size_t end_index = INT_MAX; | 98 size_t end_index = INT_MAX; |
99 if (cmd->HasSwitch(kEndSwitch)) { | 99 if (cmd->HasSwitch(kEndSwitch)) { |
100 int temp = atoi(cmd->GetSwitchValueASCII(kEndSwitch).c_str()); | 100 int temp = atoi(cmd->GetSwitchValueASCII(kEndSwitch).c_str()); |
101 if (temp > 0) | 101 if (temp > 0) |
102 end_index = static_cast<size_t>(temp); | 102 end_index = static_cast<size_t>(temp); |
103 } | 103 } |
104 | 104 |
105 bool has_indices = cmd->HasSwitch(kInSwitch); | |
106 std::vector<bool> indices; | |
107 | |
108 bool has_regexp = cmd->HasSwitch(kRegexpSwitch); | 105 bool has_regexp = cmd->HasSwitch(kRegexpSwitch); |
109 RE2 filter_pattern(cmd->GetSwitchValueASCII(kRegexpSwitch)); | 106 RE2 filter_pattern(cmd->GetSwitchValueASCII(kRegexpSwitch)); |
110 | 107 |
111 bool invert = cmd->HasSwitch(kInvertSwitch); | 108 bool invert = cmd->HasSwitch(kInvertSwitch); |
112 bool perform_dump = cmd->HasSwitch(kDumpSwitch); | 109 bool perform_dump = cmd->HasSwitch(kDumpSwitch); |
113 | 110 |
114 std::vector<base::FilePath::StringType> input_file_names; | 111 std::vector<base::FilePath::StringType> input_file_names; |
115 base::FilePath::StringType output_file_name; | 112 base::FilePath::StringType output_file_name; |
116 base::SplitString(args[0], ',', &input_file_names); | 113 base::SplitString(args[0], ',', &input_file_names); |
117 | 114 |
118 if (!perform_dump) { | 115 if (!perform_dump) { |
119 if (args.size() < 2) { | 116 if (args.size() < 2) { |
120 usage(); | 117 usage(); |
121 return EXIT_FAILURE; | 118 return EXIT_FAILURE; |
122 } | 119 } |
123 output_file_name = args[1]; | 120 output_file_name = args[1]; |
124 } | 121 } |
125 | 122 |
126 ipc_fuzzer::MessageVector input_message_vector; | 123 ipc_fuzzer::MessageVector input_message_vector; |
127 for (std::vector<base::FilePath::StringType>::iterator | 124 for (std::vector<base::FilePath::StringType>::iterator |
128 it = input_file_names.begin(); it != input_file_names.end(); ++it) { | 125 it = input_file_names.begin(); it != input_file_names.end(); ++it) { |
129 ipc_fuzzer::MessageVector message_vector; | 126 ipc_fuzzer::MessageVector message_vector; |
130 if (!ipc_fuzzer::MessageFile::Read(base::FilePath(*it), &message_vector)) | 127 if (!ipc_fuzzer::MessageFile::Read(base::FilePath(*it), &message_vector)) |
131 return EXIT_FAILURE; | 128 return EXIT_FAILURE; |
132 input_message_vector.insert(input_message_vector.end(), | 129 input_message_vector.insert(input_message_vector.end(), |
133 message_vector.begin(), message_vector.end()); | 130 message_vector.begin(), message_vector.end()); |
134 message_vector.weak_clear(); | 131 message_vector.weak_clear(); |
135 } | 132 } |
136 | 133 |
| 134 bool has_indices = cmd->HasSwitch(kInSwitch); |
| 135 std::vector<bool> indices; |
| 136 |
137 if (has_indices) { | 137 if (has_indices) { |
138 indices.resize(input_message_vector.size(), false); | 138 indices.resize(input_message_vector.size(), false); |
139 std::vector<std::string> index_strings; | 139 std::vector<std::string> index_strings; |
140 base::SplitString(cmd->GetSwitchValueASCII(kInSwitch), ',', &index_strings); | 140 base::SplitString(cmd->GetSwitchValueASCII(kInSwitch), ',', &index_strings); |
141 for (std::vector<std::string>::iterator it = index_strings.begin(); | 141 for (std::vector<std::string>::iterator it = index_strings.begin(); |
142 it != index_strings.end(); ++it) { | 142 it != index_strings.end(); ++it) { |
143 int index = atoi(it->c_str()); | 143 int index = atoi(it->c_str()); |
144 if (index >= 0 && static_cast<size_t>(index) < indices.size()) | 144 if (index >= 0 && static_cast<size_t>(index) < indices.size()) |
145 indices[index] = true; | 145 indices[index] = true; |
146 } | 146 } |
(...skipping 24 matching lines...) Expand all Loading... |
171 } | 171 } |
172 } else { | 172 } else { |
173 if (!ipc_fuzzer::MessageFile::Write( | 173 if (!ipc_fuzzer::MessageFile::Write( |
174 base::FilePath(output_file_name), output_message_vector)) { | 174 base::FilePath(output_file_name), output_message_vector)) { |
175 return EXIT_FAILURE; | 175 return EXIT_FAILURE; |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 return EXIT_SUCCESS; | 179 return EXIT_SUCCESS; |
180 } | 180 } |
OLD | NEW |