1 diff -urN busybox-1.6.0.org/coreutils/printf.c busybox-1.6.0/coreutils/printf.c
2 --- busybox-1.6.0.org/coreutils/printf.c 2007-06-01 13:48:34.000000000 +0200
3 +++ busybox-1.6.0/coreutils/printf.c 2007-06-03 20:27:45.511646939 +0200
6 // 19990508 Busy Boxed! Dave Cinege
9 +#define BB_FEATURE_PRINTF_GETTEXT
13 typedef void (*converter)(const char *arg, void *result);
14 @@ -285,19 +288,137 @@
15 return save_argc - argc;
19 + * Very pure gettext added by Michal Moskal <malekith@pld-linux.org>
20 + * This possibly could be converted into utility function
21 + * and used in other places as well.
24 +#ifdef BB_FEATURE_PRINTF_GETTEXT
25 +/* The magic number of the GNU message catalog format. */
26 +#define _MAGIC 0x950412de
28 +/* Header for binary .mo file format. */
29 +struct mo_file_header
31 + /* The magic number. */
33 + /* The revision number of the file format. */
35 + /* The number of strings pairs. */
37 + /* Offset of table with start offsets of original strings. */
38 + u_int32_t orig_tab_offset;
39 + /* Offset of table with start offsets of translation strings. */
40 + u_int32_t trans_tab_offset;
41 + /* Size of hashing table. */
42 + u_int32_t hash_tab_size;
43 + /* Offset of first hashing entry. */
44 + u_int32_t hash_tab_offset;
49 + /* Length of addressed string. */
51 + /* Offset of string in file. */
55 +static u_int32_t swap(u_int32_t i)
57 + return (i << 24) | ((i & 0xff00) << 8) |
58 + ((i >> 8) & 0xff00) | (i >> 24);
60 +#define swap_if(a) ((has_to_swap) ? swap(a) : (a))
61 +static char *getmsg(const char *filename, const char *msgid)
64 + struct mo_file_header *ptr;
68 + struct string_desc *orig_tab, *trans_tab = NULL;
70 + char *ret = (char*)msgid;
72 + if (filename == NULL || stat(filename, &st))
75 + fd = open(filename, O_RDONLY);
79 + ptr = (struct mo_file_header *) mmap(NULL, st.st_size, PROT_READ,
80 + MAP_PRIVATE, fd, 0);
83 + if (ptr == (void*)-1)
86 + has_to_swap = ptr->magic != _MAGIC;
88 + if (swap_if(ptr->magic) != _MAGIC)
91 + /* FIXME: use hash table */
93 + orig_tab = (struct string_desc *)
94 + ((char *) ptr + swap_if(ptr->orig_tab_offset));
95 + trans_tab = (struct string_desc *)
96 + ((char *) ptr + swap_if(ptr->trans_tab_offset));
99 + top = swap_if(ptr->nstrings);
100 + while (bottom < top) {
102 + act = (bottom + top) / 2;
105 + ((char *) ptr + swap_if(orig_tab[act].offset)));
108 + else if (cmp_val > 0)
117 + ret = strdup(((char *) ptr + swap_if(trans_tab[act].offset)));
118 + munmap(ptr, st.st_size);
122 +# define getmsg(a,b) (b)
125 int printf_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
126 int printf_main(int argc, char **argv)
130 + int args_used, opt;
131 + const char *nls_file = NULL;
133 + while ((opt = getopt(argc, argv, "n:")) != -1)
142 + format = getmsg(nls_file, argv[optind++]);
144 if (argc <= 1 || argv[1][0] == '-') {
155 args_used = print_formatted(format, argc, argv);