Rev 219 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package test.display;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* Used to analyse possible sections in the file. You add sections that you
* find and then call analyze which sorts them and sees if there are any gaps
* or overlaps - in which case you have found the wrong thing or are missing
* some.
*/
public class SectList
implements Iterable<Section
> {
private final List<Section
> sections =
new ArrayList<Section
>();
public Section get
(int n
) {
return sections.
get(n
);
}
public void add
(Section sect
) {
sections.
add(sect
);
}
public void add
(int n, Section section
) {
sections.
add(n, section
);
}
public int size
() {
return sections.
size();
}
public Iterator<Section
> iterator
() {
return sections.
iterator();
}
public void analyze
(PrintStream outStream
) {
outStream.
println("--Analyse sections that are known--");
List<Section
> sectionList =
new ArrayList<Section
>(sections
);
Collections.
sort(sectionList
);
for (int i =
0; i
< sectionList.
size(); i++
) {
Section s = sectionList.
get(i
);
outStream.
printf("%-15s %08x len=%-6x next=%08x\n",
s.
getName(), s.
getStart(), s.
getLen(), s.
getEnd());
if (s.
getRecordSize() > 0) {
outStream.
printf(" fixed record size %d\n", s.
getRecordSize());
if (s.
getLen() > 0) {
double nrecords =
(double) s.
getLen() / s.
getRecordSize();
outStream.
printf(" number of records %.2f\n", nrecords
);
if (nrecords
!=
(int) nrecords
)
outStream.
printf(" +++ FRACTIONAL NUMBER OF RECORDS\n");
}
}
// The implied size is the distance between this sect and the next.
// Usually if we have everything, then the size of the section
// should be equal to the implied size. This allows us to spot
// missing sections.
if (i
< sectionList.
size() -
1) {
Section next = sectionList.
get(i +
1);
long implen = next.
getStart() - s.
getStart();
outStream.
printf(" implied size=%-10d (%#x)%s\n",
implen, implen,
(implen==s.
getLen() || s.
getStart() ==
0)?"":
" +++MISMATCH");
// If there is a length and it is smaller than the implied length, see
// if it is a simple multiple of it.
int len = s.
getLen();
if (len
> 0 && len
< implen
) {
double scale =
(double)implen/len
;
outStream.
printf(" size multiplier %.2f %d\n", scale, implen/len
);
// s.setRecordSize((int) (implen/len));
}
}
}
outStream.
println("--End of section dump--");
}
}