1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-20 21:01:25 +03:00

Merged upstream arduino branch

This commit is contained in:
Cristian Maglie
2012-10-18 15:50:09 +02:00
364 changed files with 153088 additions and 102 deletions

View File

@ -1095,9 +1095,10 @@ public class Editor extends JFrame implements RunnerListener {
item = newJMenuItemShift(_("Find in Reference"), 'F');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (textarea.isSelectionActive()) {
handleFindReference();
}
// if (textarea.isSelectionActive()) {
// handleFindReference();
// }
handleFindReference();
}
});
menu.add(item);
@ -1830,25 +1831,58 @@ public class Editor extends JFrame implements RunnerListener {
stopCompoundEdit();
}
protected String getCurrentKeyword() {
String text = "";
if (textarea.getSelectedText() != null)
text = textarea.getSelectedText().trim();
protected void handleFindReference() {
String text = textarea.getSelectedText().trim();
try {
int current = textarea.getCaretPosition();
int startOffset = 0;
int endIndex = current;
String tmp = textarea.getDocument().getText(current, 1);
// TODO probably a regexp that matches Arduino lang special chars
// already exists.
String regexp = "[\\s\\n();\\\\.!='\\[\\]{}]";
if (text.length() == 0) {
statusNotice(_("First select a word to find in the reference."));
while (!tmp.matches(regexp)) {
endIndex++;
tmp = textarea.getDocument().getText(endIndex, 1);
}
// For some reason document index start at 2.
// if( current - start < 2 ) return;
} else {
String referenceFile = PdeKeywords.getReference(text);
//System.out.println("reference file is " + referenceFile);
if (referenceFile == null) {
statusNotice(
I18n.format(_("No reference available for \"{0}\""), text)
);
} else {
Base.showReference(I18n.format(_("{0}.html"), referenceFile));
}
}
}
tmp = "";
while (!tmp.matches(regexp)) {
startOffset++;
if (current - startOffset < 0) {
tmp = textarea.getDocument().getText(0, 1);
break;
} else
tmp = textarea.getDocument().getText(current - startOffset, 1);
}
startOffset--;
int length = endIndex - current + startOffset;
text = textarea.getDocument().getText(current - startOffset, length);
} catch (BadLocationException bl) {
bl.printStackTrace();
} finally {
return text;
}
}
protected void handleFindReference() {
String text = getCurrentKeyword();
String referenceFile = PdeKeywords.getReference(text);
if (referenceFile == null) {
statusNotice(I18n.format(_("No reference available for \"{0}\""), text));
} else {
Base.showReference(I18n.format(_("{0}.html"), referenceFile));
}
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
@ -2775,16 +2809,15 @@ public class Editor extends JFrame implements RunnerListener {
copyItem.setEnabled(true);
discourseItem.setEnabled(true);
String sel = textarea.getSelectedText().trim();
referenceFile = PdeKeywords.getReference(sel);
referenceItem.setEnabled(referenceFile != null);
} else {
cutItem.setEnabled(false);
copyItem.setEnabled(false);
discourseItem.setEnabled(false);
referenceItem.setEnabled(false);
}
referenceFile = PdeKeywords.getReference(getCurrentKeyword());
referenceItem.setEnabled(referenceFile != null);
super.show(component, x, y);
}
}

View File

@ -178,9 +178,6 @@
#: Editor.java:1255
!Use\ Selection\ For\ Find=
#: Editor.java:1816
!First\ select\ a\ word\ to\ find\ in\ the\ reference.=
#: Editor.java:1823
#, java-format
!No\ reference\ available\ for\ "{0}"=

View File

@ -110,7 +110,7 @@ public class PdePreprocessor {
}
//String importRegexp = "(?:^|\\s|;)(import\\s+)(\\S+)(\\s*;)";
String importRegexp = "^\\s*#include\\s+[<\"](\\S+)[\">]";
String importRegexp = "^\\s*#include\\s*[<\"](\\S+)[\">]";
programImports = new ArrayList<String>();
String[][] pieces = PApplet.matchAll(program, importRegexp);
@ -205,7 +205,8 @@ public class PdePreprocessor {
for (int i = 0; i < prototypes.size(); i++) {
out.print(prototypes.get(i) + "\n");
}
out.println("#line 1");
String[] lines = program.substring(0, prototypeInsertionPoint).split("\n", -1);
out.println("#line " + (lines.length - 1));
out.print(program.substring(prototypeInsertionPoint));
}
@ -316,13 +317,31 @@ public class PdePreprocessor {
// XXX: doesn't handle ... varargs
// XXX: doesn't handle function pointers
Pattern pattern = Pattern.compile("[\\w\\[\\]\\*]+\\s+[&\\[\\]\\*\\w\\s]+\\([&,\\[\\]\\*\\w\\s]*\\)(?=\\s*\\{)");
Pattern prototypePattern = Pattern.compile("[\\w\\[\\]\\*]+\\s+[&\\[\\]\\*\\w\\s]+\\([&,\\[\\]\\*\\w\\s]*\\)(?=\\s*;)");
Pattern functionPattern = Pattern.compile("[\\w\\[\\]\\*]+\\s+[&\\[\\]\\*\\w\\s]+\\([&,\\[\\]\\*\\w\\s]*\\)(?=\\s*\\{)");
ArrayList<String> matches = new ArrayList<String>();
Matcher matcher = pattern.matcher(in);
while (matcher.find())
matches.add(matcher.group(0) + ";");
// Find already declared prototypes
ArrayList<String> prototypeMatches = new ArrayList<String>();
Matcher prototypeMatcher = prototypePattern.matcher(in);
while (prototypeMatcher.find())
prototypeMatches.add(prototypeMatcher.group(0) + ";");
return matches;
// Find all functions and generate prototypes for them
ArrayList<String> functionMatches = new ArrayList<String>();
Matcher functionMatcher = functionPattern.matcher(in);
while (functionMatcher.find())
functionMatches.add(functionMatcher.group(0) + ";");
// Remove generated prototypes that exactly match ones found in the source file
for (int functionIndex=functionMatches.size() - 1; functionIndex >= 0; functionIndex--) {
for (int prototypeIndex=0; prototypeIndex < prototypeMatches.size(); prototypeIndex++) {
if ((functionMatches.get(functionIndex)).equals(prototypeMatches.get(prototypeIndex))) {
functionMatches.remove(functionIndex);
break;
}
}
}
return functionMatches;
}
}

