From: Bruno Haible Date: Sun, 26 Apr 2020 21:51:23 +0000 (+0200) Subject: xgettext: Define alternate parser signature for the Ruby support. X-Git-Tag: v0.21~79 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4da9b03f016dbf1f956e42d4cc3262e9efc11fb;p=thirdparty%2Fgettext.git xgettext: Define alternate parser signature for the Ruby support. * gettext-tools/src/xgettext.c (extract_from_stream_func): Renamed from extractor_func. (extract_from_file_func): New type. (struct extractor_ty): Rename field func to extract_from_stream. New field extract_from_file. (main): Consider both fields. (xgettext_find_file): New function. (extract_from_file): Add alternative code for when the other extraction function is defined. (language_to_extractor): In the table, rename field func to extract_from_stream, and add new field extract_from_file. * gettext-tools/src/x-*.h (SCANNERS_*): Update. --- diff --git a/gettext-tools/src/x-appdata.h b/gettext-tools/src/x-appdata.h index 5d13989bc..bf85997bc 100644 --- a/gettext-tools/src/x-appdata.h +++ b/gettext-tools/src/x-appdata.h @@ -1,5 +1,5 @@ /* 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 , 2015. This program is free software: you can redistribute it and/or modify @@ -32,7 +32,7 @@ extern "C" { #define EXTENSIONS_APPDATA #define SCANNERS_APPDATA \ - { "appdata", NULL, NULL, NULL, NULL }, + { "appdata", NULL, NULL, NULL, NULL, NULL }, #ifdef __cplusplus diff --git a/gettext-tools/src/x-awk.h b/gettext-tools/src/x-awk.h index af35d3711..a8c7bbd26 100644 --- a/gettext-tools/src/x-awk.h +++ b/gettext-tools/src/x-awk.h @@ -1,5 +1,5 @@ /* 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 , 2002. This program is free software: you can redistribute it and/or modify @@ -33,7 +33,7 @@ extern "C" { { "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. */ diff --git a/gettext-tools/src/x-c.h b/gettext-tools/src/x-c.h index 323c6187e..c1635e7f4 100644 --- a/gettext-tools/src/x-c.h +++ b/gettext-tools/src/x-c.h @@ -1,5 +1,5 @@ /* 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 , 2001. This program is free software: you can redistribute it and/or modify @@ -41,16 +41,16 @@ extern "C" { { "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 }, \ diff --git a/gettext-tools/src/x-csharp.h b/gettext-tools/src/x-csharp.h index 54fb0582c..143787e2e 100644 --- a/gettext-tools/src/x-csharp.h +++ b/gettext-tools/src/x-csharp.h @@ -1,5 +1,5 @@ /* 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 , 2003. This program is free software: you can redistribute it and/or modify @@ -31,7 +31,7 @@ extern "C" { { "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, diff --git a/gettext-tools/src/x-desktop.h b/gettext-tools/src/x-desktop.h index b60653055..1a73e6293 100644 --- a/gettext-tools/src/x-desktop.h +++ b/gettext-tools/src/x-desktop.h @@ -1,5 +1,5 @@ /* 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 , 2014. This program is free software: you can redistribute it and/or modify @@ -31,7 +31,7 @@ extern "C" { { "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, diff --git a/gettext-tools/src/x-elisp.h b/gettext-tools/src/x-elisp.h index f3806de60..033868e82 100644 --- a/gettext-tools/src/x-elisp.h +++ b/gettext-tools/src/x-elisp.h @@ -1,5 +1,5 @@ /* 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 , 2002. This program is free software: you can redistribute it and/or modify @@ -31,7 +31,7 @@ extern "C" { { "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. */ diff --git a/gettext-tools/src/x-glade.h b/gettext-tools/src/x-glade.h index 1c70bba37..d80958b8c 100644 --- a/gettext-tools/src/x-glade.h +++ b/gettext-tools/src/x-glade.h @@ -1,5 +1,5 @@ /* 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 , 2002. This program is free software: you can redistribute it and/or modify @@ -36,7 +36,7 @@ extern "C" { { "ui", NULL }, \ #define SCANNERS_GLADE \ - { "glade", NULL, NULL, NULL, NULL }, \ + { "glade", NULL, NULL, NULL, NULL, NULL }, \ #ifdef __cplusplus diff --git a/gettext-tools/src/x-gsettings.h b/gettext-tools/src/x-gsettings.h index 2f1da540f..c852c4c40 100644 --- a/gettext-tools/src/x-gsettings.h +++ b/gettext-tools/src/x-gsettings.h @@ -1,5 +1,5 @@ /* 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 , 2013. This program is free software: you can redistribute it and/or modify @@ -33,7 +33,7 @@ extern "C" { { "gschema.xml", NULL }, \ #define SCANNERS_GSETTINGS \ - { "gsettings", NULL, NULL, NULL, NULL }, \ + { "gsettings", NULL, NULL, NULL, NULL, NULL }, \ #ifdef __cplusplus diff --git a/gettext-tools/src/x-java.h b/gettext-tools/src/x-java.h index c46feeee4..05e997c55 100644 --- a/gettext-tools/src/x-java.h +++ b/gettext-tools/src/x-java.h @@ -1,5 +1,5 @@ /* 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 , 2001. This program is free software: you can redistribute it and/or modify @@ -31,7 +31,7 @@ extern "C" { { "java", "Java" }, \ #define SCANNERS_JAVA \ - { "Java", extract_java, \ + { "Java", extract_java, NULL, \ &flag_table_java, \ &formatstring_java, &formatstring_java_printf }, \ diff --git a/gettext-tools/src/x-javascript.h b/gettext-tools/src/x-javascript.h index 6188750a5..09b530704 100644 --- a/gettext-tools/src/x-javascript.h +++ b/gettext-tools/src/x-javascript.h @@ -1,5 +1,5 @@ /* 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 , 2010. It's based on x-python from Bruno Haible. @@ -32,7 +32,7 @@ extern "C" { { "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. */ diff --git a/gettext-tools/src/x-librep.h b/gettext-tools/src/x-librep.h index 0da791f5e..b79c875a4 100644 --- a/gettext-tools/src/x-librep.h +++ b/gettext-tools/src/x-librep.h @@ -1,5 +1,5 @@ /* 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 , 2001. This program is free software: you can redistribute it and/or modify @@ -31,7 +31,7 @@ extern "C" { { "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. */ diff --git a/gettext-tools/src/x-lisp.h b/gettext-tools/src/x-lisp.h index 97b31dccf..7b7a17a63 100644 --- a/gettext-tools/src/x-lisp.h +++ b/gettext-tools/src/x-lisp.h @@ -1,5 +1,5 @@ /* 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 , 2001. This program is free software: you can redistribute it and/or modify @@ -31,7 +31,7 @@ extern "C" { { "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. */ diff --git a/gettext-tools/src/x-lua.h b/gettext-tools/src/x-lua.h index dca3016aa..9eb949f26 100644 --- a/gettext-tools/src/x-lua.h +++ b/gettext-tools/src/x-lua.h @@ -1,5 +1,5 @@ /* 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 , 2011 This program is free software: you can redistribute it and/or modify @@ -31,7 +31,7 @@ extern "C" { "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. */ diff --git a/gettext-tools/src/x-perl.h b/gettext-tools/src/x-perl.h index b375714c3..95948dd37 100644 --- a/gettext-tools/src/x-perl.h +++ b/gettext-tools/src/x-perl.h @@ -1,5 +1,5 @@ /* 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 , 2002-2003 This program is free software: you can redistribute it and/or modify @@ -35,7 +35,7 @@ extern "C" { { "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. */ diff --git a/gettext-tools/src/x-php.h b/gettext-tools/src/x-php.h index f66abe64b..a95deab3c 100644 --- a/gettext-tools/src/x-php.h +++ b/gettext-tools/src/x-php.h @@ -1,5 +1,5 @@ /* 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 , 2002. This program is free software: you can redistribute it and/or modify @@ -33,7 +33,7 @@ extern "C" { { "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. */ diff --git a/gettext-tools/src/x-po.h b/gettext-tools/src/x-po.h index 41708db36..e948d1eb4 100644 --- a/gettext-tools/src/x-po.h +++ b/gettext-tools/src/x-po.h @@ -1,5 +1,5 @@ /* 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 , 2001. This program is free software: you can redistribute it and/or modify @@ -32,7 +32,7 @@ extern "C" { { "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, diff --git a/gettext-tools/src/x-properties.h b/gettext-tools/src/x-properties.h index 20d486fcf..ff0dc3d58 100644 --- a/gettext-tools/src/x-properties.h +++ b/gettext-tools/src/x-properties.h @@ -1,5 +1,5 @@ /* 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 , 2003. This program is free software: you can redistribute it and/or modify @@ -31,7 +31,7 @@ extern "C" { { "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, diff --git a/gettext-tools/src/x-python.h b/gettext-tools/src/x-python.h index d045ee603..11a74cffb 100644 --- a/gettext-tools/src/x-python.h +++ b/gettext-tools/src/x-python.h @@ -1,5 +1,5 @@ /* 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 , 2002. This program is free software: you can redistribute it and/or modify @@ -31,7 +31,7 @@ extern "C" { { "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. */ diff --git a/gettext-tools/src/x-rst.h b/gettext-tools/src/x-rst.h index a5c2a0495..6f27496bb 100644 --- a/gettext-tools/src/x-rst.h +++ b/gettext-tools/src/x-rst.h @@ -1,5 +1,5 @@ /* 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 , 2001. This program is free software: you can redistribute it and/or modify @@ -32,9 +32,9 @@ extern "C" { { "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. */ diff --git a/gettext-tools/src/x-scheme.h b/gettext-tools/src/x-scheme.h index 6e5562b51..cff03ac21 100644 --- a/gettext-tools/src/x-scheme.h +++ b/gettext-tools/src/x-scheme.h @@ -1,5 +1,5 @@ /* 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 , 2004. This program is free software: you can redistribute it and/or modify @@ -31,7 +31,7 @@ extern "C" { { "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. */ diff --git a/gettext-tools/src/x-sh.h b/gettext-tools/src/x-sh.h index 44b7e67ee..297480cd3 100644 --- a/gettext-tools/src/x-sh.h +++ b/gettext-tools/src/x-sh.h @@ -1,5 +1,5 @@ /* 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 , 2003. This program is free software: you can redistribute it and/or modify @@ -32,7 +32,7 @@ extern "C" { { "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. */ diff --git a/gettext-tools/src/x-smalltalk.h b/gettext-tools/src/x-smalltalk.h index 14bd5efe5..0ba2179c7 100644 --- a/gettext-tools/src/x-smalltalk.h +++ b/gettext-tools/src/x-smalltalk.h @@ -1,5 +1,5 @@ /* 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 , 2002. This program is free software: you can redistribute it and/or modify @@ -31,7 +31,7 @@ extern "C" { { "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. */ diff --git a/gettext-tools/src/x-stringtable.h b/gettext-tools/src/x-stringtable.h index 75505c48c..f5e9cc315 100644 --- a/gettext-tools/src/x-stringtable.h +++ b/gettext-tools/src/x-stringtable.h @@ -1,5 +1,5 @@ /* 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 , 2003. This program is free software: you can redistribute it and/or modify @@ -31,7 +31,7 @@ extern "C" { { "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, diff --git a/gettext-tools/src/x-tcl.h b/gettext-tools/src/x-tcl.h index 3efb09fff..8e66feccf 100644 --- a/gettext-tools/src/x-tcl.h +++ b/gettext-tools/src/x-tcl.h @@ -1,5 +1,5 @@ /* 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 , 2002. This program is free software: you can redistribute it and/or modify @@ -31,7 +31,7 @@ extern "C" { { "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. */ diff --git a/gettext-tools/src/x-vala.h b/gettext-tools/src/x-vala.h index 686283422..29b266dfd 100644 --- a/gettext-tools/src/x-vala.h +++ b/gettext-tools/src/x-vala.h @@ -1,5 +1,5 @@ /* 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 @@ -30,7 +30,7 @@ extern "C" { { "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. */ diff --git a/gettext-tools/src/x-ycp.h b/gettext-tools/src/x-ycp.h index d6f836b6b..c681ba22b 100644 --- a/gettext-tools/src/x-ycp.h +++ b/gettext-tools/src/x-ycp.h @@ -1,5 +1,5 @@ /* 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 , 2001. This program is free software: you can redistribute it and/or modify @@ -31,7 +31,7 @@ extern "C" { { "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. */ diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index a9192b385..3c85c1f03 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -269,18 +269,26 @@ static const struct option long_options[] = }; -/* 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; @@ -829,7 +837,7 @@ xgettext cannot work without keywords to look for")); 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) { @@ -1692,6 +1700,65 @@ savable_comment_to_xgettext_comment (refcounted_string_list_ty *rslp) } +/* 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, @@ -1767,25 +1834,37 @@ extract_from_file (const char *file_name, extractor_ty extractor, { 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); } @@ -2020,7 +2099,8 @@ language_to_extractor (const char *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; @@ -2066,7 +2146,8 @@ language_to_extractor (const char *name) { 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;