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;
28 while (*text != '\0' && len > 1) {
31 else if (*text == '\n') {
56 struct file_line *next;
61 static struct file_line *file_line__new(char *file, int lineno)
63 struct file_line *self = malloc(sizeof(*self));
69 self->lineno = lineno;
79 struct file_line *files;
82 static struct message *message__list;
84 static struct message *message__new(const char *msg, char *option, char *file, int lineno)
86 struct message *self = malloc(sizeof(*self));
91 self->files = file_line__new(file, lineno);
92 if (self->files == NULL)
95 self->msg = strdup(msg);
96 if (self->msg == NULL)
99 self->option = option;
111 static struct message *mesage__find(const char *msg)
113 struct message *m = message__list;
116 if (strcmp(m->msg, msg) == 0)
124 static int message__add_file_line(struct message *self, char *file, int lineno)
127 struct file_line *fl = file_line__new(file, lineno);
132 fl->next = self->files;
139 static int message__add(const char *msg, char *option, char *file, int lineno)
143 char *escaped = escape(msg, bf, sizeof(bf));
144 struct message *m = mesage__find(escaped);
147 rc = message__add_file_line(m, file, lineno);
149 m = message__new(escaped, option, file, lineno);
152 m->next = message__list;
160 void menu_build_message_list(struct menu *menu)
164 message__add(menu_get_prompt(menu), NULL,
165 menu->file == NULL ? "Root Menu" : menu->file->name,
168 if (menu->sym != NULL && menu->sym->help != NULL)
169 message__add(menu->sym->help, menu->sym->name,
170 menu->file == NULL ? "Root Menu" : menu->file->name,
173 for (child = menu->list; child != NULL; child = child->next)
174 if (child->prompt != NULL)
175 menu_build_message_list(child);
178 static void message__print_file_lineno(struct message *self)
180 struct file_line *fl = self->files;
182 printf("\n#: %s:%d", fl->file, fl->lineno);
186 printf(", %s:%d", fl->file, fl->lineno);
190 if (self->option != NULL)
191 printf(", %s:00000", self->option);
196 static void message__print_gettext_msgid_msgstr(struct message *self)
198 message__print_file_lineno(self);
201 "msgstr \"\"\n", self->msg);
204 void menu__xgettext(void)
206 struct message *m = message__list;
209 message__print_gettext_msgid_msgstr(m);
214 int main(int ac, char **av)
218 menu_build_message_list(menu_get_root_menu(NULL));