1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-09-21 19:49:03 +00:00
plantuml/src/net/sourceforge/plantuml/Option.java

809 lines
23 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2023-02-22 18:43:48 +00:00
* (C) Copyright 2009-2024, Arnaud Roques
2010-11-15 20:35:36 +00:00
*
2023-02-22 18:43:48 +00:00
* Project Info: https://plantuml.com
2010-11-15 20:35:36 +00:00
*
2017-03-15 19:13:31 +00:00
* If you like this project or if you find it useful, you can support us at:
*
2023-02-22 18:43:48 +00:00
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/paypal
2017-03-15 19:13:31 +00:00
*
2010-11-15 20:35:36 +00:00
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
2013-12-10 19:36:50 +00:00
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
2010-11-15 20:35:36 +00:00
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
2015-04-07 18:18:37 +00:00
import java.util.Arrays;
2010-11-15 20:35:36 +00:00
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
2017-04-05 17:37:42 +00:00
import net.sourceforge.plantuml.api.ApiWarning;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.dot.GraphvizUtils;
import net.sourceforge.plantuml.file.FileGroup;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.color.ColorMapper;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.preproc.Defines;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.regex.Matcher2;
import net.sourceforge.plantuml.regex.MyPattern;
import net.sourceforge.plantuml.regex.Pattern2;
2020-05-30 15:20:23 +00:00
import net.sourceforge.plantuml.security.SFile;
2016-12-01 20:29:25 +00:00
import net.sourceforge.plantuml.stats.StatsUtils;
2022-12-17 11:01:10 +00:00
import net.sourceforge.plantuml.utils.Log;
2010-11-15 20:35:36 +00:00
public class Option {
2023-02-28 21:22:51 +00:00
// ::remove file when __CORE__
// ::remove file when __HAXE__
2010-11-15 20:35:36 +00:00
2021-05-14 08:42:57 +00:00
private final List<String> excludes = new ArrayList<>();
private final List<String> config = new ArrayList<>();
2010-11-15 20:35:36 +00:00
private final Map<String, String> defines = new LinkedHashMap<String, String>();
2021-07-25 10:41:36 +00:00
2010-11-15 20:35:36 +00:00
private String charset;
2023-02-28 21:22:51 +00:00
// ::comment when __CORE__
2010-11-15 20:35:36 +00:00
private boolean computeurl = false;
private boolean decodeurl = false;
private boolean pipe = false;
2017-03-21 21:37:59 +00:00
private String pipeDelimitor;
2016-11-04 21:39:29 +00:00
private boolean pipeMap = false;
2017-04-05 17:37:42 +00:00
private boolean pipeNoStdErr = false;
2010-11-15 20:35:36 +00:00
private boolean syntax = false;
2011-08-08 17:48:29 +00:00
private boolean checkOnly = false;
2023-02-22 18:43:48 +00:00
// ::done
2018-07-27 21:56:46 +00:00
private OptionPreprocOutputMode preprocessorOutput = null;
2015-04-07 18:18:37 +00:00
private boolean failfast = false;
private boolean failfast2 = false;
2021-06-27 16:50:40 +00:00
private boolean noerror = false;
2021-05-23 15:35:13 +00:00
2011-08-08 17:48:29 +00:00
private boolean duration = false;
2016-05-11 21:31:47 +00:00
private boolean debugsvek = false;
2023-02-22 18:43:48 +00:00
private int nbThreads = 0;
2023-02-28 21:22:51 +00:00
// ::comment when __CORE__
2017-03-12 17:22:02 +00:00
private boolean splash = false;
private boolean textProgressBar = false;
2011-08-08 17:48:29 +00:00
private int ftpPort = -1;
private String picowebBindAddress = null;
2020-10-12 20:56:58 +00:00
private int picowebPort = -1;
2022-08-24 16:46:33 +00:00
private boolean picowebEnableStop = false;
2023-02-22 18:43:48 +00:00
private int stdrpt = 0;
2017-04-19 18:30:16 +00:00
private boolean hideMetadata = false;
2018-05-01 17:26:04 +00:00
private boolean checkMetadata = false;
2023-02-22 18:43:48 +00:00
private String filename;
// ::done
2017-07-03 17:59:53 +00:00
private int imageIndex = 0;
2021-05-08 01:07:20 +00:00
private String fileDir;
2010-11-15 20:35:36 +00:00
private File outputDir = null;
2011-08-08 17:48:29 +00:00
private File outputFile = null;
2013-12-10 19:36:50 +00:00
2021-05-14 08:42:57 +00:00
private final List<String> result = new ArrayList<>();
2010-11-15 20:35:36 +00:00
public Option() {
}
2017-04-05 17:37:42 +00:00
private FileFormatOption fileFormatOption = new FileFormatOption(FileFormat.PNG);
2010-11-15 20:35:36 +00:00
/**
* @deprecated Use {@link #setFileFormatOption(FileFormatOption)} instead
*/
2017-04-05 17:37:42 +00:00
@Deprecated
@ApiWarning(willBeRemoved = "in next major release")
final public void setFileFormat(FileFormat fileFormat) {
setFileFormatOption(new FileFormatOption(fileFormat));
2010-11-15 20:35:36 +00:00
}
2017-04-05 17:37:42 +00:00
final public void setFileFormatOption(FileFormatOption newFormat) {
this.fileFormatOption = newFormat;
2010-11-15 20:35:36 +00:00
}
2023-02-28 21:22:51 +00:00
// ::comment when __CORE__
2010-11-15 20:35:36 +00:00
public Option(String... arg) throws InterruptedException, IOException {
2022-08-24 16:46:33 +00:00
if (arg.length == 0)
2010-11-15 20:35:36 +00:00
OptionFlags.getInstance().setGui(true);
2022-08-24 16:46:33 +00:00
2019-02-09 21:56:24 +00:00
initInclude(GraphvizUtils.getenvDefaultConfigFilename());
2010-11-15 20:35:36 +00:00
for (int i = 0; i < arg.length; i++) {
String s = arg[i];
2018-06-12 20:50:45 +00:00
if (s.equalsIgnoreCase("-headless")) {
// Useless because done in Run.java
2022-08-24 16:46:33 +00:00
if (i != 0)
2018-06-12 20:50:45 +00:00
Log.error("Warning: -headless flag must be the first one in the command line");
2022-08-24 16:46:33 +00:00
2018-06-12 20:50:45 +00:00
System.setProperty("java.awt.headless", "true");
} else if (s.equalsIgnoreCase("-tsvg") || s.equalsIgnoreCase("-svg")) {
2017-04-05 17:37:42 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.SVG));
2017-04-05 17:37:42 +00:00
} else if (s.equalsIgnoreCase("-tsvg:nornd") || s.equalsIgnoreCase("-svg:nornd")) {
2017-04-19 18:30:16 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.SVG));
2013-12-10 19:36:50 +00:00
} else if (s.equalsIgnoreCase("-thtml") || s.equalsIgnoreCase("-html")) {
2017-04-05 17:37:42 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.HTML));
2016-04-22 20:36:08 +00:00
} else if (s.equalsIgnoreCase("-tscxml") || s.equalsIgnoreCase("-scxml")) {
2017-04-05 17:37:42 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.SCXML));
2011-01-05 18:23:06 +00:00
} else if (s.equalsIgnoreCase("-txmi") || s.equalsIgnoreCase("-xmi")) {
2017-04-05 17:37:42 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.XMI_STANDARD));
2011-01-05 18:23:06 +00:00
} else if (s.equalsIgnoreCase("-txmi:argo") || s.equalsIgnoreCase("-xmi:argo")) {
2017-04-05 17:37:42 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.XMI_ARGO));
} else if (s.equalsIgnoreCase("-txmi:script") || s.equalsIgnoreCase("-xmi:script")) {
setFileFormatOption(new FileFormatOption(FileFormat.XMI_SCRIPT));
2011-01-05 18:23:06 +00:00
} else if (s.equalsIgnoreCase("-txmi:star") || s.equalsIgnoreCase("-xmi:star")) {
2017-04-05 17:37:42 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.XMI_STAR));
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-teps") || s.equalsIgnoreCase("-eps")) {
2017-04-05 17:37:42 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.EPS));
2011-08-08 17:48:29 +00:00
} else if (s.equalsIgnoreCase("-teps:text") || s.equalsIgnoreCase("-eps:text")) {
2017-04-05 17:37:42 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.EPS_TEXT));
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-ttxt") || s.equalsIgnoreCase("-txt")) {
2017-04-05 17:37:42 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.ATXT));
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-tutxt") || s.equalsIgnoreCase("-utxt")) {
2017-04-05 17:37:42 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.UTXT));
2016-08-25 20:45:37 +00:00
} else if (s.equalsIgnoreCase("-braille") || s.equalsIgnoreCase("-tbraille")) {
2017-04-05 17:37:42 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.BRAILLE_PNG));
2013-12-10 19:36:50 +00:00
} else if (s.equalsIgnoreCase("-png") || s.equalsIgnoreCase("-tpng")) {
2017-04-05 17:37:42 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.PNG));
2013-12-10 19:36:50 +00:00
} else if (s.equalsIgnoreCase("-vdx") || s.equalsIgnoreCase("-tvdx")) {
2017-04-05 17:37:42 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.VDX));
2015-04-07 18:18:37 +00:00
} else if (s.equalsIgnoreCase("-latex") || s.equalsIgnoreCase("-tlatex")) {
2017-04-05 17:37:42 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.LATEX));
2016-03-06 16:47:34 +00:00
} else if (s.equalsIgnoreCase("-latex:nopreamble") || s.equalsIgnoreCase("-tlatex:nopreamble")) {
2017-04-05 17:37:42 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.LATEX_NO_PREAMBLE));
2015-04-07 18:18:37 +00:00
} else if (s.equalsIgnoreCase("-base64") || s.equalsIgnoreCase("-tbase64")) {
2017-04-05 17:37:42 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.BASE64));
2011-08-08 17:48:29 +00:00
} else if (s.equalsIgnoreCase("-pdf") || s.equalsIgnoreCase("-tpdf")) {
2017-04-05 17:37:42 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.PDF));
2022-09-23 16:53:33 +00:00
} else if (s.equalsIgnoreCase("-darkmode")) {
2022-10-18 20:57:44 +00:00
setFileFormatOption(this.fileFormatOption.withColorMapper(ColorMapper.DARK_MODE));
2013-12-10 19:36:50 +00:00
} else if (s.equalsIgnoreCase("-overwrite")) {
OptionFlags.getInstance().setOverwrite(true);
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-output") || s.equalsIgnoreCase("-o")) {
i++;
2022-08-24 16:46:33 +00:00
if (i == arg.length)
2010-11-15 20:35:36 +00:00
continue;
2022-08-24 16:46:33 +00:00
2010-11-15 20:35:36 +00:00
outputDir = new File(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]));
2011-08-08 17:48:29 +00:00
} else if (s.equalsIgnoreCase("-ofile")) {
i++;
2022-08-24 16:46:33 +00:00
if (i == arg.length)
2011-08-08 17:48:29 +00:00
continue;
2022-08-24 16:46:33 +00:00
2011-08-08 17:48:29 +00:00
outputFile = new File(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]));
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-graphvizdot") || s.equalsIgnoreCase("-graphviz_dot")) {
i++;
2022-08-24 16:46:33 +00:00
if (i == arg.length)
2010-11-15 20:35:36 +00:00
continue;
2022-08-24 16:46:33 +00:00
2016-04-04 19:05:10 +00:00
GraphvizUtils.setDotExecutable(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]));
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-charset")) {
i++;
2022-08-24 16:46:33 +00:00
if (i == arg.length)
2010-11-15 20:35:36 +00:00
continue;
2022-08-24 16:46:33 +00:00
2010-11-15 20:35:36 +00:00
charset = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]);
2017-12-11 21:02:10 +00:00
} else if (s.equalsIgnoreCase("-filename")) {
i++;
2022-08-24 16:46:33 +00:00
if (i == arg.length)
2017-12-11 21:02:10 +00:00
continue;
2022-08-24 16:46:33 +00:00
2017-12-11 21:02:10 +00:00
filename = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]);
2021-05-08 01:07:20 +00:00
} else if (s.equalsIgnoreCase("-filedir")) {
i++;
2022-08-24 16:46:33 +00:00
if (i == arg.length)
2021-05-08 01:07:20 +00:00
continue;
2022-08-24 16:46:33 +00:00
2021-05-08 01:07:20 +00:00
fileDir = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]);
2010-11-15 20:35:36 +00:00
} else if (s.startsWith("-o") && s.length() > 3) {
s = s.substring(2);
outputDir = new File(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s));
} else if (s.equalsIgnoreCase("-exclude") || s.equalsIgnoreCase("-x")) {
i++;
2022-08-24 16:46:33 +00:00
if (i == arg.length)
2010-11-15 20:35:36 +00:00
continue;
2022-08-24 16:46:33 +00:00
2010-11-15 20:35:36 +00:00
excludes.add(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]));
2011-08-08 17:48:29 +00:00
} else if (s.equalsIgnoreCase("-nbthread") || s.equalsIgnoreCase("-nbthreads")) {
i++;
2022-08-24 16:46:33 +00:00
if (i == arg.length)
2011-08-08 17:48:29 +00:00
continue;
2022-08-24 16:46:33 +00:00
2011-08-08 17:48:29 +00:00
final String nb = arg[i];
2022-08-24 16:46:33 +00:00
if ("auto".equalsIgnoreCase(nb))
2011-08-08 17:48:29 +00:00
this.nbThreads = defaultNbThreads();
2022-08-24 16:46:33 +00:00
else if (nb.matches("\\d+"))
2011-08-08 17:48:29 +00:00
this.nbThreads = Integer.parseInt(nb);
2022-08-24 16:46:33 +00:00
2017-04-05 17:37:42 +00:00
} else if (s.equalsIgnoreCase("-timeout")) {
i++;
2022-08-24 16:46:33 +00:00
if (i == arg.length)
2017-04-05 17:37:42 +00:00
continue;
2022-08-24 16:46:33 +00:00
2017-04-05 17:37:42 +00:00
final String timeSeconds = arg[i];
2022-08-24 16:46:33 +00:00
if (timeSeconds.matches("\\d+"))
2017-04-05 17:37:42 +00:00
OptionFlags.getInstance().setTimeoutMs(Integer.parseInt(timeSeconds) * 1000L);
2022-08-24 16:46:33 +00:00
2015-04-07 18:18:37 +00:00
} else if (s.equalsIgnoreCase("-failfast")) {
this.failfast = true;
2015-04-07 18:18:37 +00:00
} else if (s.equalsIgnoreCase("-failfast2")) {
this.failfast2 = true;
2021-06-27 16:50:40 +00:00
} else if (s.equalsIgnoreCase("-noerror")) {
this.noerror = true;
2011-08-08 17:48:29 +00:00
} else if (s.equalsIgnoreCase("-checkonly")) {
this.checkOnly = true;
2021-05-03 20:11:48 +00:00
} else if (s.equalsIgnoreCase("-theme")) {
i++;
2022-08-24 16:46:33 +00:00
if (i == arg.length)
2021-05-03 20:11:48 +00:00
continue;
2022-08-24 16:46:33 +00:00
2021-05-03 20:11:48 +00:00
this.config.add(0, "!theme " + arg[i]);
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-config")) {
i++;
2022-08-24 16:46:33 +00:00
if (i == arg.length)
2010-11-15 20:35:36 +00:00
continue;
2022-08-24 16:46:33 +00:00
2010-11-15 20:35:36 +00:00
initConfig(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]));
2017-03-15 19:13:31 +00:00
} else if (s.startsWith("-I")) {
initInclude(s.substring(2));
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-computeurl") || s.equalsIgnoreCase("-encodeurl")) {
this.computeurl = true;
2010-11-15 20:35:36 +00:00
} else if (s.startsWith("-x")) {
s = s.substring(2);
excludes.add(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s));
} else if (s.equalsIgnoreCase("-verbose") || s.equalsIgnoreCase("--verbose") || s.equalsIgnoreCase("-v")) {
2010-11-15 20:35:36 +00:00
OptionFlags.getInstance().setVerbose(true);
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-pipe") || s.equalsIgnoreCase("-p")) {
pipe = true;
2017-03-21 21:37:59 +00:00
} else if (s.equalsIgnoreCase("-pipedelimitor")) {
i++;
2022-08-24 16:46:33 +00:00
if (i == arg.length)
2017-03-21 21:37:59 +00:00
continue;
2022-08-24 16:46:33 +00:00
2017-03-21 21:37:59 +00:00
pipeDelimitor = arg[i];
2016-11-04 21:39:29 +00:00
} else if (s.equalsIgnoreCase("-pipemap")) {
pipeMap = true;
2017-04-05 17:37:42 +00:00
} else if (s.equalsIgnoreCase("-pipenostderr")) {
pipeNoStdErr = true;
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-syntax")) {
syntax = true;
OptionFlags.getInstance().setQuiet(true);
2011-08-08 17:48:29 +00:00
} else if (s.equalsIgnoreCase("-duration")) {
duration = true;
2016-05-11 21:31:47 +00:00
} else if (s.equalsIgnoreCase("-debugsvek") || s.equalsIgnoreCase("-debug_svek")) {
debugsvek = true;
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-keepfiles") || s.equalsIgnoreCase("-keepfile")) {
2016-05-11 21:31:47 +00:00
System.err.println("-keepfiles option has been removed. Please consider -debugsvek instead");
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-metadata")) {
2017-04-19 18:30:16 +00:00
OptionFlags.getInstance().setExtractFromMetadata(true);
2011-08-08 17:48:29 +00:00
} else if (s.equalsIgnoreCase("-logdata")) {
i++;
2022-08-24 16:46:33 +00:00
if (i == arg.length)
2011-08-08 17:48:29 +00:00
continue;
2022-08-24 16:46:33 +00:00
2020-05-30 15:20:23 +00:00
OptionFlags.getInstance()
.setLogData(new SFile(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i])));
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-word")) {
OptionFlags.getInstance().setWord(true);
OptionFlags.getInstance().setQuiet(true);
2017-07-03 17:59:53 +00:00
this.charset = "UTF-8";
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-quiet")) {
OptionFlags.getInstance().setQuiet(true);
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-decodeurl")) {
this.decodeurl = true;
} else if (s.equalsIgnoreCase("-version") || s.equalsIgnoreCase("--version")) {
2010-11-15 20:35:36 +00:00
OptionPrint.printVersion();
2013-12-10 19:36:50 +00:00
} else if (s.matches("(?i)^-li[sc][ea]n[sc]e\\s*$")) {
OptionPrint.printLicense();
2018-08-26 12:09:50 +00:00
} else if (s.startsWith("-DPLANTUML_LIMIT_SIZE=")) {
final String v = s.substring("-DPLANTUML_LIMIT_SIZE=".length());
2022-08-24 16:46:33 +00:00
if (v.matches("\\d+"))
2018-08-26 12:09:50 +00:00
System.setProperty("PLANTUML_LIMIT_SIZE", v);
2022-08-24 16:46:33 +00:00
2010-11-15 20:35:36 +00:00
} else if (s.startsWith("-D")) {
manageDefine(s.substring(2));
2011-04-19 16:50:40 +00:00
} else if (s.startsWith("-S")) {
manageSkinParam(s.substring(2));
2021-07-25 10:41:36 +00:00
} else if (s.startsWith("-P")) {
managePragma(s.substring(2));
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-testdot")) {
OptionPrint.printTestDot();
2020-05-30 15:20:23 +00:00
} else if (s.equalsIgnoreCase("-about") || s.equalsIgnoreCase("-author")
|| s.equalsIgnoreCase("-authors")) {
2010-11-15 20:35:36 +00:00
OptionPrint.printAbout();
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-help") || s.equalsIgnoreCase("-h") || s.equalsIgnoreCase("-?")) {
OptionPrint.printHelp();
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-language")) {
OptionPrint.printLanguage();
2010-11-15 20:35:36 +00:00
} else if (s.equalsIgnoreCase("-gui")) {
OptionFlags.getInstance().setGui(true);
2013-12-10 19:36:50 +00:00
} else if (s.equalsIgnoreCase("-encodesprite")) {
OptionFlags.getInstance().setEncodesprite(true);
2011-08-08 17:48:29 +00:00
} else if (s.equalsIgnoreCase("-printfonts")) {
OptionFlags.getInstance().setPrintFonts(true);
2016-12-01 20:29:25 +00:00
} else if (s.equalsIgnoreCase("-dumphtmlstats")) {
OptionFlags.getInstance().setDumpHtmlStats(true);
2016-12-01 20:29:25 +00:00
} else if (s.equalsIgnoreCase("-dumpstats")) {
OptionFlags.getInstance().setDumpStats(true);
2016-12-01 20:29:25 +00:00
} else if (s.equalsIgnoreCase("-loopstats")) {
OptionFlags.getInstance().setLoopStats(true);
2016-12-14 21:01:03 +00:00
} else if (s.equalsIgnoreCase("-enablestats")) {
OptionFlags.getInstance().setEnableStats(true);
2016-12-14 21:01:03 +00:00
} else if (s.equalsIgnoreCase("-disablestats")) {
OptionFlags.getInstance().setEnableStats(false);
2017-12-11 21:02:10 +00:00
} else if (s.equalsIgnoreCase("-extractstdlib")) {
OptionFlags.getInstance().setExtractStdLib(true);
2018-06-12 20:50:45 +00:00
} else if (s.equalsIgnoreCase("-stdlib")) {
OptionFlags.getInstance().setStdLib(true);
2018-06-12 20:50:45 +00:00
} else if (s.equalsIgnoreCase("-clipboard")) {
OptionFlags.getInstance().setClipboard(true);
2018-06-12 20:50:45 +00:00
} else if (s.equalsIgnoreCase("-clipboardloop")) {
OptionFlags.getInstance().setClipboardLoop(true);
2016-12-01 20:29:25 +00:00
} else if (s.equalsIgnoreCase("-htmlstats")) {
StatsUtils.setHtmlStats(true);
2016-12-01 20:29:25 +00:00
} else if (s.equalsIgnoreCase("-xmlstats")) {
StatsUtils.setXmlStats(true);
2016-12-01 20:29:25 +00:00
} else if (s.equalsIgnoreCase("-realtimestats")) {
StatsUtils.setRealTimeStats(true);
2016-12-01 20:29:25 +00:00
} else if (s.equalsIgnoreCase("-useseparatorminus")) {
OptionFlags.getInstance().setFileSeparator("-");
2017-03-12 17:22:02 +00:00
} else if (s.equalsIgnoreCase("-splash")) {
splash = true;
2017-03-12 17:22:02 +00:00
} else if (s.equalsIgnoreCase("-progress")) {
textProgressBar = true;
2017-04-19 18:30:16 +00:00
} else if (s.equalsIgnoreCase("-nometadata")) {
hideMetadata = true;
2018-07-27 21:56:46 +00:00
} else if (s.equalsIgnoreCase("-preproc")) {
preprocessorOutput = OptionPreprocOutputMode.NORMAL;
2023-12-11 17:34:23 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.PREPROC));
2018-07-27 21:56:46 +00:00
} else if (s.equalsIgnoreCase("-cypher")) {
preprocessorOutput = OptionPreprocOutputMode.CYPHER;
2023-12-11 17:34:23 +00:00
setFileFormatOption(new FileFormatOption(FileFormat.PREPROC));
2018-05-01 17:26:04 +00:00
} else if (s.equalsIgnoreCase("-checkmetadata")) {
checkMetadata = true;
2018-12-22 11:11:40 +00:00
} else if (s.equalsIgnoreCase("-stdrpt:1")) {
stdrpt = 1;
2020-08-25 17:24:17 +00:00
} else if (s.equalsIgnoreCase("-stdrpt:2")) {
stdrpt = 2;
2018-12-22 11:11:40 +00:00
} else if (s.equalsIgnoreCase("-stdrpt")) {
2020-08-25 17:24:17 +00:00
stdrpt = 2;
2017-07-03 17:59:53 +00:00
} else if (s.equalsIgnoreCase("-pipeimageindex")) {
i++;
2022-08-24 16:46:33 +00:00
if (i == arg.length)
2017-07-03 17:59:53 +00:00
continue;
2022-08-24 16:46:33 +00:00
2017-07-03 17:59:53 +00:00
final String nb = arg[i];
2022-08-24 16:46:33 +00:00
if (nb.matches("\\d+"))
2017-07-03 17:59:53 +00:00
this.imageIndex = Integer.parseInt(nb);
2022-08-24 16:46:33 +00:00
2015-04-07 18:18:37 +00:00
} else if (StringUtils.goLowerCase(s).startsWith("-ftp")) {
2011-08-08 17:48:29 +00:00
final int x = s.indexOf(':');
2022-08-24 16:46:33 +00:00
if (x == -1)
2011-08-08 17:48:29 +00:00
this.ftpPort = 4242;
2022-08-24 16:46:33 +00:00
else
2011-08-08 17:48:29 +00:00
this.ftpPort = Integer.parseInt(s.substring(x + 1));
2022-08-24 16:46:33 +00:00
2020-10-12 20:56:58 +00:00
} else if (StringUtils.goLowerCase(s).startsWith("-picoweb")) {
final String[] parts = s.split(":");
this.picowebPort = parts.length > 1 ? Integer.parseInt(parts[1]) : 8080;
this.picowebBindAddress = parts.length > 2 ? parts[2] : null;
2022-08-24 16:46:33 +00:00
this.picowebEnableStop = StringUtils.goLowerCase(s).contains("stop");
2013-12-10 19:36:50 +00:00
} else if (s.startsWith("-c")) {
s = s.substring(2);
config.add(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s));
2010-11-15 20:35:36 +00:00
} else {
result.add(s);
}
}
}
2018-12-22 11:11:40 +00:00
public Stdrpt getStdrpt() {
2022-08-24 16:46:33 +00:00
if (stdrpt == 1)
2018-12-22 11:11:40 +00:00
return new StdrptV1();
2022-08-24 16:46:33 +00:00
if (stdrpt == 2)
2020-08-25 17:24:17 +00:00
return new StdrptV2();
2022-08-24 16:46:33 +00:00
2018-12-22 11:11:40 +00:00
// Legacy case
2022-08-24 16:46:33 +00:00
if (isPipe() || isPipeMap() || isSyntax())
2018-12-22 11:11:40 +00:00
return new StdrptPipe0();
2022-08-24 16:46:33 +00:00
2018-12-22 11:11:40 +00:00
return new StdrptNull();
}
2011-08-08 17:48:29 +00:00
public int getFtpPort() {
return ftpPort;
}
public String getPicowebBindAddress() {
return picowebBindAddress;
}
2020-10-12 20:56:58 +00:00
public int getPicowebPort() {
return picowebPort;
}
2022-08-24 16:46:33 +00:00
public boolean getPicowebEnableStop() {
return picowebEnableStop;
}
2023-02-22 18:43:48 +00:00
// ::done
2022-08-24 16:46:33 +00:00
2020-05-30 15:20:23 +00:00
private void addInConfig(BufferedReader br) throws IOException {
2022-08-24 16:46:33 +00:00
if (br == null)
2020-05-30 15:20:23 +00:00
return;
2022-08-24 16:46:33 +00:00
2010-11-15 20:35:36 +00:00
try {
String s = null;
2022-08-24 16:46:33 +00:00
while ((s = br.readLine()) != null)
2010-11-15 20:35:36 +00:00
config.add(s);
2022-08-24 16:46:33 +00:00
2010-11-15 20:35:36 +00:00
} finally {
2020-05-30 15:20:23 +00:00
br.close();
2010-11-15 20:35:36 +00:00
}
}
2017-03-15 19:13:31 +00:00
public void initConfig(String filename) throws IOException {
2020-05-30 15:20:23 +00:00
final BufferedReader br = new BufferedReader(new FileReader(filename));
addInConfig(br);
2017-03-15 19:13:31 +00:00
}
private void initInclude(String filename) throws IOException {
2022-08-24 16:46:33 +00:00
if (filename == null)
2019-02-09 21:56:24 +00:00
return;
2022-08-24 16:46:33 +00:00
2017-03-15 19:13:31 +00:00
if (filename.contains("*")) {
2020-05-30 15:20:23 +00:00
final FileGroup group = new FileGroup(filename, Collections.<String>emptyList(), null);
2022-08-24 16:46:33 +00:00
for (File f : group.getFiles())
if (f.exists() && f.canRead())
2020-05-30 15:20:23 +00:00
addInConfig(new BufferedReader(new FileReader(f)));
2022-08-24 16:46:33 +00:00
2017-03-15 19:13:31 +00:00
} else {
2019-02-09 21:56:24 +00:00
final File f = new File(filename);
2022-08-24 16:46:33 +00:00
if (f.exists() && f.canRead())
2020-05-30 15:20:23 +00:00
addInConfig(new BufferedReader(new FileReader(f)));
2022-08-24 16:46:33 +00:00
2017-03-15 19:13:31 +00:00
}
}
2010-11-15 20:35:36 +00:00
private void manageDefine(String s) {
2016-05-31 19:41:55 +00:00
final Pattern2 p = MyPattern.cmpile("^(\\w+)(?:=(.*))?$");
final Matcher2 m = p.matcher(s);
2022-08-24 16:46:33 +00:00
if (m.find())
2010-11-15 20:35:36 +00:00
define(m.group(1), m.group(2));
2022-08-24 16:46:33 +00:00
2010-11-15 20:35:36 +00:00
}
2021-07-25 10:41:36 +00:00
private void managePragma(String s) {
2016-05-31 19:41:55 +00:00
final Pattern2 p = MyPattern.cmpile("^(\\w+)(?:=(.*))?$");
final Matcher2 m = p.matcher(s);
2011-04-19 16:50:40 +00:00
if (m.find()) {
2021-07-25 10:41:36 +00:00
final String var = m.group(1);
final String value = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m.group(2));
2022-08-24 16:46:33 +00:00
if (var != null && value != null)
2021-07-25 10:41:36 +00:00
config.add("!pragma " + var + " " + value);
2022-08-24 16:46:33 +00:00
2011-04-19 16:50:40 +00:00
}
}
2021-07-25 10:41:36 +00:00
private void manageSkinParam(String s) {
final Pattern2 p = MyPattern.cmpile("^(\\w+)(?:=(.*))?$");
final Matcher2 m = p.matcher(s);
if (m.find()) {
final String var = m.group(1);
final String value = m.group(2);
2022-08-24 16:46:33 +00:00
if (var != null && value != null)
2021-07-25 10:41:36 +00:00
config.add("skinparamlocked " + var + " " + value);
2022-08-24 16:46:33 +00:00
2011-04-19 16:50:40 +00:00
}
}
2010-11-15 20:35:36 +00:00
public final File getOutputDir() {
return outputDir;
}
public final static String getPattern() {
2020-04-19 16:04:39 +00:00
return "(?i)^.*\\.(txt|tex|java|htm|html|c|h|cpp|apt|pu|puml|hpp|hh)$";
2010-11-15 20:35:36 +00:00
}
public void setOutputDir(File f) {
outputDir = f;
}
public final List<String> getExcludes() {
return Collections.unmodifiableList(excludes);
}
2023-02-28 21:22:51 +00:00
// ::comment when __CORE__
2020-05-30 15:20:23 +00:00
public Defines getDefaultDefines(SFile f) {
final Defines result = Defines.createWithFileName(f);
for (Map.Entry<String, String> ent : defines.entrySet()) {
String value = ent.getValue();
2022-08-24 16:46:33 +00:00
if (value == null)
2020-05-30 15:20:23 +00:00
value = "";
2022-08-24 16:46:33 +00:00
2020-05-30 15:20:23 +00:00
result.define(ent.getKey(), Arrays.asList(value), false, null);
}
return result;
}
public Defines getDefaultDefines(java.io.File f) {
2017-04-05 17:37:42 +00:00
final Defines result = Defines.createWithFileName(f);
2010-11-15 20:35:36 +00:00
for (Map.Entry<String, String> ent : defines.entrySet()) {
2020-01-12 22:13:17 +00:00
String value = ent.getValue();
if (value == null) {
value = "";
}
result.define(ent.getKey(), Arrays.asList(value), false, null);
2018-01-04 22:32:45 +00:00
}
return result;
}
2010-11-15 20:35:36 +00:00
2018-01-04 22:32:45 +00:00
public Defines getDefaultDefines() {
final Defines result = Defines.createEmpty();
result.overrideFilename(filename);
2022-08-24 16:46:33 +00:00
for (Map.Entry<String, String> ent : defines.entrySet())
2018-12-22 11:11:40 +00:00
result.define(ent.getKey(), Arrays.asList(ent.getValue()), false, null);
2022-08-24 16:46:33 +00:00
2010-11-15 20:35:36 +00:00
return result;
}
2023-02-22 18:43:48 +00:00
// ::done
2010-11-15 20:35:36 +00:00
public void define(String name, String value) {
defines.put(name, value);
}
public List<String> getConfig() {
return Collections.unmodifiableList(config);
}
public final List<String> getResult() {
return Collections.unmodifiableList(result);
}
public final String getCharset() {
return charset;
}
public void setCharset(String s) {
this.charset = s;
}
2023-02-28 21:22:51 +00:00
// ::comment when __CORE__
2010-11-15 20:35:36 +00:00
public final boolean isComputeurl() {
return computeurl;
}
public final boolean isDecodeurl() {
return decodeurl;
}
public final boolean isPipe() {
return pipe;
}
2016-11-04 21:39:29 +00:00
public final boolean isPipeMap() {
return pipeMap;
}
2010-11-15 20:35:36 +00:00
public final boolean isSyntax() {
return syntax;
}
2011-01-05 18:23:06 +00:00
public FileFormatOption getFileFormatOption() {
2022-08-24 16:46:33 +00:00
if (debugsvek)
2016-05-11 21:31:47 +00:00
fileFormatOption.setDebugSvek(true);
2022-08-24 16:46:33 +00:00
if (hideMetadata)
2017-04-19 18:30:16 +00:00
fileFormatOption.hideMetadata();
2022-08-24 16:46:33 +00:00
2016-05-11 21:31:47 +00:00
return fileFormatOption;
2011-01-05 18:23:06 +00:00
}
2023-02-22 18:43:48 +00:00
// ::done
2011-01-05 18:23:06 +00:00
2011-08-08 17:48:29 +00:00
public final boolean isDuration() {
return duration;
}
public final int getNbThreads() {
return nbThreads;
}
public final void setNbThreads(int nb) {
this.nbThreads = nb;
}
public static int defaultNbThreads() {
return Runtime.getRuntime().availableProcessors();
}
2023-02-28 21:22:51 +00:00
// ::comment when __CORE__
2011-08-08 17:48:29 +00:00
public final boolean isCheckOnly() {
return checkOnly;
}
public final void setCheckOnly(boolean checkOnly) {
this.checkOnly = checkOnly;
}
2023-02-22 18:43:48 +00:00
// ::done
2011-08-08 17:48:29 +00:00
2015-04-07 18:18:37 +00:00
public final boolean isFailfastOrFailfast2() {
return failfast || failfast2;
}
public final boolean isFailfast2() {
return failfast2;
}
public final void setFailfast(boolean failfast) {
this.failfast = failfast;
}
public final void setFailfast2(boolean failfast2) {
this.failfast2 = failfast2;
}
2021-06-27 16:50:40 +00:00
public final void setNoerror(boolean noerror) {
this.noerror = noerror;
}
public final boolean isNoerror() {
return noerror;
}
2011-08-08 17:48:29 +00:00
public final File getOutputFile() {
return outputFile;
}
2016-05-11 21:31:47 +00:00
public final void setDebugSvek(boolean debugsvek) {
this.debugsvek = debugsvek;
}
boolean isDebugSvek() {
return debugsvek;
}
2023-02-28 21:22:51 +00:00
// ::comment when __CORE__
2017-03-12 17:22:02 +00:00
public final boolean isSplash() {
return splash;
}
public final void setSplash(boolean splash) {
this.splash = splash;
}
public final boolean isTextProgressBar() {
return textProgressBar;
}
2017-03-21 21:37:59 +00:00
public String getPipeDelimitor() {
return pipeDelimitor;
}
2017-04-05 17:37:42 +00:00
public final boolean isPipeNoStdErr() {
return pipeNoStdErr;
}
2023-02-22 18:43:48 +00:00
public final boolean isCheckMetadata() {
return checkMetadata;
2017-07-03 17:59:53 +00:00
}
2017-12-11 21:02:10 +00:00
public final void setFilename(String filename) {
this.filename = filename;
}
2023-02-22 18:43:48 +00:00
// ::done
public final int getImageIndex() {
return imageIndex;
2018-05-01 17:26:04 +00:00
}
2018-07-27 21:56:46 +00:00
public final OptionPreprocOutputMode getPreprocessorOutputMode() {
return preprocessorOutput;
}
2021-05-08 01:07:20 +00:00
public String getFileDir() {
return fileDir;
}
2022-08-24 16:46:33 +00:00
2010-11-15 20:35:36 +00:00
}