1 diff -ur busybox-1.00.orig/coreutils/printf.c busybox-1.00/coreutils/printf.c
2 --- busybox-1.00.orig/coreutils/printf.c 2004-09-15 02:05:23.000000000 +0000
3 +++ busybox-1.00/coreutils/printf.c 2004-11-11 18:16:33.724386928 +0000
6 // 19990508 Busy Boxed! Dave Cinege
9 +#define BB_FEATURE_PRINTF_GETTEXT
13 +#include <sys/mman.h>
14 +#include <sys/stat.h>
15 #include <sys/types.h>
19 static void print_direc __P( (char *start, size_t length,
20 int field_width, int precision, char *argument));
23 + * Very pure gettext added by Michal Moskal <malekith@pld-linux.org>
24 + * This possibly could be converted into utility function
25 + * and used in other places as well.
28 +#ifdef BB_FEATURE_PRINTF_GETTEXT
29 +/* The magic number of the GNU message catalog format. */
30 +#define _MAGIC 0x950412de
32 +/* Header for binary .mo file format. */
33 +struct mo_file_header
35 + /* The magic number. */
37 + /* The revision number of the file format. */
39 + /* The number of strings pairs. */
41 + /* Offset of table with start offsets of original strings. */
42 + u_int32_t orig_tab_offset;
43 + /* Offset of table with start offsets of translation strings. */
44 + u_int32_t trans_tab_offset;
45 + /* Size of hashing table. */
46 + u_int32_t hash_tab_size;
47 + /* Offset of first hashing entry. */
48 + u_int32_t hash_tab_offset;
53 + /* Length of addressed string. */
55 + /* Offset of string in file. */
59 +static u_int32_t swap(u_int32_t i)
61 + return (i << 24) | ((i & 0xff00) << 8) |
62 + ((i >> 8) & 0xff00) | (i >> 24);
65 +#define swap_if(a) ((has_to_swap) ? swap(a) : (a))
67 +static char *getmsg(const char *filename, const char *msgid)
70 + struct mo_file_header *ptr;
74 + struct string_desc *orig_tab, *trans_tab = NULL;
76 + char *ret = (char*)msgid;
78 + if (filename == NULL || stat(filename, &st))
81 + fd = open(filename, O_RDONLY);
85 + ptr = (struct mo_file_header *) mmap(NULL, st.st_size, PROT_READ,
86 + MAP_PRIVATE, fd, 0);
89 + if (ptr == (void*)-1)
92 + has_to_swap = ptr->magic != _MAGIC;
94 + if (swap_if(ptr->magic) != _MAGIC)
97 + /* FIXME: use hash table */
99 + orig_tab = (struct string_desc *)
100 + ((char *) ptr + swap_if(ptr->orig_tab_offset));
101 + trans_tab = (struct string_desc *)
102 + ((char *) ptr + swap_if(ptr->trans_tab_offset));
105 + top = swap_if(ptr->nstrings);
106 + while (bottom < top) {
109 + act = (bottom + top) / 2;
112 + ((char *) ptr + swap_if(orig_tab[act].offset)));
115 + else if (cmp_val > 0)
124 + ret = strdup(((char *) ptr + swap_if(trans_tab[act].offset)));
125 + munmap(ptr, st.st_size);
129 +# define getmsg(a,b) (b)
132 int printf_main(int argc, char **argv)
137 + const char *nls_file = NULL;
139 - if (argc <= 1 || **(argv + 1) == '-') {
142 + while ((opt = getopt(argc, argv, "n:")) != -1)
152 + format = getmsg(nls_file, argv[optind++]);
161 args_used = print_formatted(format, argc, argv);