/plugins/AStylePlugin/tags/astyle-0-7/astyle/AStyle.java

# · Java · 693 lines · 589 code · 64 blank · 40 comment · 155 complexity · b3da06f6e7d7e9240c2d26f23b658cda MD5 · raw file

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