]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/diff/exgettext
MFC ObsoleteFiles.inc 1.91, 1.92, and 1.93:
[FreeBSD/FreeBSD.git] / contrib / diff / exgettext
1 #! /bin/sh
2 # Wrapper around gettext for programs using the msgid convention.
3
4 # Copyright (C) 1998, 2001, 2004 Free Software Foundation, Inc.
5
6 # Written by Paul Eggert <eggert@twinsun.com>.
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with GNU CC; see the file COPYING.  If not, write to
20 # the Free Software Foundation, 59 Temple Place - Suite 330,
21 # Boston, MA 02111-1307, USA.
22
23 # Always operate in the C locale.
24 LANG=C
25 LANGUAGE=C
26 LC_ALL=C
27 export LANG LANGUAGE LC_ALL
28
29 # Set AWK if environment has not already set it.
30 AWK=${AWK-awk}
31
32 # The argument to this wrapper is the xgettext command to be executed.
33 # Extract the xgettext program name from the rest of the command.
34 xgettext=${1?}
35 shift
36
37 # Save work if we're just wrapping a no-op.
38 case $xgettext in
39 :) exit;;
40 esac
41
42 # Find the files to be scanned, and the directory to scan them from.
43 directory=.
44 files=
45 for i
46 do
47   case $i in
48   --directory=*)
49     directory=`expr " $i" : ' --directory=\(.*\)'`;;
50   --files-from=*)
51     files_from=`expr " $i" : ' --files-from=\(.*\)'`
52     files=`$AWK '/^[^#]/ { print }' $files_from`;;
53   esac
54 done
55
56 # Generate keyword options for xgettext,
57 # by scanning for declarations of functions
58 # whose parameter names end in "msgid".
59 generate_keyword_options='
60   /^[A-Z_a-z].*\(.*msgid[,)]/ {
61
62     paren_index = index($0, "(")
63
64     name = substr($0, 1, paren_index - 1)
65     sub(/[^0-9A-Z_a-z]*$/, "", name)
66     sub(/[       ]+PARAMS/, "", name)
67     sub(/[       ]+VPARAMS/, "", name)
68     sub(/.*[^0-9A-Z_a-z]/, "", name)
69
70     args = substr($0, paren_index)
71     sub(/msgid[,)].*/, "", args)
72     for (n = 1; sub(/^[^,]*,/, "", args); n++) {
73       continue;
74     }
75
76     if (n == 1) {
77       keyword = name
78     } else {
79       keyword = name ":" n
80     }
81
82     if (! keyword_seen[keyword]++) {
83       print "--keyword=" keyword
84     }
85   }
86 '
87 keyword_options=`(
88   cd $directory &&
89   $AWK "$generate_keyword_options" $files < /dev/null
90 )` || exit
91
92 # Run the xgettext command, with extra input containing the extra
93 # msgids that it wouldn't normally find.
94 generate_emsgids='
95   /%e.*}/ {
96     line = $0
97     while ((percent_index = index(line, "%e")) != 0) {
98       line = substr(line, percent_index + 2)
99       bracket_index = index(line, "}")
100       if (bracket_index == 0) {
101         continue
102       }
103       msgid = substr(line, 1, bracket_index - 1)
104       if (index(msgid, "%") != 0) {
105         continue
106       }
107       printf "#line %d \"%s\"\n", FNR, FILENAME
108       printf "_(\"%s\")\n", msgid
109       line = substr(line, bracket_index + 1)
110     }
111   }
112 '
113 (cd $directory &&
114  $AWK "$generate_emsgids" $files < /dev/null
115 ) | "$xgettext" $keyword_options ${1+"$@"} -