1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| package net.sourceforge.astyleclipse.astyle; |
30 |
| |
31 |
| |
32 |
| import java.io.*; |
33 |
| import java.util.*; |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| public class AStyle implements ASResource { |
40 |
| |
41 |
| public static final String VERSION = "1.14.1"; |
42 |
| |
43 |
| |
44 |
0
| private AStyle() {}
|
45 |
| |
46 |
| |
47 |
0
| public static void main(String[] argv) {
|
48 |
0
| ASFormatter formatter = new ASFormatter();
|
49 |
0
| Vector fileNameVector = new Vector();
|
50 |
0
| Vector optionsVector = new Vector();
|
51 |
0
| String optionsFileName = "";
|
52 |
0
| boolean ok = true;
|
53 |
0
| boolean shouldPrintHelp = false;
|
54 |
0
| boolean shouldParseOptionsFile = true;
|
55 |
| |
56 |
0
| _err = System.err;
|
57 |
0
| _suffix = ".orig";
|
58 |
0
| _modeManuallySet = false;
|
59 |
| |
60 |
| |
61 |
0
| for (int i = 0; i < argv.length; i++) {
|
62 |
0
| String arg = argv[i];
|
63 |
0
| if (IS_PARAM_OPTION(arg ,"--options=none")) {
|
64 |
0
| shouldParseOptionsFile = false;
|
65 |
| } |
66 |
0
| else if (IS_PARAM_OPTION(arg ,"--options=")) {
|
67 |
0
| optionsFileName = GET_PARAM(arg, "--options=");
|
68 |
| } |
69 |
0
| else if (IS_OPTION(arg, "-h") || IS_OPTION(arg, "--help") ||
|
70 |
| IS_OPTION(arg, "-?")) { |
71 |
0
| shouldPrintHelp = true;
|
72 |
| } |
73 |
0
| else if (arg.charAt(0) == '-') {
|
74 |
0
| optionsVector.addElement(arg);
|
75 |
| } |
76 |
| else { |
77 |
| |
78 |
0
| fileNameVector.addElement(arg);
|
79 |
| } |
80 |
| } |
81 |
| |
82 |
| |
83 |
0
| if (shouldParseOptionsFile) {
|
84 |
0
| if (optionsFileName.length() == 0) {
|
85 |
0
| String env = System.getProperty("ASTYLE_OPTIONS");
|
86 |
0
| if (env != null) {
|
87 |
0
| optionsFileName = env;
|
88 |
| } |
89 |
| } |
90 |
| |
91 |
0
| if (optionsFileName.length() == 0) {
|
92 |
0
| String env = System.getProperty("user.home");
|
93 |
0
| if (env != null) {
|
94 |
0
| optionsFileName = env + "/.astylerc";
|
95 |
0
| File optFile = new File(optionsFileName);
|
96 |
0
| if (!optFile.exists() || !optFile.canRead()) {
|
97 |
0
| optionsFileName = "";
|
98 |
0
| optFile = null;
|
99 |
| } |
100 |
| } |
101 |
| } |
102 |
| |
103 |
0
| if (optionsFileName.length() != 0) try {
|
104 |
0
| BufferedReader optionsIn = new BufferedReader(
|
105 |
| new FileReader(optionsFileName)); |
106 |
0
| Vector fileOptionsVector = new Vector();
|
107 |
0
| try {
|
108 |
0
| importOptions(optionsIn, fileOptionsVector);
|
109 |
0
| ok = parseOptions(formatter, fileOptionsVector,
|
110 |
| "Unknown option in default options file: "); |
111 |
0
| optionsIn.close();
|
112 |
| } catch(IOException ioex) { |
113 |
0
| _err.println("Error reading options file: " + optionsFileName);
|
114 |
0
| ok = false;
|
115 |
| } |
116 |
0
| if (!ok) {
|
117 |
0
| _err.println("For help on options, type 'astyle -h'.");
|
118 |
| } |
119 |
| } catch (FileNotFoundException fnfex) { |
120 |
0
| error("Could not open astyle options file:" , optionsFileName);
|
121 |
| } |
122 |
| } |
123 |
| |
124 |
| |
125 |
0
| ok = parseOptions(formatter, optionsVector, "Unknown command line option: ");
|
126 |
0
| if (!ok) {
|
127 |
0
| _err.println("For help on options, type 'astyle -h'.");
|
128 |
0
| System.exit(1);
|
129 |
| } |
130 |
| |
131 |
0
| if (shouldPrintHelp) {
|
132 |
0
| printHelp();
|
133 |
0
| System.exit(1);
|
134 |
| } |
135 |
| |
136 |
| |
137 |
| |
138 |
0
| if (fileNameVector.isEmpty()) {
|
139 |
0
| formatter.init(new ASStreamIterator(System.in));
|
140 |
0
| while (formatter.hasMoreLines()) {
|
141 |
0
| System.out.print(formatter.nextLine());
|
142 |
0
| if (formatter.hasMoreLines()) {
|
143 |
0
| System.out.println();
|
144 |
| } |
145 |
| } |
146 |
0
| System.out.flush();
|
147 |
| } else { |
148 |
| |
149 |
0
| for (int i = 0; i < fileNameVector.size(); i++) {
|
150 |
0
| String origFileName = (String) fileNameVector.elementAt(i);
|
151 |
0
| String inFileName = origFileName + _suffix;
|
152 |
0
| File origFile = new File(origFileName);
|
153 |
0
| File inFile = new File(inFileName);
|
154 |
| |
155 |
0
| if (inFile.exists() && !inFile.delete()) {
|
156 |
0
| error("Could not delete file", inFile.toString());
|
157 |
| } |
158 |
| |
159 |
0
| if (!origFile.renameTo(inFile)) {
|
160 |
0
| error("Could not rename",
|
161 |
| origFile.toString() + " to " + inFile.toString()); |
162 |
| } |
163 |
| |
164 |
0
| BufferedReader in = null;
|
165 |
0
| try {
|
166 |
0
| in = new BufferedReader(new FileReader(inFile));
|
167 |
| } catch (FileNotFoundException fnfex) { |
168 |
0
| error("Could not open input file", inFile.toString());
|
169 |
| } |
170 |
| |
171 |
0
| BufferedWriter out = null;
|
172 |
0
| try {
|
173 |
0
| out = new BufferedWriter(new FileWriter(origFile));
|
174 |
| } catch (IOException ioex) { |
175 |
0
| error("Could not open output file", origFile.toString());
|
176 |
| } |
177 |
| |
178 |
| |
179 |
| |
180 |
0
| if (!_modeManuallySet) {
|
181 |
0
| if (origFileName.endsWith(".java")) {
|
182 |
0
| formatter.setCStyle(false);
|
183 |
| } else { |
184 |
0
| formatter.setCStyle(true);
|
185 |
| } |
186 |
| } |
187 |
| |
188 |
0
| formatter.init(new ASStreamIterator(in));
|
189 |
0
| try {
|
190 |
0
| while (formatter.hasMoreLines()) {
|
191 |
0
| String line = formatter.nextLine();
|
192 |
0
| out.write(line, 0, line.length());
|
193 |
0
| if (formatter.hasMoreLines()) {
|
194 |
0
| out.newLine();
|
195 |
| } |
196 |
| } |
197 |
0
| out.flush();
|
198 |
| } catch(IOException ioex) { |
199 |
0
| error("Could not write to output file", origFile.toString());
|
200 |
| } |
201 |
| |
202 |
0
| try { out.close(); } catch (IOException ioex) { }
|
203 |
0
| try { in.close(); } catch (IOException ioex) { }
|
204 |
| } |
205 |
| } |
206 |
0
| return;
|
207 |
| } |
208 |
| |
209 |
| |
210 |
0
| private static final boolean IS_OPTION(String arg, String op) {
|
211 |
0
| return arg.equals(op);
|
212 |
| } |
213 |
| |
214 |
| |
215 |
0
| private static final boolean IS_OPTIONS(String arg, String a, String b) {
|
216 |
0
| return IS_OPTION(arg, a) || IS_OPTION(arg, b);
|
217 |
| } |
218 |
| |
219 |
| |
220 |
0
| private static final boolean IS_PARAM_OPTION(String arg, String op) {
|
221 |
0
| return arg.startsWith(op);
|
222 |
| } |
223 |
| |
224 |
| |
225 |
0
| private static final boolean IS_PARAM_OPTIONS(String arg, String a, String b) {
|
226 |
0
| return IS_PARAM_OPTION(arg, a) || IS_PARAM_OPTION(arg, b);
|
227 |
| } |
228 |
| |
229 |
| |
230 |
0
| private static final String GET_PARAM(String arg, String op) {
|
231 |
0
| return arg.substring(op.length());
|
232 |
| } |
233 |
| |
234 |
| |
235 |
0
| private static final String GET_PARAMS(String arg, String a, String b) {
|
236 |
0
| return IS_PARAM_OPTION(arg, a) ? GET_PARAM(arg, a) : GET_PARAM(arg, b);
|
237 |
| } |
238 |
| |
239 |
| |
240 |
0
| private static final int GET_NUM_PARAM(String arg, int defaultValue) {
|
241 |
0
| int num = defaultValue;
|
242 |
0
| if (arg.length() > 0) try {
|
243 |
0
| num = Integer.parseInt(arg);
|
244 |
| } catch (NumberFormatException ex) {} |
245 |
0
| return num;
|
246 |
| } |
247 |
| |
248 |
| |
249 |
0
| private static void error(String why, String what) {
|
250 |
0
| _err.println(why + ' ' + what);
|
251 |
0
| System.exit(1);
|
252 |
| } |
253 |
| |
254 |
| |
255 |
0
| private static boolean parseOptions(ASFormatter formatter, Vector options, String errorInfo) {
|
256 |
0
| boolean ok = true;
|
257 |
0
| String subArg = "";
|
258 |
0
| String arg;
|
259 |
| |
260 |
0
| for (Enumeration e = options.elements(); e.hasMoreElements(); ) {
|
261 |
0
| arg = e.nextElement().toString();
|
262 |
0
| if (arg.startsWith("--")) {
|
263 |
0
| ok &= parseOption(formatter, arg.substring(2), errorInfo);
|
264 |
| } |
265 |
0
| else if (arg.charAt(0) == '-') {
|
266 |
0
| for (int i = 1; i < arg.length(); ++i) {
|
267 |
0
| if (Character.isLetter(arg.charAt(i)) && i > 1) {
|
268 |
0
| ok &= parseOption(formatter, subArg, errorInfo);
|
269 |
0
| subArg = "";
|
270 |
| } |
271 |
0
| subArg.concat(String.valueOf(arg.charAt(i)));
|
272 |
| } |
273 |
0
| ok &= parseOption(formatter, subArg, errorInfo);
|
274 |
0
| subArg = "";
|
275 |
| } |
276 |
| else { |
277 |
0
| ok &= parseOption(formatter, arg, errorInfo);
|
278 |
0
| subArg = "";
|
279 |
| } |
280 |
| } |
281 |
0
| return ok;
|
282 |
| } |
283 |
| |
284 |
| |
285 |
0
| private static boolean parseOption(ASFormatter formatter, String arg, String errorInfo) {
|
286 |
0
| if (IS_PARAM_OPTION(arg, "suffix=")) {
|
287 |
0
| String suffixParam = GET_PARAM(arg, "suffix=");
|
288 |
0
| if (suffixParam.length() > 0) {
|
289 |
0
| _suffix = suffixParam;
|
290 |
| } |
291 |
| } |
292 |
0
| else if (IS_OPTION(arg ,"style=ansi")) {
|
293 |
0
| formatter.setBracketIndent(false);
|
294 |
0
| formatter.setSpaceIndentation(4);
|
295 |
0
| formatter.setBracketFormatMode(BREAK_MODE);
|
296 |
0
| formatter.setClassIndent(false);
|
297 |
0
| formatter.setSwitchIndent(false);
|
298 |
0
| formatter.setNamespaceIndent(false);
|
299 |
| } |
300 |
0
| else if (IS_OPTION(arg ,"style=gnu")) {
|
301 |
0
| formatter.setBlockIndent(true);
|
302 |
0
| formatter.setSpaceIndentation(2);
|
303 |
0
| formatter.setBracketFormatMode(BREAK_MODE);
|
304 |
0
| formatter.setClassIndent(false);
|
305 |
0
| formatter.setSwitchIndent(false);
|
306 |
0
| formatter.setNamespaceIndent(false);
|
307 |
| } |
308 |
0
| else if (IS_OPTION(arg ,"style=java")) {
|
309 |
0
| manuallySetJavaStyle(formatter);
|
310 |
0
| formatter.setBracketIndent(false);
|
311 |
0
| formatter.setSpaceIndentation(4);
|
312 |
0
| formatter.setBracketFormatMode(ATTACH_MODE);
|
313 |
0
| formatter.setSwitchIndent(false);
|
314 |
| } |
315 |
0
| else if (IS_OPTION(arg ,"style=kr")) {
|
316 |
| |
317 |
0
| formatter.setBracketIndent(false);
|
318 |
0
| formatter.setSpaceIndentation(4);
|
319 |
0
| formatter.setBracketFormatMode(ATTACH_MODE);
|
320 |
0
| formatter.setClassIndent(false);
|
321 |
0
| formatter.setSwitchIndent(false);
|
322 |
0
| formatter.setNamespaceIndent(false);
|
323 |
| } |
324 |
0
| else if (IS_OPTION(arg ,"style=linux")) {
|
325 |
0
| formatter.setBracketIndent(false);
|
326 |
0
| formatter.setSpaceIndentation(8);
|
327 |
0
| formatter.setBracketFormatMode(BDAC_MODE);
|
328 |
0
| formatter.setClassIndent(false);
|
329 |
0
| formatter.setSwitchIndent(false);
|
330 |
0
| formatter.setNamespaceIndent(false);
|
331 |
| } |
332 |
0
| else if (IS_OPTIONS(arg ,"c", "mode=c")) {
|
333 |
0
| manuallySetCStyle(formatter);
|
334 |
| } |
335 |
0
| else if (IS_OPTIONS(arg ,"j", "mode=java")) {
|
336 |
0
| manuallySetJavaStyle(formatter);
|
337 |
| } |
338 |
0
| else if (IS_OPTIONS(arg, "t", "indent=tab=")) {
|
339 |
0
| String spaceNumParam = GET_PARAMS(arg, "t", "indent=tab=");
|
340 |
0
| formatter.setTabIndentation(GET_NUM_PARAM(spaceNumParam, 4));
|
341 |
0
| formatter.setForceTabs(false);
|
342 |
| } |
343 |
0
| else if (IS_OPTIONS(arg, "T", "force-indent=tab=")) {
|
344 |
0
| String spaceNumParam = GET_PARAMS(arg, "T", "force-indent=tab=");
|
345 |
0
| formatter.setTabIndentation(GET_NUM_PARAM(spaceNumParam, 4));
|
346 |
0
| formatter.setForceTabs(true);
|
347 |
| } |
348 |
0
| else if (IS_PARAM_OPTION(arg, "indent=tab")) {
|
349 |
0
| formatter.setTabIndentation(4);
|
350 |
0
| formatter.setForceTabs(false);
|
351 |
| } |
352 |
0
| else if (IS_PARAM_OPTIONS(arg, "s", "indent=spaces=")) {
|
353 |
0
| String spaceNumParam = GET_PARAMS(arg, "s", "indent=spaces=");
|
354 |
0
| formatter.setSpaceIndentation(GET_NUM_PARAM(spaceNumParam, 4));
|
355 |
| } |
356 |
0
| else if (IS_PARAM_OPTION(arg, "indent=spaces")) {
|
357 |
0
| formatter.setSpaceIndentation(4);
|
358 |
| } |
359 |
0
| else if (IS_PARAM_OPTIONS(arg, "m", "min-conditional-indent=")) {
|
360 |
0
| String minIndentParam = GET_PARAMS(arg, "m", "min-conditional-indent=");
|
361 |
0
| formatter.setMinConditionalIndentLength(GET_NUM_PARAM(minIndentParam, 0));
|
362 |
| } |
363 |
0
| else if (IS_PARAM_OPTIONS(arg, "M", "max-instatement-indent=")) {
|
364 |
0
| String maxIndentParam = GET_PARAMS(arg, "M", "max-instatement-indent=");
|
365 |
0
| formatter.setMaxInStatementIndentLength(GET_NUM_PARAM(maxIndentParam, 40));
|
366 |
| } |
367 |
0
| else if (IS_OPTIONS(arg, "B", "indent-brackets")) {
|
368 |
0
| formatter.setBracketIndent(true);
|
369 |
| } |
370 |
0
| else if (IS_OPTIONS(arg, "G", "indent-blocks")) {
|
371 |
0
| formatter.setBlockIndent(true);
|
372 |
| } |
373 |
0
| else if (IS_OPTIONS(arg, "N", "indent-namespaces")) {
|
374 |
0
| formatter.setNamespaceIndent(true);
|
375 |
| } |
376 |
0
| else if (IS_OPTIONS(arg, "C", "indent-classes")) {
|
377 |
0
| formatter.setClassIndent(true);
|
378 |
| } |
379 |
0
| else if (IS_OPTIONS(arg, "S", "indent-switches")) {
|
380 |
0
| formatter.setSwitchIndent(true);
|
381 |
| } |
382 |
0
| else if (IS_OPTIONS(arg, "K", "indent-cases")) {
|
383 |
0
| formatter.setCaseIndent(true);
|
384 |
| } |
385 |
0
| else if (IS_OPTIONS(arg, "L", "indent-labels")) {
|
386 |
0
| formatter.setLabelIndent(true);
|
387 |
| } |
388 |
0
| else if (IS_OPTION(arg, "brackets=break-closing-headers")) {
|
389 |
0
| formatter.setBreakClosingHeaderBracketsMode(true);
|
390 |
| } |
391 |
0
| else if (IS_OPTIONS(arg, "b", "brackets=break")) {
|
392 |
0
| formatter.setBracketFormatMode(BREAK_MODE);
|
393 |
| } |
394 |
0
| else if (IS_OPTIONS(arg, "a", "brackets=attach")) {
|
395 |
0
| formatter.setBracketFormatMode(ATTACH_MODE);
|
396 |
| } |
397 |
0
| else if (IS_OPTIONS(arg, "l", "brackets=linux")) {
|
398 |
0
| formatter.setBracketFormatMode(BDAC_MODE);
|
399 |
| } |
400 |
0
| else if (IS_OPTIONS(arg, "O", "one-line=keep-blocks")) {
|
401 |
0
| formatter.setBreakOneLineBlocksMode(false);
|
402 |
| } |
403 |
0
| else if (IS_OPTIONS(arg, "o", "one-line=keep-statements")) {
|
404 |
0
| formatter.setSingleStatementsMode(false);
|
405 |
| } |
406 |
0
| else if (IS_OPTION(arg, "pad=paren")) {
|
407 |
0
| formatter.setParenthesisPaddingMode(true);
|
408 |
| } |
409 |
0
| else if (IS_OPTIONS(arg, "P", "pad=all")) {
|
410 |
0
| formatter.setOperatorPaddingMode(true);
|
411 |
0
| formatter.setParenthesisPaddingMode(true);
|
412 |
| } |
413 |
0
| else if (IS_OPTIONS(arg, "p", "pad=oper")) {
|
414 |
0
| formatter.setOperatorPaddingMode(true);
|
415 |
| } |
416 |
0
| else if (IS_OPTIONS(arg, "E", "fill-empty-lines")) {
|
417 |
0
| formatter.setEmptyLineFill(true);
|
418 |
| } |
419 |
0
| else if (IS_OPTION(arg, "indent-preprocessor")) {
|
420 |
0
| formatter.setPreprocessorIndent(true);
|
421 |
| } |
422 |
0
| else if (IS_OPTION(arg, "convert-tabs")) {
|
423 |
0
| formatter.setTabSpaceConversionMode(true);
|
424 |
| } |
425 |
0
| else if (IS_OPTION(arg, "break-blocks=all")) {
|
426 |
0
| formatter.setBreakBlocksMode(true);
|
427 |
0
| formatter.setBreakClosingHeaderBlocksMode(true);
|
428 |
| } |
429 |
0
| else if (IS_OPTION(arg, "break-blocks")) {
|
430 |
0
| formatter.setBreakBlocksMode(true);
|
431 |
| } |
432 |
0
| else if (IS_OPTION(arg, "break-elseifs")) {
|
433 |
0
| formatter.setBreakElseIfsMode(true);
|
434 |
| } |
435 |
0
| else if (IS_OPTIONS(arg, "X", "errors-to-standard-output")) {
|
436 |
0
| _err = System.out;
|
437 |
| } |
438 |
0
| else if (IS_OPTIONS(arg ,"v", "version")) {
|
439 |
0
| System.out.println("AStyle " + VERSION + " (Java)");
|
440 |
0
| System.exit(1);
|
441 |
| } |
442 |
| else { |
443 |
0
| _err.println(errorInfo + arg);
|
444 |
0
| return false;
|
445 |
| } |
446 |
0
| return true;
|
447 |
| } |
448 |
| |
449 |
| |
450 |
0
| private static void importOptions(Reader in, Vector optionsVector)
|
451 |
| throws IOException |
452 |
| { |
453 |
0
| StringBuffer currentTokenBuf;
|
454 |
0
| boolean eof = false;
|
455 |
| |
456 |
0
| while (!eof) {
|
457 |
0
| currentTokenBuf = new StringBuffer();
|
458 |
0
| do {
|
459 |
0
| int c = in.read();
|
460 |
0
| if (c == -1) {
|
461 |
0
| eof = true;
|
462 |
0
| break;
|
463 |
| } |
464 |
0
| char ch = (char) c;
|
465 |
0
| if (ch == '#') {
|
466 |
0
| do {
|
467 |
0
| c = in.read();
|
468 |
0
| if (c == -1) {
|
469 |
0
| eof = true;
|
470 |
0
| break;
|
471 |
| } |
472 |
0
| ch = (char) c;
|
473 |
0
| } while (ch != '\n' && ch != '\r');
|
474 |
| } |
475 |
0
| if (!eof) {
|
476 |
| |
477 |
0
| if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r') {
|
478 |
0
| break;
|
479 |
| } else { |
480 |
0
| currentTokenBuf.append(ch);
|
481 |
| } |
482 |
| } |
483 |
0
| } while (!eof);
|
484 |
0
| String currentToken = currentTokenBuf.toString().trim();
|
485 |
0
| if (currentToken.length() != 0) {
|
486 |
0
| optionsVector.addElement(currentToken);
|
487 |
| } |
488 |
| } |
489 |
| } |
490 |
| |
491 |
| |
492 |
0
| private static void manuallySetJavaStyle(ASFormatter formatter) {
|
493 |
0
| formatter.setCStyle(true);
|
494 |
0
| _modeManuallySet = true;
|
495 |
| } |
496 |
| |
497 |
| |
498 |
0
| private static void manuallySetCStyle(ASFormatter formatter) {
|
499 |
0
| formatter.setCStyle(false);
|
500 |
0
| _modeManuallySet = true;
|
501 |
| } |
502 |
| |
503 |
| |
504 |
0
| private boolean stringEndsWith(String str, String suffix) {
|
505 |
0
| return str.toLowerCase().endsWith(suffix.toLowerCase());
|
506 |
| } |
507 |
| |
508 |
| |
509 |
| private static final String HELP = |
510 |
| "\n" |
511 |
| + "AStyle " + VERSION + " (Java)\n" |
512 |
| + " (http://astyle.sourceforge.net)\n" |
513 |
| + " (created by Tal Davidson, davidsont@bigfoot.com)\n" |
514 |
| + " (ported to Java by Dirk Moebius, dmoebius@gmx.net)\n" |
515 |
| + "\n" |
516 |
| + "Usage: astyle [options] < Original > Beautified\n" |
517 |
| + " astyle [options] Foo.cpp Bar.cpp [...]\n" |
518 |
| + "\n" |
519 |
| + "When indenting a specific file, the resulting indented file RETAINS the\n" |
520 |
| + "original file-name. The original pre-indented file is renamed, with a suffix\n" |
521 |
| + "of \".orig\" added to the original filename.\n" |
522 |
| + "\n" |
523 |
| + "By default, astyle is set up to indent C/C++ files, with 4 spaces per indent,\n" |
524 |
| + "a maximal indentation of 40 spaces inside continuous statements and\n" |
525 |
| + "NO formatting.\n" |
526 |
| + "\n" |
527 |
| + "Option's Format:\n" |
528 |
| + "----------------\n" |
529 |
| + " Long options (starting with '--') must be written one at a time.\n" |
530 |
| + " Short options (starting with '-') may be appended together.\n" |
531 |
| + " Thus, -bps4 is the same as -b -p -s4.\n" |
532 |
| + "\n" |
533 |
| + "Predefined Styling options:\n" |
534 |
| + "---------------------------\n" |
535 |
| + " --style=ansi\n" |
536 |
| + " ANSI style formatting/indenting.\n" |
537 |
| + "\n" |
538 |
| + " --style=kr\n" |
539 |
| + " Kernighan&Ritchie style formatting/indenting.\n" |
540 |
| + "\n" |
541 |
| + " --style=gnu\n" |
542 |
| + " GNU style formatting/indenting.\n" |
543 |
| + "\n" |
544 |
| + " --style=java\n" |
545 |
| + " Java mode, with standard java style formatting/indenting.\n" |
546 |
| + "\n" |
547 |
| + " --style=linux\n" |
548 |
| + " Linux mode (i.e. 8 spaces per indent, break definition-block brackets,\n" |
549 |
| + " but attach command-block brackets).\n" |
550 |
| + "\n" |
551 |
| + "Indentation options:\n" |
552 |
| + "--------------------\n" |
553 |
| + " -c OR --mode=c\n" |
554 |
| + " Indent a C or C++ source file (default)\n" |
555 |
| + "\n" |
556 |
| + " -j OR --mode=java\n" |
557 |
| + " Indent a Java(TM) source file\n" |
558 |
| + "\n" |
559 |
| + " -s OR -s# OR --indent=spaces=#\n" |
560 |
| + " Indent using # spaces per indent. The default is 4 spaces per indent.\n" |
561 |
| + "\n" |
562 |
| + " -t OR -t# OR --indent=tab=#\n" |
563 |
| + " Indent using tab characters, assuming that each tab is # spaces long.\n" |
564 |
| + " The default is 4 spaces per tab.\n" |
565 |
| + "\n" |
566 |
| + " -T OR -T# OR --force-indent=tab=#\n" |
567 |
| + " Indent using tab characters, assuming that each tab is # spaces long.\n" |
568 |
| + " Force tabs to be used in areas, where AStyle would prefer to use spaces.\n" |
569 |
| + "\n" |
570 |
| + " -C OR --indent-classes\n" |
571 |
| + " Indent 'class' blocks, so that the inner 'public:', 'protected:' and\n" |
572 |
| + " 'private:' headers are indented in relation to the class block.\n" |
573 |
| + "\n" |
574 |
| + " -S OR --indent-switches\n" |
575 |
| + " Indent 'switch' blocks, so that the inner 'case XXX:' headers are\n" |
576 |
| + " indented in relation to the switch block.\n" |
577 |
| + "\n" |
578 |
| + " -K OR --indent-cases\n" |
579 |
| + " Indent 'case XXX:' lines, so that they are flush with their bodies.\n" |
580 |
| + "\n" |
581 |
| + " -N OR --indent-namespaces\n" |
582 |
| + " Indent the contents of namespace blocks.\n" |
583 |
| + "\n" |
584 |
| + " -B OR --indent-brackets\n" |
585 |
| + " Add extra indentation to '{' and '}' block brackets.\n" |
586 |
| + "\n" |
587 |
| + " -G OR --indent-blocks\n" |
588 |
| + " Add extra indentation entire blocks (including brackets).\n" |
589 |
| + "\n" |
590 |
| + " -L OR --indent-labels\n" |
591 |
| + " Indent labels so that they appear one indent less than the current\n" |
592 |
| + " indentation level, rather than being flushed completely to the left\n" |
593 |
| + " (which is the default).\n" |
594 |
| + "\n" |
595 |
| + " -m# OR --min-conditional-indent=#\n" |
596 |
| + " Indent a minimal # spaces in a continuous conditional belonging to a\n" |
597 |
| + " conditional header.\n" |
598 |
| + "\n" |
599 |
| + " -M# OR --max-instatement-indent=#\n" |
600 |
| + " Indent a maximal # spaces in a continuous statement, relatively to the\n" |
601 |
| + " previous line.\n" |
602 |
| + "\n" |
603 |
| + " -E OR --fill-empty-lines\n" |
604 |
| + " Fill empty lines with the white space of their previous lines.\n" |
605 |
| + "\n" |
606 |
| + " --indent-preprocessor\n" |
607 |
| + " Indent multi-line #define statements.\n" |
608 |
| + "\n" |
609 |
| + "Formatting options:\n" |
610 |
| + "-------------------\n" |
611 |
| + " -b OR --brackets=break\n" |
612 |
| + " Break brackets from pre-block code (i.e. ANSI C/C++ style).\n" |
613 |
| + "\n" |
614 |
| + " -a OR --brackets=attach\n" |
615 |
| + " Attach brackets to pre-block code (i.e. Java/K&R style).\n" |
616 |
| + "\n" |
617 |
| + " -l OR --brackets=linux\n" |
618 |
| + " Break definition-block brackets and attach command-block brackets.\n" |
619 |
| + "\n" |
620 |
| + " --brackets=break-closing-headers\n" |
621 |
| + " Break brackets before closing headers (e.g. 'else', 'catch', ...).\n" |
622 |
| + " Should be appended to --brackets=attach or --brackets=linux.\n" |
623 |
| + "\n" |
624 |
| + " -o OR --one-line=keep-statements\n" |
625 |
| + " Don't break lines containing multiple statements into multiple\n" |
626 |
| + " single-statement lines.\n" |
627 |
| + "\n" |
628 |
| + " -O OR --one-line=keep-blocks\n" |
629 |
| + " Don't break blocks residing completely on one line.\n" |
630 |
| + "\n" |
631 |
| + " -p OR --pad=oper\n" |
632 |
| + " Insert space paddings around operators only.\n" |
633 |
| + "\n" |
634 |
| + " --pad=paren\n" |
635 |
| + " Insert space paddings around parenthesies only.\n" |
636 |
| + "\n" |
637 |
| + " -P OR --pad=all\n" |
638 |
| + " Insert space paddings around operators AND parenthesies.\n" |
639 |
| + "\n" |
640 |
| + " --convert-tabs\n" |
641 |
| + " Convert tabs to spaces.\n" |
642 |
| + "\n" |
643 |
| + " --break-blocks\n" |
644 |
| + " Insert empty lines around unrelated blocks, labels, classes, ...\n" |
645 |
| + "\n" |
646 |
| + " --break-blocks=all\n" |
647 |
| + " Like --break-blocks, except also insert empty lines around closing\n" |
648 |
| + " headers (e.g. 'else', 'catch', ...).\n" |
649 |
| + "\n" |
650 |
| + " --break-elseifs\n" |
651 |
| + " Break 'else if()' statements into two different lines.\n" |
652 |
| + "\n" |
653 |
| + "Other options:\n" |
654 |
| + "--------------\n" |
655 |
| + " --suffix=####\n" |
656 |
| + " Append the suffix #### instead of '.orig' to original filename.\n" |
657 |
| + "\n" |
658 |
| + " -X OR --errors-to-standard-output\n" |
659 |
| + " Print errors and help information to standard-output rather than to\n" |
660 |
| + " standard-error.\n" |
661 |
| + "\n" |
662 |
| + " -v OR --version\n" |
663 |
| + " Print version number.\n" |
664 |
| + "\n" |
665 |
| + " -h OR -? OR --help\n" |
666 |
| + " Print this help message.\n" |
667 |
| + "\n" |
668 |
| + "Default options file:\n" |
669 |
| + "---------------------\n" |
670 |
| + " AStyle looks for a default options file in the following order:\n" |
671 |
| + " 1. The contents of the ASTYLE_OPTIONS property, if it has been set\n" |
672 |
| + " on start of the Java VM with the -D option.\n" |
673 |
| + " 2. The file called .astylerc in the home directory. The location of the\n" |
674 |
| + " home directory depends on the operating system and the Java VM. On this\n" |
675 |
| + " system it is: " + System.getProperty("user.home") + "\n" |
676 |
| + " If a default options file is found, the options in this file will be\n" |
677 |
| + " parsed BEFORE the command-line options.\n" |
678 |
| + " Options within the default option file may be written without the\n" |
679 |
| + " preliminary '-' or '--'.\n" |
680 |
| + "\n"; |
681 |
| |
682 |
| |
683 |
0
| private static void printHelp() {
|
684 |
0
| _err.print(HELP);
|
685 |
| } |
686 |
| |
687 |
| |
688 |
| private static PrintStream _err = System.err; |
689 |
| private static String _suffix = ".orig"; |
690 |
| private static boolean _modeManuallySet = false; |
691 |
| |
692 |
| } |
693 |
| |