1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#include <inttypes.h>
#include <stdio.h>
#include <libcss/libcss.h>
#include "stylesheet.h"
#include "testutils.h"
static void *myrealloc(void *ptr, size_t len, void *pw)
{
UNUSED(pw);
return realloc(ptr, len);
}
int main(int argc, char **argv)
{
css_stylesheet *sheet;
FILE *fp;
size_t len, origlen;
#define CHUNK_SIZE (4096)
uint8_t buf[CHUNK_SIZE];
css_error error;
if (argc != 3) {
printf("Usage: %s <aliases_file> <filename>\n", argv[0]);
return 1;
}
/* Initialise library */
assert(css_initialise(argv[1], myrealloc, NULL) == CSS_OK);
sheet = css_stylesheet_create(CSS_LEVEL_21, "UTF-8", argv[2], NULL,
CSS_ORIGIN_AUTHOR, CSS_MEDIA_ALL, NULL, NULL,
myrealloc, NULL);
assert(sheet != NULL);
fp = fopen(argv[2], "rb");
if (fp == NULL) {
printf("Failed opening %s\n", argv[2]);
return 1;
}
fseek(fp, 0, SEEK_END);
origlen = len = ftell(fp);
fseek(fp, 0, SEEK_SET);
while (len >= CHUNK_SIZE) {
fread(buf, 1, CHUNK_SIZE, fp);
error = css_stylesheet_append_data(sheet, buf, CHUNK_SIZE);
assert(error == CSS_OK || error == CSS_NEEDDATA);
len -= CHUNK_SIZE;
}
if (len > 0) {
fread(buf, 1, len, fp);
error = css_stylesheet_append_data(sheet, buf, len);
assert(error == CSS_OK || error == CSS_NEEDDATA);
len = 0;
}
fclose(fp);
assert(css_stylesheet_data_done(sheet) == CSS_OK);
css_stylesheet_dump(sheet, stdout);
css_stylesheet_destroy(sheet);
assert(css_finalise(myrealloc, NULL) == CSS_OK);
printf("PASS\n");
return 0;
}
|