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(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, char *file, int lineno)
95 struct message *self = malloc(sizeof(*self));
100 self->files = file_line__new(file, lineno);
101 if (self->files == NULL)
104 self->msg = strdup(msg);
105 if (self->msg == NULL)
108 self->option = option;
120 static struct message *mesage__find(const char *msg)
122 struct message *m = message__list;
125 if (strcmp(m->msg, msg) == 0)
133 static int message__add_file_line(struct message *self, char *file, int lineno)
136 struct file_line *fl = file_line__new(file, lineno);
141 fl->next = self->files;
148 static int message__add(const char *msg, char *option, char *file, int lineno)
152 char *escaped = escape(msg, bf, sizeof(bf));
153 struct message *m = mesage__find(escaped);
156 rc = message__add_file_line(m, file, lineno);
158 m = message__new(escaped, option, file, lineno);
161 m->next = message__list;
169 void menu_build_message_list(struct menu *menu)
173 message__add(menu_get_prompt(menu), NULL,
174 menu->file == NULL ? "Root Menu" : menu->file->name,
177 if (menu->sym != NULL && menu_has_help(menu))
178 message__add(menu_get_help(menu), menu->sym->name,
179 menu->file == NULL ? "Root Menu" : menu->file->name,
182 for (child = menu->list; child != NULL; child = child->next)
183 if (child->prompt != NULL)
184 menu_build_message_list(child);
187 static void message__print_file_lineno(struct message *self)
189 struct file_line *fl = self->files;
192 if (self->option != NULL)
193 printf("# %s:00000\n", self->option);
195 printf("#: %s:%d", fl->file, fl->lineno);
199 printf(", %s:%d", fl->file, fl->lineno);
206 static void message__print_gettext_msgid_msgstr(struct message *self)
208 message__print_file_lineno(self);
211 "msgstr \"\"\n", self->msg);
214 void menu__xgettext(void)
216 struct message *m = message__list;
219 /* skip empty lines ("") */
220 if (strlen(m->msg) > sizeof("\"\""))
221 message__print_gettext_msgid_msgstr(m);
226 int main(int ac, char **av)
230 menu_build_message_list(menu_get_root_menu(NULL));