Skip to content

Commit

Permalink
Fix typo and whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
stathissideris committed Jan 13, 2018
1 parent d928e2f commit 9d3ca31
Showing 1 changed file with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* ditaa - Diagrams Through Ascii Art
*
*
* Copyright (C) 2004-2011 Efstathios Sideris
*
* ditaa is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
Expand All @@ -15,7 +15,7 @@
*
* You should have received a copy of the GNU Lesser General Public
* License along with ditaa. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package org.stathissideris.ascii2image.core;

Expand All @@ -37,19 +37,19 @@
import org.stathissideris.ascii2image.text.TextGrid;

/**
*
*
* @author Efstathios Sideris
*/
public class CommandLineConverter {

private static String notice = "ditaa version 0.11, Copyright (C) 2004--2017 Efstathios (Stathis) Sideris";

private static String[] markupModeAllowedValues = {"use", "ignore", "render"};

public static void main(String[] args){

long startTime = System.currentTimeMillis();

Options cmdLnOptions = new Options();
cmdLnOptions.addOption(
OptionBuilder.withLongOpt("help")
Expand All @@ -65,7 +65,7 @@ public static void main(String[] args){
cmdLnOptions.addOption("E", "no-separation", false, "Prevents the separation of common edges of shapes.");
cmdLnOptions.addOption("h", "html", false, "In this case the input is an HTML file. The contents of the <pre class=\"textdiagram\"> tags are rendered as diagrams and saved in the images directory and a new HTML file is produced with the appropriate <img> tags.");
cmdLnOptions.addOption("T", "transparent", false, "Causes the diagram to be rendered on a transparent background. Overrides --background.");

cmdLnOptions.addOption(
OptionBuilder.withLongOpt("encoding")
.withDescription("The encoding of the input file.")
Expand All @@ -89,18 +89,18 @@ public static void main(String[] args){
.withArgName("TABS")
.create('t')
);

cmdLnOptions.addOption(
OptionBuilder.withLongOpt("background")
.withDescription("The background colour of the image. The format should be a six-digit hexadecimal number (as in HTML, FF0000 for red). Pass an eight-digit hex to define transparency. This is overridden by --transparent.")
.hasArg()
.withArgName("BACKGROUND")
.create('b')
);

cmdLnOptions.addOption(
OptionBuilder.withLongOpt("svg")
.withDescription( "Write a SVG image as destination file." )
.withDescription( "Write an SVG image as destination file." )
.create()
);

Expand All @@ -119,36 +119,36 @@ public static void main(String[] args){
// .hasArg()
// .withArgName("CONFIG_FILE")
// .create('c') );

CommandLine cmdLine = null;



///// parse command line options
try {
// parse the command line arguments
CommandLineParser parser = new PosixParser();

cmdLine = parser.parse(cmdLnOptions, args);

// validate that block-size has been set
if( cmdLine.hasOption( "block-size" ) ) {
// print the value of block-size
System.out.println( cmdLine.getOptionValue( "block-size" ) );
}

} catch (org.apache.commons.cli.ParseException e) {
System.err.println(e.getMessage());
new HelpFormatter().printHelp("java -jar ditaa.jar <INPFILE> [OUTFILE]", cmdLnOptions, true);
System.exit(2);
}


if(cmdLine.hasOption("help") || args.length == 0 ){
new HelpFormatter().printHelp("java -jar ditaa.jar <INPFILE> [OUTFILE]", cmdLnOptions, true);
System.exit(0);
System.exit(0);
}

ConversionOptions options = null;
try {
options = new ConversionOptions(cmdLine);
Expand All @@ -160,23 +160,23 @@ public static void main(String[] args){
new HelpFormatter().printHelp("java -jar ditaa.jar <INPFILE> [OUTFILE]", cmdLnOptions, true);
System.exit(2);
}

args = cmdLine.getArgs();

if(args.length == 0) {
System.err.println("Error: Please provide the input file filename");
new HelpFormatter().printHelp("java -jar ditaa.jar <inpfile> [outfile]", cmdLnOptions, true);
System.exit(2);
}
}

if(cmdLine.hasOption("html")){
/////// print options before running
printRunInfo(cmdLine);
String filename = args[0];

boolean overwrite = false;
if(options.processingOptions.overwriteFiles()) overwrite = true;

String toFilename;
if(args.length == 1){
toFilename = FileUtils.makeTargetPathname(filename, "html", "_processed", true);
Expand All @@ -188,12 +188,12 @@ public static void main(String[] args){
System.out.println("Error: File "+toFilename+" exists. If you would like to overwrite it, please use the --overwrite option.");
System.exit(0);
}

new HTMLConverter().convertHTMLFile(filename, toFilename, "ditaa_diagram", "images", options);
System.exit(0);

} else { //simple mode

TextGrid grid = new TextGrid();
if(options.processingOptions.getCustomShapes() != null){
grid.addToMarkupTags(options.processingOptions.getCustomShapes().keySet());
Expand All @@ -208,7 +208,7 @@ public static void main(String[] args){

boolean overwrite = false;
if(options.processingOptions.overwriteFiles()) overwrite = true;

if(args.length == 1){
if (stdIn) { // if using stdin and no output specified, use stdout
stdOut = true;
Expand Down Expand Up @@ -243,25 +243,25 @@ public static void main(String[] args){
System.err.println("Error: Cannot open file "+fromFilename+" for reading");
System.exit(1);
}

if(options.processingOptions.printDebugOutput()){
if (!stdOut) System.out.println("Using grid:");
grid.printDebug();
}

Diagram diagram = new Diagram(grid, options);
if (!stdOut) System.out.println("Rendering to file: "+toFilename);

try {

if(cmdLine.hasOption("svg")){
String content = new SVGRenderer().renderToImage(diagram, options.renderingOptions);

PrintStream stream = stdOut ? System.out : new PrintStream(new FileOutputStream(toFilename));
stream.print(content);
} else {
RenderedImage image = new BitmapRenderer().renderToImage(diagram, options.renderingOptions);

OutputStream os = stdOut ? System.out : new FileOutputStream(toFilename);
ImageIO.write(image, "png", os);
}
Expand All @@ -271,25 +271,25 @@ public static void main(String[] args){
System.err.println("Error: Cannot write to file "+toFilename);
System.exit(1);
}

//BitmapRenderer.renderToPNG(diagram, toFilename, options.renderingOptions);

long endTime = System.currentTimeMillis();
long totalTime = (endTime - startTime) / 1000;
if (!stdOut) System.out.println("Done in "+totalTime+"sec");

// try {
// Thread.sleep(Long.MAX_VALUE);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }

}
}
}

private static void printRunInfo(CommandLine cmdLine) {
System.out.println("\n"+notice+"\n");

System.out.println("Running with options:");
Option[] opts = cmdLine.getOptions();
for (Option option : opts) {
Expand Down

0 comments on commit 9d3ca31

Please sign in to comment.