diff --git a/app/PdeEditor.java b/app/PdeEditor.java index f10ae6247..25b35b65e 100644 --- a/app/PdeEditor.java +++ b/app/PdeEditor.java @@ -1793,211 +1793,6 @@ public class PdeEditor extends JFrame } */ - protected void handleExport(File appletDir, String exportSketchName, - File dataDir) { - try { - String program = textarea.getText(); - - // create the project directory - // pass null for datapath because the files shouldn't be - // copied to the build dir.. that's only for the temp stuff - appletDir.mkdirs(); - - // build the sketch - exportSketchName = - build(program, exportSketchName, appletDir.getPath(), true); - - // (already reported) error during export, exit this function - if (exportSketchName == null) { - buttons.clear(); - return; - } - - int wide = BApplet.DEFAULT_WIDTH; - int high = BApplet.DEFAULT_HEIGHT; - - try { - PatternMatcher matcher = new Perl5Matcher(); - PatternCompiler compiler = new Perl5Compiler(); - - // don't just use this version, since it only grabs the numbers - //String sizing = "[\\s\\;]size\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\);"; - - // this matches against any uses of the size() function, whether they - // contain numbers of variables or whatever. this way, no warning is - // shown if size() isn't actually used in the applet, which is the case - // especially for beginners that are cutting/pasting from the reference. - String sizing = "[\\s\\;]size\\s*\\(\\s*(\\S+)\\s*,\\s*(\\S+)\\s*\\);"; - - Pattern pattern = compiler.compile(sizing); - - // adds a space at the beginning, in case size() is the very first - // thing in the program (very common), since the regexp needs to check - // for things in front of it. - PatternMatcherInput input = new PatternMatcherInput(" " + program); - if (matcher.contains(input, pattern)) { - MatchResult result = matcher.getMatch(); - try { - wide = Integer.parseInt(result.group(1).toString()); - high = Integer.parseInt(result.group(2).toString()); - //System.out.println("width " + wide + " high " + high); - - } catch (NumberFormatException e) { - - // found a reference to size, but it didn't seem to contain numbers - final String message = - "The size of this applet could not automatically be\n" + - "determined from your code. You'll have to edit the\n" + - "HTML file to set the size of the applet."; - - JOptionPane.showMessageDialog(this, message, - "Could not find applet size", - JOptionPane.WARNING_MESSAGE); - } - } // else no size() command found - - } catch (MalformedPatternException e){ - e.printStackTrace(); - //System.err.println("Bad pattern."); - //System.err.println(e.getMessage()); - } - - File htmlOutputFile = new File(appletDir, "index.html"); - FileOutputStream fos = new FileOutputStream(htmlOutputFile); - PrintStream ps = new PrintStream(fos); - - // wide, high, and exportSketchName - - // @@sketch@@, @@width@@, @@height@@, @@archive@@ - - InputStream is = PdeBase.getStream("applet.html"); - BufferedReader reader = new BufferedReader(new InputStreamReader(is)); - - String line = null; - while ((line = reader.readLine()) != null) { - if (line.indexOf("@@") != -1) { - StringBuffer sb = new StringBuffer(line); - int index = 0; - while ((index = sb.indexOf("@@sketch@@")) != -1) { - sb.replace(index, index + "@@sketch@@".length(), - exportSketchName); - } - while ((index = sb.indexOf("@@archive@@")) != -1) { - sb.replace(index, index + "@@archive@@".length(), - exportSketchName + ".jar"); - } - while ((index = sb.indexOf("@@width@@")) != -1) { - sb.replace(index, index + "@@width@@".length(), - String.valueOf(wide)); - } - while ((index = sb.indexOf("@@height@@")) != -1) { - sb.replace(index, index + "@@height@@".length(), - String.valueOf(wide)); - } - line = sb.toString(); - } - ps.println(line); - } - - reader.close(); - - ps.flush(); - ps.close(); - - // create new .jar file - FileOutputStream zipOutputFile = - new FileOutputStream(new File(appletDir, exportSketchName + ".jar")); - ZipOutputStream zos = new ZipOutputStream(zipOutputFile); - ZipEntry entry; - - File codeFolder = new File(sketchDir, "code"); - if (codeFolder.exists()) { - String includes = PdeCompiler.includeFolder(codeFolder); - PdeCompiler.magicExports(includes, zos); - } - - // add standard .class files to the jar - // these are the bagel classes found in export - // they are a jdk11-only version of bagel - String exportDir = ("lib" + File.separator + - "export" + File.separator); - String bagelClasses[] = new File(exportDir).list(); - - for (int i = 0; i < bagelClasses.length; i++) { - if (!bagelClasses[i].endsWith(".class")) continue; - entry = new ZipEntry(bagelClasses[i]); - zos.putNextEntry(entry); - zos.write(PdeBase.grabFile(new File(exportDir + bagelClasses[i]))); - zos.closeEntry(); - } - - // files to include from data directory - if ((dataDir != null) && (dataDir.exists())) { - String datafiles[] = dataDir.list(); - for (int i = 0; i < datafiles.length; i++) { - // don't export hidden files, this handles, . .. .DS_Store - if (datafiles[i].charAt(0) == '.') continue; - //if (datafiles[i].equals(".") || datafiles[i].equals("..")) { - //continue; - //} - entry = new ZipEntry(datafiles[i]); - zos.putNextEntry(entry); - zos.write(PdeBase.grabFile(new File(dataDir, datafiles[i]))); - zos.closeEntry(); - } - } - - // add the project's .class to the jar - // actually, these should grab everything from the build directory - // since there may be some inner classes - // (add any .class files from the applet dir, then delete them) - String classfiles[] = appletDir.list(); - for (int i = 0; i < classfiles.length; i++) { - if (classfiles[i].endsWith(".class")) { - entry = new ZipEntry(classfiles[i]); - zos.putNextEntry(entry); - zos.write(PdeBase.grabFile(new File(appletDir, classfiles[i]))); - zos.closeEntry(); - } - } - - // remove the .class files from the applet folder. if they're not - // removed, the msjvm will complain about an illegal access error, - // since the classes are outside the jar file. - for (int i = 0; i < classfiles.length; i++) { - if (classfiles[i].endsWith(".class")) { - File deadguy = new File(appletDir, classfiles[i]); - if (!deadguy.delete()) { - System.err.println(classfiles[i] + - " could not be deleted from the applet folder."); - System.err.println("You'll need to remove it by hand."); - } - } - } - - // close up the jar file - zos.flush(); - zos.close(); - - // make a copy of the .pde file to post on the web - FileOutputStream sketchOutput = - new FileOutputStream(new File(appletDir, exportSketchName + ".pde")); - PrintWriter sketchWriter = - new PrintWriter(new OutputStreamWriter(sketchOutput)); - sketchWriter.print(program); - sketchWriter.flush(); - sketchWriter.close(); - - message("Done exporting."); - PdeBase.openFolder(appletDir); - - } catch (Exception e) { - message("Error during export."); - e.printStackTrace(); - } - buttons.clear(); - } - public void doPrint() { /* diff --git a/app/PdePreprocessor.java b/app/PdePreprocessor.java index 127f872a4..53fd6c738 100644 --- a/app/PdePreprocessor.java +++ b/app/PdePreprocessor.java @@ -80,6 +80,40 @@ public class PdePreprocessor { this.programReader = new StringReader(program); this.buildPath = buildPath; + if (PdePreferences.getBoolean("compiler.convert_unicode")) { + // check for non-ascii chars (these will be/must be in unicode format) + char p[] = program.toCharArray(); + int unicodeCount = 0; + for (int i = 0; i < p.length; i++) { + if (p[i] > 127) unicodeCount++; + } + // if non-ascii chars are in there, convert to unicode escapes + if (unicodeCount != 0) { + // add unicodeCount * 5.. replacing each unicode char + // with six digit \uXXXX sequence (xxxx is in hex) + // (except for nbsp chars which will be a replaced with a space) + int index = 0; + char p2[] = new char[p.length + unicodeCount*5]; + for (int i = 0; i < p.length; i++) { + if (p[i] < 128) { + p2[index++] = p[i]; + + } else if (p[i] == 160) { // unicode for non-breaking space + p2[index++] = ' '; + + } else { + int c = p[i]; + p2[index++] = '\\'; + p2[index++] = 'u'; + char str[] = Integer.toHexString(c).toCharArray(); + // add leading zeros, so that the length is 4 + for (int i = 0; i < 4 - str.length; i++) p2[index++] = '0'; + System.arraycopy(str, 0, p2, index, str.length); + } + } + } + } + // create a lexer with the stream reader, and tell it to handle // hidden tokens (eg whitespace, comments) since we want to pass these // through so that the line numbers when the compiler reports errors diff --git a/app/PdeSketch.java b/app/PdeSketch.java index 0e2949d63..24d47eba7 100644 --- a/app/PdeSketch.java +++ b/app/PdeSketch.java @@ -673,15 +673,19 @@ public class PdeSketch { } */ + // TODO these two loops are insufficient. + // should instead recursively add entire contents of build folder + // the data folder will already be a subdirectory + // and the classes may be buried in subfolders if a package name was used + // files to include from data directory if ((dataDir != null) && (dataDir.exists())) { String datafiles[] = dataDir.list(); for (int i = 0; i < datafiles.length; i++) { - // don't export hidden files, this handles, . .. .DS_Store + // don't export hidden files + // skipping dot prefix removes all: . .. .DS_Store if (datafiles[i].charAt(0) == '.') continue; - //if (datafiles[i].equals(".") || datafiles[i].equals("..")) { - //continue; - //} + entry = new ZipEntry(datafiles[i]); zos.putNextEntry(entry); zos.write(PdeBase.grabFile(new File(dataDir, datafiles[i]))); @@ -689,8 +693,8 @@ public class PdeSketch { } } - // add the project's .class to the jar - // actually, these should grab everything from the build directory + // add the project's .class files to the jar + // just grabs everything from the build directory // since there may be some inner classes // (add any .class files from the applet dir, then delete them) String classfiles[] = appletDir.list(); @@ -710,9 +714,10 @@ public class PdeSketch { if (classfiles[i].endsWith(".class")) { File deadguy = new File(appletDir, classfiles[i]); if (!deadguy.delete()) { - System.err.println(classfiles[i] + - " could not be deleted from the applet folder."); - System.err.println("You'll need to remove it by hand."); + PdeBase.showWarning("Could not delete", + classfiles[i] + " could not \n" + + "be deleted from the applet folder. \n" + + "You'll need to remove it by hand.", null); } } } diff --git a/todo.txt b/todo.txt index b07731014..c2bcc1819 100644 --- a/todo.txt +++ b/todo.txt @@ -68,16 +68,27 @@ o http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;acti o try ariel's Thread.yield() suggestion o set default framerate of 24? 30? 2x that? -_ fix make.sh and dist.sh for all platforms to include new export setup +_ international: convert unicode chars to \uXXXX in the preproc + +_ fix command keys for menus (broken since switching to swing) + +_ fix make.sh and dist.sh for all platforms to include new export setup _ re-implement history (disabled for 68) -_ sync files into lib/build rather than copying everything new _ history: "archive this version" _ makes a numbered archive of the current sketch as a zip file _ checks to see if there are other versions in the current folder _ or maybe just increments the numbers at the end of the sketch name +VOLUNTEER +_ fix export to recursively copy contents of build folder +_ currently only copies top-level classes and contents of data folder +_ sync files into lib/build rather than copying everything new +_ check file existence and modification dates to know which to copy +_ and which files to delete if some have been removed +_ this also means that the file copying has to set mod dates (JDK13) + when creating a new file, suggest untitled.pde they can put a .java or .pde extension on the file if no extension is found, add the .pde extension @@ -88,10 +99,6 @@ _ sphereDetail() function + reference _ optimized the flat_rect() function for solid colours (20% faster) _ noise() is (partially) broken in v67 -_ international: convert unicode chars to \uXXXX in the preproc - -_ fix command keys for menus (broken since switching to swing) - _ option for having multiple files open X need ui for tabs from casey X tabbed interface for multiple files