| 24 | #include "xsHost.h" |
| 25 | |
| 26 | void xs_qrcode(xsMachine *the) |
| 27 | { |
| 28 | size_t bufferSize; |
| 29 | uint8_t *qr0 = C_NULL; |
| 30 | void *data; |
| 31 | xsType type; |
| 32 | uint8_t ok; |
| 33 | int x, y; |
| 34 | uint8_t *module; |
| 35 | int maxVersion = qrcodegen_VERSION_MAX; |
| 36 | |
| 37 | xsmcVars(3); |
| 38 | |
| 39 | if (xsmcGet(xsVar(0), xsArg(0), xsID_maxVersion)) { |
| 40 | maxVersion = xsmcToInteger(xsVar(0)); |
| 41 | if ((maxVersion > qrcodegen_VERSION_MAX) || (maxVersion < qrcodegen_VERSION_MIN)) |
| 42 | xsRangeError("invalid"); |
| 43 | } |
| 44 | |
| 45 | uint8_t padding = 0; |
| 46 | if (xsmcGet(xsVar(0), xsArg(0), xsID_bitmap)) { |
| 47 | if (xsBooleanType == xsmcTypeOf(xsVar(0))) { |
| 48 | if (xsmcTest(xsVar(0))) |
| 49 | padding = 8; |
| 50 | } |
| 51 | else { |
| 52 | int t = xsmcToInteger(xsVar(0)); |
| 53 | if ((8 != t) && (16 != t) && (32 != t)) |
| 54 | xsRangeError("invalid"); |
| 55 | padding = (uint8_t)t; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | uint16_t fit = 0; |
| 60 | if (padding && xsmcGet(xsVar(0), xsArg(0), xsID_fit)) { |
| 61 | int t = xsmcToInteger(xsVar(0)); |
| 62 | if ((t <= 0) || (t > 32767)) |
| 63 | xsRangeError("invalid"); |
| 64 | fit = (uint16_t)t; |
| 65 | } |
| 66 | |
| 67 | bufferSize = qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion); |
| 68 | qr0 = c_malloc(bufferSize << 1); |
| 69 | if (!qr0) |
| 70 | xsUnknownError("no memory"); |
| 71 | |
| 72 | xsTry { |
| 73 | xsmcGet(xsVar(0), xsArg(0), xsID_input); |
| 74 | type = xsmcTypeOf(xsVar(0)); |
| 75 | if (xsStringType == type) { |
| 76 | data = xsmcToString(xsVar(0)); |
| 77 | ok = qrcodegen_encodeText(data, qr0 + bufferSize, qr0, |
| 78 | qrcodegen_Ecc_MEDIUM, qrcodegen_VERSION_MIN, maxVersion, qrcodegen_Mask_AUTO, true); |
| 79 | } |
| 80 | else { |
| 81 | xsUnsignedValue dataSize; |
| 82 | |
| 83 | xsmcGetBufferReadable(xsVar(0), &data, &dataSize); |
nothing calls this directly
no test coverage detected