1//
2//  testgenerateoflabel.c
3//
4//  Copyright 2012 Apple Inc. All rights reserved.
5//
6
7#include <stdio.h>
8#include <string.h>
9#include <stdlib.h>
10#include <CoreFoundation/CoreFoundation.h>
11#include <ApplicationServices/ApplicationServices.h>
12#include "bless.h"
13
14
15// cc -o testgenerate testgenerateoflabel.c libbless.a -framework CoreFoundation -framework ApplicationServices
16
17
18int main(int argc, char *argv[])
19{
20    int         err;
21    int         scale;
22    CFStringRef path;
23    CFURLRef    url;
24    CFDataRef   labelData;
25
26    if (argc < 3 || argc > 4 || (argc == 4 && strcmp(argv[3], "-2x"))) {
27        fprintf(stderr, "Usage: %s label file [-2x]\n", getprogname());
28        exit(1);
29    }
30
31    path = CFStringCreateWithCString(kCFAllocatorDefault, argv[2], kCFStringEncodingUTF8);
32    if (!path) {
33        fprintf(stderr, "Couldn't create string from %s\n", argv[2]);
34        exit(1);
35    }
36
37    url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path, kCFURLPOSIXPathStyle, false);
38    if (!url) {
39        fprintf(stderr, "Couldn't create URL for %s\n", argv[2]);
40        exit(1);
41    }
42
43    scale = (argc == 4) ? kBitmapScale_2x : kBitmapScale_1x;
44
45    err = BLGenerateLabelData(NULL, argv[1], scale, &labelData);
46    if (err) {
47        fprintf(stderr, "Couldn't create label data\n");
48        exit(1);
49    }
50
51    CFURLWriteDataAndPropertiesToResource(url, labelData, NULL, NULL);
52
53    CFRelease(path);
54    CFRelease(url);
55    CFRelease(labelData);
56
57    return 0;
58}
59