mirror of
https://github.com/processing/processing4.git
synced 2026-02-13 02:20:45 +01:00
fix main() so that it handles args, also allows direct launch
This commit is contained in:
@@ -36,10 +36,10 @@ import processing.core.PApplet;
|
||||
* Contributed by Martin Gomez, additional bug fixes by Ben Fry.
|
||||
* Additional fixes by Jonathan Feinberg in March 2010.
|
||||
* <p/>
|
||||
* After some further digging, this code in fact appears to be a modified
|
||||
* version of Jason Pell's GPLed "Java Beautifier" class found
|
||||
* After some further digging, this code in fact appears to be a modified
|
||||
* version of Jason Pell's GPLed "Java Beautifier" class found
|
||||
* <a href="http://www.geocities.com/jasonpell/programs.html">here</a>.
|
||||
* Which is itself based on code from Van Di-Han Ho from
|
||||
* Which is itself based on code from Van Di-Han Ho from
|
||||
* <a href="http://www.geocities.com/~starkville/vancbj_idx.html">here</a>.
|
||||
* [Ben Fry, August 2009]
|
||||
*/
|
||||
@@ -73,8 +73,8 @@ public class AutoFormat implements Formatter {
|
||||
private char c;
|
||||
|
||||
private final Stack<Boolean> castFlags = new Stack<Boolean>();
|
||||
|
||||
|
||||
|
||||
|
||||
private void comment() {
|
||||
final boolean save_s_flg = s_flag;
|
||||
|
||||
@@ -101,7 +101,7 @@ public class AutoFormat implements Formatter {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private char get_string() {
|
||||
char ch;
|
||||
while (true) {
|
||||
@@ -129,7 +129,7 @@ public class AutoFormat implements Formatter {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void writeIndentedLine() {
|
||||
if (buf.length() == 0) {
|
||||
if (s_flag) {
|
||||
@@ -154,7 +154,7 @@ public class AutoFormat implements Formatter {
|
||||
buf.setLength(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void writeIndentedComment() {
|
||||
final boolean saved_s_flag = s_flag;
|
||||
if (buf.length() > 0) {
|
||||
@@ -186,7 +186,7 @@ public class AutoFormat implements Formatter {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void handleSingleLineComment() {
|
||||
c = next();
|
||||
while (c != '\n') {
|
||||
@@ -198,7 +198,7 @@ public class AutoFormat implements Formatter {
|
||||
s_flag = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void printIndentation() {
|
||||
if (tabs < 0) {
|
||||
tabs = 0;
|
||||
@@ -212,7 +212,7 @@ public class AutoFormat implements Formatter {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private char peek() {
|
||||
if (pos + 1 >= chars.length) {
|
||||
return 0;
|
||||
@@ -220,10 +220,10 @@ public class AutoFormat implements Formatter {
|
||||
return chars[pos + 1];
|
||||
}
|
||||
|
||||
|
||||
|
||||
private char lastNonWhitespace = 0;
|
||||
|
||||
|
||||
|
||||
private int prev() {
|
||||
return lastNonWhitespace;
|
||||
}
|
||||
@@ -272,7 +272,7 @@ public class AutoFormat implements Formatter {
|
||||
if_flg = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* read to new_line */
|
||||
private boolean getnl() {
|
||||
final int savedTabs = tabs;
|
||||
@@ -306,7 +306,7 @@ public class AutoFormat implements Formatter {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private boolean lookup(final String keyword) {
|
||||
return Pattern.matches("^\\s*" + keyword + "(?![a-zA-Z0-9_&]).*$", buf);
|
||||
}
|
||||
@@ -316,8 +316,8 @@ public class AutoFormat implements Formatter {
|
||||
final String regex = "^\\s*" + keyword.replaceAll("\\*", "\\\\*") + ".*$";
|
||||
return Pattern.matches(regex, buf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void trimRight(final StringBuilder sb) {
|
||||
while (sb.length() >= 1
|
||||
&& Character.isWhitespace(sb.charAt(sb.length() - 1)))
|
||||
@@ -430,9 +430,8 @@ public class AutoFormat implements Formatter {
|
||||
tabs--;
|
||||
}
|
||||
trimRight(buf);
|
||||
if (buf.length() > 0
|
||||
|| (result.length() > 0 && !Character.isWhitespace(result
|
||||
.charAt(result.length() - 1))))
|
||||
if (buf.length() > 0 ||
|
||||
(result.length() > 0 && !Character.isWhitespace(result.charAt(result.length() - 1))))
|
||||
buf.append(" ");
|
||||
buf.append(c);
|
||||
writeIndentedLine();
|
||||
|
||||
@@ -263,6 +263,7 @@ public class JavaBuild {
|
||||
File outputFolder = (packageName == null) ?
|
||||
srcFolder : new File(srcFolder, packageName.replace('.', '/'));
|
||||
outputFolder.mkdirs();
|
||||
// Base.openFolder(outputFolder);
|
||||
final File java = new File(outputFolder, sketch.getName() + ".java");
|
||||
final PrintWriter stream = new PrintWriter(new FileWriter(java));
|
||||
try {
|
||||
@@ -276,7 +277,6 @@ public class JavaBuild {
|
||||
throw new SketchException(msg);
|
||||
} catch (antlr.RecognitionException re) {
|
||||
// re also returns a column that we're not bothering with for now
|
||||
|
||||
// first assume that it's the main file
|
||||
// int errorFile = 0;
|
||||
int errorLine = re.getLine() - 1;
|
||||
|
||||
@@ -828,28 +828,29 @@ public class PdePreprocessor {
|
||||
*/
|
||||
protected void writeFooter(PrintWriter out, String className) {
|
||||
if (mode == Mode.STATIC) {
|
||||
// close off draw() definition
|
||||
out.println(indent + "noLoop();");
|
||||
out.println("} ");
|
||||
// close off setup() definition
|
||||
out.println(indent + indent + "noLoop();");
|
||||
out.println(indent + "}");
|
||||
out.println();
|
||||
}
|
||||
|
||||
if ((mode == Mode.STATIC) || (mode == Mode.ACTIVE)) {
|
||||
if (sketchWidth != null && !hasMethod("sketchWidth")) {
|
||||
// Only include if it's a number (a variable will be a problem)
|
||||
if (PApplet.parseInt(sketchWidth, -1) != -1 || sketchWidth.equals("displayWidth")) {
|
||||
if (PApplet.parseInt(sketchWidth, -1) != -1 || sketchWidth.equals("displayWidth")) {
|
||||
out.println(indent + "public int sketchWidth() { return " + sketchWidth + "; }");
|
||||
}
|
||||
}
|
||||
if (sketchHeight != null && !hasMethod("sketchHeight")) {
|
||||
// Only include if it's a number
|
||||
if (PApplet.parseInt(sketchHeight, -1) != -1 || sketchHeight.equals("displayHeight")) {
|
||||
if (PApplet.parseInt(sketchHeight, -1) != -1 || sketchHeight.equals("displayHeight")) {
|
||||
out.println(indent + "public int sketchHeight() { return " + sketchHeight + "; }");
|
||||
}
|
||||
}
|
||||
if (sketchRenderer != null && !hasMethod("sketchRenderer")) {
|
||||
// Only include if it's a known renderer (otherwise it might be a variable)
|
||||
if (sketchRenderer.equals("P2D") ||
|
||||
sketchRenderer.equals("P3D") ||
|
||||
if (sketchRenderer.equals("P2D") ||
|
||||
sketchRenderer.equals("P3D") ||
|
||||
sketchRenderer.equals("OPENGL") ||
|
||||
sketchRenderer.equals("JAVA2D")) {
|
||||
out.println(indent + "public String sketchRenderer() { return " + sketchRenderer + "; }");
|
||||
@@ -857,8 +858,9 @@ public class PdePreprocessor {
|
||||
}
|
||||
|
||||
if (!hasMethod("main")) {
|
||||
out.println(indent + "static public void main(String args[]) {");
|
||||
out.print(indent + indent + "PApplet.main(new String[] { ");
|
||||
out.println(indent + "static public void main(String[] passedArgs) {");
|
||||
//out.print(indent + indent + "PApplet.main(new String[] { ");
|
||||
out.print(indent + indent + "String[] appletArgs = new String[] { ");
|
||||
|
||||
if (Preferences.getBoolean("export.application.fullscreen")) {
|
||||
out.print("\"" + PApplet.ARGS_FULL_SCREEN + "\", ");
|
||||
@@ -878,7 +880,14 @@ public class PdePreprocessor {
|
||||
// String farbe = Preferences.get("run.window.bgcolor");
|
||||
// out.print("\"" + PApplet.ARGS_BGCOLOR + "=" + farbe + "\", ");
|
||||
}
|
||||
out.println("\"" + className + "\" });");
|
||||
out.println("\"" + className + "\" };");
|
||||
|
||||
out.println(indent + indent + "if (passedArgs != null) {");
|
||||
out.println(indent + indent + " PApplet.main(concat(appletArgs, passedArgs));");
|
||||
out.println(indent + indent + "} else {");
|
||||
out.println(indent + indent + " PApplet.main(appletArgs);");
|
||||
out.println(indent + indent + "}");
|
||||
|
||||
out.println(indent + "}");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user