void test_struct_semilong(void) { QRcode_List *codes, *list; const char *str = "asdfasdfasdfasdfasdfASDFASDASDFASDFAsdfasdfasdfasdASDFASDFADSADadsfasdf"; int num, size; testStart("Testing semi-long structured-append symbols"); codes = QRcode_encodeString8bitStructured(str, 1, QR_ECLEVEL_L); list = codes; num = 0; while(list != NULL) { num++; assert_equal(list->code->version, 1, "version number is %d (1 expected)\n", list->code->version); list = list->next; } size = QRcode_List_size(codes); assert_equal(num, size, "QRcode_List_size returns wrong size?"); QRcode_List_free(codes); codes = QRcode_encodeStringStructured(str, 1, QR_ECLEVEL_L, QR_MODE_8, 1); list = codes; num = 0; while(list != NULL) { num++; assert_equal(list->code->version, 1, "version number is %d (1 expected)\n", list->code->version); list = list->next; } size = QRcode_List_size(codes); assert_equal(num, size, "QRcode_List_size returns wrong size?"); QRcode_List_free(codes); testFinish(); }
QRcode_List *QRcode_encodeInputStructured(QRinput_Struct *s) { QRcode_List *head = NULL; QRcode_List *tail = NULL; QRcode_List *entry; QRinput_InputList *list = s->head; while(list != NULL) { if(head == NULL) { entry = QRcode_List_newEntry(); if(entry == NULL) goto ABORT; head = entry; tail = head; } else { entry = QRcode_List_newEntry(); if(entry == NULL) goto ABORT; tail->next = entry; tail = tail->next; } tail->code = QRcode_encodeInput(list->input); if(tail->code == NULL) { goto ABORT; } list = list->next; } return head; ABORT: QRcode_List_free(head); return NULL; }
void draw_structuredQRcode(QRinput_Struct *s) { int i, w, h, n, x, y; int swidth; QRcode_List *qrcodes, *p; qrcodes = QRcode_encodeInputStructured(s); if(qrcodes == NULL) return; swidth = (qrcodes->code->width + margin * 2) * size; n = QRcode_List_size(qrcodes); w = (n < 4)?n:4; h = (n - 1) / 4 + 1; screen = SDL_SetVideoMode(swidth * w, swidth * h, 32, 0); SDL_FillRect(screen, NULL, 0xffffff); p = qrcodes; for(i=0; i<n; i++) { x = (i % 4) * swidth; y = (i / 4) * swidth; draw_QRcode(p->code, x, y); p = p->next; } SDL_Flip(screen); QRcode_List_free(qrcodes); }
void test_null_free(void) { testStart("Testing free NULL pointers"); assert_nothing(QRcode_free(NULL), "Check QRcode_free(NULL).\n"); assert_nothing(QRcode_List_free(NULL), "Check QRcode_List_free(NULL).\n"); assert_nothing(QRraw_free(NULL), "Check QRraw_free(NULL).\n"); testFinish(); }
static void qrencodeStructured(const char *intext, const char *outfile) { QRcode_List *qrlist, *p; char filename[FILENAME_MAX]; char *base, *q, *suffix = NULL; int i = 1; base = strdup(outfile); if(base == NULL) { fprintf(stderr, "Failed to allocate memory.\n"); exit(EXIT_FAILURE); } if(strlen(base) > 4) { q = base + strlen(base) - 4; if(strcasecmp(".png", q) == 0) { suffix = strdup(q); *q = '\0'; } } qrlist = encodeStructured(intext); if(qrlist == NULL) { perror("Failed to encode the input data:"); exit(EXIT_FAILURE); } for(p = qrlist; p != NULL; p = p->next) { if(p->code == NULL) { fprintf(stderr, "Failed to encode the input data.\n"); exit(EXIT_FAILURE); } if(suffix) { snprintf(filename, FILENAME_MAX, "%s-%02d%s", base, i, suffix); } else { snprintf(filename, FILENAME_MAX, "%s-%02d", base, i); } writePNG(p->code, filename); i++; } free(base); if(suffix) { free(suffix); } QRcode_List_free(qrlist); }
void test_struct_example(void) { QRcode_List *codes, *list; const char *str = "an example of four Structured Append symbols,"; int num; testStart("Testing the example of structured-append symbols"); codes = QRcode_encodeString8bitStructured(str, 1, QR_ECLEVEL_M); list = codes; num = 0; while(list != NULL) { num++; assert_equal(list->code->version, 1, "version number is %d (1 expected)\n", list->code->version); list = list->next; } assert_equal(num, 4, "number of symbols is %d (4 expected).", num); testFinish(); QRcode_List_free(codes); }
void test_split_structure(int num) { QRinput *input; QRinput_Struct *s; QRcode_List *codes, *list; QRinput_InputList *il; int version; QRecLevel level; int c, i, ret; version = (int)drand(40) + 1; level = (QRecLevel)drand(4); fill8bitString(); input = QRinput_new2(version, level); if(input == NULL) { perror("test_split_structure aborted at QRinput_new2():"); return; } ret = Split_splitStringToQRinput((char *)data, input, QR_MODE_KANJI, 1); if(ret < 0) { perror("test_split_structure aborted at Split_splitStringToQRinput():"); QRinput_free(input); return; } s = QRinput_splitQRinputToStruct(input); if(s == NULL) { if(errno != 0 && errno != ERANGE) { perror("test_split_structure aborted at QRinput_splitQRinputToStruct():"); } QRinput_free(input); return; } il = s->head; i = 0; while(il != NULL) { if(il->input->version != version) { printf("Test: version %d, level %c\n", version, levelChar[level]); printf("wrong version number.\n"); printQRinputInfo(il->input); exit(1); } i++; il = il->next; } codes = QRcode_encodeInputStructured(s); if(codes == NULL) { perror("test_split_structure aborted at QRcode_encodeInputStructured():"); QRinput_free(input); QRinput_Struct_free(s); return; } list = codes; il = s->head; c = 0; while(list != NULL) { if(list->code->version != version) { printf("#%d: data mismatched.\n", num); printf("Test: version %d, level %c\n", version, levelChar[level]); printf("code #%d\n", c); printf("Version mismatch: %d should be %d\n", list->code->version, version); printf("max bits: %d\n", QRspec_getDataLength(version, level) * 8 - 20); printQRinputInfo(il->input); printQRinput(input); exit(1); } list = list->next; il = il->next; c++; } QRinput_free(input); QRinput_Struct_free(s); QRcode_List_free(codes); }
static void qrencodeStructured(const unsigned char *intext, int length, const char *outfile) { QRcode_List *qrlist, *p; char filename[FILENAME_MAX]; char *base, *q, *suffix = NULL; const char *type_suffix; int i = 1; size_t suffix_size; switch(image_type) { case PNG_TYPE: type_suffix = ".png"; break; case EPS_TYPE: type_suffix = ".eps"; break; case SVG_TYPE: type_suffix = ".svg"; break; case ANSI_TYPE: case ANSI256_TYPE: case ASCII_TYPE: case UTF8_TYPE: case ANSIUTF8_TYPE: type_suffix = ".txt"; break; default: fprintf(stderr, "Unknown image type.\n"); exit(EXIT_FAILURE); } if(outfile == NULL) { fprintf(stderr, "An output filename must be specified to store the structured images.\n"); exit(EXIT_FAILURE); } base = strdup(outfile); if(base == NULL) { fprintf(stderr, "Failed to allocate memory.\n"); exit(EXIT_FAILURE); } suffix_size = strlen(type_suffix); if(strlen(base) > suffix_size) { q = base + strlen(base) - suffix_size; if(strcasecmp(type_suffix, q) == 0) { suffix = strdup(q); *q = '\0'; } } qrlist = encodeStructured(intext, length); if(qrlist == NULL) { perror("Failed to encode the input data"); exit(EXIT_FAILURE); } for(p = qrlist; p != NULL; p = p->next) { if(p->code == NULL) { fprintf(stderr, "Failed to encode the input data.\n"); exit(EXIT_FAILURE); } if(suffix) { snprintf(filename, FILENAME_MAX, "%s-%02d%s", base, i, suffix); } else { snprintf(filename, FILENAME_MAX, "%s-%02d", base, i); } if(verbose) { fprintf(stderr, "File: %s, Version: %d\n", filename, p->code->version); } switch(image_type) { case PNG_TYPE: writePNG(p->code, filename); break; case EPS_TYPE: writeEPS(p->code, filename); break; case SVG_TYPE: writeSVG(p->code, filename); break; case ANSI_TYPE: case ANSI256_TYPE: writeANSI(p->code, filename); break; case ASCIIi_TYPE: writeASCII(p->code, filename, 1); break; case ASCII_TYPE: writeASCII(p->code, filename, 0); break; case UTF8_TYPE: writeUTF8(p->code, filename, 0); break; case ANSIUTF8_TYPE: writeUTF8(p->code, filename, 0); break; default: fprintf(stderr, "Unknown image type.\n"); exit(EXIT_FAILURE); } i++; } free(base); if(suffix) { free(suffix); } QRcode_List_free(qrlist); }
static void qrencodeStructured(const unsigned char *intext, int length, const char *outfile) { QRcode_List *qrlist, *p; char filename[FILENAME_MAX]; char *base, *q, *suffix = NULL; const char *type_suffix; int i = 1; int suffix_size; switch(image_type) { case PNG_TYPE: type_suffix = ".png"; break; case EPS_TYPE: type_suffix = ".eps"; break; default: fprintf(stderr, "Unknown image type.\n"); exit(EXIT_FAILURE); } base = strdup(outfile); if(base == NULL) { fprintf(stderr, "Failed to allocate memory.\n"); exit(EXIT_FAILURE); } suffix_size = strlen(type_suffix); if(strlen(base) > suffix_size) { q = base + strlen(base) - suffix_size; if(strcasecmp(type_suffix, q) == 0) { suffix = strdup(q); *q = '\0'; } } qrlist = encodeStructured(intext, length); if(qrlist == NULL) { perror("Failed to encode the input data"); exit(EXIT_FAILURE); } for(p = qrlist; p != NULL; p = p->next) { if(p->code == NULL) { fprintf(stderr, "Failed to encode the input data.\n"); exit(EXIT_FAILURE); } if(suffix) { snprintf(filename, FILENAME_MAX, "%s-%02d%s", base, i, suffix); } else { snprintf(filename, FILENAME_MAX, "%s-%02d", base, i); } switch(image_type) { case PNG_TYPE: writePNG(p->code, filename); break; case EPS_TYPE: writeEPS(p->code, filename); break; default: fprintf(stderr, "Unknown image type.\n"); exit(EXIT_FAILURE); } i++; } free(base); if(suffix) { free(suffix); } QRcode_List_free(qrlist); }
void orcqrencode(char *ctx) { int version; int level; int hint; int size; int margin; int i; int doEncodeStructured; char buf[MAX_DATA_SIZE]; char buf2[MAX_DATA_SIZE]; char qrfile[SIZE_QRFILE]; char qrfile_suffix[SIZE_QRFILE + 10]; char *p; QRcode *code; QRcode_List *head, *entry; OPENLOG; if((p = strchr(CTX(ctx, OFFSET_INFILE), ' ')) != NULL) *p = '\0'; if((p = strchr(CTX(ctx, OFFSET_QRFILE), ' ')) != NULL) *p = '\0'; memset(CTX(ctx, OFFSET_RET_CODE), QRENCODE_OK, SIZE_RET_CODE); if(euc2sjis(CTX(ctx, OFFSET_INFILE), buf) != 0){ memset(CTX(ctx, OFFSET_RET_CODE), CHAR_CONV_ERROR, SIZE_RET_CODE); return; } hint = ctx_string2int(ctx, OFFSET_HINT, SIZE_HINT); if (hint < 2) { if(parse_csv(buf, buf2) !=0){ memset(CTX(ctx, OFFSET_RET_CODE), KANA_CONV_ERROR, SIZE_RET_CODE); return; } } else { lf2crlf(buf,buf2); } snprintf(qrfile, SIZE_QRFILE, "%s", CTX(ctx, OFFSET_QRFILE)); version = ctx_string2int(ctx, OFFSET_VERSION, SIZE_VERSION); if(version <= 0 || version > 40){ memset(CTX(ctx, OFFSET_RET_CODE), PARAM_ERROR, SIZE_RET_CODE); return; } switch(*CTX(ctx, OFFSET_LEVEL)){ case 'L': level = QR_ECLEVEL_L; break; case 'M': level = QR_ECLEVEL_M; break; case 'Q': level = QR_ECLEVEL_Q; break; case 'H': level = QR_ECLEVEL_H; break; default: level = QR_ECLEVEL_L; } p = strrchr(qrfile, '.'); if(p != NULL)*p = '\0'; doEncodeStructured = ctx_string2int(ctx, OFFSET_STRUCTURED, SIZE_STRUCTURED); hint = (hint % 2) == 0 ? QR_MODE_KANJI : QR_MODE_8; size = ctx_string2int(ctx, OFFSET_PIXEL, SIZE_PIXEL); margin = ctx_string2int(ctx, OFFSET_MARGIN, SIZE_MARGIN); code = QRcode_encodeString(buf2, version, level, hint, 1); if (code != NULL) { if (code->version <= version) { snprintf(qrfile_suffix, sizeof(qrfile_suffix), "%s_%02d.png", qrfile, 1); if(writePNG(code, qrfile_suffix, size, margin) != 0){ memset(CTX(ctx, OFFSET_RET_CODE), WRITE_PNG_ERROR, SIZE_RET_CODE); QRcode_free(code); return; } SYSLOG("write single image"); sprintf(buf, "%02d" , code->version); memcpy(CTX(ctx, OFFSET_RET_VERSION), buf, SIZE_RET_VERSION); sprintf(buf, "%02d" , 1); memcpy(CTX(ctx, OFFSET_RET_SYMBOLS), "01", SIZE_RET_SYMBOLS); QRcode_free(code); return; } QRcode_free(code); } if (doEncodeStructured) { head = QRcode_encodeStringStructured(buf2, version, level, hint ,1); if(head) { entry = head; i = 0; while(entry != NULL) { code = entry->code; snprintf(qrfile_suffix, sizeof(qrfile_suffix), "%s_%02d.png", qrfile, i + 1); if(writePNG(code, qrfile_suffix, size, margin) != 0){ memset(CTX(ctx, OFFSET_RET_CODE), WRITE_PNG_ERROR, SIZE_RET_CODE); break; } entry = entry->next; i++; } SYSLOG("write multi images"); QRcode_List_free(entry); } else { memset(CTX(ctx, OFFSET_RET_CODE), QRENCODE_ERROR, SIZE_RET_CODE); return; } sprintf(buf, "%02d" , head->code->version); memcpy(CTX(ctx, OFFSET_RET_VERSION), buf, SIZE_RET_VERSION); sprintf(buf, "%02d" , i); memcpy(CTX(ctx, OFFSET_RET_SYMBOLS), buf, SIZE_RET_SYMBOLS); QRcode_List_free(head); } #if 1 print_ctx(ctx); #endif SYSLOG("end"); return; }