@@ -153,18 +153,17 @@ private static Options buildOptions() {
153153 .withLongOpt ("transformer-factory" )
154154 .create ('t' ));
155155 options .addOption (OptionBuilder
156- .hasOptionalArg ()
156+ .hasArg ()
157157 .withArgName ("pattern" )
158- .withDescription ("keep comments matching given pattern "
159- + "or any pattern if pattern is omitted or empty" )
160- .withLongOpt ("keep-comments" )
158+ .withDescription ("use give pattern to match comments" )
159+ .withLongOpt ("comment-pattern" )
161160 .create ('c' ));
162161 options .addOption (OptionBuilder
163162 .hasArg ()
164163 .withArgName ("flags" )
165164 .withDescription ("flags following the specification of XPath "
166- + "except for flag v (see NOTES below)" )
167- .withLongOpt ("matching-flags" )
165+ + "except for flag \" v \" (see NOTES below)" )
166+ .withLongOpt ("comment- matching-flags" )
168167 .create ('g' ));
169168 options .addOption (OptionBuilder
170169 .hasArg ()
@@ -182,12 +181,13 @@ private static Options buildOptions() {
182181 private static void printUsage (Options options ) {
183182 new HelpFormatter ().printHelp ("java -jar ruleml2tptp.jar" ,
184183 null , options , String .format ("%nNOTES%n"
185- + "If '-s' or '-o' is omitted, the standard input or "
186- + "output will be used accordingly.%n"
187- + "If '-h' is used, "
188- + "no XML transformation will be performed.%n"
189- + "Flag v means the matching behavior is reverted, "
190- + "so comments DO NOT match the given pattern are kept. "
184+ + "If '-s' or '-o' is omitted, the standard input or output will be used accordingly.%n"
185+ + "If '-h' is used, no XML transformation will be performed.%n"
186+ + "By default, all the comments in the source will be kept in the output. "
187+ + "Use '-c' to switch to keep only those matching the given pattern. "
188+ + "An empty pattern has no effect. "
189+ + "Flag \" v\" reverts the behavior by keeping those not matching the pattern, "
190+ + "or by ignoring all the comments if no or empty pattern is given."
191191 ),
192192 true );
193193 System .out .println ();
@@ -246,15 +246,19 @@ public void run(CommandLine cmd) throws FileNotFoundException, IOException,
246246 new BufferedReader (new InputStreamReader (
247247 xsltNormalizer ))));
248248 } else {
249+ // parse translator parameters
249250 String commentPattern = cmd .getOptionValue ('c' );
250- String matchingFlags = cmd .getOptionValue ('g' );
251- if (matchingFlags == null ) {
252- matchingFlags = "" ;
251+ if (commentPattern == null ) {
252+ commentPattern = "" ;
253+ }
254+ String commentMatchingFlags = cmd .getOptionValue ('g' );
255+ if (commentMatchingFlags == null ) {
256+ commentMatchingFlags = "" ;
253257 }
254- boolean keepComments = cmd .hasOption ('c' )
255- && (matchingFlags .indexOf ('v' ) == -1 );
256- matchingFlags = matchingFlags .replaceAll ("v" , "" );
258+ boolean keepComments = (commentMatchingFlags .indexOf ('v' ) == -1 );
259+ commentMatchingFlags = commentMatchingFlags .replaceAll ("v" , "" );
257260 boolean useCrlf = cmd .hasOption ('r' );
261+
258262 Transformer translator = null ; // to set params
259263 if (xsltNormalizer == null ) {
260264 translator = tFactory .newTransformer (
@@ -273,14 +277,8 @@ public void run(CommandLine cmd) throws FileNotFoundException, IOException,
273277 new BufferedReader (new InputStreamReader (
274278 xsltNormalizer ))));
275279 }
276- if (commentPattern != null && !commentPattern .isEmpty ()) {
277- translator .setParameter (
278- "match-comments" , commentPattern );
279- }
280- if (!matchingFlags .isEmpty ()) {
281- translator .setParameter (
282- "matching-flags" , matchingFlags );
283- }
280+ translator .setParameter ("comment-pattern" , commentPattern );
281+ translator .setParameter ("comment-matching-flags" , commentMatchingFlags );
284282 translator .setParameter ("keep-comments" , keepComments );
285283 translator .setParameter ("use-crlf" , useCrlf );
286284 }
0 commit comments