public void clientEvent(Client myClient) {

    String response = myClient.readString();

    if (response != null) parent.println("response: " + response);

    if (response != null && isConnected) {

      if (parent.match(response, "100") != null && !isLoggedIn) {

        parent.println("trying to log in...");
        myClient.write("login(test,test)\n");
      }

      if (parent.match(response, "200") != null && !isLoggedIn) {

        isLoggedIn = true;
        myClient.write("task.set(active,true)\n");
        parent.println("we are logged in!");
      }

      if (parent.match(response, "200") != null && isLoggedIn) {

        serverIsReady = true;
        parent.println("server is now ready for tasks!");
      }
    }
  }
Example #2
0
  public static String[] parseSketchSmooth(String code, boolean fussy) {
    String[] matches = PApplet.match(scrubComments(code), SMOOTH_REGEX);

    if (matches != null) {
      boolean badSmooth = false;

      if (PApplet.parseInt(matches[1], -1) == -1) {
        badSmooth = true;
      }

      if (badSmooth && fussy) {
        // found a reference to smooth, but it didn't seem to contain numbers
        final String message =
            "The smooth level of this applet could not automatically\n"
                + "be determined from your code. Use only a numeric\n"
                + "value (not variables) for the smooth() command.\n"
                + "See the smooth() reference for an explanation.";
        //				Messages.showWarning("Could not find smooth level", message, null);
        showWarning("Could not find smooth level", message);
        //        new Exception().printStackTrace(System.out);
        return null;
      }

      return matches;
    }
    return new String[] {null, null}; // not an error, just empty
  }
Example #3
0
 protected static String[] matchMethod(String methodName, String searchArea) {
   final String left = "(?:^|\\s|;)";
   // doesn't match empty pairs of parens
   // final String right = "\\s*\\(([^\\)]+)\\)\\s*\\;";
   final String right = "\\s*\\(([^\\)]*)\\)\\s*\\;";
   return PApplet.match(searchArea, left + methodName + right);
 }
  /**
   * Removes import statements from tabSource, replaces each with white spaces and adds the import
   * to the list of program imports
   *
   * @param tabProgram - Code in a tab
   * @param tabNumber - index of the tab
   * @return String - Tab code with imports replaced with white spaces
   */
  private String scrapImportStatements(String tabProgram, int tabNumber) {

    String tabSource = new String(tabProgram);
    do {
      // System.out.println("-->\n" + sourceAlt + "\n<--");
      String[] pieces = PApplet.match(tabSource, importRegexp);

      // Stop the loop if we've removed all the import lines
      if (pieces == null) break;

      String piece = pieces[1] + pieces[2] + pieces[3];
      int len = piece.length(); // how much to trim out

      // programImports.add(piece); // the package name

      // find index of this import in the program
      int idx = tabSource.indexOf(piece);
      // System.out.print("Import -> " + piece);
      // System.out.println(" - "
      // + Base.countLines(tabSource.substring(0, idx)) + " tab "
      // + tabNumber);
      programImports.add(
          new ImportStatement(piece, tabNumber, Base.countLines(tabSource.substring(0, idx))));
      // Remove the import from the main program
      // Substitue with white spaces
      String whiteSpace = "";
      for (int j = 0; j < piece.length(); j++) {
        whiteSpace += " ";
      }
      tabSource = tabSource.substring(0, idx) + whiteSpace + tabSource.substring(idx + len);

    } while (true);
    // System.out.println(tabSource);
    return tabSource;
  }
