Skip to content

Commit 0b632db

Browse files
committed
Merge branch 'ide-1.5.x' into dev-ide-1.5.x-discovery
Conflicts: hardware/arduino/avr/cores/arduino/USBCore.cpp
2 parents 0c7a75f + d3be60e commit 0b632db

File tree

17 files changed

+370
-343
lines changed

17 files changed

+370
-343
lines changed

app/src/processing/app/helpers/StringReplacer.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static String[] formatAndSplit(String src, Map<String, String> dict,
3434
String res;
3535

3636
// Recursive replace with a max depth of 10 levels.
37-
for (int i=0; i<10; i++) {
37+
for (int i = 0; i < 10; i++) {
3838
// Do a replace with dictionary
3939
res = StringReplacer.replaceFromMapping(src, dict);
4040
if (!recursive)
@@ -45,42 +45,45 @@ public static String[] formatAndSplit(String src, Map<String, String> dict,
4545
}
4646

4747
// Split the resulting string in arguments
48-
return quotedSplit(src, '"', false);
48+
return quotedSplit(src, "\"'", false);
4949
}
5050

51-
public static String[] quotedSplit(String src, char escapeChar,
51+
public static String[] quotedSplit(String src, String quoteChars,
5252
boolean acceptEmptyArguments)
5353
throws Exception {
54-
String quote = "" + escapeChar;
5554
List<String> res = new ArrayList<String>();
5655
String escapedArg = null;
57-
boolean escaping = false;
56+
String escapingChar = null;
5857
for (String i : src.split(" ")) {
59-
if (!escaping) {
60-
if (!i.startsWith(quote)) {
58+
if (escapingChar == null) {
59+
// If the first char is not an escape char..
60+
String first = null;
61+
if (i.length() > 0)
62+
first = i.substring(0, 1);
63+
if (first == null || !quoteChars.contains(first)) {
6164
if (i.trim().length() != 0 || acceptEmptyArguments)
6265
res.add(i);
6366
continue;
6467
}
6568

66-
escaping = true;
69+
escapingChar = first;
6770
i = i.substring(1);
6871
escapedArg = "";
6972
}
7073

71-
if (!i.endsWith(quote)) {
74+
if (!i.endsWith(escapingChar)) {
7275
escapedArg += i + " ";
7376
continue;
7477
}
7578

7679
escapedArg += i.substring(0, i.length() - 1);
7780
if (escapedArg.trim().length() != 0 || acceptEmptyArguments)
7881
res.add(escapedArg);
79-
escaping = false;
82+
escapingChar = null;
8083
}
81-
if (escaping)
82-
throw new Exception("Invalid quoting: no closing '" + escapeChar +
83-
"' char found.");
84+
if (escapingChar != null)
85+
throw new Exception("Invalid quoting: no closing [" + escapingChar +
86+
"] char found.");
8487
return res.toArray(new String[0]);
8588
}
8689

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package processing.app.helpers;
2+
3+
import static org.junit.Assert.assertArrayEquals;
4+
5+
import org.junit.Test;
6+
7+
public class StringReplacerTest {
8+
9+
@Test
10+
public void quotingCheck() throws Exception {
11+
String in = "a\"bc ab'c 'abc abc' ";
12+
in += "\"abc abc\" '\"abc abc\"' ";
13+
in += "\"'abc abc'\"";
14+
String[] res = StringReplacer.quotedSplit(in, "\"'", false);
15+
assertArrayEquals(res, new String[] { "a\"bc", "ab'c", "abc abc",
16+
"abc abc", "\"abc abc\"", "'abc abc'" });
17+
}
18+
19+
@Test
20+
public void quotingCheckWithEmptyStringsAccepted() throws Exception {
21+
String in = "a\"bc ab'c 'abc abc' ";
22+
in += "\"abc abc\" '\"abc abc\"' ";
23+
in += "\"'abc abc'\"";
24+
String[] res = StringReplacer.quotedSplit(in, "\"'", true);
25+
assertArrayEquals(res, new String[] { "a\"bc", "ab'c", "", "", "abc abc",
26+
"abc abc", "\"abc abc\"", "'abc abc'" });
27+
}
28+
29+
}

hardware/arduino/avr/boards.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,11 @@ leonardo.build.mcu=atmega32u4
233233
leonardo.build.f_cpu=16000000L
234234
leonardo.build.vid=0x2341
235235
leonardo.build.pid=0x8036
236+
leonardo.build.usb_product="Arduino Leonardo"
236237
leonardo.build.board=AVR_LEONARDO
237238
leonardo.build.core=arduino
238239
leonardo.build.variant=leonardo
239-
leonardo.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid}
240+
leonardo.build.extra_flags={build.usb_flags}
240241

241242
##############################################################
242243

@@ -262,10 +263,11 @@ micro.build.mcu=atmega32u4
262263
micro.build.f_cpu=16000000L
263264
micro.build.vid=0x2341
264265
micro.build.pid=0x8037
266+
micro.build.usb_product="Arduino Micro"
265267
micro.build.board=AVR_MICRO
266268
micro.build.core=arduino
267269
micro.build.variant=micro
268-
micro.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid}
270+
micro.build.extra_flags={build.usb_flags}
269271

270272
##############################################################
271273

@@ -295,10 +297,11 @@ esplora.build.mcu=atmega32u4
295297
esplora.build.f_cpu=16000000L
296298
esplora.build.vid=0x2341
297299
esplora.build.pid=0x803c
300+
esplora.build.usb_product="Arduino Esplora"
298301
esplora.build.board=AVR_ESPLORA
299302
esplora.build.core=arduino
300303
esplora.build.variant=leonardo
301-
esplora.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid}
304+
esplora.build.extra_flags={build.usb_flags}
302305

303306
##############################################################
304307

@@ -456,15 +459,15 @@ LilyPadUSB.bootloader.extended_fuses=0xce
456459
LilyPadUSB.bootloader.file=caterina-LilyPadUSB/Caterina-LilyPadUSB.hex
457460
LilyPadUSB.bootloader.unlock_bits=0x3F
458461
LilyPadUSB.bootloader.lock_bits=0x2F
459-
460462
LilyPadUSB.build.mcu=atmega32u4
461463
LilyPadUSB.build.f_cpu=8000000L
462464
LilyPadUSB.build.vid=0x1B4F
463465
LilyPadUSB.build.pid=0x9208
466+
LilyPadUSB.build.usb_product="LilyPad USB"
464467
LilyPadUSB.build.board=AVR_LILYPAD_USB
465468
LilyPadUSB.build.core=arduino
466469
LilyPadUSB.build.variant=leonardo
467-
LilyPadUSB.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid}
470+
LilyPadUSB.build.extra_flags={build.usb_flags}
468471

469472
##############################################################
470473

hardware/arduino/avr/cores/arduino/CDC.cpp

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,6 @@
2323
#if defined(USBCON)
2424
#ifdef CDC_ENABLED
2525

26-
#if (RAMEND < 1000)
27-
#define SERIAL_BUFFER_SIZE 16
28-
#else
29-
#define SERIAL_BUFFER_SIZE 64
30-
#endif
31-
32-
struct ring_buffer
33-
{
34-
unsigned char buffer[SERIAL_BUFFER_SIZE];
35-
volatile int head;
36-
volatile int tail;
37-
};
38-
39-
ring_buffer cdc_rx_buffer = { { 0 }, 0, 0};
40-
4126
typedef struct
4227
{
4328
u32 dwDTERate;
@@ -140,51 +125,47 @@ void Serial_::end(void)
140125

141126
void Serial_::accept(void)
142127
{
143-
ring_buffer *buffer = &cdc_rx_buffer;
144-
int i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE;
128+
int i = (unsigned int)(_rx_buffer_head+1) % SERIAL_BUFFER_SIZE;
145129

146130
// if we should be storing the received character into the location
147131
// just before the tail (meaning that the head would advance to the
148132
// current location of the tail), we're about to overflow the buffer
149133
// and so we don't write the character or advance the head.
150134

151135
// while we have room to store a byte
152-
while (i != buffer->tail) {
136+
while (i != _rx_buffer_tail) {
153137
int c = USB_Recv(CDC_RX);
154138
if (c == -1)
155139
break; // no more data
156-
buffer->buffer[buffer->head] = c;
157-
buffer->head = i;
140+
_rx_buffer[_rx_buffer_head] = c;
141+
_rx_buffer_head = i;
158142

159-
i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE;
143+
i = (unsigned int)(_rx_buffer_head+1) % SERIAL_BUFFER_SIZE;
160144
}
161145
}
162146

163147
int Serial_::available(void)
164148
{
165-
ring_buffer *buffer = &cdc_rx_buffer;
166-
return (unsigned int)(SERIAL_BUFFER_SIZE + buffer->head - buffer->tail) % SERIAL_BUFFER_SIZE;
149+
return (unsigned int)(SERIAL_BUFFER_SIZE + _rx_buffer_head - _rx_buffer_tail) % SERIAL_BUFFER_SIZE;
167150
}
168151

169152
int Serial_::peek(void)
170153
{
171-
ring_buffer *buffer = &cdc_rx_buffer;
172-
if (buffer->head == buffer->tail) {
154+
if (_rx_buffer_head == _rx_buffer_tail) {
173155
return -1;
174156
} else {
175-
return buffer->buffer[buffer->tail];
157+
return _rx_buffer[_rx_buffer_tail];
176158
}
177159
}
178160

179161
int Serial_::read(void)
180162
{
181-
ring_buffer *buffer = &cdc_rx_buffer;
182163
// if the head isn't ahead of the tail, we don't have any characters
183-
if (buffer->head == buffer->tail) {
164+
if (_rx_buffer_head == _rx_buffer_tail) {
184165
return -1;
185166
} else {
186-
unsigned char c = buffer->buffer[buffer->tail];
187-
buffer->tail = (unsigned int)(buffer->tail + 1) % SERIAL_BUFFER_SIZE;
167+
unsigned char c = _rx_buffer[_rx_buffer_tail];
168+
_rx_buffer_tail = (unsigned int)(_rx_buffer_tail + 1) % SERIAL_BUFFER_SIZE;
188169
return c;
189170
}
190171
}

0 commit comments

Comments
 (0)