diff --git a/language/buildNumber.properties b/language/buildNumber.properties index 9348490a4..55c1d7483 100644 --- a/language/buildNumber.properties +++ b/language/buildNumber.properties @@ -1,3 +1,3 @@ #maven.buildNumber.plugin properties file -#Wed Mar 27 14:15:30 CDT 2024 -buildNumber\\d*=12888 +#Wed Apr 24 08:17:20 CDT 2024 +buildNumber\\d*=12894 diff --git a/language/src/main/java/edu/uiuc/ncsa/qdl/evaluate/StemEvaluator.java b/language/src/main/java/edu/uiuc/ncsa/qdl/evaluate/StemEvaluator.java index 8867bb0d8..a68c6ad87 100644 --- a/language/src/main/java/edu/uiuc/ncsa/qdl/evaluate/StemEvaluator.java +++ b/language/src/main/java/edu/uiuc/ncsa/qdl/evaluate/StemEvaluator.java @@ -764,22 +764,31 @@ private void doStar(Polyad polyad, State state) { private void doRemap(Polyad polyad, State state) { if (polyad.isSizeQuery()) { - polyad.setResult(new int[]{2, 3}); + polyad.setResult(new int[]{1, 2, 3}); polyad.setEvaluated(true); return; } - if (polyad.getArgCount() < 2) { + /* if (polyad.getArgCount() < 2) { throw new MissingArgException(REMAP + " requires at least two arguments", polyad.getArgCount() == 1 ? polyad.getArgAt(0) : polyad); } if (3 < polyad.getArgCount()) { throw new ExtraArgException(REMAP + " takes at most 3 arguments", polyad.getArgAt(3)); - } + }*/ Object arg1 = polyad.evalArg(0, state); checkNull(arg1, polyad.getArgAt(0)); if (!isStem(arg1)) { throw new BadArgException(REMAP + " requires stem as its first argument", polyad.getArgAt(0)); } QDLStem stem = (QDLStem) arg1; + if (polyad.getArgCount() == 1) { + // reverse keys and values + QDLStem out = reverseKeysAndValues(stem); + polyad.setResult(out); + polyad.setEvaluated(true); + polyad.setResultType(STEM_TYPE); + return; + } + Object arg2 = polyad.evalArg(1, state); checkNull(arg2, polyad.getArgAt(1)); @@ -808,6 +817,19 @@ private void doRemap(Polyad polyad, State state) { } + protected QDLStem reverseKeysAndValues(QDLStem inStem) { + QDLStem out = new QDLStem(); + for (Object kk : inStem.keySet()) { + Object v = inStem.get(kk); + if (isLong(v) || isString(v)) { + out.putLongOrString(v, kk); + } + if (isStem(v)) { + out.putLongOrString(kk, reverseKeysAndValues((QDLStem) v)); + } + } + return out; + } protected void doIndices(Polyad polyad, State state) { if (polyad.isSizeQuery()) { polyad.setResult(new int[]{1, 2}); diff --git a/language/src/main/java/edu/uiuc/ncsa/qdl/gui/editor/EditorKeyPressedAdapter.java b/language/src/main/java/edu/uiuc/ncsa/qdl/gui/editor/EditorKeyPressedAdapter.java index 8f7b3f1ff..9f10ea6c8 100644 --- a/language/src/main/java/edu/uiuc/ncsa/qdl/gui/editor/EditorKeyPressedAdapter.java +++ b/language/src/main/java/edu/uiuc/ncsa/qdl/gui/editor/EditorKeyPressedAdapter.java @@ -4,6 +4,7 @@ import edu.uiuc.ncsa.qdl.parsing.QDLParserDriver; import edu.uiuc.ncsa.qdl.parsing.QDLRunner; import edu.uiuc.ncsa.qdl.state.State; +import edu.uiuc.ncsa.qdl.util.QDLFileUtil; import edu.uiuc.ncsa.qdl.workspace.WorkspaceCommands; import edu.uiuc.ncsa.security.core.configuration.XProperties; import edu.uiuc.ncsa.security.core.util.DebugUtil; @@ -101,23 +102,14 @@ protected String getGUIHelp() { InputStream helpStream = getClass().getResourceAsStream("/editor_help.txt"); if (helpStream != null) { - InputStreamReader isr = new InputStreamReader(helpStream); - BufferedReader bufferedReader = new BufferedReader(isr); - StringBuilder stringBuilder = new StringBuilder(); try { - String lineIn = bufferedReader.readLine(); - while (lineIn != null) { - stringBuilder.append(lineIn + "\n"); - lineIn = bufferedReader.readLine(); - } - guiHelp = stringBuilder.toString(); - bufferedReader.close(); + guiHelp = QDLFileUtil.isToString(helpStream); + helpStream.close(); } catch (IOException e) { if (DebugUtil.isEnabled()) { e.printStackTrace(); } } - } } return guiHelp; @@ -173,28 +165,28 @@ public void keyPressed(KeyEvent e) { case KeyEvent.VK_I: // Insert in input form if (e.isControlDown()) { - try { - String out = (String) getClipboard().getData(DataFlavor.stringFlavor); - out = LineUtil.toInputForm(out, e.isShiftDown()); - String content = input.getText(); - int position = input.getCaretPosition(); - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(content.substring(0, position)); - stringBuilder.append(out); - if (position + 1 < content.length()) { - stringBuilder.append(content.substring(position + 1)); - } - input.setText(null); - input.setText(stringBuilder.toString()); - input.repaint(); - input.setCaretPosition(position); - - } catch (UnsupportedFlavorException | IOException ex) { - if (DebugUtil.isEnabled()) { - ex.printStackTrace(); - } - break; + try { + String out = (String) getClipboard().getData(DataFlavor.stringFlavor); + out = LineUtil.toInputForm(out, e.isShiftDown()); + String content = input.getText(); + int position = input.getCaretPosition(); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(content.substring(0, position)); + stringBuilder.append(out); + if (position + 1 < content.length()) { + stringBuilder.append(content.substring(position + 1)); + } + input.setText(null); + input.setText(stringBuilder.toString()); + input.repaint(); + input.setCaretPosition(position); + + } catch (UnsupportedFlavorException | IOException ex) { + if (DebugUtil.isEnabled()) { + ex.printStackTrace(); } + break; + } } break; case KeyEvent.VK_H: @@ -285,10 +277,10 @@ public void keyPressed(KeyEvent e) { case KeyEvent.VK_F1: // If no selected text, put up a generic help message. Otherwise, // search online help. - if(e.isControlDown()&& !e.isAltDown()){ + if (e.isControlDown() && !e.isAltDown()) { String x = getHelp("keyboard"); if (x != null) { - String helpMessage = x; + String helpMessage = x; } showHelp("QDL keyboard layout", x); break; @@ -364,7 +356,6 @@ public void keyPressed(KeyEvent e) { } - protected void doQuit(boolean forceQuit) { if (forceQuit) { System.exit(0); diff --git a/language/src/main/java/edu/uiuc/ncsa/qdl/util/QDLFileUtil.java b/language/src/main/java/edu/uiuc/ncsa/qdl/util/QDLFileUtil.java index 04a22fa6f..29c5f87ef 100644 --- a/language/src/main/java/edu/uiuc/ncsa/qdl/util/QDLFileUtil.java +++ b/language/src/main/java/edu/uiuc/ncsa/qdl/util/QDLFileUtil.java @@ -37,13 +37,44 @@ *
  • {@link #readTextFileAsStem(State, String)} - reads a text file as a stem list.
  • *
  • {@link #writeTextFile(State, String, String)}
  • *
  • {@link #readAttributes(State, String)} - get the attributes for a file (length, name, path...)
  • - * + * * * These are a facade for several calls. Note that for all workspace programming you should use these *

    Created by Jeff Gaynor
    * on 1/29/20 at 9:52 AM */ public class QDLFileUtil extends FileUtil { + /** + * Reads an {@link InputStream} as a string, does not close it when done! + * + * @param inputStream + * @return + * @throws Throwable + */ + public static String isToString(InputStream inputStream) throws IOException { + InputStreamReader isr = new InputStreamReader(inputStream); + return readerToString(isr); + } + + public static String readerToString(Reader reader) throws IOException { + if(reader == null){ + return ""; + } + BufferedReader bufferedReader; + + if(reader instanceof BufferedReader){ + bufferedReader = (BufferedReader) reader; + }else{ + bufferedReader = new BufferedReader(reader); + } + StringBuilder stringBuilder = new StringBuilder(); + String lineIn = bufferedReader.readLine(); + while (lineIn != null) { + stringBuilder.append(lineIn + "\n"); + lineIn = bufferedReader.readLine(); + } + return stringBuilder.toString(); + } public static QDLStem readFileAsStem(String fileName) throws Throwable { checkFile(fileName); @@ -71,10 +102,10 @@ public static QDLStem readFileAsStem(String fileName) throws Throwable { public static List readTextFileAsLines(State state, String fullPath) throws Throwable { if (isVFSPath(fullPath)) { String x = readTextVFS(state, fullPath); - if(x == null){ + if (x == null) { return null; } - return StringUtils.stringToList(x); + return StringUtils.stringToList(x); } if (state.isServerMode()) { throw new QDLServerModeException("unsupported in server mode"); @@ -84,6 +115,7 @@ public static List readTextFileAsLines(State state, String fullPath) thr /** * Main entry point for reading a text file as lines + * * @param state * @param fullPath * @return @@ -101,6 +133,7 @@ public static String readTextFile(State state, String fullPath) throws Throwable /** * main entry point for reading a text file as a stem. + * * @param state * @param fullPath * @return @@ -115,6 +148,7 @@ public static QDLStem readTextFileAsStem(State state, String fullPath) throws Th /** * Main entry point for reading a binary file. + * * @param state * @param fullPath * @return @@ -132,6 +166,7 @@ public static byte[] readBinaryFile(State state, String fullPath) throws Throwab /** * Main entry point for writing a binary file + * * @param state * @param fullPath * @param bytes @@ -147,7 +182,7 @@ public static void writeBinaryFile(State state, String fullPath, byte[] bytes) t Files.write(Paths.get(fullPath), bytes); } - public static void writeTextFile(State state, String fullPath, String contents) throws Throwable{ + public static void writeTextFile(State state, String fullPath, String contents) throws Throwable { if (isVFSPath(fullPath)) { writeTextVFS(state, fullPath, contents); } @@ -158,7 +193,7 @@ public static void writeTextFile(State state, String fullPath, String contents) } - public static void writeTextFile(State state, String fullPath, List contents) throws Throwable{ + public static void writeTextFile(State state, String fullPath, List contents) throws Throwable { if (isVFSPath(fullPath)) { writeTextVFS(state, fullPath, StringUtils.listToString(contents)); } @@ -220,7 +255,7 @@ public static void writeTextVFS(State state, String path, String content) throws public static byte[] readBinaryVFS(State state, String path) throws Throwable { VFSFileProvider vfs = getVfsFileProvider(state, path); VFSEntry vfsEntry = vfs.get(path, AbstractEvaluator.FILE_OP_BINARY); - if(vfsEntry == null){ + if (vfsEntry == null) { throw new QDLFileNotFoundException("file '" + path + "' not found"); } return vfsEntry.getBytes(); @@ -229,7 +264,7 @@ public static byte[] readBinaryVFS(State state, String path) throws Throwable { public static String readTextVFS(State state, String path) throws Throwable { VFSFileProvider vfs = getVfsFileProvider(state, path); VFSEntry vfsEntry = vfs.get(path, AbstractEvaluator.FILE_OP_TEXT_STRING); - if(vfsEntry == null){ + if (vfsEntry == null) { throw new QDLFileNotFoundException("file '" + path + "' not found"); } return vfsEntry.getText(); @@ -379,6 +414,7 @@ public static class FileAttributes { /** * Read off the file attributes (such as name, length etc.) from the given file + * * @param state * @param fullPath * @return @@ -413,19 +449,20 @@ public static FileAttributes readAttributes(State state, String fullPath) throws } - public static InputStream readFileAsInputStream(State state, String fullPath) throws Throwable{ - if(isVFSPath(fullPath)){ + public static InputStream readFileAsInputStream(State state, String fullPath) throws Throwable { + if (isVFSPath(fullPath)) { return new ByteArrayInputStream(readBinaryVFS(state, fullPath)); } if (state.isServerMode()) { - throw new QDLServerModeException("This operation is unsupported in server mode."); - } + throw new QDLServerModeException("This operation is unsupported in server mode."); + } return new FileInputStream(new File(fullPath)); } - public static void copy(State state, String source, String target) throws Throwable { + public static void copy(State state, String source, String target) throws Throwable { writeBinaryFile(state, target, readBinaryFile(state, source)); - } + } + public static void main(String[] args) { System.out.println(resolvePath("/a/b/c", "p/q")); System.out.println(resolvePath("vfs#/a/b/c", "p/q")); diff --git a/language/src/main/java/edu/uiuc/ncsa/qdl/workspace/WorkspaceCommands.java b/language/src/main/java/edu/uiuc/ncsa/qdl/workspace/WorkspaceCommands.java index ac5388cab..ae1a9aa78 100644 --- a/language/src/main/java/edu/uiuc/ncsa/qdl/workspace/WorkspaceCommands.java +++ b/language/src/main/java/edu/uiuc/ncsa/qdl/workspace/WorkspaceCommands.java @@ -95,6 +95,8 @@ */ public class WorkspaceCommands implements Logable, Serializable { + private InputStream helpS; + public WorkspaceCommands() { } @@ -6018,7 +6020,19 @@ public void init(InputLine inputLine) throws Throwable { } } } - + helpStream.close(); + // now add the editor help + helpStream = getClass().getResourceAsStream("/editor_help.txt"); + String x = "(missing help)"; + try{ + x= QDLFileUtil.isToString(helpStream); + helpStream.close(); + }catch(IOException iox){ + if(isDebugOn()){ + iox.printStackTrace(); + } + } + onlineHelp.put("editor", x); } if (inputLine.hasArg(CONFIG_FILE_FLAG)) { fromConfigFile(inputLine); diff --git a/language/src/main/resources/editor_help.txt b/language/src/main/resources/editor_help.txt index 5c310caba..59aa37f92 100644 --- a/language/src/main/resources/editor_help.txt +++ b/language/src/main/resources/editor_help.txt @@ -1,4 +1,5 @@ -Help for the editor. +Help for the editor. This also applies to the main QDL input +panel when using the GUI. (To get help for a topic, select the word, hit F1). To see the special characters, select this word in the input window: diff --git a/language/src/main/resources/func_help.xml b/language/src/main/resources/func_help.xml index fd8621d06..15fbc355f 100644 --- a/language/src/main/resources/func_help.xml +++ b/language/src/main/resources/func_help.xml @@ -658,9 +658,11 @@ See also: copy]]> -