1#!/bin/sh
2# Create the messages header file from the master source file or a translation.
3# Missing messages are filled in from the master message file and, if
4# requested, character set conversion is performed.
5
6if test -z $2 ; then
7    echo "Error: missing parameters"
8    echo "Usage: $0 <messages file> <character set>"
9    exit 1
10fi
11
12MASTER=help/help_mp-en.h
13TARGET=help_mp.h
14
15TRANSLATION=$1
16CHARSET=$2
17
18missing_messages(){
19curr=""
20
21while read -r line; do
22    if echo "$line" | grep -q '^#define' ; then
23        curr=`printf "%s\n" "$line" | cut -d ' ' -f 2`
24        if grep -q "^#define $curr[	 ]" "$TRANSLATION" ; then
25            curr=""
26        fi
27    elif [ -z "$line" ]; then
28        curr=""
29    fi
30    if [ -n "$curr" ]; then
31        printf "%s\n" "$line"
32    fi
33done
34}
35
36cat <<EOF > "$TARGET"
37/* WARNING! This is a generated file, do NOT edit.
38 * See the help/ subdirectory for the editable files. */
39
40#ifndef MPLAYER_HELP_MP_H
41#define MPLAYER_HELP_MP_H
42
43#include <inttypes.h>
44#include "config.h"
45
46EOF
47
48cat "$TRANSLATION" >> "$TARGET"
49
50cat <<EOF >> "$TARGET"
51
52/* untranslated messages from the English master file */
53
54EOF
55
56if test "$MASTER" != "$TRANSLATION" ; then
57    missing_messages < "$MASTER" >> "$TARGET"
58fi
59
60cat <<EOF >> "$TARGET"
61
62#endif /* MPLAYER_HELP_MP_H */
63EOF
64
65if test $CHARSET != UTF-8 ; then
66    iconv -f UTF-8 -t "$CHARSET" "$TARGET" > "${TARGET}.tmp"
67    mv "${TARGET}.tmp" "$TARGET"
68fi
69