OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [extra/] [locale/] [lmmtolso.c] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
#include <stdio.h>
2
#include <stdlib.h>
3
#include <fcntl.h>
4
#include <unistd.h>
5
#include <sys/types.h>
6
#include <sys/stat.h>
7
 
8
int main(void)
9
{
10
        FILE *lmm;                                      /* mmap-able file */
11
        FILE *lso;                                      /* static object */
12
        struct stat fd_stat;
13
        int c;
14
        size_t i;
15
 
16
        if (!(lmm = fopen("locale.mmap", "r"))) {
17
                printf("can't open locale.mmap!\n");
18
                return EXIT_FAILURE;
19
        }
20
 
21
        if (fstat(fileno(lmm), &fd_stat)) {
22
                printf("can't stat locale.mmap!\n");
23
                fclose(lmm);
24
                return EXIT_FAILURE;
25
        }
26
 
27
        if (!(lso = fopen("locale_data.c", "w"))) {
28
                printf("can't open locale_data.c!\n");
29
                fclose(lmm);
30
                return EXIT_FAILURE;
31
        }
32
 
33
        fprintf(lso,
34
                        "#include <stddef.h>\n"
35
                        "#include <stdint.h>\n"
36
                        "#include \"lt_defines.h\"\n"
37
                        "#include \"locale_mmap.h\"\n\n"
38
                        "typedef union {\n"
39
                        "\tunsigned char buf[%zu];\n"
40
                        "\t__locale_mmap_t lmm;\n"
41
                        "} locale_union_t;\n\n"
42
                        "static const locale_union_t locale_union = { {",
43
                        (size_t) fd_stat.st_size
44
                        );
45
 
46
        i = 0;
47
        while ((c = getc(lmm)) != EOF) {
48
                if (!(i & 0x7)) {
49
                        fprintf(lso, "\n\t");
50
                }
51
                fprintf(lso, "%#04x, ", c);
52
                ++i;
53
        }
54
        fprintf(lso,
55
                        "\n} };\n\n"
56
                        "const __locale_mmap_t *__locale_mmap = &locale_union.lmm;\n\n"
57
                        );
58
 
59
        if (ferror(lmm)) {
60
                printf("error reading!\n");
61
                return EXIT_FAILURE;
62
        }
63
 
64
        if (ferror(lso) || fclose(lso)) {
65
                printf("error writing!\n");
66
                return EXIT_FAILURE;
67
        }
68
 
69
        fclose(lmm);
70
 
71
        return EXIT_SUCCESS;
72
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.