rendered paste body private void calchk(String line) {
String temp = "";
boolean ende = false;
if (type == 0) {
String filename;
if ((filename = pMatch("\\*\\*\\*\\* CFGFILE:(.*?)$", line, 1)) != null) {
System.out.println(line);
file = true;
type = 1;
} else if ((filename = pMatch("\\*\\*\\*\\* BINFILE:(.*?)$", line,
1)) != null) {
file = true;
System.out.println(line);
type = 2;
} else {
if (pMatch("\\*\\*\\*\\* (.*?) CONFIGURATION EXPORT", line, 0) != null) {
file = false;
System.out.println(line);
type = 3;
return;
}
if (pMatch("\\*\\*\\*\\* END OF EXPORT (.*?)", line, 0) != null) {
expected = line.substring(19, 27);
System.out.println(line);
}
}
if (file) {
line = filename + '\0';
updateCRC(line);
/*crc.update(line.getBytes());
debug(crc);*/
file = false;
return;
}
} else {
if (type == 1) {
if (line.indexOf("**** END OF FILE") == 0) {
type = 0;
if (last != null) {
updateCRC(last);
/*crc.update(last.getBytes());
debug(crc);*/
}
last = null;
return;
}
if (last != null) {
last = last + '\n';
updateCRC(last);
/*crc.update(last.getBytes());
debug(crc);*/
}
last = line;
return;
}
if (type == 2) {
if (line.indexOf("**** END OF FILE") == 0) {
type = 0;
return;
}
String hex = line.trim().toLowerCase();
for (int i = 0; i < hex.length(); i += 2) {
int b = Integer.parseInt(hex.substring(i, i + 2), 16);
/*crc.update(b);*/
updateCRC(b);
}
return;
}
if (type == 3) {
if (line.indexOf("****") != -1) {
type = 0;
calchk(line);
}
if (pMatch("(\\S*?)=(\\S*?)", line, 0) != null) {
line = line.replaceFirst("=", "");
line = line + '\0';
updateCRC(line);
/*crc.update(line.getBytes());
debug(crc);*/
return;
} else {
return;
}
}
}
}
public static boolean getchecksum() {
String checksum = Long.toHexString(crc.getValue()).toUpperCase();
if (!checksum.equals(expected)) {
System.out.println("WRONG CHECKSUM " + checksum + " vs. " + expected);
System.out.println("CHECKSUM FIXED");
return false;
} else {
System.out.println("CHECKSUM OK");
return true;
}
}