1*b30d1939SAndy Fiddaman########################################################################
2*b30d1939SAndy Fiddaman#                                                                      #
3*b30d1939SAndy Fiddaman#               This software is part of the ast package               #
4*b30d1939SAndy Fiddaman#          Copyright (c) 2000-2011 AT&T Intellectual Property          #
5*b30d1939SAndy Fiddaman#                      and is licensed under the                       #
6*b30d1939SAndy Fiddaman#                 Eclipse Public License, Version 1.0                  #
7*b30d1939SAndy Fiddaman#                    by AT&T Intellectual Property                     #
8*b30d1939SAndy Fiddaman#                                                                      #
9*b30d1939SAndy Fiddaman#                A copy of the License is available at                 #
10*b30d1939SAndy Fiddaman#          http://www.eclipse.org/org/documents/epl-v10.html           #
11*b30d1939SAndy Fiddaman#         (with md5 checksum b35adb5213ca9657e911e9befb180842)         #
12*b30d1939SAndy Fiddaman#                                                                      #
13*b30d1939SAndy Fiddaman#              Information and Software Systems Research               #
14*b30d1939SAndy Fiddaman#                            AT&T Research                             #
15*b30d1939SAndy Fiddaman#                           Florham Park NJ                            #
16*b30d1939SAndy Fiddaman#                                                                      #
17*b30d1939SAndy Fiddaman#                 Glenn Fowler <gsf@research.att.com>                  #
18*b30d1939SAndy Fiddaman#                                                                      #
19*b30d1939SAndy Fiddaman########################################################################
20*b30d1939SAndy Fiddaman: message catalog administration
21*b30d1939SAndy Fiddaman
22*b30d1939SAndy Fiddamancommand=msgadmin
23*b30d1939SAndy Fiddaman
24*b30d1939SAndy Fiddamancase `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in
25*b30d1939SAndy Fiddaman0123)	ARGV0="-a $command"
26*b30d1939SAndy Fiddaman	USAGE=$'
27*b30d1939SAndy Fiddaman[-?
28*b30d1939SAndy Fiddaman@(#)$Id: msgadmin (AT&T Labs Research) 2001-06-08 $
29*b30d1939SAndy Fiddaman]
30*b30d1939SAndy Fiddaman'$USAGE_LICENSE$'
31*b30d1939SAndy Fiddaman[+NAME?'$command$' - message catalog file administration]
32*b30d1939SAndy Fiddaman[+DESCRIPTION?\b'$command$'\b administers message catalog files. If no \afile\a
33*b30d1939SAndy Fiddaman	operands are specified then all message files in the local
34*b30d1939SAndy Fiddaman	\b$INSTALLROOT\b source tree are operated on. Exactly one of
35*b30d1939SAndy Fiddaman	\b--generate\b, \b--remove\b, \b--translate\b, or \b--verify\b
36*b30d1939SAndy Fiddaman	must be specified.]
37*b30d1939SAndy Fiddaman[D:debug?Passed to \btranslate\b(1).]
38*b30d1939SAndy Fiddaman[a:all?Passed to \btranslate\b(1).]
39*b30d1939SAndy Fiddaman[c:cache?Passed to \btranslate\b(1).]
40*b30d1939SAndy Fiddaman[d:dialect?Operate on the dialects in the \b,\b separated \adialect\a list.
41*b30d1939SAndy Fiddaman	\b-\b means all dialects supported by \btranslate\b(1).]:[dialect:=-]
42*b30d1939SAndy Fiddaman[f:force?Force binary catalog generation even when the current binary is newer
43*b30d1939SAndy Fiddaman	than the source.]
44*b30d1939SAndy Fiddaman[g:generate?Generate and install \bgencat\b(1) binary message catalogs.]
45*b30d1939SAndy Fiddaman[l:list?List each installed message catalog name paired with its input source.]
46*b30d1939SAndy Fiddaman[n:show?Show commands but do not execute.]
47*b30d1939SAndy Fiddaman[o:omit?Omit \btranslate\b(1) methods matching the \bksh\b(1)
48*b30d1939SAndy Fiddaman	\apattern\a.]:[pattern]
49*b30d1939SAndy Fiddaman[r:remove?Remove all translated message files and work directories.]
50*b30d1939SAndy Fiddaman[s:share?Generate and install \bmsggen\b(1) machine independent binary
51*b30d1939SAndy Fiddaman	message catalogs.]
52*b30d1939SAndy Fiddaman[t:translate?Translate using \btranslate\b(1).]
53*b30d1939SAndy Fiddaman[v:verify?Verify that translated message files satisfy \bgencat\b(1) syntax.]
54*b30d1939SAndy Fiddaman
55*b30d1939SAndy Fiddaman[ file ... ]
56*b30d1939SAndy Fiddaman
57*b30d1939SAndy Fiddaman[+SEE ALSO?\bgencat\b(1), \bksh\b(1), \bmsggen\b(1), \btranslate\b(1)]
58*b30d1939SAndy Fiddaman'
59*b30d1939SAndy Fiddaman	;;
60*b30d1939SAndy Fiddaman*)	ARGV0=""
61*b30d1939SAndy Fiddaman	USAGE="Dcd:gno:rstv [ file ... ]"
62*b30d1939SAndy Fiddaman	;;
63*b30d1939SAndy Fiddamanesac
64*b30d1939SAndy Fiddaman
65*b30d1939SAndy Fiddamanusage()
66*b30d1939SAndy Fiddaman{
67*b30d1939SAndy Fiddaman	OPTIND=0
68*b30d1939SAndy Fiddaman	getopts $ARGV0 "$USAGE" OPT '-?'
69*b30d1939SAndy Fiddaman	exit 2
70*b30d1939SAndy Fiddaman}
71*b30d1939SAndy Fiddaman
72*b30d1939SAndy Fiddamanmessages()
73*b30d1939SAndy Fiddaman{
74*b30d1939SAndy Fiddaman	if	[[ $PACKAGEROOT && -d $PACKAGEROOT ]]
75*b30d1939SAndy Fiddaman	then	MSGROOT=$PACKAGEROOT
76*b30d1939SAndy Fiddaman	else	MSGROOT=$HOME
77*b30d1939SAndy Fiddaman	fi
78*b30d1939SAndy Fiddaman	set -- $MSGROOT/arch/*/src/cmd/INIT/INIT.msg
79*b30d1939SAndy Fiddaman	[[ -f $1 ]] || { print -u2 $"$command: INIT.msg: not found"; exit 1; }
80*b30d1939SAndy Fiddaman	MSGROOT=${1%/src/cmd/INIT/INIT.msg}
81*b30d1939SAndy Fiddaman	grep -l '^1' $MSGROOT/src/@(cmd|lib)/*/*.msg
82*b30d1939SAndy Fiddaman}
83*b30d1939SAndy Fiddaman
84*b30d1939SAndy Fiddamaninteger n
85*b30d1939SAndy Fiddamantypeset all cache dialect=- exec force omit op show verbose
86*b30d1939SAndy Fiddamantypeset dir=$INSTALLROOT gen=gencat
87*b30d1939SAndy Fiddaman
88*b30d1939SAndy Fiddamanwhile	getopts $ARGV0 "$USAGE" OPT
89*b30d1939SAndy Fiddamando	case $OPT in
90*b30d1939SAndy Fiddaman	D)	debug=-D ;;
91*b30d1939SAndy Fiddaman	a)	all=-a ;;
92*b30d1939SAndy Fiddaman	c)	cache=-c ;;
93*b30d1939SAndy Fiddaman	d)	dialect=$OPTARG ;;
94*b30d1939SAndy Fiddaman	f)	force=1 ;;
95*b30d1939SAndy Fiddaman	g)	op=generate ;;
96*b30d1939SAndy Fiddaman	l)	op=list ;;
97*b30d1939SAndy Fiddaman	n)	exec=print show=-n ;;
98*b30d1939SAndy Fiddaman	o)	omit="-o $OPTARG" ;;
99*b30d1939SAndy Fiddaman	r)	op=remove ;;
100*b30d1939SAndy Fiddaman	s)	gen=msggen dir=$dir/share ;;
101*b30d1939SAndy Fiddaman	t)	op=translate ;;
102*b30d1939SAndy Fiddaman	v)	op=verify ;;
103*b30d1939SAndy Fiddaman	*)	usage ;;
104*b30d1939SAndy Fiddaman	esac
105*b30d1939SAndy Fiddamandone
106*b30d1939SAndy Fiddamanshift $OPTIND-1
107*b30d1939SAndy Fiddaman
108*b30d1939SAndy Fiddaman[[ $INSTALLROOT ]] || { print -u2 $"$command: INSTALLROOT not defined"; exit 1; }
109*b30d1939SAndy Fiddaman
110*b30d1939SAndy Fiddamancase $op in
111*b30d1939SAndy Fiddaman
112*b30d1939SAndy Fiddamangenerate)
113*b30d1939SAndy Fiddaman	dir=$dir/lib/locale
114*b30d1939SAndy Fiddaman	[[ -d $dir ]] || { print -u2 $"$command: $dir: not found"; exit 1; }
115*b30d1939SAndy Fiddaman	(( ! $# )) && set -- C $(ls *-*.msg 2>/dev/null | sed 's,.*-\(.*\)\.msg,\1,' | sort -u)
116*b30d1939SAndy Fiddaman	owd=$PWD
117*b30d1939SAndy Fiddaman	for locale
118*b30d1939SAndy Fiddaman	do	case $locale in
119*b30d1939SAndy Fiddaman		C)	set -- $(messages) ;;
120*b30d1939SAndy Fiddaman		*)	set -- *-$locale.msg ;;
121*b30d1939SAndy Fiddaman		esac
122*b30d1939SAndy Fiddaman		if	[[ ! -f $1 ]]
123*b30d1939SAndy Fiddaman		then	print -u2 "$command: $locale: no message files"
124*b30d1939SAndy Fiddaman		else	nwd=$dir/$locale/LC_MESSAGES
125*b30d1939SAndy Fiddaman			[[ -d $nwd ]] || $exec mkdir -p $nwd || exit
126*b30d1939SAndy Fiddaman			[[ -d $nwd ]] && { cd $nwd || exit; }
127*b30d1939SAndy Fiddaman			for file
128*b30d1939SAndy Fiddaman			do	case $file in
129*b30d1939SAndy Fiddaman				/*)	name=${file##*/}
130*b30d1939SAndy Fiddaman					name=${name%*.msg}
131*b30d1939SAndy Fiddaman					;;
132*b30d1939SAndy Fiddaman				*)	name=${file%-$locale.msg}
133*b30d1939SAndy Fiddaman					file=$owd/$file
134*b30d1939SAndy Fiddaman					;;
135*b30d1939SAndy Fiddaman				esac
136*b30d1939SAndy Fiddaman				if	[[ $force || ! $name -nt $file ]]
137*b30d1939SAndy Fiddaman				then	print -u2 $locale $name:
138*b30d1939SAndy Fiddaman					$exec rm -f $name $name.*
139*b30d1939SAndy Fiddaman					$exec $gen $name $file
140*b30d1939SAndy Fiddaman				fi
141*b30d1939SAndy Fiddaman			done
142*b30d1939SAndy Fiddaman			cd $owd
143*b30d1939SAndy Fiddaman		fi
144*b30d1939SAndy Fiddaman	done
145*b30d1939SAndy Fiddaman	;;
146*b30d1939SAndy Fiddaman
147*b30d1939SAndy Fiddamanlist)	messages | sed 's,^.*/\(.*\)\.msg$,\1 &,'
148*b30d1939SAndy Fiddaman	;;
149*b30d1939SAndy Fiddaman
150*b30d1939SAndy Fiddamanremove)	(( !$# )) && set -- *.msg translate.tmp
151*b30d1939SAndy Fiddaman	$exec rm -rf "$@"
152*b30d1939SAndy Fiddaman	;;
153*b30d1939SAndy Fiddaman
154*b30d1939SAndy Fiddamantranslate)
155*b30d1939SAndy Fiddaman	(( !$# )) && set -- $(messages)
156*b30d1939SAndy Fiddaman	translate -lmv $all $cache $debug $omit $show $dialect "$@"
157*b30d1939SAndy Fiddaman	;;
158*b30d1939SAndy Fiddaman
159*b30d1939SAndy Fiddamanverify)	(( ! $# )) && set -- *.msg
160*b30d1939SAndy Fiddaman	for file
161*b30d1939SAndy Fiddaman	do	n=0
162*b30d1939SAndy Fiddaman		while	read -r num txt
163*b30d1939SAndy Fiddaman		do	if	[[ $num == +([0-9]) ]]
164*b30d1939SAndy Fiddaman			then	((n++))
165*b30d1939SAndy Fiddaman				if	[[ $n != $num ]]
166*b30d1939SAndy Fiddaman				then	if	(( n == $num-1 ))
167*b30d1939SAndy Fiddaman					then	print -u2 "$file: [$n] missing"
168*b30d1939SAndy Fiddaman					else	print -u2 "$file: [$n-$(($num-1))] missing"
169*b30d1939SAndy Fiddaman					fi
170*b30d1939SAndy Fiddaman					n=$num
171*b30d1939SAndy Fiddaman				fi
172*b30d1939SAndy Fiddaman			fi
173*b30d1939SAndy Fiddaman		done < $file
174*b30d1939SAndy Fiddaman	done
175*b30d1939SAndy Fiddaman	;;
176*b30d1939SAndy Fiddaman
177*b30d1939SAndy Fiddaman*)	usage
178*b30d1939SAndy Fiddaman	;;
179*b30d1939SAndy Fiddaman
180*b30d1939SAndy Fiddamanesac
181