+2007-01-18 Joel E. Denny <jdenny@ces.clemson.edu>
+
+ Implement @gettext<...@> directive to call gettext from skeletons. It
+ can be used anywhere including inside arguments of directives of the
+ form @foo(...@). Eventually, it should be possible to write an
+ xgettext-like utility to extract @gettext<...@> text from skeletons.
+ * data/bison.m4 (b4_check_user_names): Use @gettext<...@> when invoking
+ b4_warn_at since b4_warn_at doesn't invoke gettext anymore.
+ * data/glr.cc, data/lalr1.cc: Likewise but for b4_fatal and
+ b4_complain reporting a push-parsing request or a missing %defines.
+ * src/scan-skel.l (INITIAL): Recognize `@gettext<' to start...
+ (SC_AT_GETTEXT_ARG): ... this new start condition where gettext is
+ invoked.
+ (SC_AT_DIRECTIVE_ARG): Rename to...
+ (SC_AT_DIRECTIVE_ARGS): ... this, and recognize `@gettext<' to start
+ SC_AT_GETTEXT_ARG.
+ (at_directive_perform): Don't invoke gettext for @warn(...@),
+ @warn_at(...@), etc. Instead, let the skeletons decide what should be
+ passed to @gettext<...@>.
+ * tests/skeletons.at (@gettext<...@>): New test case.
+
+ * tests/skeletons.at (installed skeleton file name): Rename to...
+ (installed skeleton file names): ... this.
+
2007-01-17 Joel E. Denny <jdenny@ces.clemson.edu>
Implement support for relative and absolute skeleton file names.
static void fail_for_invalid_at (char const *at);
/* In SC_AT_DIRECTIVE_ARG context, the name of the directive. */
-static char *at_directive_name;
+static char *at_directive_name = NULL;
/* Currently, only the @warn, @complain, @fatal, @warn_at, @complain_at, and
@fatal_at directives take multiple arguments, and the last three already
static char *at_directive_argv[AT_DIRECTIVE_ARGC_MAX];
%}
-%x SC_AT_DIRECTIVE_ARG
+%x SC_AT_GETTEXT_ARG
+%x SC_AT_DIRECTIVE_ARGS
%x SC_AT_DIRECTIVE_SKIP_WS
%%
"@ofile@" QPUTS (outname);
"@dir_prefix@" QPUTS (dir_prefix);
+"@gettext<" BEGIN SC_AT_GETTEXT_ARG;
+
@[a-z_]+"(" {
yytext[yyleng-1] = '\0';
at_directive_name = xstrdup (yytext);
- BEGIN SC_AT_DIRECTIVE_ARG;
+ BEGIN SC_AT_DIRECTIVE_ARGS;
}
/* This pattern must not match more than the previous @ patterns. */
-@[^@{}(\n]* fail_for_invalid_at (yytext);
+@[^<@{}(\n]* fail_for_invalid_at (yytext);
\n out_lineno++; ECHO;
[^@\n]+ ECHO;
return EOF;
}
-<SC_AT_DIRECTIVE_ARG>{
- [^@]+ { STRING_GROW; }
+<SC_AT_GETTEXT_ARG>{
+ "@>" {
+ char *arg;
+ obstack_1grow (&obstack_for_string, '\0');
+ arg = obstack_finish (&obstack_for_string);
+ if (!at_directive_name)
+ {
+ fprintf (yyout, "%s", _(arg));
+ obstack_free (&obstack_for_string, arg);
+ BEGIN INITIAL;
+ }
+ else
+ {
+ char const *translated = _(arg);
+ size_t parent_size = strlen (at_directive_argv[at_directive_argc]);
+ size_t translated_size = strlen (translated);
+ char *copy = xmalloc (parent_size + translated_size + 1);
+ strcpy (copy, at_directive_argv[at_directive_argc]);
+ strcpy (copy + parent_size, translated);
+ obstack_free (&obstack_for_string,
+ at_directive_argv[at_directive_argc]);
+ obstack_grow (&obstack_for_string, copy,
+ parent_size + translated_size);
+ free (copy);
+ BEGIN SC_AT_DIRECTIVE_ARGS;
+ }
+ }
+}
- "@@" { obstack_1grow (&obstack_for_string, '@'); }
- "@{" { obstack_1grow (&obstack_for_string, '['); }
- "@}" { obstack_1grow (&obstack_for_string, ']'); }
+<SC_AT_DIRECTIVE_ARGS>{
"@`" /* Emtpy. Useful for starting an argument
that begins with whitespace. */
+ "@gettext<" {
+ if (at_directive_argc >= AT_DIRECTIVE_ARGC_MAX)
+ fail_for_at_directive_too_many_args ();
+ obstack_1grow (&obstack_for_string, '\0');
+ at_directive_argv[at_directive_argc] =
+ obstack_finish (&obstack_for_string);
+ BEGIN SC_AT_GETTEXT_ARG;
+ }
+
@[,)] {
if (at_directive_argc >= AT_DIRECTIVE_ARGC_MAX)
fail_for_at_directive_too_many_args ();
obstack_free (&obstack_for_string, at_directive_argv[0]);
at_directive_argc = 0;
free (at_directive_name);
+ at_directive_name = NULL;
BEGIN INITIAL;
}
}
+}
+<SC_AT_GETTEXT_ARG,SC_AT_DIRECTIVE_ARGS>{
+ [^@]+ { STRING_GROW; }
+ "@@" { obstack_1grow (&obstack_for_string, '@'); }
+ "@{" { obstack_1grow (&obstack_for_string, '['); }
+ "@}" { obstack_1grow (&obstack_for_string, ']'); }
@.? { fail_for_invalid_at (yytext); }
}
<SC_AT_DIRECTIVE_SKIP_WS>{
[ \t\r\n]
- . { yyless (0); BEGIN SC_AT_DIRECTIVE_ARG; }
+ . { yyless (0); BEGIN SC_AT_DIRECTIVE_ARGS; }
}
-<SC_AT_DIRECTIVE_ARG,SC_AT_DIRECTIVE_SKIP_WS>{
+<SC_AT_GETTEXT_ARG,SC_AT_DIRECTIVE_ARGS,SC_AT_DIRECTIVE_SKIP_WS>{
<<EOF>> {
- fatal (_("unclosed %s directive in skeleton"), at_directive_name);
+ fatal (_("unclosed %s directive in skeleton"),
+ at_directive_name ? at_directive_name : "@gettext");
}
}
switch (at_directive_argc)
{
case 1:
- func (_(at_directive_argv[0]));
+ func (at_directive_argv[0]);
break;
case 2:
- func (_(at_directive_argv[0]), at_directive_argv[1]);
+ func (at_directive_argv[0], at_directive_argv[1]);
break;
case 3:
- func (_(at_directive_argv[0]), at_directive_argv[1],
+ func (at_directive_argv[0], at_directive_argv[1],
at_directive_argv[2]);
break;
case 4:
- func (_(at_directive_argv[0]), at_directive_argv[1],
+ func (at_directive_argv[0], at_directive_argv[1],
at_directive_argv[2], at_directive_argv[3]);
break;
case 5:
- func (_(at_directive_argv[0]), at_directive_argv[1],
+ func (at_directive_argv[0], at_directive_argv[1],
at_directive_argv[2], at_directive_argv[3],
at_directive_argv[4]);
break;
switch (at_directive_argc)
{
case 3:
- func (loc, _(at_directive_argv[2]));
+ func (loc, at_directive_argv[2]);
break;
case 4:
- func (loc, _(at_directive_argv[2]), at_directive_argv[3]);
+ func (loc, at_directive_argv[2], at_directive_argv[3]);
break;
case 5:
- func (loc, _(at_directive_argv[2]), at_directive_argv[3],
+ func (loc, at_directive_argv[2], at_directive_argv[3],
at_directive_argv[4]);
break;
case 6:
- func (loc, _(at_directive_argv[2]), at_directive_argv[3],
+ func (loc, at_directive_argv[2], at_directive_argv[3],
at_directive_argv[4], at_directive_argv[5]);
break;
case 7:
- func (loc, _(at_directive_argv[2]), at_directive_argv[3],
+ func (loc, at_directive_argv[2], at_directive_argv[3],
at_directive_argv[4], at_directive_argv[5],
at_directive_argv[6]);
break;
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
-AT_BANNER([[Skeletons Support.]])
+AT_BANNER([[Skeleton Support.]])
## ------------------------------ ##
## relative skeleton file names. ##
AT_CLEANUP
-## ------------------------------ ##
-## installed skeleton file name. ##
-## ------------------------------ ##
+## ------------------------------- ##
+## installed skeleton file names. ##
+## ------------------------------- ##
-AT_SETUP([[installed skeleton file name]])
+AT_SETUP([[installed skeleton file names]])
m4_pushdef([AT_GRAM],
[[%{
m4_popdef([AT_GRAM])
AT_CLEANUP
+
+
+## ---------------- ##
+## @gettext<...@>. ##
+## ---------------- ##
+
+AT_SETUP([[@gettext<...@>]])
+
+AT_DATA([[skel.c]],
+[[m4@&t@_divert_push(0)d@&t@nl
+@output(b4_parser_file_name@)d@&t@nl
+b4_warn([[@gettext<cannot close file@>]])d@&t@nl
+`@gettext<cannot close file@>'
+m4@&t@_divert_pop(0)
+]])
+
+AT_DATA([[input.y]],
+[[%skeleton "./skel.c"
+%%
+start: ;
+]])
+
+AT_CHECK([[LC_ALL= LC_MESSAGES= LANGUAGE=fr LANG=fr_FR bison input.y]], [[0]],
+[],
+[[input.y: AVERTISSEMENT: ne peut fermer le fichier
+]])
+
+AT_CHECK([[cat input.tab.c]], [[0]],
+[[`ne peut fermer le fichier'
+]])
+
+AT_CLEANUP