Example #5
0
 protected static void list(final AndroidSDK sdk) throws IOException {
   try {
     avdList = new ArrayList<String>();
     badList = new ArrayList<String>();
     ProcessResult listResult =
         new ProcessHelper(sdk.getAndroidToolPath(), "list", "avds").execute();
     if (listResult.succeeded()) {
       boolean badness = false;
       for (String line : listResult) {
         String[] m = PApplet.match(line, "\\s+Name\\:\\s+(\\S+)");
         if (m != null) {
           if (!badness) {
             //              System.out.println("good: " + m[1]);
             avdList.add(m[1]);
           } else {
             //              System.out.println("bad: " + m[1]);
             badList.add(m[1]);
           }
           //          } else {
           //            System.out.println("nope: " + line);
         }
         // "The following Android Virtual Devices could not be loaded:"
         if (line.contains("could not be loaded:")) {
           //            System.out.println("starting the bad list");
           //            System.err.println("Could not list AVDs:");
           //            System.err.println(listResult);
           badness = true;
           //            break;
         }
       }
     } else {
       System.err.println("Unhappy inside exists()");
       System.err.println(listResult);
     }
   } catch (final InterruptedException ie) {
   }
 }
Example #6
0
  /**
   * Part of the MessageConsumer interface, this is called
   * whenever a piece (usually a line) of error message is spewed
   * out from the compiler. The errors are parsed for their contents
   * and line number, which is then reported back to Editor.
   */
  public void message(String s) {
    int i;

    System.out.println("**************[ROBOTIS]***********************************");
    // remove the build path so people only see the filename
    // can't use replaceAll() because the path may have characters in it which
    // have meaning in a regular expression.
    if (!verbose) {
      while ((i = s.indexOf(buildPath + File.separator)) != -1) {
        s = s.substring(0, i) + s.substring(i + (buildPath + File.separator).length());
      }
    }
  
    // look for error line, which contains file name, line number,
    // and at least the first line of the error message
    String errorFormat = "([\\w\\d_]+.\\w+):(\\d+):\\s*error:\\s*(.*)\\s*";
    String[] pieces = PApplet.match(s, errorFormat);

//    if (pieces != null && exception == null) {
//      exception = sketch.placeException(pieces[3], pieces[1], PApplet.parseInt(pieces[2]) - 1);
//      if (exception != null) exception.hideStackTrace();
//    }
    
    if (pieces != null) {
      String error = pieces[3], msg = "";
      
      if (pieces[3].trim().equals("SPI.h: No such file or directory")) {
        error = _("Please import the SPI library from the Sketch > Import Library menu.");
        msg = _("\nAs of Arduino 0019, the Ethernet library depends on the SPI library." +
              "\nYou appear to be using it or another library that depends on the SPI library.\n\n");
      }
      
      if (pieces[3].trim().equals("'BYTE' was not declared in this scope")) {
        error = _("The 'BYTE' keyword is no longer supported.");
        msg = _("\nAs of Arduino 1.0, the 'BYTE' keyword is no longer supported." +
              "\nPlease use Serial.write() instead.\n\n");
      }
      
      if (pieces[3].trim().equals("no matching function for call to 'Server::Server(int)'")) {
        error = _("The Server class has been renamed EthernetServer.");
        msg = _("\nAs of Arduino 1.0, the Server class in the Ethernet library " +
              "has been renamed to EthernetServer.\n\n");
      }
      
      if (pieces[3].trim().equals("no matching function for call to 'Client::Client(byte [4], int)'")) {
        error = _("The Client class has been renamed EthernetClient.");
        msg = _("\nAs of Arduino 1.0, the Client class in the Ethernet library " +
              "has been renamed to EthernetClient.\n\n");
      }
      
      if (pieces[3].trim().equals("'Udp' was not declared in this scope")) {
        error = _("The Udp class has been renamed EthernetUdp.");
        msg = _("\nAs of Arduino 1.0, the Udp class in the Ethernet library " +
              "has been renamed to EthernetUdp.\n\n");
      }
      
      if (pieces[3].trim().equals("'class TwoWire' has no member named 'send'")) {
        error = _("Wire.send() has been renamed Wire.write().");
        msg = _("\nAs of Arduino 1.0, the Wire.send() function was renamed " +
              "to Wire.write() for consistency with other libraries.\n\n");
      }
      
      if (pieces[3].trim().equals("'class TwoWire' has no member named 'receive'")) {
        error = _("Wire.receive() has been renamed Wire.read().");
        msg = _("\nAs of Arduino 1.0, the Wire.receive() function was renamed " +
              "to Wire.read() for consistency with other libraries.\n\n");
      }

      if (pieces[3].trim().equals("'Mouse' was not declared in this scope")) {
        error = _("'Mouse' only supported on the Arduino Leonardo");
        //msg = _("\nThe 'Mouse' class is only supported on the Arduino Leonardo.\n\n");
      }
      
      if (pieces[3].trim().equals("'Keyboard' was not declared in this scope")) {
        error = _("'Keyboard' only supported on the Arduino Leonardo");
        //msg = _("\nThe 'Keyboard' class is only supported on the Arduino Leonardo.\n\n");
      }
      
      RunnerException e = null;
      if (!sketchIsCompiled) {
        // Place errors when compiling the sketch, but never while compiling libraries
        // or the core.  The user's sketch might contain the same filename!
        e = sketch.placeException(error, pieces[1], PApplet.parseInt(pieces[2]) - 1);
      }

      // replace full file path with the name of the sketch tab (unless we're
      // in verbose mode, in which case don't modify the compiler output)
      if (e != null && !verbose) {
        SketchCode code = sketch.getCode(e.getCodeIndex());
        String fileName = (code.isExtension("ino") || code.isExtension("pde")) ? code.getPrettyName() : code.getFileName();
        int lineNum = e.getCodeLine() + 1;
        s = fileName + ":" + lineNum + ": error: " + pieces[3] + msg;        
      }
            
      if (exception == null && e != null) {
        exception = e;
        exception.hideStackTrace();
      }      
    }
    
    System.err.print(s);
  }
