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); }
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); }