OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCommandLineFlags.h" | 8 #include "SkCommandLineFlags.h" |
9 #include "SkTDArray.h" | 9 #include "SkTDArray.h" |
10 #include "SkTSort.h" | 10 #include "SkTSort.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 133 } |
134 | 134 |
135 SkFlagInfo* SkCommandLineFlags::gHead; | 135 SkFlagInfo* SkCommandLineFlags::gHead; |
136 SkString SkCommandLineFlags::gUsage; | 136 SkString SkCommandLineFlags::gUsage; |
137 | 137 |
138 void SkCommandLineFlags::SetUsage(const char* usage) { | 138 void SkCommandLineFlags::SetUsage(const char* usage) { |
139 gUsage.set(usage); | 139 gUsage.set(usage); |
140 } | 140 } |
141 | 141 |
142 // Maximum line length for the help message. | 142 // Maximum line length for the help message. |
143 #define LINE_LENGTH 80 | 143 #define LINE_LENGTH 72 |
144 | 144 |
145 static void print_help_for_flag(const SkFlagInfo* flag) { | 145 static void print_help_for_flag(const SkFlagInfo* flag) { |
146 SkDebugf("\t--%s", flag->name().c_str()); | 146 SkDebugf(" --%s", flag->name().c_str()); |
147 const SkString& shortName = flag->shortName(); | 147 const SkString& shortName = flag->shortName(); |
148 if (shortName.size() > 0) { | 148 if (shortName.size() > 0) { |
149 SkDebugf(" or -%s", shortName.c_str()); | 149 SkDebugf(" or -%s", shortName.c_str()); |
150 } | 150 } |
151 SkDebugf(":\ttype: %s", flag->typeAsString().c_str()); | 151 SkDebugf(":\ttype: %s", flag->typeAsString().c_str()); |
152 if (flag->defaultValue().size() > 0) { | 152 if (flag->defaultValue().size() > 0) { |
153 SkDebugf("\tdefault: %s", flag->defaultValue().c_str()); | 153 SkDebugf("\tdefault: %s", flag->defaultValue().c_str()); |
154 } | 154 } |
155 SkDebugf("\n"); | 155 SkDebugf("\n"); |
156 const SkString& help = flag->help(); | 156 const SkString& help = flag->help(); |
157 size_t length = help.size(); | 157 size_t length = help.size(); |
158 const char* currLine = help.c_str(); | 158 const char* currLine = help.c_str(); |
159 const char* stop = currLine + length; | 159 const char* stop = currLine + length; |
160 while (currLine < stop) { | 160 while (currLine < stop) { |
161 if (strlen(currLine) < LINE_LENGTH) { | 161 if (strlen(currLine) < LINE_LENGTH) { |
162 // Only one line length's worth of text left. | 162 // Only one line length's worth of text left. |
163 SkDebugf("\t\t%s\n", currLine); | 163 SkDebugf(" %s\n", currLine); |
164 break; | 164 break; |
165 } | 165 } |
166 int lineBreak = SkStrFind(currLine, "\n"); | 166 int lineBreak = SkStrFind(currLine, "\n"); |
167 if (lineBreak < 0 || lineBreak > LINE_LENGTH) { | 167 if (lineBreak < 0 || lineBreak > LINE_LENGTH) { |
168 // No line break within line length. Will need to insert one. | 168 // No line break within line length. Will need to insert one. |
169 // Find a space before the line break. | 169 // Find a space before the line break. |
170 int spaceIndex = LINE_LENGTH - 1; | 170 int spaceIndex = LINE_LENGTH - 1; |
171 while (spaceIndex > 0 && currLine[spaceIndex] != ' ') { | 171 while (spaceIndex > 0 && currLine[spaceIndex] != ' ') { |
172 spaceIndex--; | 172 spaceIndex--; |
173 } | 173 } |
174 int gap; | 174 int gap; |
175 if (0 == spaceIndex) { | 175 if (0 == spaceIndex) { |
176 // No spaces on the entire line. Go ahead and break mid word. | 176 // No spaces on the entire line. Go ahead and break mid word. |
177 spaceIndex = LINE_LENGTH; | 177 spaceIndex = LINE_LENGTH; |
178 gap = 0; | 178 gap = 0; |
179 } else { | 179 } else { |
180 // Skip the space on the next line | 180 // Skip the space on the next line |
181 gap = 1; | 181 gap = 1; |
182 } | 182 } |
183 SkDebugf("\t\t%.*s\n", spaceIndex, currLine); | 183 SkDebugf(" %.*s\n", spaceIndex, currLine); |
184 currLine += spaceIndex + gap; | 184 currLine += spaceIndex + gap; |
185 } else { | 185 } else { |
186 // the line break is within the limit. Break there. | 186 // the line break is within the limit. Break there. |
187 lineBreak++; | 187 lineBreak++; |
188 SkDebugf("\t\t%.*s", lineBreak, currLine); | 188 SkDebugf(" %.*s", lineBreak, currLine); |
189 currLine += lineBreak; | 189 currLine += lineBreak; |
190 } | 190 } |
191 } | 191 } |
192 SkDebugf("\n"); | 192 SkDebugf("\n"); |
193 } | 193 } |
194 | 194 |
195 namespace { | 195 namespace { |
196 struct CompareFlagsByName { | 196 struct CompareFlagsByName { |
197 bool operator()(SkFlagInfo* a, SkFlagInfo* b) const { | 197 bool operator()(SkFlagInfo* a, SkFlagInfo* b) const { |
198 return strcmp(a->name().c_str(), b->name().c_str()) < 0; | 198 return strcmp(a->name().c_str(), b->name().c_str()) < 0; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 print_help_for_flag(flag); | 249 print_help_for_flag(flag); |
250 helpFlags.remove(k); | 250 helpFlags.remove(k); |
251 break; | 251 break; |
252 } | 252 } |
253 } | 253 } |
254 } | 254 } |
255 } | 255 } |
256 if (helpFlags.count() > 0) { | 256 if (helpFlags.count() > 0) { |
257 SkDebugf("Requested help for unrecognized flags:\n"); | 257 SkDebugf("Requested help for unrecognized flags:\n"); |
258 for (int k = 0; k < helpFlags.count(); k++) { | 258 for (int k = 0; k < helpFlags.count(); k++) { |
259 SkDebugf("\t--%s\n", helpFlags[k]); | 259 SkDebugf(" --%s\n", helpFlags[k]); |
260 } | 260 } |
261 } | 261 } |
262 helpPrinted = true; | 262 helpPrinted = true; |
263 } | 263 } |
264 if (!helpPrinted) { | 264 if (!helpPrinted) { |
265 bool flagMatched = false; | 265 bool flagMatched = false; |
266 SkFlagInfo* flag = gHead; | 266 SkFlagInfo* flag = gHead; |
267 while (flag != NULL) { | 267 while (flag != NULL) { |
268 if (flag->match(argv[i])) { | 268 if (flag->match(argv[i])) { |
269 flagMatched = true; | 269 flagMatched = true; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 } | 371 } |
372 | 372 |
373 } // namespace | 373 } // namespace |
374 | 374 |
375 bool SkCommandLineFlags::ShouldSkip(const SkTDArray<const char*>& strings, const
char* name) { | 375 bool SkCommandLineFlags::ShouldSkip(const SkTDArray<const char*>& strings, const
char* name) { |
376 return ShouldSkipImpl(strings, name); | 376 return ShouldSkipImpl(strings, name); |
377 } | 377 } |
378 bool SkCommandLineFlags::ShouldSkip(const StringArray& strings, const char* name
) { | 378 bool SkCommandLineFlags::ShouldSkip(const StringArray& strings, const char* name
) { |
379 return ShouldSkipImpl(strings, name); | 379 return ShouldSkipImpl(strings, name); |
380 } | 380 } |
OLD | NEW |