Example #7
0
  /**
   * Parse a chunk of code and extract the size() command and its contents. Also goes after
   * fullScreen(), smooth(), and noSmooth().
   *
   * @param code The code from the main tab in the sketch
   * @param fussy true if it should show an error message if bad size()
   * @return null if there was an error, otherwise an array (might contain some/all nulls)
   */
  public static SurfaceInfo parseSketchSize(String code, boolean fussy) throws SketchException {
    // This matches against any uses of the size() function, whether numbers
    // or variables or whatever. This way, no warning is shown if size() isn't
    // actually used in the applet, which is the case especially for anyone
    // who is cutting/pasting from the reference.

    //    String scrubbed = scrubComments(sketch.getCode(0).getProgram());
    //    String[] matches = PApplet.match(scrubbed, SIZE_REGEX);
    //    String[] matches = PApplet.match(scrubComments(code), SIZE_REGEX);

    /*
    1. no size() or fullScreen() method at all
       will use the non-overridden settings() method in PApplet
    2. size() or fullScreen() found inside setup() (static mode sketch or otherwise)
       make sure that it uses numbers (or displayWidth/Height), copy into settings
    3. size() or fullScreen() already in settings()
       don't mess with the sketch, don't insert any defaults

    really only need to deal with situation #2.. nothing to be done for 1 and 3
    */
    // if static mode sketch, all we need is regex
    // easy proxy for static in this case is whether [^\s]void\s is present

    String searchArea = scrubComments(code);
    String[] setupMatch = PApplet.match(searchArea, VOID_SETUP_REGEX);
    if (setupMatch != null) {
      String found = setupMatch[0];
      int start = searchArea.indexOf(found) + found.length();
      int openBrace = searchArea.indexOf("{", start);
      char[] c = searchArea.toCharArray();
      int depth = 0;
      int closeBrace = -1;
      StringBuilder sb = new StringBuilder();
      for (int i = openBrace; i < c.length; i++) {
        if (c[i] == '{') {
          depth++;
        } else if (c[i] == '}') {
          depth--;
          if (depth == 0) {
            closeBrace = ++i;
            break;
          }
        } else {
          sb.append(c[i]);
        }
      }
      if (closeBrace == -1) {
        throw new SketchException("Found a { that's missing a matching }", false);
        //        return null;
      }
      searchArea = sb.toString();
    }

    StringList extraStatements = new StringList();

    // First look for noSmooth() or smooth(N) so we can hoist it into settings.
    String[] smoothContents = matchMethod("smooth", searchArea);
    if (smoothContents != null) {
      extraStatements.append(smoothContents[0]);
    }
    String[] noContents = matchMethod("noSmooth", searchArea);
    if (noContents != null) {
      if (extraStatements.size() != 0) {
        throw new SketchException("smooth() and noSmooth() cannot be used in the same sketch");
      } else {
        extraStatements.append(noContents[0]);
      }
    }
    String[] pixelDensityContents = matchMethod("pixelDensity", searchArea);
    if (pixelDensityContents != null) {
      extraStatements.append(pixelDensityContents[0]);
    }

    String[] sizeContents = matchMethod("size", searchArea);
    String[] fullContents = matchMethod("fullScreen", searchArea);
    // First check and make sure they aren't both being used, otherwise it'll
    // throw a confusing state exception error that one "can't be used here".
    if (sizeContents != null && fullContents != null) {
      throw new SketchException("size() and fullScreen() cannot be used in the same sketch", false);
    }

    // Get everything inside the parens for the size() method
    // String[] contents = PApplet.match(searchArea, SIZE_CONTENTS_REGEX);
    if (sizeContents != null) {
      StringList args = breakCommas(sizeContents[1]);
      SurfaceInfo info = new SurfaceInfo();
      info.statement = sizeContents[0];
      info.width = args.get(0).trim();
      info.height = args.get(1).trim();
      info.renderer = (args.size() >= 3) ? args.get(2).trim() : null;
      info.path = (args.size() >= 4) ? args.get(3).trim() : null;

      // Trying to remember why we wanted to allow people to use displayWidth
      // as the height or displayHeight as the width, but maybe it's for
      // making a square sketch window? Not going to

      if (info.hasOldSyntax()) {
        //        return null;
        throw new SketchException("Please update your code to continue.", false);
      }

      if (info.hasBadSize() && fussy) {
        // found a reference to size, but it didn't seem to contain numbers
        final String message =
            "The size of this sketch could not be determined from your code.\n"
                + "Use only numbers (not variables) for the size() command.\n"
                + "Read the size() reference for more details.";
        Base.showWarning("Could not find sketch size", message, null);
        //        new Exception().printStackTrace(System.out);
        //        return null;
        throw new SketchException("Please fix the size() line to continue.", false);
      }

      if (extraStatements.size() != 0) {
        info.statement += extraStatements.join(" ");
      }
      info.checkEmpty();
      return info;
      // return new String[] { contents[0], width, height, renderer, path };
    }
    // if no size() found, check for fullScreen()
    // contents = PApplet.match(searchArea, FULL_SCREEN_CONTENTS_REGEX);
    if (fullContents != null) {
      SurfaceInfo info = new SurfaceInfo();
      info.statement = fullContents[0];
      StringList args = breakCommas(fullContents[1]);
      if (args.size() > 0) { // might have no args
        String args0 = args.get(0).trim();
        if (args.size() == 1) {
          // could be either fullScreen(1) or fullScreen(P2D), figure out which
          if (args0.equals("SPAN") || PApplet.parseInt(args0, -1) != -1) {
            // it's the display parameter, not the renderer
            info.display = args0;
          } else {
            info.renderer = args0;
          }
        } else if (args.size() == 2) {
          info.renderer = args0;
          info.display = args.get(1).trim();
        } else {
          throw new SketchException("That's too many parameters for fullScreen()");
        }
      }
      info.width = "displayWidth";
      info.height = "displayHeight";
      if (extraStatements.size() != 0) {
        info.statement += extraStatements.join(" ");
      }
      info.checkEmpty();
      return info;
    }

    // Made it this far, but no size() or fullScreen(), and still
    // need to pull out the noSmooth() and smooth(N) methods.
    if (extraStatements.size() != 0) {
      SurfaceInfo info = new SurfaceInfo();
      info.statement = extraStatements.join(" ");
      return info;
    }

    // not an error, just no size() specified
    // return new String[] { null, null, null, null, null };
    return new SurfaceInfo();
  }