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') {
61 struct file_line
*next
;
66 static struct file_line
*file_line__new(char *file
, int lineno
)
68 struct file_line
*self
= malloc(sizeof(*self
));
74 self
->lineno
= lineno
;
84 struct file_line
*files
;
87 static struct message
*message__list
;
89 static struct message
*message__new(const char *msg
, char *option
, char *file
, int lineno
)
91 struct message
*self
= malloc(sizeof(*self
));
96 self
->files
= file_line__new(file
, lineno
);
97 if (self
->files
== NULL
)
100 self
->msg
= strdup(msg
);
101 if (self
->msg
== NULL
)
104 self
->option
= option
;
116 static struct message
*mesage__find(const char *msg
)
118 struct message
*m
= message__list
;
121 if (strcmp(m
->msg
, msg
) == 0)
129 static int message__add_file_line(struct message
*self
, char *file
, int lineno
)
132 struct file_line
*fl
= file_line__new(file
, lineno
);
137 fl
->next
= self
->files
;
144 static int message__add(const char *msg
, char *option
, char *file
, int lineno
)
148 char *escaped
= escape(msg
, bf
, sizeof(bf
));
149 struct message
*m
= mesage__find(escaped
);
152 rc
= message__add_file_line(m
, file
, lineno
);
154 m
= message__new(escaped
, option
, file
, lineno
);
157 m
->next
= message__list
;
165 void menu_build_message_list(struct menu
*menu
)
169 message__add(menu_get_prompt(menu
), NULL
,
170 menu
->file
== NULL
? "Root Menu" : menu
->file
->name
,
173 if (menu
->sym
!= NULL
&& menu_has_help(menu
))
174 message__add(menu_get_help(menu
), menu
->sym
->name
,
175 menu
->file
== NULL
? "Root Menu" : menu
->file
->name
,
178 for (child
= menu
->list
; child
!= NULL
; child
= child
->next
)
179 if (child
->prompt
!= NULL
)
180 menu_build_message_list(child
);
183 static void message__print_file_lineno(struct message
*self
)
185 struct file_line
*fl
= self
->files
;
188 if (self
->option
!= NULL
)
189 printf("# %s:00000\n", self
->option
);
191 printf("#: %s:%d", fl
->file
, fl
->lineno
);
195 printf(", %s:%d", fl
->file
, fl
->lineno
);
202 static void message__print_gettext_msgid_msgstr(struct message
*self
)
204 message__print_file_lineno(self
);
207 "msgstr \"\"\n", self
->msg
);
210 void menu__xgettext(void)
212 struct message
*m
= message__list
;
215 /* skip empty lines ("") */
216 if (strlen(m
->msg
) > sizeof("\"\""))
217 message__print_gettext_msgid_msgstr(m
);
222 int main(int ac
, char **av
)
226 menu_build_message_list(menu_get_root_menu(NULL
));