2 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>, 2005
4 * Released under the terms of the GNU GPL v2.0
10 #define LKC_DIRECT_LINK
13 static char *escape(const char* text, char *bf, int len)
16 int multiline = strchr(text, '\n') != NULL;
18 int textlen = strlen(text);
20 if ((textlen > 0) && (text[textlen-1] == '\n'))
33 while (*text != '\0' && len > 1) {
36 else if (*text == '\n') {
46 else if (*text == '\\') {
65 struct file_line *next;
70 static struct file_line *file_line__new(const char *file, int lineno)
72 struct file_line *self = malloc(sizeof(*self));
78 self->lineno = lineno;
88 struct file_line *files;
91 static struct message *message__list;
93 static struct message *message__new(const char *msg, char *option,
94 const char *file, int lineno)
96 struct message *self = malloc(sizeof(*self));
101 self->files = file_line__new(file, lineno);
102 if (self->files == NULL)
105 self->msg = strdup(msg);
106 if (self->msg == NULL)
109 self->option = option;
121 static struct message *mesage__find(const char *msg)
123 struct message *m = message__list;
126 if (strcmp(m->msg, msg) == 0)
134 static int message__add_file_line(struct message *self, const char *file,
138 struct file_line *fl = file_line__new(file, lineno);
143 fl->next = self->files;
150 static int message__add(const char *msg, char *option, const char *file,
155 char *escaped = escape(msg, bf, sizeof(bf));
156 struct message *m = mesage__find(escaped);
159 rc = message__add_file_line(m, file, lineno);
161 m = message__new(escaped, option, file, lineno);
164 m->next = message__list;
172 static void menu_build_message_list(struct menu *menu)
176 message__add(menu_get_prompt(menu), NULL,
177 menu->file == NULL ? "Root Menu" : menu->file->name,
180 if (menu->sym != NULL && menu_has_help(menu))
181 message__add(menu_get_help(menu), menu->sym->name,
182 menu->file == NULL ? "Root Menu" : menu->file->name,
185 for (child = menu->list; child != NULL; child = child->next)
186 if (child->prompt != NULL)
187 menu_build_message_list(child);
190 static void message__print_file_lineno(struct message *self)
192 struct file_line *fl = self->files;
195 if (self->option != NULL)
196 printf("# %s:00000\n", self->option);
198 printf("#: %s:%d", fl->file, fl->lineno);
202 printf(", %s:%d", fl->file, fl->lineno);
209 static void message__print_gettext_msgid_msgstr(struct message *self)
211 message__print_file_lineno(self);
214 "msgstr \"\"\n", self->msg);
217 static void menu__xgettext(void)
219 struct message *m = message__list;
222 /* skip empty lines ("") */
223 if (strlen(m->msg) > sizeof("\"\""))
224 message__print_gettext_msgid_msgstr(m);
229 int main(int ac, char **av)
233 menu_build_message_list(menu_get_root_menu(NULL));