forked from arduino/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSizer.java
More file actions
106 lines (86 loc) · 3.11 KB
/
Sizer.java
File metadata and controls
106 lines (86 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Sizer - computes the size of a .hex file
Part of the Arduino project - http://www.arduino.cc/
Copyright (c) 2006 David A. Mellis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id$
*/
package processing.app.debug;
import processing.app.Base;
import java.io.*;
import java.util.*;
public class Sizer implements MessageConsumer {
private String buildPath, sketchName;
private String firstLine;
private long size;
private RunnerException exception;
public Sizer(String buildPath, String sketchName) {
this.buildPath = buildPath;
this.sketchName = sketchName;
}
public long computeSize() throws RunnerException {
String avrBasePath = Base.getAvrBasePath();
String commandSize[] = new String[] {
avrBasePath + "avr-size",
" "
};
commandSize[1] = buildPath + File.separator + sketchName + ".hex";
int r = 0;
try {
exception = null;
size = -1;
firstLine = null;
Process process = Runtime.getRuntime().exec(commandSize);
MessageSiphon in = new MessageSiphon(process.getInputStream(), this);
MessageSiphon err = new MessageSiphon(process.getErrorStream(), this);
boolean running = true;
while(running) {
try {
in.join();
err.join();
r = process.waitFor();
running = false;
} catch (InterruptedException intExc) { }
}
} catch (Exception e) {
// The default Throwable.toString() never returns null, but apparently
// some sub-class has overridden it to do so, thus we need to check for
// it. See: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1166589459
exception = new RunnerException(
(e.toString() == null) ? e.getClass().getName() + r : e.toString() + r);
}
if (exception != null)
throw exception;
if (size == -1)
throw new RunnerException(firstLine);
return size;
}
public void message(String s) {
if (firstLine == null)
firstLine = s;
else {
StringTokenizer st = new StringTokenizer(s, " ");
try {
st.nextToken();
st.nextToken();
st.nextToken();
size = (new Integer(st.nextToken().trim())).longValue();
} catch (NoSuchElementException e) {
exception = new RunnerException(e.toString());
} catch (NumberFormatException e) {
exception = new RunnerException(e.toString());
}
}
}
}