Reorganized a chunk of code in worker program of {Java, Python, C, C++} language versions, without changing behavior.

This commit is contained in:
Project Nayuki 2017-08-28 04:03:05 +00:00
parent 712dfb9f77
commit 4d6185a5d3
4 changed files with 29 additions and 41 deletions

View File

@ -99,17 +99,16 @@ int main(void) {
free(data);
free(tempBuffer);
// Print grid of modules
if (!ok)
printf("-1\n");
else {
if (ok) {
// Print grid of modules
int size = qrcodegen_getSize(qrcode);
printf("%d\n", (size - 17) / 4);
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++)
printf("%d\n", qrcodegen_getModule(qrcode, x, y) ? 1 : 0);
}
}
} else
printf("-1\n");
free(qrcode);
fflush(stdout);
}

View File

@ -83,11 +83,9 @@ int main() {
} else
segs.push_back(QrSegment::makeBytes(data));
// Try to make QR Code symbol
try {
try { // Try to make QR Code symbol
const QrCode qr = QrCode::encodeSegments(segs,
*ECC_LEVELS[errCorLvl], minVersion, maxVersion, mask, boostEcl == 1);
// Print grid of modules
std::cout << qr.version << std::endl;
for (int y = 0; y < qr.size; y++) {
@ -96,12 +94,11 @@ int main() {
}
} catch (const char *msg) {
if (strcmp(msg, "Data too long") == 0)
std::cout << -1 << std::endl;
else {
if (strcmp(msg, "Data too long") != 0) {
std::cerr << msg << std::endl;
return EXIT_FAILURE;
}
std::cout << -1 << std::endl;
}
std::cout << std::flush;
}

View File

@ -77,24 +77,20 @@ public final class QrCodeGeneratorWorker {
else
segs = Arrays.asList(QrSegment.makeBytes(data));
// Try to make QR Code symbol
QrCode qr;
try {
qr = QrCode.encodeSegments(segs, QrCode.Ecc.values()[errCorLvl], minVersion, maxVersion, mask, boostEcl != 0);
} catch (IllegalArgumentException e) {
if (e.getMessage().equals("Data too long")) {
System.out.println(-1);
System.out.flush();
continue;
} else
throw e;
}
// Print grid of modules
System.out.println(qr.version);
for (int y = 0; y < qr.size; y++) {
for (int x = 0; x < qr.size; x++)
System.out.println(qr.getModule(x, y));
try { // Try to make QR Code symbol
QrCode qr = QrCode.encodeSegments(segs, QrCode.Ecc.values()[errCorLvl], minVersion, maxVersion, mask, boostEcl != 0);
// Print grid of modules
System.out.println(qr.version);
for (int y = 0; y < qr.size; y++) {
for (int x = 0; x < qr.size; x++)
System.out.println(qr.getModule(x, y));
}
} catch (IllegalArgumentException e) {
if (!e.getMessage().equals("Data too long"))
throw e;
System.out.println(-1);
}
System.out.flush();
}

View File

@ -60,22 +60,18 @@ def main():
else:
segs = [qrcodegen.QrSegment.make_bytes("".join(chr(b) for b in data))]
# Try to make QR Code symbol
try:
try: # Try to make QR Code symbol
qr = qrcodegen.QrCode.encode_segments(segs, ECC_LEVELS[errcorlvl], minversion, maxversion, mask, boostecl != 0)
# Print grid of modules
print(qr.get_version())
for y in range(qr.get_size()):
for x in range(qr.get_size()):
print(qr.get_module(x, y))
except ValueError as e:
if e.args[0] == "Data too long":
print(-1)
sys.stdout.flush()
continue
else:
if e.args[0] != "Data too long":
raise
# Print grid of modules
print(qr.get_version())
for y in range(qr.get_size()):
for x in range(qr.get_size()):
print(qr.get_module(x, y))
print(-1)
sys.stdout.flush()