View File

@ -99,7 +99,7 @@ public class AutoFormat implements Tool {
c = string[j++] = getchr(); // extra char
while (done == 0) {
c = string[j++] = getchr();
while ((c != '/') && (j < string.length)) {
while ((c != '/') && (j < string.length) && EOF == 0) {
if(c == '\n' || c == '\r') {
lineNumber++;
putcoms();
@ -111,7 +111,9 @@ public class AutoFormat implements Tool {
if (j>1 && string[j-2] == '*') {
done = 1;
jdoc = 0;
}
} else if (EOF != 0) {
done = 1;
}
}
putcoms();
@ -134,7 +136,7 @@ public class AutoFormat implements Tool {
}
if (ch == '\'' || ch == '"') {
cc = string[j++] = getchr();
while (cc != ch) {
while (cc != ch && EOF == 0) {
if (cc == '\\') string[j++] = getchr();
cc = string[j++] = getchr();
}
@ -207,7 +209,7 @@ public class AutoFormat implements Tool {
}
string[j] = '\0';
i = 0;
while (string[i] == ' ') i++;
while (string[i] == ' ' && EOF == 0) i++;
if (lookup_com(w_jdoc) == 1) jdoc = 1;
String strBuffer = new String(string,0,j);
if (string[i] == '/' && string[i+1]=='*')
@ -241,7 +243,7 @@ public class AutoFormat implements Tool {
public void cpp_comment() throws IOException
{
c = getchr();
while(c != '\n' && c != '\r' && j<133)
while(c != '\n' && c != '\r' && EOF == 0)
{
string[j++] = c;
c = getchr();
@ -337,7 +339,7 @@ public class AutoFormat implements Tool {
peekc = getchr();
//while ((peekc == '\t' || peekc == ' ') &&
// (j < string.length)) {
while (peekc == '\t' || peekc == ' ') {
while ((peekc == '\t' || peekc == ' ') && EOF == 0) {
string[j++] = peekc;
peek = -1;
peekc = '`';
@ -398,7 +400,7 @@ public class AutoFormat implements Tool {
if (j<1) return (0);
kk=0;
while(string[kk] == ' ')kk++;
while(string[kk] == ' ' && EOF == 0)kk++;
l=0;
l = j_string.indexOf(keyword);
if (l<0 || l!=kk)
@ -421,7 +423,7 @@ public class AutoFormat implements Tool {
if (j<1) return (0);
kk=0;
while(string[kk] == ' ')kk++;
while(string[kk] == ' ' && EOF == 0) kk++;
l=0;
l = j_string.indexOf(keyword);
if (l<0 || l!=kk)
@ -637,7 +639,8 @@ public class AutoFormat implements Tool {
case '\'':
string[j++] = c;
cc = getchr();
while(cc != c)
int count = 0;
while(cc != c && EOF == 0)
{
// max. length of line should be 256
string[j++] = cc;
@ -784,7 +787,7 @@ public class AutoFormat implements Tool {
case '#':
string[j++] = c;
cc = getchr();
while(cc != '\n')
while(cc != '\n' && EOF == 0)
{
string[j++] = cc;
cc = getchr();
@ -827,13 +830,13 @@ public class AutoFormat implements Tool {
if ((lookup(w_for) == 1))
{
c = get_string();
while(c != ';') c = get_string();
while(c != ';' && EOF == 0) c = get_string();
ct=0;
int for_done = 0;
while (for_done==0)
while (for_done == 0 && EOF == 0)
{
c = get_string();
while(c != ')')
while(c != ')' && EOF == 0)
{
if(c == '(') ct++;
c = get_string();