2 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>, 2005
4 * Released under the terms of the GNU GPL v2.0
12 static char *escape(const char* text
, char *bf
, int len
)
15 int multiline
= strchr(text
, '\n') != NULL
;
17 int textlen
= strlen(text
);
19 if ((textlen
> 0) && (text
[textlen
-1] == '\n'))
32 while (*text
!= '\0' && len
> 1) {
35 else if (*text
== '\n') {
45 else if (*text
== '\\') {
64 struct file_line
*next
;
69 static struct file_line
*file_line__new(const char *file
, int lineno
)
71 struct file_line
*self
= malloc(sizeof(*self
));
77 self
->lineno
= lineno
;
87 struct file_line
*files
;
90 static struct message
*message__list
;
92 static struct message
*message__new(const char *msg
, char *option
,
93 const 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
= xstrdup(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
, const char *file
,
137 struct file_line
*fl
= file_line__new(file
, lineno
);
142 fl
->next
= self
->files
;
149 static int message__add(const char *msg
, char *option
, const char *file
,
154 char *escaped
= escape(msg
, bf
, sizeof(bf
));
155 struct message
*m
= mesage__find(escaped
);
158 rc
= message__add_file_line(m
, file
, lineno
);
160 m
= message__new(escaped
, option
, file
, lineno
);
163 m
->next
= message__list
;
171 static void menu_build_message_list(struct menu
*menu
)
175 message__add(menu_get_prompt(menu
), NULL
,
176 menu
->file
== NULL
? "Root Menu" : menu
->file
->name
,
179 if (menu
->sym
!= NULL
&& menu_has_help(menu
))
180 message__add(menu_get_help(menu
), menu
->sym
->name
,
181 menu
->file
== NULL
? "Root Menu" : menu
->file
->name
,
184 for (child
= menu
->list
; child
!= NULL
; child
= child
->next
)
185 if (child
->prompt
!= NULL
)
186 menu_build_message_list(child
);
189 static void message__print_file_lineno(struct message
*self
)
191 struct file_line
*fl
= self
->files
;
194 if (self
->option
!= NULL
)
195 printf("# %s:00000\n", self
->option
);
197 printf("#: %s:%d", fl
->file
, fl
->lineno
);
201 printf(", %s:%d", fl
->file
, fl
->lineno
);
208 static void message__print_gettext_msgid_msgstr(struct message
*self
)
210 message__print_file_lineno(self
);
213 "msgstr \"\"\n", self
->msg
);
216 static void menu__xgettext(void)
218 struct message
*m
= message__list
;
221 /* skip empty lines ("") */
222 if (strlen(m
->msg
) > sizeof("\"\""))
223 message__print_gettext_msgid_msgstr(m
);
228 int main(int ac
, char **av
)
232 menu_build_message_list(menu_get_root_menu(NULL
));