Reorganized a chunk of code in worker program of {Java, Python, C, C++} language versions, without changing behavior.
This commit is contained in:
parent
712dfb9f77
commit
4d6185a5d3
|
@ -99,17 +99,16 @@ int main(void) {
|
||||||
free(data);
|
free(data);
|
||||||
free(tempBuffer);
|
free(tempBuffer);
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
// Print grid of modules
|
// Print grid of modules
|
||||||
if (!ok)
|
|
||||||
printf("-1\n");
|
|
||||||
else {
|
|
||||||
int size = qrcodegen_getSize(qrcode);
|
int size = qrcodegen_getSize(qrcode);
|
||||||
printf("%d\n", (size - 17) / 4);
|
printf("%d\n", (size - 17) / 4);
|
||||||
for (int y = 0; y < size; y++) {
|
for (int y = 0; y < size; y++) {
|
||||||
for (int x = 0; x < size; x++)
|
for (int x = 0; x < size; x++)
|
||||||
printf("%d\n", qrcodegen_getModule(qrcode, x, y) ? 1 : 0);
|
printf("%d\n", qrcodegen_getModule(qrcode, x, y) ? 1 : 0);
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
|
printf("-1\n");
|
||||||
free(qrcode);
|
free(qrcode);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,11 +83,9 @@ int main() {
|
||||||
} else
|
} else
|
||||||
segs.push_back(QrSegment::makeBytes(data));
|
segs.push_back(QrSegment::makeBytes(data));
|
||||||
|
|
||||||
// Try to make QR Code symbol
|
try { // Try to make QR Code symbol
|
||||||
try {
|
|
||||||
const QrCode qr = QrCode::encodeSegments(segs,
|
const QrCode qr = QrCode::encodeSegments(segs,
|
||||||
*ECC_LEVELS[errCorLvl], minVersion, maxVersion, mask, boostEcl == 1);
|
*ECC_LEVELS[errCorLvl], minVersion, maxVersion, mask, boostEcl == 1);
|
||||||
|
|
||||||
// Print grid of modules
|
// Print grid of modules
|
||||||
std::cout << qr.version << std::endl;
|
std::cout << qr.version << std::endl;
|
||||||
for (int y = 0; y < qr.size; y++) {
|
for (int y = 0; y < qr.size; y++) {
|
||||||
|
@ -96,12 +94,11 @@ int main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (const char *msg) {
|
} catch (const char *msg) {
|
||||||
if (strcmp(msg, "Data too long") == 0)
|
if (strcmp(msg, "Data too long") != 0) {
|
||||||
std::cout << -1 << std::endl;
|
|
||||||
else {
|
|
||||||
std::cerr << msg << std::endl;
|
std::cerr << msg << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
std::cout << -1 << std::endl;
|
||||||
}
|
}
|
||||||
std::cout << std::flush;
|
std::cout << std::flush;
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,25 +77,21 @@ public final class QrCodeGeneratorWorker {
|
||||||
else
|
else
|
||||||
segs = Arrays.asList(QrSegment.makeBytes(data));
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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
|
// Print grid of modules
|
||||||
System.out.println(qr.version);
|
System.out.println(qr.version);
|
||||||
for (int y = 0; y < qr.size; y++) {
|
for (int y = 0; y < qr.size; y++) {
|
||||||
for (int x = 0; x < qr.size; x++)
|
for (int x = 0; x < qr.size; x++)
|
||||||
System.out.println(qr.getModule(x, y));
|
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();
|
System.out.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,22 +60,18 @@ def main():
|
||||||
else:
|
else:
|
||||||
segs = [qrcodegen.QrSegment.make_bytes("".join(chr(b) for b in data))]
|
segs = [qrcodegen.QrSegment.make_bytes("".join(chr(b) for b in data))]
|
||||||
|
|
||||||
# Try to make QR Code symbol
|
try: # Try to make QR Code symbol
|
||||||
try:
|
|
||||||
qr = qrcodegen.QrCode.encode_segments(segs, ECC_LEVELS[errcorlvl], minversion, maxversion, mask, boostecl != 0)
|
qr = qrcodegen.QrCode.encode_segments(segs, ECC_LEVELS[errcorlvl], minversion, maxversion, mask, boostecl != 0)
|
||||||
except ValueError as e:
|
|
||||||
if e.args[0] == "Data too long":
|
|
||||||
print(-1)
|
|
||||||
sys.stdout.flush()
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
|
|
||||||
# Print grid of modules
|
# Print grid of modules
|
||||||
print(qr.get_version())
|
print(qr.get_version())
|
||||||
for y in range(qr.get_size()):
|
for y in range(qr.get_size()):
|
||||||
for x in range(qr.get_size()):
|
for x in range(qr.get_size()):
|
||||||
print(qr.get_module(x, y))
|
print(qr.get_module(x, y))
|
||||||
|
|
||||||
|
except ValueError as e:
|
||||||
|
if e.args[0] != "Data too long":
|
||||||
|
raise
|
||||||
|
print(-1)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue