/* xgettext AppData file backend.
- Copyright (C) 2002-2003, 2006, 2013, 2015, 2017-2018 Free Software Foundation, Inc.
+ Copyright (C) 2002-2003, 2006, 2013, 2015, 2017-2018, 2020 Free Software Foundation, Inc.
Written by Philip Withnall <philip.withnall@collabora.co.uk>, 2015.
This program is free software: you can redistribute it and/or modify
#define EXTENSIONS_APPDATA
#define SCANNERS_APPDATA \
- { "appdata", NULL, NULL, NULL, NULL },
+ { "appdata", NULL, NULL, NULL, NULL, NULL },
#ifdef __cplusplus
/* xgettext awk backend.
- Copyright (C) 2002-2003, 2006, 2014-2015, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2002-2003, 2006, 2014-2015, 2018, 2020 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2002.
This program is free software: you can redistribute it and/or modify
{ "twjr", "awk" }, \
#define SCANNERS_AWK \
- { "awk", extract_awk, \
+ { "awk", extract_awk, NULL, \
&flag_table_awk, &formatstring_awk, NULL }, \
/* Scan an awk file and add its translatable strings to mdlp. */
/* xgettext C/C++/ObjectiveC backend.
- Copyright (C) 2001-2003, 2006, 2009, 2014-2015, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2001-2003, 2006, 2009, 2014-2015, 2018, 2020 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
This program is free software: you can redistribute it and/or modify
{ "m", "ObjectiveC" }, \
#define SCANNERS_C \
- { "C", extract_c, \
+ { "C", extract_c, NULL, \
&flag_table_c, \
&formatstring_c, NULL }, \
- { "C++", extract_cxx, \
+ { "C++", extract_cxx, NULL, \
&flag_table_c, \
&formatstring_c, NULL }, \
- { "ObjectiveC", extract_objc, \
+ { "ObjectiveC", extract_objc, NULL, \
&flag_table_objc, \
&formatstring_c, &formatstring_objc }, \
- { "GCC-source", extract_c, \
+ { "GCC-source", extract_c, NULL, \
&flag_table_gcc_internal, \
&formatstring_gcc_internal, &formatstring_gfc_internal }, \
/* xgettext C# backend.
- Copyright (C) 2003-2004, 2006, 2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2003-2004, 2006, 2014, 2018, 2020 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
This program is free software: you can redistribute it and/or modify
{ "cs", "C#" }, \
#define SCANNERS_CSHARP \
- { "C#", extract_csharp, \
+ { "C#", extract_csharp, NULL, \
&flag_table_csharp, &formatstring_csharp, NULL }, \
extern void extract_csharp (FILE *fp, const char *real_filename,
/* xgettext Desktop Entry backend.
- Copyright (C) 2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2014, 2018, 2020 Free Software Foundation, Inc.
Written by Daiki Ueno <ueno@gnu.org>, 2014.
This program is free software: you can redistribute it and/or modify
{ "desktop", "Desktop" }, \
#define SCANNERS_DESKTOP \
- { "Desktop", extract_desktop, NULL, NULL, NULL }, \
+ { "Desktop", extract_desktop, NULL, NULL, NULL, NULL }, \
/* Scan a Desktop Entry file and add its translatable strings to mdlp. */
extern void extract_desktop (FILE *fp, const char *real_filename,
/* xgettext Emacs Lisp backend.
- Copyright (C) 2002-2003, 2006, 2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2002-2003, 2006, 2014, 2018, 2020 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2002.
This program is free software: you can redistribute it and/or modify
{ "el", "EmacsLisp" }, \
#define SCANNERS_ELISP \
- { "EmacsLisp", extract_elisp, \
+ { "EmacsLisp", extract_elisp, NULL, \
&flag_table_elisp, &formatstring_elisp, NULL }, \
/* Scan an Emacs Lisp file and add its translatable strings to mdlp. */
/* xgettext glade backend.
- Copyright (C) 2002-2003, 2006, 2013-2015, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2002-2003, 2006, 2013-2015, 2018, 2020 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2002.
This program is free software: you can redistribute it and/or modify
{ "ui", NULL }, \
#define SCANNERS_GLADE \
- { "glade", NULL, NULL, NULL, NULL }, \
+ { "glade", NULL, NULL, NULL, NULL, NULL }, \
#ifdef __cplusplus
/* xgettext GSettings schema file backend.
- Copyright (C) 2002-2003, 2006, 2013-2015, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2002-2003, 2006, 2013-2015, 2018, 2020 Free Software Foundation, Inc.
Written by Daiki Ueno <ueno@gnu.org>, 2013.
This program is free software: you can redistribute it and/or modify
{ "gschema.xml", NULL }, \
#define SCANNERS_GSETTINGS \
- { "gsettings", NULL, NULL, NULL, NULL }, \
+ { "gsettings", NULL, NULL, NULL, NULL, NULL }, \
#ifdef __cplusplus
/* xgettext Java backend.
- Copyright (C) 2001-2003, 2006, 2014, 2018-2019 Free Software Foundation, Inc.
+ Copyright (C) 2001-2003, 2006, 2014, 2018-2020 Free Software Foundation, Inc.
Written by Tommy Johansson <tommy.johansson@kanalen.org>, 2001.
This program is free software: you can redistribute it and/or modify
{ "java", "Java" }, \
#define SCANNERS_JAVA \
- { "Java", extract_java, \
+ { "Java", extract_java, NULL, \
&flag_table_java, \
&formatstring_java, &formatstring_java_printf }, \
/* xgettext JavaScript backend.
- Copyright (C) 2002-2003, 2006, 2010, 2013-2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2002-2003, 2006, 2010, 2013-2014, 2018, 2020 Free Software Foundation, Inc.
This file was written by Andreas Stricker <andy@knitter.ch>, 2010.
It's based on x-python from Bruno Haible.
{ "js", "JavaScript" }, \
#define SCANNERS_JAVASCRIPT \
- { "JavaScript", extract_javascript, \
+ { "JavaScript", extract_javascript, NULL, \
&flag_table_javascript, &formatstring_javascript, NULL }, \
/* Scan a Python file and add its translatable strings to mdlp. */
/* xgettext librep backend.
- Copyright (C) 2001-2003, 2006, 2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2001-2003, 2006, 2014, 2018, 2020 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
This program is free software: you can redistribute it and/or modify
{ "jl", "librep" }, \
#define SCANNERS_LIBREP \
- { "librep", extract_librep, \
+ { "librep", extract_librep, NULL, \
&flag_table_librep, &formatstring_librep, NULL }, \
/* Scan a librep file and add its translatable strings to mdlp. */
/* xgettext Lisp backend.
- Copyright (C) 2001-2003, 2006, 2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2001-2003, 2006, 2014, 2018, 2020 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
This program is free software: you can redistribute it and/or modify
{ "lisp", "Lisp" }, \
#define SCANNERS_LISP \
- { "Lisp", extract_lisp, \
+ { "Lisp", extract_lisp, NULL, \
&flag_table_lisp, &formatstring_lisp, NULL }, \
/* Scan a Lisp file and add its translatable strings to mdlp. */
/* xgettext Lua backend.
- Copyright (C) 2011-2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2011-2014, 2018, 2020 Free Software Foundation, Inc.
Written by ĽubomÃr Remák <lubomirrk@lubomirr.eu>, 2011
This program is free software: you can redistribute it and/or modify
{ "lua", "Lua" }, \
#define SCANNERS_LUA \
- { "Lua", extract_lua, \
+ { "Lua", extract_lua, NULL, \
&flag_table_lua, &formatstring_lua, NULL }, \
/* Scan a Lua file and add its translatable strings to mdlp. */
/* xgettext Perl backend.
- Copyright (C) 2002-2003, 2006, 2010, 2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2002-2003, 2006, 2010, 2014, 2018, 2020 Free Software Foundation, Inc.
Written by Guido Flohr <guido@imperia.net>, 2002-2003
This program is free software: you can redistribute it and/or modify
{ "cgi", "perl" }, \
#define SCANNERS_PERL \
- { "perl", extract_perl, \
+ { "perl", extract_perl, NULL, \
&flag_table_perl, &formatstring_perl, &formatstring_perl_brace }, \
/* Scan a Perl file and add its translatable strings to mdlp. */
/* xgettext PHP backend.
- Copyright (C) 2002-2003, 2006, 2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2002-2003, 2006, 2014, 2018, 2020 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2002.
This program is free software: you can redistribute it and/or modify
{ "php4", "PHP" }, \
#define SCANNERS_PHP \
- { "PHP", extract_php, \
+ { "PHP", extract_php, NULL, \
&flag_table_php, &formatstring_php, NULL }, \
/* Scan a PHP file and add its translatable strings to mdlp. */
/* xgettext PO backend.
- Copyright (C) 2001-2003, 2006, 2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2001-2003, 2006, 2014, 2018, 2020 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
This program is free software: you can redistribute it and/or modify
{ "pot", "PO" }, \
#define SCANNERS_PO \
- { "PO", extract_po, NULL, NULL, NULL }, \
+ { "PO", extract_po, NULL, NULL, NULL, NULL }, \
/* Scan a PO file and add its translatable strings to mdlp. */
extern void extract_po (FILE *fp, const char *real_filename,
/* xgettext JavaProperties backend.
- Copyright (C) 2003, 2006, 2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2006, 2014, 2018, 2020 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
This program is free software: you can redistribute it and/or modify
{ "properties", "JavaProperties" }, \
#define SCANNERS_PROPERTIES \
- { "JavaProperties", extract_properties, NULL, NULL, NULL }, \
+ { "JavaProperties", extract_properties, NULL, NULL, NULL, NULL }, \
/* Scan a JavaProperties file and add its translatable strings to mdlp. */
extern void extract_properties (FILE *fp, const char *real_filename,
/* xgettext Python backend.
- Copyright (C) 2002-2003, 2006, 2013-2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2002-2003, 2006, 2013-2014, 2018, 2020 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2002.
This program is free software: you can redistribute it and/or modify
{ "py", "Python" }, \
#define SCANNERS_PYTHON \
- { "Python", extract_python, \
+ { "Python", extract_python, NULL, \
&flag_table_python, &formatstring_python, &formatstring_python_brace }, \
/* Scan a Python file and add its translatable strings to mdlp. */
/* xgettext RST/RSJ backend.
- Copyright (C) 2001-2003, 2006, 2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2001-2003, 2006, 2014, 2018, 2020 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
This program is free software: you can redistribute it and/or modify
{ "rsj", "RSJ" }, \
#define SCANNERS_RST \
- { "RST", extract_rst, \
+ { "RST", extract_rst, NULL, \
NULL, &formatstring_pascal, NULL }, \
- { "RSJ", extract_rsj, \
+ { "RSJ", extract_rsj, NULL, \
NULL, &formatstring_pascal, NULL }, \
/* Scan an RST file and add its translatable strings to mdlp. */
/* xgettext Scheme backend.
- Copyright (C) 2004, 2006, 2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2006, 2014, 2018, 2020 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2004.
This program is free software: you can redistribute it and/or modify
{ "scm", "Scheme" }, \
#define SCANNERS_SCHEME \
- { "Scheme", extract_scheme, \
+ { "Scheme", extract_scheme, NULL, \
&flag_table_scheme, &formatstring_scheme, NULL }, \
/* Scan a Scheme file and add its translatable strings to mdlp. */
/* xgettext sh backend.
- Copyright (C) 2003, 2006, 2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2006, 2014, 2018, 2020 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
This program is free software: you can redistribute it and/or modify
{ "bash", "Shell" }, \
#define SCANNERS_SH \
- { "Shell", extract_sh, \
+ { "Shell", extract_sh, NULL, \
&flag_table_sh, &formatstring_sh, NULL }, \
/* Scan a shell script file and add its translatable strings to mdlp. */
/* xgettext Smalltalk backend.
- Copyright (C) 2002-2003, 2006, 2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2002-2003, 2006, 2014, 2018, 2020 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2002.
This program is free software: you can redistribute it and/or modify
{ "st", "Smalltalk" }, \
#define SCANNERS_SMALLTALK \
- { "Smalltalk", extract_smalltalk, \
+ { "Smalltalk", extract_smalltalk, NULL, \
NULL, &formatstring_smalltalk, NULL }, \
/* Scan a Smalltalk file and add its translatable strings to mdlp. */
/* xgettext NXStringTable backend.
- Copyright (C) 2003, 2006, 2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2006, 2014, 2018, 2020 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
This program is free software: you can redistribute it and/or modify
{ "strings", "NXStringTable" }, \
#define SCANNERS_STRINGTABLE \
- { "NXStringTable", extract_stringtable, NULL, NULL, NULL }, \
+ { "NXStringTable", extract_stringtable, NULL, NULL, NULL, NULL }, \
/* Scan an NXStringTable file and add its translatable strings to mdlp. */
extern void extract_stringtable (FILE *fp, const char *real_filename,
/* xgettext Tcl Lisp backend.
- Copyright (C) 2002-2003, 2006, 2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2002-2003, 2006, 2014, 2018, 2020 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2002.
This program is free software: you can redistribute it and/or modify
{ "tcl", "Tcl" }, \
#define SCANNERS_TCL \
- { "Tcl", extract_tcl, \
+ { "Tcl", extract_tcl, NULL, \
&flag_table_tcl, &formatstring_tcl, NULL }, \
/* Scan a Tcl file and add its translatable strings to mdlp. */
/* xgettext Vala backend.
- Copyright (C) 2002-2003, 2006, 2013-2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2002-2003, 2006, 2013-2014, 2018, 2020 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
{ "vala", "Vala" }, \
#define SCANNERS_VALA \
- { "Vala", extract_vala, \
+ { "Vala", extract_vala, NULL, \
&flag_table_vala, &formatstring_c, NULL }, \
/* Scan a Vala file and add its translatable strings to mdlp. */
/* xgettext YCP backend.
- Copyright (C) 2001-2003, 2006, 2014, 2018 Free Software Foundation, Inc.
+ Copyright (C) 2001-2003, 2006, 2014, 2018, 2020 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
This program is free software: you can redistribute it and/or modify
{ "ycp", "YCP" }, \
#define SCANNERS_YCP \
- { "YCP", extract_ycp, \
+ { "YCP", extract_ycp, NULL, \
&flag_table_ycp, &formatstring_ycp, NULL }, \
/* Scan an YCP file and add its translatable strings to mdlp. */
};
-/* The extractors must all be functions returning void and taking three
- arguments designating the input stream and one message domain list argument
- in which to add the messages. */
-typedef void (*extractor_func) (FILE *fp, const char *real_filename,
- const char *logical_filename,
- flag_context_list_table_ty *flag_table,
- msgdomain_list_ty *mdlp);
+/* The extractors must all be functions returning void and taking as arguments
+ - the file name or file stream,
+ - the flag table,
+ - a message domain list argument in which to add the messages.
+ An extract_from_stream_func is preferred, because it supports extracting from
+ stdin. */
+typedef void (*extract_from_stream_func) (FILE *fp, const char *real_filename,
+ const char *logical_filename,
+ flag_context_list_table_ty *flag_table,
+ msgdomain_list_ty *mdlp);
+typedef void (*extract_from_file_func) (const char *real_filename,
+ const char *logical_filename,
+ flag_context_list_table_ty *flag_table,
+ msgdomain_list_ty *mdlp);
typedef struct extractor_ty extractor_ty;
struct extractor_ty
{
- extractor_func func;
+ extract_from_stream_func extract_from_stream;
+ extract_from_file_func extract_from_file;
flag_context_list_table_ty *flag_table;
struct formatstring_parser *formatstring_parser1;
struct formatstring_parser *formatstring_parser2;
filename = file_list->item[i];
- if (extractor.func)
+ if (extractor.extract_from_stream || extractor.extract_from_file)
this_file_extractor = extractor;
else if (explicit_its_filename != NULL)
{
}
+/* xgettext_find_file and xgettext_open look up a file, taking into account
+ the --directory options.
+ xgettext_find_file merely returns the file name. This function is useful
+ for parsers implemented as separate programs.
+ xgettext_open returns the open file stream. This function is useful for
+ built-in parsers. */
+
+static void
+xgettext_find_file (const char *fn,
+ char **logical_file_name_p, char **real_file_name_p)
+{
+ char *new_name;
+ char *logical_file_name;
+ struct stat statbuf;
+
+ /* We cannot handle "-" here. "/dev/fd/0" is not portable, and it cannot
+ be opened multiple times. */
+ if (IS_RELATIVE_FILE_NAME (fn))
+ {
+ int j;
+
+ for (j = 0; ; ++j)
+ {
+ const char *dir = dir_list_nth (j);
+
+ if (dir == NULL)
+ error (EXIT_FAILURE, ENOENT,
+ _("error while opening \"%s\" for reading"), fn);
+
+ new_name = xconcatenated_filename (dir, fn, NULL);
+
+ if (stat (new_name, &statbuf) == 0)
+ break;
+
+ if (errno != ENOENT)
+ error (EXIT_FAILURE, errno,
+ _("error while opening \"%s\" for reading"), new_name);
+ free (new_name);
+ }
+
+ /* Note that the NEW_NAME variable contains the actual file name
+ and the logical file name is what is reported by xgettext. In
+ this case NEW_NAME is set to the file which was found along the
+ directory search path, and LOGICAL_FILE_NAME is is set to the
+ file name which was searched for. */
+ logical_file_name = xstrdup (fn);
+ }
+ else
+ {
+ new_name = xstrdup (fn);
+ if (stat (fn, &statbuf) != 0)
+ error (EXIT_FAILURE, errno,
+ _("error while opening \"%s\" for reading"), fn);
+ logical_file_name = xstrdup (new_name);
+ }
+
+ *logical_file_name_p = logical_file_name;
+ *real_file_name_p = new_name;
+}
static FILE *
xgettext_open (const char *fn,
{
char *logical_file_name;
char *real_file_name;
- FILE *fp = xgettext_open (file_name, &logical_file_name, &real_file_name);
-
- /* Set the default for the source file encoding. May be overridden by
- the extractor function. */
- xgettext_current_source_encoding =
- (xgettext_global_source_encoding != NULL ? xgettext_global_source_encoding :
- po_charset_ascii);
-#if HAVE_ICONV
- xgettext_current_source_iconv = xgettext_global_source_iconv;
-#endif
current_formatstring_parser1 = extractor.formatstring_parser1;
current_formatstring_parser2 = extractor.formatstring_parser2;
current_formatstring_parser3 = extractor.formatstring_parser3;
- extractor.func (fp, real_file_name, logical_file_name, extractor.flag_table,
- mdlp);
- if (fp != stdin)
- fclose (fp);
+ if (extractor.extract_from_stream)
+ {
+ FILE *fp = xgettext_open (file_name, &logical_file_name, &real_file_name);
+
+ /* Set the default for the source file encoding. May be overridden by
+ the extractor function. */
+ xgettext_current_source_encoding =
+ (xgettext_global_source_encoding != NULL ? xgettext_global_source_encoding :
+ po_charset_ascii);
+#if HAVE_ICONV
+ xgettext_current_source_iconv = xgettext_global_source_iconv;
+#endif
+
+ extractor.extract_from_stream (fp, real_file_name, logical_file_name,
+ extractor.flag_table, mdlp);
+
+ if (fp != stdin)
+ fclose (fp);
+ }
+ else
+ {
+ xgettext_find_file (file_name, &logical_file_name, &real_file_name);
+
+ extractor.extract_from_file (real_file_name, logical_file_name,
+ extractor.flag_table, mdlp);
+ }
free (logical_file_name);
free (real_file_name);
}
struct table_ty
{
const char *name;
- extractor_func func;
+ extract_from_stream_func extract_from_stream;
+ extract_from_file_func extract_from_file;
flag_context_list_table_ty *flag_table;
struct formatstring_parser *formatstring_parser1;
struct formatstring_parser *formatstring_parser2;
{
extractor_ty result;
- result.func = tp->func;
+ result.extract_from_stream = tp->extract_from_stream;
+ result.extract_from_file = tp->extract_from_file;
result.flag_table = tp->flag_table;
result.formatstring_parser1 = tp->formatstring_parser1;
result.formatstring_parser2 = tp->formatstring_parser2;