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