1 --- busybox-1.12.2/coreutils/printf.c 2008-09-28 20:04:18.000000000 +0200
2 +++ busybox-1.12.2.patch/coreutils/printf.c 2008-11-19 13:00:54.187842550 +0100
5 // 19990508 Busy Boxed! Dave Cinege
8 +#define BB_FEATURE_PRINTF_GETTEXT
12 /* A note on bad input: neither bash 3.2 nor coreutils 6.10 stop on it.
13 @@ -334,10 +337,131 @@
18 + * Very pure gettext added by Michal Moskal <malekith@pld-linux.org>
19 + * This possibly could be converted into utility function
20 + * and used in other places as well.
23 +#ifdef BB_FEATURE_PRINTF_GETTEXT
24 +/* The magic number of the GNU message catalog format. */
25 +#define _MAGIC 0x950412de
27 +/* Header for binary .mo file format. */
28 +struct mo_file_header
30 + /* The magic number. */
32 + /* The revision number of the file format. */
34 + /* The number of strings pairs. */
36 + /* Offset of table with start offsets of original strings. */
37 + u_int32_t orig_tab_offset;
38 + /* Offset of table with start offsets of translation strings. */
39 + u_int32_t trans_tab_offset;
40 + /* Size of hashing table. */
41 + u_int32_t hash_tab_size;
42 + /* Offset of first hashing entry. */
43 + u_int32_t hash_tab_offset;
48 + /* Length of addressed string. */
50 + /* Offset of string in file. */
54 +static u_int32_t swap(u_int32_t i)
56 + return (i << 24) | ((i & 0xff00) << 8) |
57 + ((i >> 8) & 0xff00) | (i >> 24);
59 +#define swap_if(a) ((has_to_swap) ? swap(a) : (a))
60 +static char *getmsg(const char *filename, const char *msgid)
63 + struct mo_file_header *ptr;
67 + struct string_desc *orig_tab, *trans_tab = NULL;
69 + char *ret = (char*)msgid;
71 + if (filename == NULL || stat(filename, &st))
74 + fd = open(filename, O_RDONLY);
78 + ptr = (struct mo_file_header *) mmap(NULL, st.st_size, PROT_READ,
79 + MAP_PRIVATE, fd, 0);
82 + if (ptr == (void*)-1)
85 + has_to_swap = ptr->magic != _MAGIC;
87 + if (swap_if(ptr->magic) != _MAGIC)
90 + /* FIXME: use hash table */
92 + orig_tab = (struct string_desc *)
93 + ((char *) ptr + swap_if(ptr->orig_tab_offset));
94 + trans_tab = (struct string_desc *)
95 + ((char *) ptr + swap_if(ptr->trans_tab_offset));
98 + top = swap_if(ptr->nstrings);
99 + while (bottom < top) {
101 + act = (bottom + top) / 2;
104 + ((char *) ptr + swap_if(orig_tab[act].offset)));
107 + else if (cmp_val > 0)
116 + ret = strdup(((char *) ptr + swap_if(trans_tab[act].offset)));
117 + munmap(ptr, st.st_size);
121 +# define getmsg(a,b) (b)
124 int printf_main(int argc UNUSED_PARAM, char **argv)
130 + const char *nls_file = NULL;
132 + while ((opt = getopt(argc, argv, "n:")) != -1)
142 + format = getmsg(nls_file, argv[optind++]);
144 /* We must check that stdout is not closed.