1 --- busybox-1.3.1/coreutils/printf.c.orig 2006-12-27 05:54:50.000000000 +0100
2 +++ busybox-1.3.1/coreutils/printf.c 2006-12-30 12:28:27.605589427 +0100
5 // 19990508 Busy Boxed! Dave Cinege
8 +#define BB_FEATURE_PRINTF_GETTEXT
12 static int print_formatted(char *format, int argc, char **argv);
13 @@ -109,18 +112,137 @@
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);
60 +#define swap_if(a) ((has_to_swap) ? swap(a) : (a))
62 +static char *getmsg(const char *filename, const char *msgid)
65 + struct mo_file_header *ptr;
69 + struct string_desc *orig_tab, *trans_tab = NULL;
71 + char *ret = (char*)msgid;
73 + if (filename == NULL || stat(filename, &st))
76 + fd = open(filename, O_RDONLY);
80 + ptr = (struct mo_file_header *) mmap(NULL, st.st_size, PROT_READ,
81 + MAP_PRIVATE, fd, 0);
84 + if (ptr == (void*)-1)
87 + has_to_swap = ptr->magic != _MAGIC;
89 + if (swap_if(ptr->magic) != _MAGIC)
92 + /* FIXME: use hash table */
94 + orig_tab = (struct string_desc *)
95 + ((char *) ptr + swap_if(ptr->orig_tab_offset));
96 + trans_tab = (struct string_desc *)
97 + ((char *) ptr + swap_if(ptr->trans_tab_offset));
100 + top = swap_if(ptr->nstrings);
101 + while (bottom < top) {
104 + act = (bottom + top) / 2;
107 + ((char *) ptr + swap_if(orig_tab[act].offset)));
110 + else if (cmp_val > 0)
119 + ret = strdup(((char *) ptr + swap_if(trans_tab[act].offset)));
120 + munmap(ptr, st.st_size);
124 +# define getmsg(a,b) (b)
127 int printf_main(int argc, char **argv)
132 + const char *nls_file = NULL;
134 - if (argc <= 1 || argv[1][0] == '-') {
137 + while ((opt = getopt(argc, argv, "n:")) != -1)
147 + format = getmsg(nls_file, argv[optind++]);
156 args_used = print_formatted(format, argc, argv);